]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Moved a ton of functions into helperfuncs.h to speed up recompiles
[user/henk/code/inspircd.git] / src / dynamic.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "globals.h"
18 #include <dlfcn.h>
19 #include "dynamic.h"
20 #include "inspstring.h"
21 #include "helperfuncs.h"
22
23 DLLManager::DLLManager(const char *fname)
24 {
25     // Try to open the library now and get any error message.
26         
27         h=dlopen( fname, RTLD_NOW );
28         err=dlerror();
29 }
30
31 DLLManager::~DLLManager()
32 {
33         // close the library if it isn't null
34         if (h!=0)
35         dlclose(h);
36 }
37
38
39 bool DLLManager::GetSymbol(void **v, const char *sym_name)
40 {
41         // try extract a symbol from the library
42         // get any error message is there is any
43         
44         if( h!=0 )
45         {
46                 *v = dlsym( h, sym_name );
47         err=dlerror();
48             if( err==0 )
49           return true;
50         else
51           return false;
52         }
53         else
54         {       
55         return false;
56         }
57         
58 }
59
60
61 DLLFactoryBase::DLLFactoryBase(const char *fname, const char *factory) : DLLManager(fname)
62 {
63         // try get the factory function if there is no error yet
64         
65         factory_func=0;
66         
67         if( LastError()==0 )
68         {               
69         GetSymbol( (void **)&factory_func, factory ? factory : "init_module" );
70         }
71         
72 }
73
74
75 DLLFactoryBase::~DLLFactoryBase()
76 {
77 }
78
79
80