]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/dynamic.cpp
Changed to use __single_client_alloc, faster on most systems in a single thread
[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 using namespace std;
18
19 #include "globals.h"
20 #include <dlfcn.h>
21 #include "dynamic.h"
22 #include "inspstring.h"
23 #include "helperfuncs.h"
24
25 DLLManager::DLLManager(const char *fname)
26 {
27     // Try to open the library now and get any error message.
28         
29         h=dlopen( fname, RTLD_NOW );
30         err=dlerror();
31 }
32
33 DLLManager::~DLLManager()
34 {
35         // close the library if it isn't null
36         if (h!=0)
37         dlclose(h);
38 }
39
40
41 bool DLLManager::GetSymbol(void **v, const char *sym_name)
42 {
43         // try extract a symbol from the library
44         // get any error message is there is any
45         
46         if( h!=0 )
47         {
48                 *v = dlsym( h, sym_name );
49         err=dlerror();
50             if( err==0 )
51           return true;
52         else
53           return false;
54         }
55         else
56         {       
57         return false;
58         }
59         
60 }
61
62
63 DLLFactoryBase::DLLFactoryBase(const char *fname, const char *factory) : DLLManager(fname)
64 {
65         // try get the factory function if there is no error yet
66         
67         factory_func=0;
68         
69         if( LastError()==0 )
70         {               
71         GetSymbol( (void **)&factory_func, factory ? factory : "init_module" );
72         }
73         
74 }
75
76
77 DLLFactoryBase::~DLLFactoryBase()
78 {
79 }
80
81
82