27 pluginApi_.
context =
reinterpret_cast<void*
>(
this);
32 for (
auto&
func : exitFunc_) {
36 JAMI_ERR() <<
"Exception caught during plugin exit";
40 dynPluginMap_.clear();
41 exactMatchMap_.clear();
49 auto it = dynPluginMap_.find(path);
50 if (
it != dynPluginMap_.end()) {
65 JAMI_ERR() <<
"Plugin: no init symbol" << error;
70 if (!registerPlugin(
plugin))
74 dynPluginMap_[path] = {std::move(
plugin),
true};
81 destroyPluginComponents(path);
82 auto it = dynPluginMap_.find(path);
83 if (
it != dynPluginMap_.end()) {
84 std::lock_guard
lk(mtx_);
86 dynPluginMap_.erase(
it);
87 exitFunc_.erase(path);
96 for (
const auto&
item : dynPluginMap_) {
103std::vector<std::string>
106 std::vector<std::string>
res {};
107 for (
const auto&
pair : dynPluginMap_) {
108 if (
pair.second.second)
115PluginManager::destroyPluginComponents(
const std::string& path)
120 auto clcm = componentsLifeCycleManagers_.find(
pairIt->first);
121 if (
clcm != componentsLifeCycleManagers_.end()) {
122 clcm->second.destroyComponent(
pairIt->second, mtx_);
130PluginManager::callPluginInitFunction(
const std::string& path)
133 auto it = dynPluginMap_.find(path);
134 if (
it != dynPluginMap_.end()) {
136 std::shared_ptr<DLPlugin>
plugin = std::static_pointer_cast<DLPlugin>(
it->second.first);
143 }
catch (
const std::runtime_error&
e) {
149 JAMI_ERR() <<
"Plugin: init failed";
161PluginManager::registerPlugin(std::unique_ptr<Plugin>&
plugin)
170 pluginPtr->api_.registerObjectFactory = registerObjectFactory_;
178 JAMI_ERR() <<
"invokeService called with null plugin API";
190 JAMI_ERR() <<
"createComponent called with null context";
195 JAMI_ERR() <<
"createComponent called with null plugin API";
203 }
catch (
const std::runtime_error&
e) {
208 JAMI_ERR() <<
"Plugin: init failed";
219 services_[name] = std::forward<ServiceFunction>(
func);
226 services_.erase(name);
230PluginManager::invokeService(
const DLPlugin*
plugin,
const std::string& name,
void* data)
233 const auto&
iterFunc = services_.find(name);
235 JAMI_ERR() <<
"Services not found: " << name;
244 }
catch (
const std::runtime_error&
e) {
251PluginManager::manageComponent(
const DLPlugin*
plugin,
const std::string& name,
void* data)
253 const auto&
iter = componentsLifeCycleManagers_.find(name);
254 if (
iter == componentsLifeCycleManagers_.end()) {
255 JAMI_ERR() <<
"Component lifecycle manager not found: " << name;
264 pluginComponentsMap_[
plugin->getPath()].emplace_back(name, data);
267 }
catch (
const std::runtime_error&
e) {
290 const std::string key(type);
298 wildCardVec_.push_back(
factory);
303 if (exactMatchMap_.find(key) != exactMatchMap_.end())
313 ComponentFunction&& destroyComponent)
315 componentsLifeCycleManagers_[name] = {std::forward<ComponentFunction>(
takeOwnership),
316 std::forward<ComponentFunction>(destroyComponent)};
320std::unique_ptr<void, PluginManager::ObjectDeleter>
321PluginManager::createObject(
const std::string& type)
324 return {
nullptr,
nullptr};
332 const auto&
factoryIter = exactMatchMap_.find(type);
341 for (
const auto&
factory : wildCardVec_) {
348 JAMI_ERR() <<
"failed to register object " <<
op.type;
349 return {
nullptr,
nullptr};
356 return {
nullptr,
nullptr};
360PluginManager::registerObjectFactory_(
const JAMI_PluginAPI* api,
const char* type,
void* data)
364 JAMI_ERR() <<
"registerObjectFactory called with null plugin API";
369 JAMI_ERR() <<
"registerObjectFactory called with null factory data";
This class is used after a plugin library is successfully loaded.
bool registerComponentManager(const std::string &name, ComponentFunction &&takeOwnership, ComponentFunction &&destroyComponent)
Registers a component manager that will have two functions, one to take ownership of the component an...
std::vector< std::string > getLoadedPlugins() const
Returns vector with loaded plugins' libraries paths.
bool unload(const std::string &path)
Unloads the plugin.
void unRegisterService(const std::string &name)
Unregister a service from the Plugin System.
bool checkLoadedPlugin(const std::string &rootPath) const
Returns True if plugin is loaded.
bool registerObjectFactory(const char *type, const JAMI_PluginObjectFactory &factory)
Function called from plugin implementation register a new object factory.
bool registerService(const std::string &name, ServiceFunction &&func)
Register a new service in the Plugin System.
bool load(const std::string &path)
Load a dynamic plugin by filename.
static Plugin * load(const std::string &path, std::string &error)
Load plugin's library.
#define JAMI_PLUGIN_ABI_VERSION
void(* JAMI_PluginExitFunc)(void)
#define JAMI_PLUGIN_API_VERSION
void emitSignal(Args... args)
This structure is filled by the PluginManager.
JAMI_PluginVersion version
This structure is filled by plugin.
JAMI_PluginCreateFunc parameter.