PicoScenes API Docs
 
Loading...
Searching...
No Matches
PicoScenesPluginManager.hxx
Go to the documentation of this file.
1//
2// Created by Zhiping Jiang on 2020/1/8.
3//
4
5#ifndef PICOSCENES_PLATFORM_PICOSCENESPLUGINMANAGER_HXX
6#define PICOSCENES_PLATFORM_PICOSCENESPLUGINMANAGER_HXX
7
8
9#include <utility>
10#include <vector>
11#include "BoostHeaders.hxx"
13#include "AbstractNIC.hxx"
14#include "NICDLLImport.hxx"
15
16namespace fs = std::filesystem;
17
19
21
22class AbstractNIC;
23
30public:
37 PicoScenesPluginWrapper(const std::string &filePath, std::shared_ptr<PicoScenesPluginManager> manager);
38
43 [[nodiscard]] std::shared_ptr<PicoScenesPluginManager> getManager() const {
44 return manager;
45 }
46
51 [[nodiscard]] std::shared_ptr<AbstractPicoScenesPlugin> getPluginCore() const {
52 return pluginCore;
53 }
54
59 [[nodiscard]] const std::string &getLibraryFilePath() const {
60 return libraryFilePath;
61 }
62
63private:
64 std::string libraryFilePath;
65 boost::function<std::shared_ptr<AbstractPicoScenesPlugin>()> libraryHandle;
66 std::shared_ptr<AbstractPicoScenesPlugin> pluginCore;
67 std::shared_ptr<PicoScenesPluginManager> manager;
68};
69
75class PicoScenesPluginManager : public std::enable_shared_from_this<PicoScenesPluginManager> {
76public:
82 static std::shared_ptr<PicoScenesPluginManager> getInstance(const std::shared_ptr<AbstractNIC> &nic);
83
88 static std::vector<std::string> listPluginsInFolder();
89
94 static const std::vector<std::shared_ptr<po::options_description>> &getPluginOptions();
95
101 std::pair<bool, std::string> tryInstallPlugin(const std::string &pluginFilePath);
102
107 void parseAndExecuteCommands(const std::string &commandString);
108
113 void callRxHandles(const ModularPicoScenesRxFrame &rxs);
114
119 const std::vector<std::shared_ptr<PicoScenesPluginWrapper>> &getAllPlugins() const;
120
125 void uninstallPlugin(const std::string &plugInName);
126
131
136
137 NIC_API static std::string pluginDir;
138
139private:
144 explicit PicoScenesPluginManager(std::shared_ptr<AbstractNIC> nic) : nic(std::move(nic)) {}
145
146 std::shared_ptr<AbstractNIC> nic;
147 std::vector<std::shared_ptr<PicoScenesPluginWrapper>> plugins;
148 static std::vector<std::shared_ptr<po::options_description>> pluginOptions;
149
154 static void ensureSinglePluginDescription(const std::shared_ptr<AbstractPicoScenesPlugin> &getPluginCore);
155};
156//
157
158#endif //PICOSCENES_PLATFORM_PICOSCENESPLUGINMANAGER_HXX
#define NIC_API
Abstract base class for Network Interface Card (NIC) operations.
Abstract base class that defines the interface for all PicoScenes plugins.
Manager class for PicoScenes plugins.
static NIC_API std::string pluginDir
Directory containing plugin files.
static std::vector< std::string > listPluginsInFolder()
List all available plugins in the plugin directory.
void deactivateAllPlugins()
Deactivate all plugins.
void callRxHandles(const ModularPicoScenesRxFrame &rxs)
Call rx handlers for all plugins.
static std::shared_ptr< PicoScenesPluginManager > getInstance(const std::shared_ptr< AbstractNIC > &nic)
Get plugin manager instance for specific NIC.
void uninstallAllPlugins()
Uninstall all plugins.
std::pair< bool, std::string > tryInstallPlugin(const std::string &pluginFilePath)
Attempt to install a plugin.
const std::vector< std::shared_ptr< PicoScenesPluginWrapper > > & getAllPlugins() const
Get all installed plugins.
void parseAndExecuteCommands(const std::string &commandString)
Parse and execute plugin commands.
void uninstallPlugin(const std::string &plugInName)
Uninstall a specific plugin.
static const std::vector< std::shared_ptr< po::options_description > > & getPluginOptions()
Get all plugin options.
Wrapper class for PicoScenes plugins.
std::shared_ptr< PicoScenesPluginManager > getManager() const
Get the plugin manager instance.
const std::string & getLibraryFilePath() const
Get the plugin library file path.
std::shared_ptr< AbstractPicoScenesPlugin > getPluginCore() const
Get the plugin core instance.
PicoScenesPluginWrapper(const std::string &filePath, std::shared_ptr< PicoScenesPluginManager > manager)
Construct a new plugin wrapper.