]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/dynamic.h
a8b7392bf73e547e65b3fe1afa0b12d16d24662c
[user/henk/code/inspircd.git] / include / dynamic.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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
18 #ifndef __DLL_H
19 #define __DLL_H
20
21 typedef void * (initfunc) (void);
22
23 #include "inspircd_config.h"
24
25 extern void do_log(int, const char*, ...);
26
27 class DLLManager
28 {
29  public:
30         DLLManager(const char *fname);
31         virtual ~DLLManager();
32
33
34 #ifdef STATIC_LINK
35         bool GetSymbol( initfunc* &v, const char *sym_name );
36 #else
37         bool GetSymbol( void **, const char *sym_name );
38 #endif
39
40         char* LastError() 
41         {
42                  return err;
43         }
44         
45  protected:
46         void *h;
47         char *err;
48 #ifdef STATIC_LINK
49         char staticname[1024];
50 #endif
51 };
52
53
54 class DLLFactoryBase : public DLLManager
55 {
56  public:
57         DLLFactoryBase(const char *fname, const char *func_name = 0);
58         virtual ~DLLFactoryBase();
59 #ifdef STATIC_LINK
60         initfunc *factory_func;
61 #else
62         void * (*factory_func)(void);   
63 #endif
64 };
65
66 template <class T> class DLLFactory : public DLLFactoryBase
67 {
68  public:
69         DLLFactory(const char *fname, const char *func_name=0) : DLLFactoryBase(fname,func_name)
70         {
71                 if (factory_func)
72                         factory = reinterpret_cast<T*>(factory_func());
73                 else
74                         factory = reinterpret_cast<T*>(-1);
75         }
76         
77         ~DLLFactory()
78         {
79                 if (factory)
80                         delete factory;
81         }
82
83         T *factory;
84 };
85
86 #endif