module_web.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "module_web.h"
  2. #include"module_const.h"
  3. #include"module_call_help.h"
  4. #include"module_call.h"
  5. #include"module_area.h"
  6. void module_web::accept( int ID, std::string const& name,
  7. sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
  8. {
  9. log_debug("收到web发来的数据");
  10. if(data->get_flag() == sio::message::flag_object)
  11. {
  12. log_error("发来的数据不是对象");
  13. return;
  14. }
  15. std::string cmd = data->get_map()[JSON_ROOT_KEY_CMD]->get_string();
  16. if(cmd.empty())
  17. {
  18. log_error("cmd字段为空");
  19. return;
  20. }
  21. if (JSON_CMD_VALUE_REQUEST_ALL_DATA == cmd)//web登录请求所有信息
  22. {
  23. response_login();
  24. }
  25. else if(JSON_CMD_VALUE_DEAL_HELP == cmd) // 处理呼救信息
  26. {
  27. module_call_help::instance()->accept_deal_help(data->get_map()[JSON_ROOT_KEY_DATA]->get_map());
  28. }
  29. else
  30. {
  31. std::string json=data->get_map()[JSON_ROOT_KEY_DATA]->get_string();
  32. rapidjson::Document doc;
  33. doc.Parse(json.c_str());
  34. if(doc.HasParseError())
  35. {
  36. log_error("发来的data字段数据有错误");
  37. return;
  38. }
  39. if(JSON_CMD_VALUE_CALL_CARD_REQUEST == cmd)//呼叫
  40. {
  41. module_call::instance()->accept_call(doc);
  42. }
  43. else if(JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST == cmd)//取消呼叫
  44. {
  45. module_call::instance()->accept_cancel(doc);
  46. }
  47. }
  48. }
  49. void module_web::init(std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE>& MsgFuncList)
  50. {
  51. // MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_REQUEST_ALL_DATA, &module_web::accept ) );
  52. // MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_DEAL_HELP, &module_web::accept ) );
  53. // MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_REQUEST, &module_web::accept ) );
  54. // MsgFuncList.insert( std::make_pair( JSON_CMD_VALUE_CALL_CARD_CANCEL_REQUEST, &module_web::accept ) );
  55. }
  56. void module_web::response_login()
  57. {
  58. rapidjson::Document doc(rapidjson::kObjectType);
  59. auto& allocator = doc.GetAllocator();
  60. rapidjson::Value nodes(rapidjson::kArrayType);
  61. //所有的呼叫信息
  62. std::string str=module_call::instance()->accept_login();
  63. if(!str.empty())
  64. {
  65. nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator);
  66. }
  67. //所有的呼救信息
  68. str=module_call_help::instance()->response_login();
  69. if(!str.empty())
  70. {
  71. nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator);
  72. }
  73. //所有其他告警
  74. str=module_area::instance()->response_login();
  75. if(!str.empty())
  76. {
  77. nodes.PushBack(rapidjson::StringRef(str.c_str()), allocator);
  78. }
  79. if(nodes.Size()>0)
  80. {
  81. doc.AddMember(JSON_ROOT_KEY_CMD,JSON_CMD_VALUE_RESPONSE_ALL_DATA, allocator);
  82. doc.AddMember(JSON_ROOT_KEY_VERSION, INTERFACE_VERSION, allocator);
  83. doc.AddMember(JSON_ROOT_KEY_DATA, nodes, allocator);
  84. swsClientMgr.send(JSON_CMD_VALUE_PUSH, tool_json::doc_to_json(doc));
  85. }
  86. }