1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // Created by zx on 2020/6/18.
- //
- #include "Locate_communicator.h"
- //#include "locate_message.pb.h"
- Locate_communicator* Locate_communicator::mp_locate_communicator=NULL;
- Locate_communicator::Locate_communicator()
- {
- }
- Locate_communicator::~Locate_communicator()
- {
- }
- Error_manager Locate_communicator::locate_request(message::Locate_request_msg request,message::Locate_response_msg& result,unsigned int timeout)
- {
- /*
- * 检查request合法性,以及模块状态
- */
- std::string response_string;
- Error_manager code=m_nnxx_client.request(request.SerializeAsString(),response_string,timeout);
- if(code==SUCCESS)
- {
- //解析返回数据
- message::Locate_response_msg response;
- if(false==response.ParseFromString(response_string))
- {
- //解析response数据错误,
- // return Error_manager(LOCATE_RESPONSE_PARSE_ERROR,MAJOR_ERROR,"response string parse failed");
- }
- else if(response.error_code()==SUCCESS)
- {
- result=response;
- return SUCCESS;
- }
- else
- {
- ///将response中的错误信息,转换成错误码,返回
- return Error_manager(Error_code(response.error_code()),MAJOR_ERROR,response.error_description().c_str());
- }
- }
- else if(code.get_error_level()==MINOR_ERROR)
- {
- //处理底层处理不了的错误
- }
- else if(code.get_error_level()==MAJOR_ERROR)
- {
- //本模块功能失败的错误,向上抛出
- return code;
- }
- }
- Error_manager Locate_communicator::create_locate_communicator(std::string str_ip,int port)
- {
- Error_manager code=SUCCESS;
- if(mp_locate_communicator==NULL)
- {
- mp_locate_communicator=new Locate_communicator();
- char connect_str[255]={0};
- sprintf(connect_str,"tcp://%s:%d",str_ip.c_str(),port);
- code=mp_locate_communicator->m_nnxx_client.connect(connect_str);
- return code;
- } else
- {
- return code;
- }
- }
- Locate_communicator* Locate_communicator::get_instance()
- {
- return mp_locate_communicator;
- }
|