1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 /** This typedef represents the init_module function within each module.
18 * The init_module function is the only exported extern "C" declaration
21 typedef void * (initfunc) (void);
23 #include "inspircd_config.h"
27 /** The DLLManager class is able to load a module file by filename,
28 * and locate its init_module symbol.
33 /** This constructor loads the module using dlopen()
34 * @param ServerInstance The creator class of this object
35 * @param fname The filename to load. This should be within
38 DLLManager(InspIRCd* ServerInstance, const char *fname);
39 virtual ~DLLManager();
43 /** Get a symbol using static linking.
44 * @param v A static function pointer, pointing at an init_module function
45 * @param sym_name The symbol name to find, usually "init_module"
46 * @return True if the symbol can be found
48 bool GetSymbol(initfunc* &v, const char *sym_name);
50 /** Get a symbol using dynamic linking.
51 * @param v A function pointer, pointing at an init_module function
52 * @param sym_name The symbol name to find, usually "init_module"
53 * @return true if the symbol can be found, also the symbol will be put into v.
55 bool GetSymbol(void **v, const char *sym_name);
57 /** Get the last error from dlopen() or dlsym().
58 * @return The last error string, or NULL if no error has occured
71 /** The last error string, or NULL
78 char staticname[1024];
82 /** This class is a specialized form of DLLManager designed to load InspIRCd modules.
83 * It's job is to call the init_module function and receive a factory pointer.
85 class DLLFactoryBase : public DLLManager
88 /** Default constructor.
89 * This constructor loads a module file by calling its DLLManager subclass constructor,
90 * then finds the symbol using DLLManager::GetSymbol(), and calls the symbol,
91 * obtaining a valid pointer to the init_module function
93 DLLFactoryBase(InspIRCd* Instance, const char *fname, const char *func_name = 0);
95 /** Default destructor
97 virtual ~DLLFactoryBase();
99 /** A function pointer to the factory function
101 initfunc *factory_func;
103 /** A function pointer to the factory function
105 void * (*factory_func)(void);
109 /** This is the highest-level class of the DLLFactory system used to load InspIRCd modules.
110 * Its job is to finally call the init_module function and obtain a pointer to a ModuleFactory.
111 * This template is a container for ModuleFactory itself, so that it may 'plug' into ModuleFactory
112 * and provide module loading capabilities transparently.
114 template <class T> class DLLFactory : public DLLFactoryBase
117 /** Default constructor.
118 * This constructor passes its paramerers down through DLLFactoryBase and then DLLManager
119 * to load the module, then calls the factory function to retrieve a pointer to a ModuleFactory
120 * class. It is then down to the core to call the ModuleFactory::CreateModule() method and
121 * receive a Module* which it can insert into its module lists.
123 DLLFactory(InspIRCd* Instance, const char *fname, const char *func_name=0) : DLLFactoryBase(Instance, fname, func_name)
126 factory = reinterpret_cast<T*>(factory_func());
128 factory = reinterpret_cast<T*>(-1);
131 /** The destructor deletes the ModuleFactory pointer.
139 /** The ModuleFactory pointer.