Locate_communicator.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /*
  14. Error_manager Locate_communicator::locate_request(message::Locate_request_msg request,message::Locate_response_msg& result,unsigned int timeout)
  15. {
  16. std::string response_string;
  17. Error_manager code=m_nnxx_client.request(request.SerializeAsString(),response_string,timeout);
  18. if(code==SUCCESS)
  19. {
  20. //解析返回数据
  21. message::Locate_response_msg response;
  22. if(false==response.ParseFromString(response_string))
  23. {
  24. //解析response数据错误,
  25. // return Error_manager(LOCATE_RESPONSE_PARSE_ERROR,MAJOR_ERROR,"response string parse failed");
  26. }
  27. else if(response.error_manager().error_code()==SUCCESS)
  28. {
  29. result=response;
  30. return SUCCESS;
  31. }
  32. else
  33. {
  34. ///将response中的错误信息,转换成错误码,返回
  35. return Error_manager(Error_code(response.error_manager().error_code()),MAJOR_ERROR,response.error_manager().error_description().c_str());
  36. }
  37. }
  38. else if(code.get_error_level()==MINOR_ERROR)
  39. {
  40. //处理底层处理不了的错误
  41. }
  42. else if(code.get_error_level()==MAJOR_ERROR)
  43. {
  44. //本模块功能失败的错误,向上抛出
  45. return code;
  46. }
  47. }
  48. */
  49. Error_manager Locate_communicator::create_locate_communicator(std::string str_ip,int port)
  50. {
  51. Error_manager code=SUCCESS;
  52. if(mp_locate_communicator==NULL)
  53. {
  54. mp_locate_communicator=new Locate_communicator();
  55. char connect_str[255]={0};
  56. sprintf(connect_str,"tcp://%s:%d",str_ip.c_str(),port);
  57. code=mp_locate_communicator->m_nnxx_client.connect(connect_str);
  58. return code;
  59. } else
  60. {
  61. return code;
  62. }
  63. }
  64. Locate_communicator* Locate_communicator::get_instance()
  65. {
  66. return mp_locate_communicator;
  67. }