2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013, 2019 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
6 * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
7 * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
8 * Copyright (C) 2007 Oliver Lupton <om@inspircd.org>
9 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10 * Copyright (C) 2006 Craig Edwards <brain@inspircd.org>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 /** The DLLManager class is able to load a module file by filename,
29 * and locate its init_module symbol.
31 class CoreExport DLLManager : public classbase
34 /** The last error string. */
37 /** The module library handle. */
44 /** The filename of the module library. */
45 const std::string libname;
47 /** Sets the last error string. */
48 void RetrieveLastError();
51 /** Attempts to load the specified module.
52 * @param name The name of the library to load.
54 DLLManager(const std::string& name);
56 /** Unloads the module if one was loaded. */
59 /** Attempts to create a new module instance from this shared library.
60 * @return Either a new instance of the Module class or NULL on error.
64 /** Retrieves the value of the specified symbol.
65 * @param name The name of the symbol to retrieve.
66 * @return Either the value of the specified symbol or or NULL if it does not exist.
68 void* GetSymbol(const char* name) const;
70 /** Retrieves the value of the specified symbol and casts it to the requested type.
71 * @param name The name of the symbol to retrieve.
72 * @return Either the value of the specified symbol or or NULL if it does not exist.
74 template <typename TReturn>
75 TReturn* GetSymbol(const char* name) const
77 return static_cast<TReturn*>(GetSymbol(name));
80 /** Retrieves the module version from the dynamic library. */
81 const char* GetVersion() const { return GetSymbol<const char>(MODULE_STR_VERSION); }
83 /** Retrieves the last error which occurred or an empty string if no errors have occurred. */
84 const std::string& LastError() const { return err; }
86 /** Retrieves the filename of the underlying shared library. */
87 const std::string& LibraryName() const { return libname; }