The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

dynamic.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef __DLL_H
00015 #define __DLL_H
00016 
00021 typedef void * (initfunc) (void);
00022 
00023 #include "inspircd_config.h"
00024 
00025 class InspIRCd;
00026 
00030 class CoreExport DLLManager
00031 {
00032  public:
00038         DLLManager(InspIRCd* ServerInstance, const char *fname);
00039         virtual ~DLLManager();
00040 
00046         bool GetSymbol(void **v, const char *sym_name);
00047 
00051         char* LastError() 
00052         {
00053                  return err;
00054         }
00055 
00060         void *h;
00061 
00062  protected:
00063 
00066         char *err;
00067 };
00068 
00072 class CoreExport DLLFactoryBase : public DLLManager
00073 {
00074  public:
00080         DLLFactoryBase(InspIRCd* Instance, const char *fname, const char *func_name = 0);
00081 
00084         virtual ~DLLFactoryBase();
00085 
00088         void * (*factory_func)(void);   
00089 };
00090 
00096 template <class T> class CoreExport DLLFactory : public DLLFactoryBase
00097 {
00098  public:
00105         DLLFactory(InspIRCd* Instance, const char *fname, const char *func_name=0) : DLLFactoryBase(Instance, fname, func_name)
00106         {
00107                 if (factory_func)
00108                         factory = reinterpret_cast<T*>(factory_func());
00109                 else
00110                         factory = reinterpret_cast<T*>(-1);
00111         }
00112         
00115         ~DLLFactory()
00116         {
00117                 if (factory)
00118                         delete factory;
00119         }
00120 
00123         T *factory;
00124 };
00125 
00126 #endif
00127