[insert project logo here (125x200px max)] Navigator Mailinglists Please report any errors or ommissions you find to our `Help' mailinglist, or post a message in the Forums. Copyright and Licensing Information Snap is (c) Jonathan T. Moore, 1999-2002 and licensed under the GNU General Public License (GPL). All other parts of Splash are (c) Willem de Bruijn, 2002-2003 and licensed under the BSD Open Source License. All sourcecode is made publicly available. Acknowledgement Splash and the Splash website are hosted by SourceForge.net |
Splash - DocumentationSNMP Plus a Lightweight API for SNAP Handlingsnap_svc/snap_svc_test.cGo to the documentation of this file.00001 /* snap service library */ 00002 /* (c) Willem de Bruijn, 2002, 2003 */ 00003 /* Licensed under the BSD License */ 00004 /* snap_svc_test library sourcefile */ 00005 00006 #include <string.h> 00007 00008 #include "d_printf.h" 00009 #include "snap_svc.h" 00010 #include "snap_svc_test.h" 00011 00012 /* 00013 HOWTO create a new library 00014 00015 this file can guide as an example on how to implement your libraries 00016 00017 (1) BUILDING and COMPILING 00018 00019 you can copy the snap_svc_TEMPLATE.h and snap_svc_TEMPLATE.c files 00020 and edit those. 00021 Just rename all instances of TEMPLATE and add your code 00022 00023 each library must include snap_svc.h and link to snap_svc.o 00024 each library should at least contain the following functions: 00025 00026 void snap_external_svclib_init(); 00027 void snap_external_svclib_done(); 00028 void snap_external_svclib_getnextfunc(char**, snapsvc_func_proto*, int*, int*); 00029 00030 please view the examples below to understand how you should implement thense 00031 00032 any other functions can be created as you please... 00033 ... there is only one restriction: 00034 00035 Although your functions need not use any arguments it is IMPERATIVE that 00036 you add a single useless argument to empty argument lists, i.e. you are not 00037 allowed to create functions that take no arguments. This follows from the 00038 typedef we use to pass functions declared in snap_svc.h 00039 00040 (2) MAKE and MAKE INSTALL 00041 adding your library to the base package is fairly simple. 00042 in Makefile.am : add a new entry to 00043 00044 lib_LTLIBRARIES = [previous entries ...] libsnap_svc_[yourlibname].la 00045 00046 and add two new lines : 00047 00048 libsnap_svc_[yourlibname]_la_SOURCES = [your source and header files ] 00049 libsnap_svc_[yourlibname]_la_LDFLAGS = -version-info 1:0:0 [your library includes] 00050 00051 and optionally add header files that should be installed to 00052 00053 include_HEADERS = [previous entries ...] [your entries ...] 00054 00055 when finished alteringn this file 00056 run : aclocal && autoconf && autoheader && automake -a --foreign 00057 00058 ofcourse, these tools must be installed on your system to work. 00059 then do a : make && make uninstall && make install 00060 00061 and finally run: ldconfig 00062 00063 DONE! 00064 00065 good luck, 00066 Willem 00067 */ 00068 00069 /* library handling functions */ 00070 void snap_external_svclib_init(){ 00071 d_printf(50,"snap_svc_test : initialized\n"); 00072 } 00073 00074 void snap_external_svclib_done(){ 00075 d_printf(50,"snap_svc_test : closed\n"); 00076 } 00077 00078 /* there is where functions inside the library should be listed for registration */ 00079 void snap_external_svclib_getnextfunc(char** snapsvc_name, snapsvc_func_proto* snapsvc_func, int* snapsvc_args, int* snapsvc_rets){ 00080 00081 switch (svc_fun_counter){ 00082 case 0 : (*snapsvc_name) = strdup ("testsimple"); 00083 (*snapsvc_func) = (snapsvc_func_proto) &snap_external_svclib_testfunc; 00084 (*snapsvc_args) = 0; 00085 (*snapsvc_rets) = SVC_SNMP_TYPE_NULL; 00086 break; 00087 case 1 : (*snapsvc_name) = strdup ("testint"); 00088 (*snapsvc_func) = (snapsvc_func_proto) &snap_external_svclib_testintfunc; 00089 (*snapsvc_args) = 1; 00090 (*snapsvc_rets) = SVC_SNMP_TYPE_NULL; 00091 break; 00092 case 2 : (*snapsvc_name) = strdup ("teststr"); 00093 (*snapsvc_func) = (snapsvc_func_proto) &snap_external_svclib_teststrfunc; 00094 (*snapsvc_args) = 1; 00095 (*snapsvc_rets) = SVC_SNMP_TYPE_NULL; 00096 break; 00097 /* unknown handler -> return NULL as end-of-list symbol */ 00098 default : (*snapsvc_name) = NULL; 00099 (*snapsvc_func) = NULL; 00100 (*snapsvc_args) = 0; 00101 (*snapsvc_rets) = 0; 00102 } 00103 svc_fun_counter ++; 00104 } 00105 00106 /* ADD SERVICES BELOW */ 00107 /* declarations of snap service handlers */ 00108 00109 /* test function : print a message to stderr */ 00110 int snap_external_svclib_testfunc(void* useless){ 00111 fprintf (stderr,"snap_svc_snmp : succesfully called the testfunction\n"); 00112 00113 return 0; 00114 } 00115 00116 /* test function : print a message containing an int */ 00117 int snap_external_svclib_testintfunc(int useless){ 00118 if (useless) 00119 fprintf (stderr,"snap_svc_snmp : succesfully called the test INT function with argument %d\n", useless); 00120 else 00121 fprintf (stderr,"snap_svc_snmp : succesfully called the test INT function with argument NULL\n"); 00122 00123 return 0; 00124 } 00125 00126 /* test function : print a message containing a string */ 00127 int snap_external_svclib_teststrfunc(char* useless){ 00128 if (useless) 00129 fprintf (stderr,"snap_svc_snmp : succesfully called the test STR function with argument %s\n",useless); 00130 else 00131 fprintf (stderr,"snap_svc_snmp : succesfully called the test STR function with argument NULL\n"); 00132 00133 return 0; 00134 } 00135 |