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