45 lines
1.1 KiB
C++
45 lines
1.1 KiB
C++
#include "PluginRegister.h"
|
|
#include "plugin_support/PluginModule.h"
|
|
#include <QDebug>
|
|
|
|
|
|
PluginRegister* PluginRegister::s_pluginRegister;
|
|
|
|
PluginRegister* PluginRegister::getInstance()
|
|
{
|
|
static std::mutex m;
|
|
// check if set without locking first (in most cases it will be set and it will never be unset) so locking the mutex everytime
|
|
// is a waist of time.
|
|
if (!s_pluginRegister) {
|
|
// not set then lock
|
|
std::lock_guard<std::mutex> guard(m);
|
|
// recheck in case someone else just set it
|
|
if (!s_pluginRegister) {
|
|
s_pluginRegister = new PluginRegister;
|
|
}
|
|
}
|
|
return s_pluginRegister;
|
|
}
|
|
|
|
PluginRegister::PluginRegister() = default;
|
|
|
|
void PluginRegister::initModules()
|
|
{
|
|
for (auto && mod : m_moduleMap) {
|
|
mod.second->init();
|
|
}
|
|
}
|
|
|
|
void PluginRegister::registerModule(PluginModuleSPtr module)
|
|
{
|
|
qDebug() << "registerModule " << module->identifier();
|
|
m_moduleMap.emplace(module->identifier(), module);
|
|
}
|
|
|
|
const PluginModule* PluginRegister::findModule(const QString &module_ident) const
|
|
{
|
|
auto res = m_moduleMap.find(module_ident);
|
|
if (res == m_moduleMap.end())
|
|
return nullptr;
|
|
return res->second.get();
|
|
}
|