Locate_communicator.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Created by zx on 2020/6/18.
  3. //
  4. #include "Locate_communicator.h"
  5. //#include "locate_message.pb.h"
  6. Locate_communicator* Locate_communicator::mp_locate_communicator=NULL;
  7. Locate_communicator::Locate_communicator()
  8. {
  9. }
  10. Locate_communicator::~Locate_communicator()
  11. {
  12. }
  13. Error_manager Locate_communicator::locate_request(message::Locate_request_msg request,message::Locate_response_msg& result,unsigned int timeout)
  14. {
  15. /*
  16. * 检查request合法性,以及模块状态
  17. */
  18. /*std::string response_string;
  19. Error_manager code=m_nnxx_client.request(request.SerializeAsString(),response_string,timeout);
  20. if(code==SUCCESS)
  21. {
  22. //解析返回数据
  23. message::Locate_response_msg response;
  24. if(false==response.ParseFromString(response_string))
  25. {
  26. //解析response数据错误,
  27. // return Error_manager(LOCATE_RESPONSE_PARSE_ERROR,MAJOR_ERROR,"response string parse failed");
  28. }
  29. else if(response.error_manager().error_code()==SUCCESS)
  30. {
  31. result=response;
  32. return SUCCESS;
  33. }
  34. else
  35. {
  36. ///将response中的错误信息,转换成错误码,返回
  37. return Error_manager(Error_code(response.error_manager().error_code()),MAJOR_ERROR,response.error_manager().error_description().c_str());
  38. }
  39. }
  40. else if(code.get_error_level()==MINOR_ERROR)
  41. {
  42. //处理底层处理不了的错误
  43. }
  44. else if(code.get_error_level()==MAJOR_ERROR)
  45. {
  46. //本模块功能失败的错误,向上抛出
  47. return code;
  48. }*/
  49. return SUCCESS;
  50. }
  51. Error_manager Locate_communicator::create_locate_communicator(std::string str_ip,int port)
  52. {
  53. /*Error_manager code=SUCCESS;
  54. if(mp_locate_communicator==NULL)
  55. {
  56. mp_locate_communicator=new Locate_communicator();
  57. char connect_str[255]={0};
  58. sprintf(connect_str,"tcp://%s:%d",str_ip.c_str(),port);
  59. code=mp_locate_communicator->m_nnxx_client.connect(connect_str);
  60. return code;
  61. } else
  62. {
  63. return code;
  64. }*/
  65. }
  66. Locate_communicator* Locate_communicator::get_instance()
  67. {
  68. return mp_locate_communicator;
  69. }