module_web.h 2.1 KB

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