]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
...
[user/henk/code/inspircd.git] / src / dynamic.cpp
1 #include "globals.h"
2 #include <dlfcn.h>
3 #include "dynamic.h"
4
5
6
7 DLLManager::DLLManager( const char *fname )
8 {
9     // Try to open the library now and get any error message.
10         
11         h=dlopen( fname, RTLD_NOW );
12         err=dlerror();
13 }
14
15 DLLManager::~DLLManager()
16 {
17         // close the library if it isn't null
18         if( h!=0 )
19         dlclose(h);
20 }
21
22
23 bool DLLManager::GetSymbol( 
24                            void **v,
25                            const char *sym_name
26                            )
27 {
28         // try extract a symbol from the library
29         // get any error message is there is any
30         
31         if( h!=0 )
32         {
33                 *v = dlsym( h, sym_name );
34         err=dlerror();
35             if( err==0 )
36           return true;
37         else
38           return false;
39         }
40         else
41         {       
42         return false;
43         }
44         
45 }
46
47
48 DLLFactoryBase::DLLFactoryBase(
49                                const char *fname,
50                                const char *factory=0
51                                ) : DLLManager(fname)
52 {
53         // try get the factory function if there is no error yet
54         
55         factory_func=0;
56         
57         if( LastError()==0 )
58         {               
59         GetSymbol( (void **)&factory_func, factory ? factory : "init_module" );
60         }
61         
62 }
63
64
65 DLLFactoryBase::~DLLFactoryBase()
66 {
67 }
68
69
70