|
1 |
| -// |
2 |
| -// Created by andrew on 2022/2/21. |
3 |
| -// |
| 1 | +/** |
| 2 | + * @file Plugin.h |
| 3 | + * @brief Definitions and interfaces for Plugin and related types. |
| 4 | + * |
| 5 | + * This file contains the enum definitions and class declarations |
| 6 | + * for Plugin and related components. The Plugin class provides |
| 7 | + * an interface for initializing, starting, stopping, resetting, |
| 8 | + * and communicating with plugins. |
| 9 | + */ |
4 | 10 |
|
5 | 11 | #ifndef DLMS_PLUGIN_H
|
6 | 12 | #define DLMS_PLUGIN_H
|
|
13 | 19 | * 实际项目中随时可以替换成动态库插件形式,这里为demo代码采用直接链接编译的方式使用
|
14 | 20 | * */
|
15 | 21 |
|
16 |
| -// 服务函数根据类型进行参数和返回值的确认 |
| 22 | +/** |
| 23 | + * @brief Enum representing the type of data a plugin service might handle. |
| 24 | + * |
| 25 | + * This enum is used to specify the type of input and output data |
| 26 | + * the service functions in a plugin can process. |
| 27 | + */ |
17 | 28 | enum PluginServiceType {
|
18 | 29 | String = 0x1,
|
19 | 30 | JSON = 0x2,
|
20 | 31 | Binary = 0x4,
|
21 | 32 | Integer = 0x8,
|
22 | 33 | };
|
23 | 34 |
|
| 35 | +/** |
| 36 | + * @brief Enum representing different notification types. |
| 37 | + * |
| 38 | + * This enum is used to specify the type of notifications |
| 39 | + * that can be issued by the plugin. |
| 40 | + */ |
24 | 41 | enum NotifyTypes {
|
25 | 42 | NetBroken = 0,
|
26 | 43 | Quit = 1,
|
27 | 44 | };
|
28 | 45 |
|
29 | 46 | class IContext;
|
| 47 | +/** |
| 48 | + * @brief Interface class for Plugin. |
| 49 | + * |
| 50 | + * This class provides an abstract interface for plugin management, |
| 51 | + * including initialization, starting, stopping, resetting, and |
| 52 | + * communication with plugins. |
| 53 | + */ |
30 | 54 | class Plugin {
|
31 | 55 | public:
|
| 56 | + /** |
| 57 | + * @brief Enum representing the status of a plugin. |
| 58 | + * |
| 59 | + * This enum is used to specify the current status of the plugin. |
| 60 | + */ |
32 | 61 | enum PluginStatus : uint8_t {
|
33 |
| - PLUGIN_UNKNOWN = 0, |
34 |
| - PLUGIN_INIT = 1, |
35 |
| - PLUGIN_RUNNING = 2, |
36 |
| - PLUGIN_STOP = 3, |
37 |
| - PLUGIN_Reset = 4, |
| 62 | + PLUGIN_UNKNOWN = 0, ///< Unknown status |
| 63 | + PLUGIN_INIT = 1, ///< Plugin initialized |
| 64 | + PLUGIN_RUNNING = 2, ///< Plugin is running |
| 65 | + PLUGIN_STOP = 3, ///< Plugin stopped |
| 66 | + PLUGIN_Reset = 4, ///< Plugin reset |
38 | 67 | };
|
39 | 68 | //
|
40 | 69 |
|
41 | 70 | public:
|
42 | 71 | virtual ~Plugin() = default;
|
43 | 72 |
|
44 | 73 | /**
|
45 |
| - * @brief 插件初始化 |
| 74 | + * @brief Initialize the plugin. |
46 | 75 | *
|
47 |
| - * @param lpIDlms 主框架对象指针 |
| 76 | + * This method performs the necessary initialization for the plugin. |
| 77 | + * |
| 78 | + * @param lpIDlms Pointer to the main framework object. |
| 79 | + * @param pluginName Name of the plugin. |
| 80 | + * @return Status code indicating success or failure. |
48 | 81 | */
|
49 | 82 | virtual Status Init(IContext *lpIDlms, std::string pluginName) = 0;
|
50 | 83 |
|
| 84 | + /** |
| 85 | + * @brief Start the plugin. |
| 86 | + * |
| 87 | + * This method starts the plugin execution. |
| 88 | + * |
| 89 | + * @return Status code indicating success or failure. |
| 90 | + */ |
51 | 91 | virtual Status Start() = 0;
|
52 | 92 |
|
| 93 | + /** |
| 94 | + * @brief Stop the plugin. |
| 95 | + * |
| 96 | + * This method stops the plugin execution. |
| 97 | + * |
| 98 | + * @return Status code indicating success or failure. |
| 99 | + */ |
53 | 100 | virtual Status Stop() = 0;
|
54 | 101 |
|
| 102 | + /** |
| 103 | + * @brief Reset the plugin. |
| 104 | + * |
| 105 | + * This method resets the plugin state. |
| 106 | + * |
| 107 | + * @return Status code indicating success or failure. |
| 108 | + */ |
55 | 109 | virtual Status Reset() = 0;
|
56 | 110 |
|
57 |
| - // 获取插件名字 |
| 111 | + /** |
| 112 | + * @brief Get the plugin name. |
| 113 | + * |
| 114 | + * This method returns the name of the plugin. |
| 115 | + * |
| 116 | + * @return The name of the plugin. |
| 117 | + */ |
58 | 118 | virtual std::string GetName() = 0;
|
59 | 119 |
|
| 120 | + /** |
| 121 | + * @brief Send a synchronous message to the plugin. |
| 122 | + * |
| 123 | + * This method sends a synchronous message to the plugin and waits for a response. |
| 124 | + * |
| 125 | + * @param in Type of the input data. |
| 126 | + * @param lpInData Pointer to the input data. |
| 127 | + * @param out Type of the output data. |
| 128 | + * @param lpOutData Pointer to the output data. |
| 129 | + * @return Status code indicating success or failure. |
| 130 | + */ |
60 | 131 | virtual Status SendSync(PluginServiceType in, void *lpInData, PluginServiceType out, void *lpOutData) = 0;
|
61 | 132 |
|
| 133 | + /** |
| 134 | + * @brief Send an asynchronous message to the plugin. |
| 135 | + * |
| 136 | + * This method sends an asynchronous message to the plugin without waiting for a response. |
| 137 | + * |
| 138 | + * @param in Type of the input data. |
| 139 | + * @param lpInData Pointer to the input data. |
| 140 | + * @return Status code indicating success or failure. |
| 141 | + */ |
62 | 142 | virtual Status SendAsync(PluginServiceType in, void *lpInData) = 0;
|
63 | 143 |
|
| 144 | + /** |
| 145 | + * @brief Notify the plugin with input data. |
| 146 | + * |
| 147 | + * This method sends a notification to the plugin with the specified input data. |
| 148 | + * |
| 149 | + * @param in Type of the input data. |
| 150 | + * @param lpInData Pointer to the input data. |
| 151 | + * @return Status code indicating success or failure. |
| 152 | + */ |
64 | 153 | virtual Status Notify(PluginServiceType in, void *lpInData) = 0;
|
65 | 154 |
|
| 155 | + /** |
| 156 | + * @brief Post a message to the plugin. |
| 157 | + * |
| 158 | + * This method posts a message to the plugin. |
| 159 | + * |
| 160 | + * @param in Type of the input data. |
| 161 | + * @param lpInData Pointer to the input data. |
| 162 | + * @return Status code indicating success or failure. |
| 163 | + */ |
66 | 164 | virtual Status PostMessage(PluginServiceType in, void *lpInData) = 0;
|
67 | 165 |
|
| 166 | + /** |
| 167 | + * @brief Check if the plugin supports a certain service type. |
| 168 | + * |
| 169 | + * This method checks whether the plugin supports the specified service type. |
| 170 | + * |
| 171 | + * @param serviceType The service type to check. |
| 172 | + * @return true if the service type is supported, false otherwise. |
| 173 | + */ |
68 | 174 | virtual bool Support(PluginServiceType serviceType) = 0;
|
69 | 175 |
|
70 | 176 | protected:
|
71 |
| - volatile PluginStatus pluginStatus{PLUGIN_UNKNOWN}; |
72 |
| - std::string pluginType; |
| 177 | + volatile PluginStatus pluginStatus{PLUGIN_UNKNOWN}; ///< The current status of the plugin |
| 178 | + std::string pluginType; ///< The type of the plugin |
73 | 179 | };
|
74 | 180 |
|
75 | 181 | #ifdef __cplusplus
|
76 | 182 | extern "C" {
|
| 183 | + |
| 184 | +/** |
| 185 | + * @brief Get the version of the plugin framework. |
| 186 | + * |
| 187 | + * This function returns a string representing the version of the |
| 188 | + * plugin framework being used. |
| 189 | + * |
| 190 | + * @return A C-string containing the version information. |
| 191 | + */ |
77 | 192 | const char *GetVersion();
|
| 193 | + |
| 194 | +/** |
| 195 | + * @brief Create a new plugin instance. |
| 196 | + * |
| 197 | + * This function creates a new instance of a plugin based on the provided |
| 198 | + * plugin type. The created plugin instance is returned as a pointer. |
| 199 | + * |
| 200 | + * @param pluginType The type of the plugin to be created. |
| 201 | + * @return A pointer to the newly created plugin instance. |
| 202 | + */ |
78 | 203 | Plugin *CreatePlugin(const char *pluginType);
|
| 204 | + |
| 205 | +/** |
| 206 | + * @brief Delete an existing plugin instance. |
| 207 | + * |
| 208 | + * This function deletes an existing plugin instance, releasing any |
| 209 | + * resources associated with it. |
| 210 | + * |
| 211 | + * @param plugin The pointer to the plugin instance to be deleted. |
| 212 | + */ |
79 | 213 | void DeletePlugin(Plugin *plugin);
|
80 |
| -} |
81 | 214 |
|
82 |
| -#endif |
| 215 | +} // extern "C" |
| 216 | +#endif // __cplusplus |
| 217 | + |
83 | 218 |
|
84 | 219 | #endif //DLMS_PLUGIN_H
|
0 commit comments