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.

86 lines
2.1 KiB

1 year ago
  1. //
  2. // Created by zwsd
  3. //
  4. #pragma once
  5. #include <fstream>
  6. #include <iostream>
  7. #include <list>
  8. #include <map>
  9. #include <memory>
  10. #include <set>
  11. #include <sstream>
  12. #include <string>
  13. #include <vector>
  14. #include "iflytop/components/restful_server/restful_server.hpp"
  15. #include "iflytop/core/components/jobs/work_queue.hpp"
  16. #include "iflytop/core/components/timer/simple_timer.hpp"
  17. #include "iflytop/core/spdlogfactory/logger.hpp"
  18. #include "iflytoplinuxsdk/src/iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp"
  19. #include "service/device_state_service.hpp"
  20. #include "service/disinfection_ctl_service.hpp"
  21. //
  22. #include "configs/gconfig.hpp"
  23. #include "iflytop/components/iflytop_front_end_service/iflytop_front_end_service.hpp"
  24. #include "zservice_container/zservice_container.hpp"
  25. //
  26. //
  27. #include "db/db_service.hpp"
  28. #include "iflytop/components/zcanreceiver/zcanhost.hpp"
  29. #include "service/data_export_service.hpp"
  30. #include "service/device_io_control_service.hpp"
  31. #include "service/disinfection_logs_manager.hpp"
  32. /**
  33. * @brief
  34. *
  35. * service: FrontMsgProcesser
  36. *
  37. * :
  38. * :
  39. * :
  40. * :
  41. *
  42. */
  43. namespace iflytop {
  44. using namespace std;
  45. using namespace core;
  46. class FrontMsgProcesser : public enable_shared_from_this<FrontMsgProcesser> {
  47. ENABLE_LOGGER(FrontMsgProcesser);
  48. public:
  49. typedef std::function<void(json& cmd, json& receipt)> MsgProcesserFn_t;
  50. private:
  51. map<string, MsgProcesserFn_t> m_msgProcesserMap;
  52. public:
  53. FrontMsgProcesser(){};
  54. void initialize();
  55. void processMsg(json& cmd, json& receipt);
  56. void registerMsgProcesser(const string& cmdName, MsgProcesserFn_t fn);
  57. };
  58. static inline void getJsonValFromJson(json j, int& val) {
  59. if (j.is_string()) {
  60. string valstr = j;
  61. val = atoi(valstr.c_str());
  62. } else if (j.is_number()) {
  63. val = j;
  64. } else {
  65. throw std::runtime_error("getJsonValFromJson(int) error");
  66. }
  67. }
  68. template <typename T>
  69. static inline T jsonGet(json j) {
  70. T val;
  71. getJsonValFromJson(j, val);
  72. return val;
  73. }
  74. #define BIND(func) bind(&func, shared_from_this(), placeholders::_1, placeholders::_2)
  75. } // namespace iflytop