// // Created by zx on 2020/7/16. // #include "pickup_terminal.h" #include "Terminal_communication.h" pickup_terminal::pickup_terminal(int terminal_id) { m_terminal_id=terminal_id; m_thread_safe_queue= nullptr; } Error_manager pickup_terminal::init(threadsafe_queue* queue) { m_thread_safe_queue=queue; m_exit_cond.reset(false,false,false); m_pthread=new std::thread(pickup_thread,this); return SUCCESS; } pickup_terminal::~pickup_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 pickup_terminal::pickup(message::Car_info& car_info) { message::Pickup_command_request_msg request; message::Base_info base_info; base_info.set_msg_type(message::ePickup_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); request.set_terminal_id(m_terminal_id); //发送停车请求 Error_manager code; message::Pickup_command_response_msg response; code=Terminal_communication::get_instance_pointer()->pickup_request(request,response); if(code!=SUCCESS) { std::cout<<"取车请求失败:"<get_picking_statu(car_info.license(), msg); if (code != SUCCESS) { if(last_signal==true) { return SUCCESS; } } else { last_signal=true; } } return FAILED; } void pickup_terminal::pickup_thread(pickup_terminal* picker) { while(picker->m_exit_cond.wait_for_millisecond(200)==false) { message::Car_info car_info; if(picker->m_thread_safe_queue== nullptr) continue; if(picker->m_thread_safe_queue->try_pop(car_info)==true) { /*LOG(WARNING)<<"取车终端:"<m_terminal_id<<",车辆:"<m_thread_safe_queue->size();*/ Error_manager code=picker->pickup(car_info); } } }