InspIRCd  4.0
dynamic.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2013, 2019-2020 Sadie Powell <[email protected]>
5  * Copyright (C) 2012 Robby <[email protected]>
6  * Copyright (C) 2012 ChrisTX <[email protected]>
7  * Copyright (C) 2009-2010 Daniel De Graaf <[email protected]>
8  * Copyright (C) 2007 Oliver Lupton <[email protected]>
9  * Copyright (C) 2007 Dennis Friis <[email protected]>
10  * Copyright (C) 2006 Craig Edwards <[email protected]>
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 
29 #if defined __APPLE__
30 # define DLL_EXTENSION ".dylib"
31 #elif defined _WIN32
32 # define DLL_EXTENSION ".dll"
33 #else
34 # define DLL_EXTENSION ".so"
35 #endif
36 
37 
41 class CoreExport DLLManager : public Cullable
42 {
43  private:
45  std::string err;
46 
48 #ifdef _WIN32
49  HMODULE lib = INVALID_HANDLE_VALUE;
50 #else
51  void* lib = nullptr;
52 #endif
53 
55  const std::string libname;
56 
58  void RetrieveLastError();
59 
60  public:
64  DLLManager(const std::string& name);
65 
67  ~DLLManager();
68 
72  Module* CallInit();
73 
78  void* GetSymbol(const char* name) const;
79 
84  template <typename TReturn>
85  TReturn* GetSymbol(const char* name) const
86  {
87  return static_cast<TReturn*>(GetSymbol(name));
88  }
89 
91  const char* GetVersion() const { return GetSymbol<const char>(MODULE_STR_VERSION); }
92 
94  const std::string& LastError() const { return err; }
95 
97  const std::string& LibraryName() const { return libname; }
98 };
Definition: cull.h:30
Definition: dynamic.h:42
const char * GetVersion() const
Definition: dynamic.h:91
const std::string & LastError() const
Definition: dynamic.h:94
TReturn * GetSymbol(const char *name) const
Definition: dynamic.h:85
const std::string & LibraryName() const
Definition: dynamic.h:97
Definition: modules.h:286