Skip to content

Commit f655b62

Browse files
add common
1 parent 86f8b6b commit f655b62

File tree

3 files changed

+74
-15
lines changed

3 files changed

+74
-15
lines changed

inc/dlms_bash.h

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
//
2-
// Created by andrew on 2022/2/21.
3-
//
1+
/**
2+
* @file IContext.h
3+
* @brief Interface for context operations in a system.
4+
*
5+
* This file contains the IContext interface which provides
6+
* methods to initialize, start, stop, reset processes, and
7+
* manage plugins.
8+
*/
49

510
#ifndef DLMS_DLMS_BASH_H
611
#define DLMS_DLMS_BASH_H
@@ -11,49 +16,77 @@
1116

1217

1318
class Plugin;
19+
/**
20+
* @brief Interface for context operations.
21+
*
22+
* This class defines an interface for managing the lifecycle of
23+
* a process and handling plugins.
24+
*/
1425
class IContext {
1526
public:
1627

1728

1829
public:
30+
/// Destructor
1931
virtual ~IContext() = default;
2032

2133
/**
22-
* @brief 主进程初始化
34+
* @brief Initializes the main process.
2335
*
24-
* @return 0:成功,其他:失败
36+
* This method is responsible for setting up the initial state
37+
* of the main process.
38+
*
39+
* @return 0 if success, other values indicate failure.
2540
*/
2641
virtual Status Init() = 0;
2742

2843
/**
29-
* @brief 启动主进程
44+
* @brief Starts the main process.
45+
*
46+
* This method will start the execution of the main process.
3047
*
31-
* @return 0:成功,其他:失败
48+
* @return 0 if success, other values indicate failure.
3249
*/
3350
virtual Status Start() = 0;
3451

3552
/**
36-
* @brief 停止主进程
53+
* @brief Stops the main process.
54+
*
55+
* This method is called to stop the execution of the main process.
3756
*
38-
* @return 0:成功,其他:失败
57+
* @return 0 if success, other values indicate failure.
3958
*/
4059
virtual Status Stop() = 0;
4160

4261
/**
43-
* @brief 退出主进程
62+
* @brief Resets the main process.
4463
*
45-
* @return 0:成功,其他:失败
64+
* This method will reset the main process state.
65+
*
66+
* @return 0 if success, other values indicate failure.
4667
*/
4768
virtual Status Reset() = 0;
4869

4970
/**
50-
* @brief 获取插件对象
71+
* @brief Gets a plugin object.
72+
*
73+
* This method retrieves a plugin instance based on the plugin name
74+
* and type provided.
5175
*
52-
* @return nullptr:失败,其他:成功
76+
* @param[in] pluginName The name of the plugin.
77+
* @param[in] type The type of the plugin.
78+
* @return A pointer to the plugin object if found, nullptr otherwise.
5379
*/
5480
virtual Plugin *GetPlugin(std::string &pluginName, std::string &type) = 0;
5581

56-
// 将需要工作的线程放到Push里面
82+
/**
83+
* @brief Dispatches a work function to a thread.
84+
*
85+
* This method assigns a work function to be executed by a thread.
86+
*
87+
* @param[in] workFunction The function to be executed by the thread.
88+
* @return 0 if success, other values indicate failure.
89+
*/
5790
virtual Status Dispatch(Func workFunction) = 0;
5891
};
5992

inc/dlms_error.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@
1111
#define OK 0
1212
#define MALLOC_FAILED 1
1313

14-
14+
/**
15+
* @brief Status codes used throughout the program.
16+
*
17+
* These enum values represent the various status codes
18+
* that functions might return, providing a clear and
19+
* type-safe way to handle these return values.
20+
*/
21+
// enum class Status : int32_t {
22+
// ERROR = -1, ///< General error
23+
// OK = 0, ///< Success
24+
// MALLOC_FAILED = 1 ///< Memory allocation failed
25+
// };
1526

1627

1728

inc/dlms_macro.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,20 @@
77

88
#define POINTER_SAFE(lp) ((nullptr == (lp)) ? "null" : (lp))
99

10+
/**
11+
* @brief Utility function to convert a pointer to a safe string representation.
12+
*
13+
* This function checks if the given pointer is nullptr and returns a string
14+
* indicating the pointer state.
15+
*
16+
* @tparam T Type of the pointer.
17+
* @param ptr Pointer to be checked.
18+
* @return "null" if the pointer is nullptr; the original pointer otherwise.
19+
*/
20+
template <typename T>
21+
constexpr const char* pointerSafe(T* ptr) {
22+
return (nullptr == ptr) ? "null" : reinterpret_cast<const char*>(ptr);
23+
}
24+
1025

1126
#endif //DLMS_DLMS_MACRO_H

0 commit comments

Comments
 (0)