Skip to content

Commit c4513ef

Browse files
添加系统监听的websocket和Http库
1 parent 9d7b8cf commit c4513ef

File tree

6 files changed

+83
-13
lines changed

6 files changed

+83
-13
lines changed

inc/dlms_bash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define DLMS_DLMS_BASH_H
77
#include <iostream>
88

9-
class IPlugin;
9+
class Plugin;
1010
class IDlms {
1111
public:
1212
virtual ~IDlms() = default;
@@ -37,14 +37,14 @@ class IDlms {
3737
*
3838
* @return 0:成功,其他:失败
3939
*/
40-
virtual int32_t Exit() = 0;
40+
virtual int32_t Reset() = 0;
4141

4242
/**
4343
* @brief 获取插件对象
4444
*
4545
* @return nullptr:失败,其他:成功
4646
*/
47-
virtual IPlugin *GetPluginByName(std::string &pluginName) = 0;
47+
virtual Plugin *GetPlugin(std::string &pluginName) = 0;
4848
};
4949

5050

inc/plugin.h

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,44 @@
55
#ifndef DLMS_PLUGIN_H
66
#define DLMS_PLUGIN_H
77
#include <iostream>
8+
#include <memory>
9+
810
#include "dlms_bash.h"
911

1012
/*
1113
* 实际项目中随时可以替换成动态库插件形式,这里为demo代码采用直接链接编译的方式使用
1214
* */
1315

16+
enum PluginType
17+
{
18+
/// \brief A World plugin
19+
WORLD_PLUGIN,
20+
/// \brief A Model plugin
21+
MODEL_PLUGIN,
22+
/// \brief A Sensor plugin
23+
SENSOR_PLUGIN,
24+
/// \brief A System plugin
25+
SYSTEM_PLUGIN,
26+
/// \brief A Visual plugin
27+
VISUAL_PLUGIN,
28+
/// \brief A GUI plugin
29+
GUI_PLUGIN
30+
};
31+
1432

15-
class IPlugin {
33+
class Plugin {
1634
public:
1735
enum PluginStatus : uint8_t {
1836
PLUGIN_UNKNOWN = 0,
1937
PLUGIN_INIT = 1,
2038
PLUGIN_RUNNING = 2,
2139
PLUGIN_STOP = 3,
22-
PLUGIN_EXIT = 4,
40+
PLUGIN_Reset = 4,
2341
};
42+
//
2443

2544
public:
26-
virtual ~IPlugin() = default;
45+
virtual ~Plugin() = default;
2746

2847
/**
2948
* @brief 插件初始化
@@ -36,13 +55,17 @@ class IPlugin {
3655

3756
virtual int32_t Stop() = 0;
3857

39-
virtual int32_t Exit() = 0;
58+
virtual int32_t Reset() = 0;
4059

60+
// 获取插件名字
61+
virtual std::string GetHandleName() = 0;
4162

4263

4364

4465
protected:
4566
volatile PluginStatus m_pluginStatus{PLUGIN_UNKNOWN};
67+
PluginType type;
68+
std::string handleName; // name of the plugin
4669
};
4770

4871

src/dlms/dlms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ int32_t CDlms::Stop() {
4545
return 0;
4646
}
4747

48-
int32_t CDlms::Exit() {
48+
int32_t CDlms::Reset() {
4949
return 0;
5050
}
5151

52-
IPlugin *CDlms::GetPluginByName(std::string &pluginName) {
52+
Plugin *CDlms::GetPlugin(std::string &pluginName) {
5353

5454
auto iter = m_mapPlugin.find(pluginName);
5555
if (iter == m_mapPlugin.end()) {

src/dlms/dlms.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "plugin.h"
1111
#include <dlms_bash.h>
12+
#include "plugin_manager.h"
1213

1314
class CDlms : public IDlms {
1415
public:
@@ -20,15 +21,14 @@ class CDlms : public IDlms {
2021

2122
int32_t Stop() override;
2223

23-
int32_t Exit() override;
24-
25-
IPlugin* GetPluginByName(std::string& pluginName) override;
24+
int32_t Reset() override;
2625

26+
Plugin* GetPlugin(std::string& pluginName) override;
2727

2828

2929

3030
private:
31-
std::map<std::string, IPlugin*> m_mapPlugin;
31+
PluginManager pluginManager;
3232

3333
};
3434

src/dlms/plugin_manager.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Created by andrew on 2022/6/10.
3+
//
4+
5+
#include "plugin_manager.h"
6+
7+
int32_t PluginManager::LoadPlugin(const std::string &path, const std::string &pluginName) {
8+
return 0;
9+
}
10+
11+
int32_t PluginManager::LoadPlugin(const std::string &path) {
12+
return 0;
13+
}
14+
15+
Plugin *PluginManager::GetPlugin(const std::string &pluginName) {
16+
return nullptr;
17+
}

src/dlms/plugin_manager.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Created by andrew on 2022/6/10.
3+
//
4+
5+
#ifndef DLMS_PLUGIN_MANAGER_H
6+
#define DLMS_PLUGIN_MANAGER_H
7+
#include <map>
8+
#include <string>
9+
10+
11+
#include "plugin.h"
12+
13+
14+
class PluginManager {
15+
public:
16+
int32_t LoadPlugin(const std::string& path, const std::string& pluginName);
17+
18+
int32_t LoadPlugin(const std::string& path);
19+
20+
Plugin *GetPlugin(const std::string& pluginName);
21+
22+
23+
24+
private:
25+
std::map<std::string, Plugin*> mapPlugins;
26+
27+
};
28+
29+
30+
#endif //DLMS_PLUGIN_MANAGER_H

0 commit comments

Comments
 (0)