import.h (1303B)
1 #pragma once 2 3 #include <map> 4 #include <mutex> 5 #include <set> 6 7 #include "bridgeLib/commands.h" 8 9 namespace synthLib 10 { 11 struct DeviceCreateParams; 12 class Device; 13 } 14 15 namespace bridgeServer 16 { 17 struct Config; 18 19 class Import 20 { 21 public: 22 typedef synthLib::Device* (*FuncBridgeDeviceCreate)(const synthLib::DeviceCreateParams& _params); 23 typedef void (*FuncBridgeDeviceDestroy)(synthLib::Device*); 24 typedef void (*FuncBridgeDeviceGetDesc)(bridgeLib::PluginDesc&); 25 26 struct Plugin final 27 { 28 std::string filename; 29 void* handle = nullptr; 30 FuncBridgeDeviceCreate funcCreate = nullptr; 31 FuncBridgeDeviceDestroy funcDestroy = nullptr; 32 FuncBridgeDeviceGetDesc funcGetDesc = nullptr; 33 }; 34 35 Import(const Config& _config); 36 ~Import(); 37 38 synthLib::Device* createDevice(const synthLib::DeviceCreateParams& _params, const bridgeLib::PluginDesc& _desc); 39 bool destroyDevice(const bridgeLib::PluginDesc& _desc, synthLib::Device* _device); 40 41 private: 42 void findPlugins(); 43 void findPlugins(const std::string& _rootPath); 44 void findPlugins(const std::string& _rootPath, const std::string& _extension); 45 void loadPlugin(const std::string& _file); 46 47 const Config& m_config; 48 49 std::map<bridgeLib::PluginDesc, Plugin> m_loadedPlugins; 50 std::set<std::string> m_loadedFiles; 51 52 std::mutex m_mutex; 53 }; 54 }