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.
30 class CoreExport DLLManager
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();
41 /** Get a symbol using dynamic linking.
42 * @param v A function pointer, pointing at an init_module function
43 * @param sym_name The symbol name to find, usually "init_module"
44 * @return true if the symbol can be found, also the symbol will be put into v.
46 bool GetSymbol(void **v, const char *sym_name);
48 /** Get the last error from dlopen() or dlsym().
49 * @return The last error string, or NULL if no error has occured.
56 /** The module handle.
57 * This is OS dependent, on POSIX platforms it is a pointer to a function
58 * pointer (yes, really!) and on windows it is a library handle.
64 /** The last error string, or NULL
69 /** This class is a specialized form of DLLManager designed to load InspIRCd modules.
70 * It's job is to call the init_module function and receive a factory pointer.
72 class CoreExport DLLFactoryBase : public DLLManager
75 /** Default constructor.
76 * This constructor loads a module file by calling its DLLManager subclass constructor,
77 * then finds the symbol using DLLManager::GetSymbol(), and calls the symbol,
78 * obtaining a valid pointer to the init_module function
80 DLLFactoryBase(InspIRCd* Instance, const char *fname, const char *func_name = 0);
82 /** Default destructor.
84 virtual ~DLLFactoryBase();
86 /** A function pointer to the factory function.
88 void * (*factory_func)(void);
91 /** This is the highest-level class of the DLLFactory system used to load InspIRCd modules.
92 * Its job is to finally call the init_module function and obtain a pointer to a ModuleFactory.
93 * This template is a container for ModuleFactory itself, so that it may 'plug' into ModuleFactory
94 * and provide module loading capabilities transparently.
96 template <class T> class CoreExport DLLFactory : public DLLFactoryBase
99 /** Default constructor.
100 * This constructor passes its paramerers down through DLLFactoryBase and then DLLManager
101 * to load the module, then calls the factory function to retrieve a pointer to a ModuleFactory
102 * class. It is then down to the core to call the ModuleFactory::CreateModule() method and
103 * receive a Module* which it can insert into its module lists.
105 DLLFactory(InspIRCd* Instance, const char *fname, const char *func_name=0) : DLLFactoryBase(Instance, fname, func_name)
108 factory = reinterpret_cast<T*>(factory_func());
110 factory = reinterpret_cast<T*>(-1);
113 /** The destructor deletes the ModuleFactory pointer.
121 /** The ModuleFactory pointer.