dmpserverplugins.cpp
2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**************************************************************************
* file: dmpserverplugins.cpp
* Author: wanzhongping
* Date: 2021-03-12 17:01:24
* Email: zhongpingw@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#include "dmpserverplugins.h"
#include <boost/dll/import.hpp>
#include "dmpapplication.h"
#include <dlfcn.h>
#include <boost/format.hpp>
#include <boost/make_shared.hpp>
#include "dmplogger.h"
std::shared_ptr<DmpPythonUtils> DmpServerPlugins::sp_python_utils_ = std::make_shared<DmpPythonUtils>();
std::vector<std::string> &DmpServerPlugins::ServerPlugins()
{
static std::vector<std::string> pluginList;
return pluginList;
}
bool DmpServerPlugins::InitPlugins(DmpServerInterface *interface)
{
sp_python_utils_->InitServerPython(interface);
if (sp_python_utils_->IsEnabled())
{
LOGGER_INFO("Python support ENABLED :-)");
}
else
{
LOGGER_WARN("Python support FAILED :-(");
return false;
}
//Init plugins: loads a list of installed plugins and filter them
//for "server" metadata
bool at_least_one_enabled = false;
std::vector<std::string> vec_plugins = sp_python_utils_->PluginList();
std::vector<std::string>::iterator iter_plugin_name;
std::string comma = ",";
for (iter_plugin_name = vec_plugins.begin(); iter_plugin_name != vec_plugins.end(); iter_plugin_name++)
{
std::string plugin_service = sp_python_utils_->GetPluginMetadata(*iter_plugin_name, "server");
if (plugin_service == "True")
{
if (sp_python_utils_->LoadPlugin(*iter_plugin_name))
{
if (sp_python_utils_->StartServerPlugin(*iter_plugin_name))
{
at_least_one_enabled = true;
ServerPlugins().push_back(*iter_plugin_name);
boost::format fmt = boost::format("Server plugin %1% loaded!") % *iter_plugin_name;
LOGGER_INFO(fmt.str());
}
else
{
LOGGER_CRITICAL("Error loading server plugin " + *iter_plugin_name);
}
}
else
{
LOGGER_CRITICAL("Error starting server plugin " + *iter_plugin_name);
}
}
}
return sp_python_utils_ && sp_python_utils_->IsEnabled() && at_least_one_enabled;
}