717aaa0274
2、调整公共接口
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
/**
|
|
* @文件路径: \datacenter\datacenter\datacenter.h
|
|
* @作者名称: zjp
|
|
* @文件版本: V1.0.0
|
|
* @创建日期: 2025-02-20 08:55:09
|
|
* @简要说明:
|
|
* @编辑时间: 2025-02-21 14:29:26
|
|
* @Copyright: 2025 Shenzhen ShenBao Electrical instruments CO.,LTD. All Rights Reserved.
|
|
*/
|
|
#ifndef _DCAPP_DATACENTER_DATACENTER_H_
|
|
#define _DCAPP_DATACENTER_DATACENTER_H_
|
|
|
|
#include <unistd.h>
|
|
#include <thread>
|
|
#include <functional>
|
|
#include "service.h"
|
|
#include "mqttClient.h"
|
|
#include "queue.h"
|
|
#include "thread_pool.h"
|
|
|
|
#define POOLSIZE 10
|
|
|
|
class DataCenter : public IService
|
|
{
|
|
public:
|
|
DataCenter()
|
|
{
|
|
printf(".1.\n");
|
|
};
|
|
~DataCenter()
|
|
{
|
|
printf(".2.\n");
|
|
}
|
|
|
|
/**
|
|
* 服务初始化
|
|
*/
|
|
virtual int Init(void *pData)
|
|
{
|
|
printf("---DataCenter --Init.....\n");
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* 执行业务(业务循环) while(1){doSomeThings...}
|
|
*/
|
|
virtual void Exec()
|
|
{
|
|
datacenterinit();
|
|
|
|
std::thread recvThread(&DataCenter::ExecPoll,this);
|
|
std::thread sendThread(&DataCenter::ExecReponse, this);
|
|
//todo 构造任务 用于监测数据是否更新
|
|
recvThread.join();
|
|
sendThread.join();
|
|
}
|
|
|
|
virtual const char *getServiceName()
|
|
{
|
|
return "DataCenter";
|
|
}
|
|
|
|
public:
|
|
static void ExecPoll(void *); // 执行轮巡业务
|
|
static void ExecReponse(void*); // 执行应答任务
|
|
// static bool handleMsg(msg_mqtt_t msg);
|
|
private:
|
|
void datacenterinit(void); // 初始化
|
|
void datacenterOnline(void);
|
|
void updateSubTopicsMap(msg_mqtt_t &);
|
|
private:
|
|
bool recvThreadFlag = false;
|
|
bool sendThreadFlag = false;
|
|
MessageQueue mQueue_In; // 输入队列
|
|
MessageQueue mQueue_Out; // 输出队列
|
|
CMqttClient *objmqttClient;
|
|
ThreadPool *objThreadPool;
|
|
std::map<std::string/*订阅主题*/,std::vector<std::string/*主题字段*/>>tmpSubTopicsMap;
|
|
|
|
};
|
|
|
|
#endif // _DCAPP_DATACENTER_DATACENTER_H_
|