Loading...
Searching...
No Matches
PluginManager.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// PluginManager.h
6//
7
8#ifndef MALENA_PLUGINHOST_H
9#define MALENA_PLUGINHOST_H
10
16
17#ifdef _WIN32
18 #include <windows.h>
19 #define LIB_HANDLE HMODULE
20 #define LOAD_LIB(path) LoadLibraryA(path)
21 #define GET_FUNC(handle,name) GetProcAddress(handle, name)
22 #define CLOSE_LIB(handle) FreeLibrary(static_cast<HMODULE>(handle))
23#else
24 #include <dlfcn.h>
25 #define LIB_HANDLE void*
26 #define LOAD_LIB(path) dlopen(path, RTLD_NOW | RTLD_GLOBAL)
27 #define GET_FUNC(handle,name) dlsym(handle, name)
28 #define CLOSE_LIB(handle) dlclose(handle)
29#endif
30
31namespace fs = std::filesystem;
32
33namespace ml
34{
83 {
84 struct PluginData
85 {
86 Plugin* plugin;
87 LIB_HANDLE handle;
88 };
89
90 std::vector<PluginData> _plugins;
91
92 std::vector<std::string> getPluginFiles(const std::string& directory);
93 std::vector<std::string> getFilesInDirectory(const std::string& directory,
94 const std::string& extension = "");
95
96 public:
103 PluginManager(const std::string& pluginPath = "");
104
117 Plugin* loadPlugin(const std::string& path);
118
127 void loadPluginsFromDirectory(const std::string& dir);
128
138 std::vector<Plugin*> getPlugins();
139
157 void unloadPlugin(Plugin* plugin);
158
170 std::vector<PluginInfo> scanPlugins(const std::string& dir);
171
172 private:
181 void doUnloadPlugin(Plugin* plugin);
182 };
183
184} // namespace ml
185
186#endif // MALENA_PLUGINHOST_H
#define LIB_HANDLE
CRTP base that gives a manager safe deferred-operation support.
Abstract base class for all Malena plugins.
Definition Plugin.h:81
void unloadPlugin(Plugin *plugin)
Unload a plugin and close its shared library.
Plugin * loadPlugin(const std::string &path)
Load a single plugin from a shared library path.
void loadPluginsFromDirectory(const std::string &dir)
Load all plugin libraries found in a directory.
std::vector< Plugin * > getPlugins()
Return all currently loaded plugins.
PluginManager(const std::string &pluginPath="")
Construct a PluginManager with a default plugin search path.
std::vector< PluginInfo > scanPlugins(const std::string &dir)
Probe a directory for plugins without keeping them loaded.
#define MALENA_API
Definition Component.h:22