#include "module_web.h" #include"module_const.h" #include"module_call_help.h" #include"module_call.h" #include"module_area.h" void module_web::accept( int ID, std::string const& name, sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp ) { log_debug("收到web发来的数据"); if(data->get_flag() == sio::message::flag_object) { log_error("发来的数据不是对象"); return; } std::string cmd = data->get_map()[JSON_ROOT_KEY_CMD]->get_string(); if(cmd.empty()) { log_error("cmd字段为空"); return; } if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)//web登录请求所有信息 { response_login(); } else if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息 { module_call_help::instance()->accept_deal_help(data->get_map()[JSON_ROOT_KEY_DATA]->get_map()); } else { std::string json=data->get_map()[JSON_ROOT_KEY_DATA]->get_string(); rapidjson::Document doc; doc.Parse(json.c_str()); if(doc.HasParseError()) { log_error("发来的data字段数据有错误"); return; } if(JSON_CMD_VALUE_CALL_CARD_REQUEST == cmd)//呼叫 { module_call::instance()->accept_call(doc); } else if(JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST == cmd)//取消呼叫 { module_call::instance()->accept_cancel(doc); } } } void module_web::init(std::map& MsgFuncList) { // 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 ) ); } void module_web::response_login() { rapidjson::Document doc(rapidjson::kObjectType); auto& allocator = doc.GetAllocator(); rapidjson::Value nodes(rapidjson::kArrayType); //所有的呼叫信息 std::string str=module_call::instance()->accept_login(); if(!str.empty()) { nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator); } //所有的呼救信息 str=module_call_help::instance()->response_login(); if(!str.empty()) { nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator); } //所有其他告警 str=module_area::instance()->response_login(); if(!str.empty()) { nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator); } if(nodes.Size()>0) { doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_RESPONSE_ALL_DATA, allocator); doc.AddMember(JSON_ROOT_KEY_VERSION, INTERFACE_VERSION, allocator); doc.AddMember(JSON_ROOT_KEY_DATA, nodes, allocator); swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc)); } }