PeriDyno 1.0.0
Loading...
Searching...
No Matches
PluginManager.h
Go to the documentation of this file.
1#pragma once
2#include <cassert>
3#include <map>
4#include <memory>
5#include <string>
6#include <atomic>
7#include <mutex>
8
9#include "PluginEntry.h"
10
11// Unix
12#if defined(_WIN32)
13 #include <windows.h>
14#elif defined(__unix__)
15 // APIs: dlopen, dlclose, dlopen
16 #include <dlfcn.h>
17#else
18 #error "Not supported operating system"
19#endif
20
21namespace dyno
22{
24 class Plugin
25 {
26 public:
27 Plugin() {}
28
29 ~Plugin();
30
31 Plugin(Plugin const&) = delete;
32 Plugin& operator=(const Plugin&) = delete;
33
34 Plugin(Plugin&& rhs);
35
36 Plugin& operator=(Plugin&& rhs);
37
38 PluginEntry* getInfo() const;
39
40 bool isLoaded() const;
41
42 void unload();
43
44 static std::shared_ptr<Plugin> load(std::string file);
45
46 private:
48 using PluginEntryFunc = PluginEntry * (*) ();
49
51 static constexpr const char* PluginEntryName = "initDynoPlugin";
52
54 void* mHnd = nullptr;
55
57 std::string mFile = "";
58
60 bool mIsLoaded = false;
61
64 };
65
71 {
72 public:
73 static PluginManager* instance();
74
75 std::string getExtension() const;
76
77 bool loadPlugin(const std::string& pluginName);
78
79 void loadPluginByPath(const std::string& pathName);
80
81 std::shared_ptr<Plugin> getPlugin(const char* pluginName);
82
83 private:
85
86 using PluginMap = std::map<std::string, std::shared_ptr<Plugin>>;
87
88 static std::atomic<PluginManager*> pInstance;
89 static std::mutex mMutex;
90
92 };
93}
static std::shared_ptr< Plugin > load(std::string file)
bool isLoaded() const
std::string mFile
Shared library file name.
bool mIsLoaded
Flag to indicate whether plugin (shared library) is loaded into current process.
PluginEntry * mEntryPoint
Pointer to shared library factory class returned by the DLL entry-point function.
Plugin(Plugin const &)=delete
PluginEntry * getInfo() const
Plugin & operator=(const Plugin &)=delete
PluginEntry *(*)() PluginEntryFunc
Function pointer to DLL entry-point.
static constexpr const char * PluginEntryName
Name of DLL entry point that a Plugin should export.
void * mHnd
Shared library handle.
std::map< std::string, std::shared_ptr< Plugin > > PluginMap
static PluginManager * instance()
bool loadPlugin(const std::string &pluginName)
void loadPluginByPath(const std::string &pathName)
std::shared_ptr< Plugin > getPlugin(const char *pluginName)
static std::atomic< PluginManager * > pInstance
static std::mutex mMutex
std::string getExtension() const
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Definition PluginEntry.h:14