]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/dynamic.h
Relocate timer stuff into TimerManager class
[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 class DLLManager
26 {
27  public:
28         DLLManager(const char *fname);
29         virtual ~DLLManager();
30
31
32 #ifdef STATIC_LINK
33         bool GetSymbol( initfunc* &v, const char *sym_name );
34 #else
35         bool GetSymbol( void **, const char *sym_name );
36 #endif
37
38         char* LastError() 
39         {
40                  return err;
41         }
42         
43  protected:
44         void *h;
45         char *err;
46 #ifdef STATIC_LINK
47         char staticname[1024];
48 #endif
49 };
50
51
52 class DLLFactoryBase : public DLLManager
53 {
54  public:
55         DLLFactoryBase(const char *fname, const char *func_name = 0);
56         virtual ~DLLFactoryBase();
57 #ifdef STATIC_LINK
58         initfunc *factory_func;
59 #else
60         void * (*factory_func)(void);   
61 #endif
62 };
63
64 template <class T> class DLLFactory : public DLLFactoryBase
65 {
66  public:
67         DLLFactory(const char *fname, const char *func_name=0) : DLLFactoryBase(fname,func_name)
68         {
69                 if (factory_func)
70                         factory = reinterpret_cast<T*>(factory_func());
71                 else
72                         factory = reinterpret_cast<T*>(-1);
73         }
74         
75         ~DLLFactory()
76         {
77                 if (factory)
78                         delete factory;
79         }
80
81         T *factory;
82 };
83
84 #endif