1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #ifndef MODULE_WEB_H
- #define MODULE_WEB_H
- /**
- * @brief 与web通信的接口类,以及json工具类:tool_json
- * @author 戴月腾
- * @date 2018-08-25
- */
- #include <memory>
- #include <string>
- #include"module_const.h"
- #include "rapidjson/prettywriter.h"
- #include "rapidjson/document.h"
- #include "websocket/wsClientMgr.h"
- class module_web : public i_thread, public singleton_base<module_web>
- {
- private:
- friend class singleton_base<module_web>;
- module_web()
- {
- }
- public:
- /**
- * @brief 用来处理WEB发送的请求(web请求回调函数)
- * @param ID
- * @param name
- * @param data
- * @param need_ack
- * @param ack_resp
- */
- static void accept( int ID, std::string const& name,
- sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp );
- /**
- * @brief 注册web请求回调函数
- * @param MsgFuncList
- */
- void init(config_file& config, std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
- {
- sleep_ms = std::stoi(config.get("service.interval_send_json_alarm","10000"));
- MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_REQUEST_ALL_DATA, &module_web::accept ) );
- MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_DEAL_HELP, &module_web::accept ) );
- MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_REQUEST, &module_web::accept ) );
- MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST, &module_web::accept ) );
- MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CLEAR_CARD, &module_web::accept ) );//手动升井
- }
- /// web前端有用户登录时,反馈给web所有信息
- void response_login();
- private:
- /**
- * @brief 线程函数
- */
- void run();
- ///获取所有的告警事件
- void get_all_events(std::vector<std::shared_ptr<ya_event>>& arr)
- {
- auto _map = event_list::instance()->m_map;
- auto it_map = _map.begin();
- for(;it_map!=_map.end();++it_map)
- {
- arr.push_back(it_map->second);
- }
- }
- ///在全局列表中删除已经处理或结束了的告警
- void delete_end(std::vector<std::shared_ptr<ya_event>>& arr)
- {
- std::vector<uint64_t> todelete;
- auto arr_iter = arr.begin();
- for(;arr_iter!=arr.end();++arr_iter)
- {
- if((*arr_iter)->is_end())//删除掉已经处理的
- {
- todelete.push_back((*arr_iter)->get_list_id());
- }
- }
- if(todelete.size())
- {
- event_list::instance()->remove(todelete);
- }
- }
- };
- #endif // MODULE_WEB_H
|