// // Created by zx on 2020/7/16. // #include "store_terminal.h" #include "Terminal_communication.h" store_terminal::store_terminal(int terminal_id) { m_terminal_id=terminal_id; m_thread_safe_queue= nullptr; m_thread_safe_output_queue=nullptr; } store_terminal::~store_terminal() { m_exit_cond.set_pass_ever(true); if(m_pthread) { if(m_pthread->joinable()) m_pthread->join(); delete m_pthread; m_pthread=nullptr; } } Error_manager store_terminal::init(threadsafe_queue* input, threadsafe_queue* output) { m_thread_safe_queue=input; m_thread_safe_output_queue=output; m_exit_cond.reset(false,false,false); m_pthread=new std::thread(storing_thread,this); return SUCCESS; } Error_manager store_terminal::storing(message::Car_info& car_info) { message::Store_command_request_msg request; message::Base_info base_info; base_info.set_msg_type(message::eStore_command_request_msg); base_info.set_sender(message::eTerminor); base_info.set_receiver(message::eMain); request.mutable_base_info()->CopyFrom(base_info); request.mutable_car_info()->CopyFrom(car_info); message::Locate_information locate_info; locate_info.set_locate_x(0.9); locate_info.set_locate_y(2.25); locate_info.set_locate_angle(90.0); locate_info.set_locate_wheel_base(2.7); locate_info.set_locate_width(car_info.car_width()); locate_info.set_locate_height(car_info.car_height()); locate_info.set_locate_correct(true); request.mutable_locate_information()->CopyFrom(locate_info); request.set_terminal_id(m_terminal_id); //发送停车请求 Error_manager code; message::Store_command_response_msg response; code=Terminal_communication::get_instance_pointer()->store_request(request,response); if(code!=SUCCESS) { std::cout<<" request_error: "<get_storing_statu(car_info.license(), msg); if (code != SUCCESS) { if(last_signal==true) { if (m_thread_safe_output_queue) m_thread_safe_output_queue->push(car_info); return SUCCESS; } } else { last_signal=true; } } return FAILED; } void store_terminal::storing_thread(store_terminal* pStore) { while(pStore->m_exit_cond.wait_for_millisecond(200)==false) { message::Car_info car_info; if(pStore->m_thread_safe_queue== nullptr) continue; if(pStore->m_thread_safe_queue->try_pop(car_info)==true) { LOG(INFO)<<"车辆:"<m_terminal_id<<"---,剩余in:" <m_thread_safe_queue->size(); Error_manager code=pStore->storing(car_info); LOG_IF(INFO,code==SUCCESS)<<"车辆:"<m_terminal_id<<"----------,剩余in:" <m_thread_safe_queue->size(); LOG_IF(ERROR,code!=SUCCESS)<<"车辆:"<m_terminal_id<<"---------,剩余in:" <m_thread_safe_queue->size(); } } }