module_web.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef MODULE_WEB_H
  2. #define MODULE_WEB_H
  3. /**
  4. * @brief 与web通信的接口类,以及json工具类:tool_json
  5. * @author 戴月腾
  6. * @date 2018-08-25
  7. */
  8. #include <memory>
  9. #include <string>
  10. #include<vector>
  11. #include "rapidjson/prettywriter.h"
  12. #include "rapidjson/document.h"
  13. #include"config_file.h"
  14. #include"module_singleton_base.h"
  15. #include"module_i_thread.h"
  16. #include "websocket/wsClientMgr.h"
  17. struct ya_event;
  18. class module_web : public i_thread, public singleton_base<module_web>
  19. {
  20. private:
  21. friend class singleton_base<module_web>;
  22. module_web()
  23. {
  24. }
  25. public:
  26. /**
  27. * @brief 用来处理WEB发送的请求(web请求回调函数)
  28. * @param ID
  29. * @param name
  30. * @param data
  31. * @param need_ack
  32. * @param ack_resp
  33. */
  34. static void accept( int ID, std::string const& name,
  35. sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
  36. /**
  37. * @brief 注册web请求回调函数
  38. * @param MsgFuncList
  39. */
  40. void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
  41. {
  42. sleep_ms = std::stoi(config.get("service.interval_send_json_alarm_ms","10000"));
  43. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_META_DATA_CHANGED, &module_web::accept ) );
  44. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_REQUEST_ALL_DATA, &module_web::accept ) );
  45. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_DEAL_HELP, &module_web::accept ) );
  46. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_REQUEST, &module_web::accept ) );
  47. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST, &module_web::accept ) );
  48. MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CLEAR_CARD, &module_web::accept ) );//手动升井
  49. }
  50. /// web前端有用户登录时,反馈给web所有信息
  51. void response_login();
  52. private:
  53. /**
  54. * @brief 线程函数
  55. */
  56. void run();
  57. ///获取所有的告警事件
  58. void _get_all_events(std::vector<std::shared_ptr<ya_event>>& arr);
  59. ///在全局列表中删除已经处理或结束了的告警
  60. void _delete_end(std::vector<std::shared_ptr<ya_event>>& arr);
  61. };
  62. #endif // MODULE_WEB_H