]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/dynamic.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / dynamic.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2019-2020 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>
11  *
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.
15  *
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
19  * details.
20  *
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/>.
23  */
24
25
26 #pragma once
27
28 /** The DLLManager class is able to load a module file by filename,
29  * and locate its init_module symbol.
30  */
31 class CoreExport DLLManager : public classbase
32 {
33  private:
34         /** The last error string. */
35         std::string err;
36
37         /** The module library handle. */
38 #ifdef _WIN32
39         HMODULE lib;
40 #else
41         void* lib;
42 #endif
43
44         /** The filename of the module library. */
45         const std::string libname;
46
47         /** Sets the last error string. */
48         void RetrieveLastError();
49
50  public:
51         /** Attempts to load the specified module.
52          * @param name The name of the library to load.
53          */
54         DLLManager(const std::string& name);
55
56         /** Unloads the module if one was loaded. */
57         ~DLLManager();
58
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.
61          */
62         Module* CallInit();
63
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.
67          */
68         void* GetSymbol(const char* name) const;
69
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.
73          */
74         template <typename TReturn>
75         TReturn* GetSymbol(const char* name) const
76         {
77                 return static_cast<TReturn*>(GetSymbol(name));
78         }
79
80         /** Retrieves the module version from the dynamic library. */
81         const char* GetVersion() const { return GetSymbol<const char>(MODULE_STR_VERSION); }
82
83         /** Retrieves the last error which occurred or an empty string if no errors have occurred. */
84         const std::string& LastError() const { return err; }
85
86         /** Retrieves the filename of the underlying shared library. */
87         const std::string& LibraryName() const { return libname; }
88 };