[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

SourceForge.net Logo

osi-open source certified logo

Splash - Documentation

SNMP Plus a Lightweight API for SNAP Handling

Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

snap-1.1-wjdb/lib/snap_svc_reg_handler.c

Go to the documentation of this file.
00001 /*
00002     snap service handler
00003     registration handler source file
00004     (c) 2003 Willem de Bruijn
00005     all code falls under the BSD License
00006 */
00007 
00008 #include "d_printf.h"
00009 #include "snap_svc_library_handler.h"
00010 #include "snap_svc_reg_table.h"
00011 #include "snap_svc_reg_handler.h"
00012 
00013 int snap_svc_register_initialized=0;
00014 tDllList hDllList = NULL;
00015 snap_svc_getlastresult pReturnLast;
00016 snap_svc_free_local_returnstruct pReturnFree;
00017 
00018 void snap_svc_register_init(){
00019     hDllList = NULL;
00020     snap_svc_register_initialized = 1;
00021 }
00022 
00023 void snap_svc_register_fini(){
00024     if (!snap_svc_register_initialized)
00025         d_printf(50,"snap_svc : trying to close possibly unopened registration data\n");
00026     else
00027         if(hDllList)
00028             snap_svc_unregisterall();
00029             
00030     snap_svc_register_initialized = 0;
00031 }
00032 
00033 void* snap_svc_register_returnlaststruct(){
00034     return pReturnLast();
00035 }
00036 
00037 void* snap_svc_register_freelaststruct(){
00038     return pReturnFree();
00039 }
00040 
00041 int snap_svc_registerlib(void* hDll){
00042     snap_svc_init pInit;
00043     snap_svc_register pReg;
00044     snapsvc_func_proto pDllFunc;
00045     int dDllArgs, dDllRets;
00046     char* strDllFuncName;
00047     
00048     if (!hDll || (int) hDll == -1)
00049         d_printf(10,"snap_svc : error : registerlib called with NULL pointeror end condition occurred\n");
00050     d_printf(100,"snap_svc : trying to bind the initialization function... \n");
00051     if (snap_svc_bind(hDll,"init", (void**) &pInit))
00052         return -1;
00053     
00054     pInit();
00055     if (snap_svc_bind(hDll,"snap_external_svclib_getnextfunc", (void**) &pReg))
00056         return -1;
00057     if (snap_svc_bind(hDll,"snap_external_svclib_getlastresult", (void**) &pReturnLast))
00058         return -1;
00059     if (snap_svc_bind(hDll,"snap_external_svclib_free_local_returnstruct", (void**) &pReturnFree))
00060         return -1;
00061     
00062     do {
00063         pReg(&strDllFuncName, &pDllFunc, &dDllArgs, &dDllRets);
00064         if (strDllFuncName){
00065             d_printf(100,"snap_svc : registered a function : (#rets = %d) %s (#args = %d)\n",dDllRets,strDllFuncName,dDllArgs);
00066             snap_svc_table_add(strDllFuncName, pDllFunc, dDllArgs, dDllRets);
00067         }
00068     } while (strDllFuncName != NULL);
00069     d_printf(100,"snap_svc : all routines registered succesfully\n");
00070     
00071     return 0;
00072 }
00073 
00074 int snap_svc_unregisterlib(void* hDll){
00075     snap_svc_init pFini;
00076     
00077     d_printf(100,"snap_svc : trying to bind the release function \n");
00078     if (snap_svc_bind(hDll,"fini", (void**) &pFini))
00079         return -1;
00080     
00081     pFini();
00082     
00083     snap_svc_close(&hDll); 
00084     
00085     return 0;
00086 }
00087 
00088 int snap_svc_registeralllibs(char* strDirectory){
00089     int dSuccessCount, dCurEntry=0;
00090     
00091     if (!strDirectory)
00092         return -1;
00093         
00094     if (hDllList)
00095         d_printf(50,"snap_svc : warning : possibly overwriting previous librarylist\n");
00096         
00097     d_printf(100,"snap_svc : trying to open all libraries that start with libsnap_svc in %s\n", strDirectory);
00098     dSuccessCount = snap_svc_openmultiple(&hDllList, strDirectory, snap_svc_openmultiple_selector_snapsvc);
00099     if (dSuccessCount == -1)
00100         return -1;
00101     while (hDllList[dCurEntry] && (int) hDllList[dCurEntry] != -1){
00102         snap_svc_registerlib(hDllList[dCurEntry]);
00103         dCurEntry++;
00104     }
00105     d_printf(100,"snap_svc : opened %d files\n",dSuccessCount);
00106     
00107     return dSuccessCount;
00108 }
00109 
00110 int snap_svc_unregisteralllibs(){
00111     int dErrorCount=0, dCurEntry=0;
00112     
00113     if (!hDllList)
00114         return -1;
00115     d_printf(100,"snap_svc : trying to close libraries\n");
00116     while (hDllList[dCurEntry]){
00117         snap_svc_unregisterlib(hDllList[dCurEntry]);
00118         dCurEntry++;
00119     }
00120     dErrorCount += snap_svc_closemultiple(&hDllList);
00121     d_printf(100,"snap_svc : closed %d files\n",dCurEntry-1);
00122 
00123     return dErrorCount;
00124 }
00125 
00126 /* EASY ACCESS FUNCTIONS (register, unregister, reregister) */
00127 void snap_svc_registerall(){
00128     if (!snap_svc_registeralllibs("/usr/local/lib")){
00129         if(!snap_svc_registeralllibs("/usr/lib")){
00130             if(!snap_svc_registeralllibs("/lib")){
00131                 d_printf(50,"snap_svc : no suitable libraries found\n");
00132             }
00133         }
00134     }
00135 }
00136 
00137 void snap_svc_unregisterall(){
00138     snap_svc_unregisteralllibs();
00139 }
00140 
00141 void snap_svc_reregisterall(){
00142     snap_svc_unregisterall();
00143     snap_svc_registerall();
00144 }