42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
/**
|
|
* @文件路径: \datacenter\datacenter\inc\usermap.h
|
|
* @作者名称: zjp
|
|
* @文件版本: V1.0.0
|
|
* @创建日期: 2025-02-20 16:47:17
|
|
* @简要说明:
|
|
* @编辑时间: 2025-02-21 14:19:37
|
|
* @Copyright: 2025 Shenzhen ShenBao Electrical instruments CO.,LTD. All Rights Reserved.
|
|
*/
|
|
#ifndef USERMAP_H_
|
|
#define USERMAP_H_
|
|
#include <map>
|
|
|
|
typedef msg_mqtt_t (*callback)(msg_mqtt_t msg);
|
|
class mapkeyfunc
|
|
{
|
|
public:
|
|
void RegFunc(std::string key, callback cb) // 按键值注册函数
|
|
{
|
|
gListKeyFun[key] = cb;
|
|
}
|
|
void UnRegFunc(void) // 清空注册
|
|
{
|
|
gListKeyFun.clear();
|
|
}
|
|
msg_mqtt_t Exec(std::string key, msg_mqtt_t msg) // 按键值执行函数
|
|
{
|
|
if (gListKeyFun[key])
|
|
return gListKeyFun[key](msg);
|
|
else
|
|
{
|
|
msg.topic = "Null";
|
|
msg.payload = "Null";
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
private:
|
|
std::map<std::string, callback> gListKeyFun; // 键值列表
|
|
};
|
|
static mapkeyfunc gObjMng; // 键值函数映射管理对象
|
|
#endif |