diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp index eab1bb2..a3e0f73 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.cpp @@ -13,22 +13,23 @@ using namespace iflytop; // "params":{ // } // } - +#define _REG_TYPE(type) regType(#type) +#define _REG_ENUM_TYPE(type, ...) regEnumType(#type, {__VA_ARGS__}) void FrontMsgProcesser::initialize() { - REG_TYPE(string); - REG_TYPE(void(void)); - REG_TYPE(int); - REG_TYPE(int32_t); - REG_TYPE(float); - REG_TYPE(double); - REG_TYPE(void); - REG_TYPE(json); - REG_TYPE(vector); - REG_TYPE(vector); - REG_TYPE(vector); - REG_TYPE(vector); - REG_TYPE(vector); - REG_TYPE(vector); + _REG_TYPE(string); + _REG_TYPE(void(void)); + _REG_TYPE(int); + _REG_TYPE(int32_t); + _REG_TYPE(float); + _REG_TYPE(double); + _REG_TYPE(void); + _REG_TYPE(json); + _REG_TYPE(vector); + _REG_TYPE(vector); + _REG_TYPE(vector); + _REG_TYPE(vector); + _REG_TYPE(vector); + _REG_TYPE(vector); } json FrontMsgProcesser::geFnList() { json rely; diff --git a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp index 33094f4..79befbe 100644 --- a/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp +++ b/appsrc/baseservice/front_msg_processer/front_msg_processer.hpp @@ -70,14 +70,20 @@ class FrontMsgProcesser { map typeInfoMap; FrontMsgProcesser() {}; + void initialize(); + bool isInit = false; public: static FrontMsgProcesser& ins() { static FrontMsgProcesser frontMsgProcesser; + if (!frontMsgProcesser.isInit) { + frontMsgProcesser.initialize(); + frontMsgProcesser.isInit = true; + } + return frontMsgProcesser; } - void initialize(); void processMsg(shared_ptr cxt); json geFnList(); @@ -87,6 +93,7 @@ class FrontMsgProcesser { TypeInfo info; info.typeName = name; typeInfoMap[type_index(typeid(T))] = info; + logger->info("regType:{} {}", name, typeid(T).name()); }; template @@ -103,6 +110,10 @@ class FrontMsgProcesser { return typeInfoMap[type_index(typeid(T))].typeName; } // return typeid(T).name(); + if (string(typeid(T).name()) == "v") { + return "void"; + } + throw std::runtime_error(fmt::format("reg {}:{} fail,getTypeName error:{}", className, fnName, typeid(T).name())); }; @@ -153,17 +164,31 @@ static inline T jsonGet(json j) { #define REGFNV_EACH_EXPTR1(_1, _2, _3, _4, _5, index, varName) params[#varName] #define REGFNV_EACH_EXPTR2(_1, _2, _3, _4, _5, index, varName) #varName -#define REG_FN(fn, type, ...) { function __fun; \ - FrontMsgProcesser::ins().regProcesser(__fun,thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, [this](shared_ptr cxt) { \ - json& params = cxt->params; \ - cxt->content = fn(MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ - });} +#define REG_FN(fn, type, ...) \ + { \ + function __fun; \ + FrontMsgProcesser::ins().regProcesser(__fun, thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, [this](shared_ptr cxt) { \ + json& params = cxt->params; \ + cxt->content = fn(MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ + }); \ + } -#define REG_FN_VOID(fn, type) { function __fun; FrontMsgProcesser::ins().regProcesser(__fun,thisClass.className, #fn, {}, [this](shared_ptr cxt) { cxt->content = fn(); });} +#define REG_FN_VOID(fn, type) \ + { \ + function __fun; \ + FrontMsgProcesser::ins().regProcesser(__fun, thisClass.className, #fn, {}, [this](shared_ptr cxt) { cxt->content = fn(); }); \ + } -#define REG_EXTFN(fn, type, ...) { function __fun; \ - FrontMsgProcesser::ins().regProcesser(__fun,thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, [this](shared_ptr cxt) { \ - json& params = cxt->params; \ - fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ - }); } -#define REG_EXTFN_VOID(fn, type) { function __fun; FrontMsgProcesser::ins().regProcesser(__fun,thisClass.className, #fn, {}, [this](shared_ptr cxt) { fn(cxt); }); } +#define REG_EXTFN(fn, type, ...) \ + { \ + function __fun; \ + FrontMsgProcesser::ins().regProcesser(__fun, thisClass.className, #fn, {MARCO_LIST(REGFNV_EACH_EXPTR2, _1, _2, _3, _4, _5, __VA_ARGS__)}, [this](shared_ptr cxt) { \ + json& params = cxt->params; \ + fn(cxt, MARCO_LIST(REGFNV_EACH_EXPTR1, _1, _2, _3, _4, _5, __VA_ARGS__)); \ + }); \ + } +#define REG_EXTFN_VOID(fn, type) \ + { \ + function __fun; \ + FrontMsgProcesser::ins().regProcesser(__fun, thisClass.className, #fn, {}, [this](shared_ptr cxt) { fn(cxt); }); \ + } diff --git a/appsrc/service/hardware/device_io_ctrl_service.cpp b/appsrc/service/hardware/device_io_ctrl_service.cpp index a3f2cfb..d37a685 100644 --- a/appsrc/service/hardware/device_io_ctrl_service.cpp +++ b/appsrc/service/hardware/device_io_ctrl_service.cpp @@ -37,42 +37,42 @@ static bool isInTestMode() { void DeviceIoControlService::initialize() { GET_TO_SERVICE(m_config); - REG_FN_VOID(AddLiquidPump_addLiquid, void()); + REG_FN_VOID(AddLiquidPump_addLiquid, void(void)); REG_FN(AddLiquidPump_run, void(int), rpm); - REG_FN_VOID(AddLiquidPump_drainLiquid, void()); - REG_FN_VOID(AddLiquidPump_stop, void()); + REG_FN_VOID(AddLiquidPump_drainLiquid, void(void)); + REG_FN_VOID(AddLiquidPump_stop, void(void)); REG_FN(SprayPump_start, void(int32_t), gpm); REG_FN(SprayPump_startInRPM, void(int32_t), rpm); - REG_FN_VOID(SprayPump_stop, void()); + REG_FN_VOID(SprayPump_stop, void(void)); REG_FN(Blower_ctrl, void(int32_t), val); - REG_FN_VOID(Blower_close, void()); - REG_FN_VOID(Blower_readEI, void()); + REG_FN_VOID(Blower_close, void(void)); + REG_FN_VOID(Blower_readEI, void(void)); REG_FN(AC_ctrl, void(int32_t), val); - REG_FN_VOID(AC_close, void()); - REG_FN_VOID(AC_readEI, void()); + REG_FN_VOID(AC_close, void(void)); + REG_FN_VOID(AC_readEI, void(void)); REG_FN(Heater_ctrl, void(int32_t), val); - REG_FN_VOID(Heater_close, void()); - REG_FN_VOID(Heater_readEI, void()); - REG_FN_VOID(Heater_readTemperature, void()); + REG_FN_VOID(Heater_close, void(void)); + REG_FN_VOID(Heater_readEI, void(void)); + REG_FN_VOID(Heater_readTemperature, void(void)); REG_FN(WarningLight_setState, void(int, int, int, int), r, g, b, warning); REG_FN(PosiPressureProp_setValve, void(int), val); - REG_FN_VOID(PosiPressureProp_readPos, void()); - REG_FN_VOID(PosiPressureProp_isBusy, void()); + REG_FN_VOID(PosiPressureProp_readPos, void(void)); + REG_FN_VOID(PosiPressureProp_isBusy, void(void)); REG_FN(NegaPressureProp_setValve, void(int32_t), val); - REG_FN_VOID(NegaPressureProp_readPos, void()); - REG_FN_VOID(NegaPressureProp_isBusy, void()); + REG_FN_VOID(NegaPressureProp_readPos, void(void)); + REG_FN_VOID(NegaPressureProp_isBusy, void(void)); REG_FN(AirLeakDetectTestModeCtrl_setMode, void(int32_t), val); - REG_FN_VOID(AirLeakDetectTestModeCtrl_getMode, void()); + REG_FN_VOID(AirLeakDetectTestModeCtrl_getMode, void(void)); REG_FN(ExtChSelector_selectCh, void(int32_t), val); REG_FN(ExtChSelector_trySelectCh, void(int32_t), val); - REG_FN_VOID(ExtChSelector_isOnline, void()); - REG_FN_VOID(WaterSensor_readEvaporationBin, void()); - REG_FN_VOID(WaterSensor_readDeviceBottom, void()); - REG_FN_VOID(ACPostPS_readPa, void()); - REG_FN_VOID(AirLeakDetectPS_readPa, void()); - REG_FN_VOID(LiquidWeightPS_readPa, void()); - REG_FN_VOID(SprayPumpPostPS_readPa, void()); - REG_FN_VOID(AddLiquidPumpPostPS_readPa, void()); + REG_FN_VOID(ExtChSelector_isOnline, void(void)); + REG_FN_VOID(WaterSensor_readEvaporationBin, void(void)); + REG_FN_VOID(WaterSensor_readDeviceBottom, void(void)); + REG_FN_VOID(ACPostPS_readPa, void(void)); + REG_FN_VOID(AirLeakDetectPS_readPa, void(void)); + REG_FN_VOID(LiquidWeightPS_readPa, void(void)); + REG_FN_VOID(SprayPumpPostPS_readPa, void(void)); + REG_FN_VOID(AddLiquidPumpPostPS_readPa, void(void)); if (isInTestMode()) { logger->warn("run in pc, skip initialize device io control service");