1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
21 /** This typedef represents the init_module function within each module.
22 * The init_module function is the only exported extern "C" declaration
25 typedef void * (initfunc) (void);
27 #include "inspircd_config.h"
31 /** The DLLManager class is able to load a module file by filename,
32 * and locate its init_module symbol.
37 /** This constructor loads the module using dlopen()
38 * @param ServerInstance The creator class of this object
39 * @param fname The filename to load. This should be within
42 DLLManager(InspIRCd* ServerInstance, const char *fname);
43 virtual ~DLLManager();
47 /** Get a symbol using static linking.
48 * @param v A static function pointer, pointing at an init_module function
49 * @param sym_name The symbol name to find, usually "init_module"
50 * @return True if the symbol can be found
52 bool GetSymbol(initfunc* &v, const char *sym_name);
54 /** Get a symbol using dynamic linking.
55 * @param v A function pointer, pointing at an init_module function
56 * @param sym_name The symbol name to find, usually "init_module"
57 * @return true if the symbol can be found, also the symbol will be put into v.
59 bool GetSymbol(void **v, const char *sym_name);
61 /** Get the last error from dlopen() or dlsym().
62 * @return The last error string, or NULL if no error has occured
75 /** The last error string, or NULL
82 char staticname[1024];
86 /** This class is a specialized form of DLLManager designed to load InspIRCd modules.
87 * It's job is to call the init_module function and receive a factory pointer.
89 class DLLFactoryBase : public DLLManager
92 /** Default constructor.
93 * This constructor loads a module file by calling its DLLManager subclass constructor,
94 * then finds the symbol using DLLManager::GetSymbol(), and calls the symbol,
95 * obtaining a valid pointer to the init_module function
97 DLLFactoryBase(InspIRCd* Instance, const char *fname, const char *func_name = 0);
99 /** Default destructor
101 virtual ~DLLFactoryBase();
103 /** A function pointer to the factory function
105 initfunc *factory_func;
107 /** A function pointer to the factory function
109 void * (*factory_func)(void);
113 /** This is the highest-level class of the DLLFactory system used to load InspIRCd modules.
114 * Its job is to finally call the init_module function and obtain a pointer to a ModuleFactory.
115 * This template is a container for ModuleFactory itself, so that it may 'plug' into ModuleFactory
116 * and provide module loading capabilities transparently.
118 template <class T> class DLLFactory : public DLLFactoryBase
121 /** Default constructor.
122 * This constructor passes its paramerers down through DLLFactoryBase and then DLLManager
123 * to load the module, then calls the factory function to retrieve a pointer to a ModuleFactory
124 * class. It is then down to the core to call the ModuleFactory::CreateModule() method and
125 * receive a Module* which it can insert into its module lists.
127 DLLFactory(InspIRCd* Instance, const char *fname, const char *func_name=0) : DLLFactoryBase(Instance, fname, func_name)
130 factory = reinterpret_cast<T*>(factory_func());
132 factory = reinterpret_cast<T*>(-1);
135 /** The destructor deletes the ModuleFactory pointer.
143 /** The ModuleFactory pointer.