You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.1 KiB

//
// Created by zwsd
//
#pragma once
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include "iflytop/components/restful_server/restful_server.hpp"
#include "iflytop/core/components/jobs/work_queue.hpp"
#include "iflytop/core/components/timer/simple_timer.hpp"
#include "iflytop/core/spdlogfactory/logger.hpp"
#include "iflytoplinuxsdk/src/iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp"
#include "service/device_state_service.hpp"
#include "service/disinfection_ctl_service.hpp"
//
#include "configs/gconfig.hpp"
#include "iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp"
#include "zservice_container/zservice_container.hpp"
//
//
#include "db/db_service.hpp"
#include "iflytop/components/zcanreceiver/zcanhost.hpp"
#include "service/data_export_service.hpp"
#include "service/device_io_control_service.hpp"
#include "service/disinfection_logs_manager.hpp"
/**
* @brief
*
* service: FrontMsgProcesser
*
* 监听事件:
* 依赖状态:
* 依赖服务:
* 作用:
*
*/
namespace iflytop {
using namespace std;
using namespace core;
class FrontMsgProcesser : public enable_shared_from_this<FrontMsgProcesser> {
ENABLE_LOGGER(FrontMsgProcesser);
public:
typedef std::function<void(json& cmd, json& receipt)> MsgProcesserFn_t;
private:
map<string, MsgProcesserFn_t> m_msgProcesserMap;
public:
FrontMsgProcesser(){};
void initialize();
void processMsg(json& cmd, json& receipt);
void registerMsgProcesser(const string& cmdName, MsgProcesserFn_t fn);
};
static inline void getJsonValFromJson(json j, int& val) {
if (j.is_string()) {
string valstr = j;
val = atoi(valstr.c_str());
} else if (j.is_number()) {
val = j;
} else {
throw std::runtime_error("getJsonValFromJson(int) error");
}
}
template <typename T>
static inline T jsonGet(json j) {
T val;
getJsonValFromJson(j, val);
return val;
}
#define BIND(func) bind(&func, shared_from_this(), placeholders::_1, placeholders::_2)
} // namespace iflytop