123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- //
- // Created by huli on 2020/7/2.
- //
- #include "system_executor.h"
- System_executor::System_executor()
- {
- }
- System_executor::~System_executor()
- {
- system_executor_uninit();
- }
- //初始化
- Error_manager System_executor::system_executor_init(int threads_size)
- {
- m_thread_pool.thread_pool_init(threads_size);
- m_system_executor_status = SYSTEM_EXECUTOR_READY;
- return Error_code::SUCCESS;
- }
- //反初始化
- Error_manager System_executor::system_executor_uninit()
- {
- m_thread_pool.thread_pool_uninit();
- m_system_executor_status = SYSTEM_EXECUTOR_UNKNOW;
- return Error_code::SUCCESS;
- }
- //检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
- Error_manager System_executor::check_msg(Communication_message* p_msg)
- {
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
-
- //检查消息类型
- switch ( p_msg->get_message_type() )
- {
- case Communication_message::Message_type::eDispatch_request_msg:
- {
- message::Dispatch_request_msg t_dispatch_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_dispatch_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_dispatch_request_msg = "<< t_dispatch_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eDispatch_response_msg:
- {
- message::Dispatch_response_msg t_dispatch_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_dispatch_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_dispatch_response_msg = "<< t_dispatch_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eDispatch_status_msg:
- {
- message::Dispatch_terminal_status_msg t_dispatch_terminal_status_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_dispatch_terminal_status_msg.ParseFromString(p_msg->get_message_buf()))
- {
- if ( t_dispatch_terminal_status_msg.id_struct().unit_id() == 0 )
- {
- LOG(INFO) << " t_dispatch_terminal_status_msg = "<< t_dispatch_terminal_status_msg.DebugString() << " -- " << this;
- }
- }
- break;
- }
- // case Communication_message::Message_type::eParkspace_allocation_status_msg:
- // {
- // message::Parkspace_allocation_status_msg t_Parkspace_allocation_status_msg;
- // //针对消息类型, 对消息进行二次解析
- // if (t_Parkspace_allocation_status_msg.ParseFromString(p_msg->get_message_buf()))
- // {
- // LOG(INFO) << " t_Parkspace_allocation_status_msg = "<< t_Parkspace_allocation_status_msg.DebugString() << " -- " << this;
- // }
- // break;
- // }
- case Communication_message::Message_type::eParkspace_allocation_request_msg:
- {
- message::Parkspace_allocation_request_msg t_Parkspace_allocation_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_allocation_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_allocation_request_msg = "<< t_Parkspace_allocation_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_allocation_response_msg:
- {
- message::Parkspace_allocation_response_msg t_Parkspace_allocation_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_allocation_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_allocation_response_msg = "<< t_Parkspace_allocation_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_search_request_msg:
- {
- message::Parkspace_search_request_msg t_Parkspace_search_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_search_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_search_request_msg = "<< t_Parkspace_search_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_search_response_msg:
- {
- message::Parkspace_search_response_msg t_Parkspace_search_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_search_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_search_response_msg = "<< t_Parkspace_search_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_release_request_msg:
- {
- message::Parkspace_release_request_msg t_Parkspace_release_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_release_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_release_request_msg = "<< t_Parkspace_release_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_release_response_msg:
- {
- message::Parkspace_release_response_msg t_Parkspace_release_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_release_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_release_response_msg = "<< t_Parkspace_release_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_force_update_request_msg:
- {
- message::Parkspace_force_update_request_msg t_Parkspace_force_update_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_force_update_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_force_update_request_msg = "<< t_Parkspace_force_update_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_force_update_response_msg:
- {
- message::Parkspace_force_update_response_msg t_Parkspace_force_update_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_force_update_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_force_update_response_msg = "<< t_Parkspace_force_update_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_confirm_alloc_request_msg:
- {
- message::Parkspace_confirm_alloc_request_msg t_Parkspace_confirm_alloc_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_confirm_alloc_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_confirm_alloc_request_msg = "<< t_Parkspace_confirm_alloc_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_confirm_alloc_response_msg:
- {
- message::Parkspace_confirm_alloc_response_msg t_Parkspace_confirm_alloc_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_confirm_alloc_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_confirm_alloc_response_msg = "<< t_Parkspace_confirm_alloc_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_refresh_request_msg:
- {
- message::Parkspace_refresh_request_msg t_Parkspace_refresh_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_refresh_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- // LOG(INFO) << " t_Parkspace_refresh_request_msg = "<< t_Parkspace_refresh_request_msg.DebugString() << " -- " << this;
- LOG(INFO) << " t_Parkspace_refresh_request_msg = "<< t_Parkspace_refresh_request_msg.base_info().msg_type() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_allocation_data_response_msg:
- {
- message::Parkspace_allocation_data_msg t_Parkspace_allocation_data_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_allocation_data_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- // LOG(INFO) << " t_Parkspace_allocation_data_response_msg = "<< t_Parkspace_allocation_data_response_msg.DebugString() << " -- " << this;
- // LOG(INFO) << " t_Parkspace_allocation_data_response_msg = "<< t_Parkspace_allocation_data_response_msg.base_info().msg_type() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_manual_search_request_msg:
- {
- message::Parkspace_manual_search_request_msg t_Parkspace_manual_search_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_manual_search_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_manual_search_request_msg = "<< t_Parkspace_manual_search_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eParkspace_manual_search_response_msg:
- {
- message::Parkspace_manual_search_response_msg t_Parkspace_manual_search_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Parkspace_manual_search_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Parkspace_manual_search_response_msg = "<< t_Parkspace_manual_search_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eStore_command_request_msg:
- {
- message::Store_command_request_msg t_Store_command_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Store_command_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Store_command_request_msg = "<< t_Store_command_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eStore_command_response_msg:
- {
- message::Store_command_response_msg t_Store_command_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Store_command_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Store_command_response_msg = "<< t_Store_command_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::ePickup_command_request_msg:
- {
- message::Pickup_command_request_msg t_Pickup_command_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Pickup_command_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Pickup_command_request_msg = "<< t_Pickup_command_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::ePickup_command_response_msg:
- {
- message::Pickup_command_response_msg t_Pickup_command_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Pickup_command_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Pickup_command_response_msg = "<< t_Pickup_command_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eEntrance_manual_operation_msg:
- {
- message::Entrance_manual_operation_msg t_Entrance_manual_operation_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Entrance_manual_operation_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Entrance_manual_operation_msg = "<< t_Entrance_manual_operation_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eProcess_manual_operation_msg:
- {
- message::Process_manual_operation_msg t_Process_manual_operation_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Process_manual_operation_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Process_manual_operation_msg = "<< t_Process_manual_operation_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eNotify_request_msg:
- {
- message::Notify_request_msg t_Notify_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Notify_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Notify_request_msg = "<< t_Notify_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eNotify_response_msg:
- {
- message::Notify_response_msg t_Notify_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Notify_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Notify_response_msg = "<< t_Notify_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eGround_detect_request_msg:
- {
- message::Ground_detect_request_msg t_Ground_detect_request_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Ground_detect_request_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Ground_detect_request_msg = "<< t_Ground_detect_request_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eGround_detect_response_msg:
- {
- message::Ground_detect_response_msg t_Ground_detect_response_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Ground_detect_response_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Ground_detect_response_msg = "<< t_Ground_detect_response_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eTerminal_status_msg:
- {
- message::Terminal_status_msg t_Terminal_status_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Terminal_status_msg.ParseFromString(p_msg->get_message_buf()))
- {
- //LOG(INFO) << " t_Terminal_status_msg = "<< t_Terminal_status_msg.DebugString() << " -- " << this;
- }
- break;
- }
- case Communication_message::Message_type::eNotify_status_msg:
- {
- message::Notify_status_msg t_Notify_status_msg;
- //针对消息类型, 对消息进行二次解析
- if (t_Notify_status_msg.ParseFromString(p_msg->get_message_buf()))
- {
- LOG(INFO) << " t_Notify_status_msg = "<< t_Notify_status_msg.DebugString() << " -- " << this;
- }
- break;
- }
- default :
- ;
- break;
- }
- //无效的消息,
- return Error_manager(Error_code::INVALID_MESSAGE, Error_level::NEGLIGIBLE_ERROR,
- " INVALID_MESSAGE error ");
- }
- //检查执行者的状态, 判断能否处理这条消息,
- Error_manager System_executor::check_executer(Communication_message* p_msg)
- {
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
- //检查执行线程池
- Error_manager t_executor_result = System_executor::get_instance_references().check_status();
- if (t_executor_result.get_error_level() == NEGLIGIBLE_ERROR)//一级故障,轻微故障,
- {
- std::cout << "executer_is_busy , " << std::endl;
- //返回繁忙之后, 通信模块1秒后再次调用check
- return Error_code::COMMUNICATION_EXCUTER_IS_BUSY;
- }
- else if (t_executor_result.get_error_level() > NEGLIGIBLE_ERROR)
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_ERROR, Error_level::MINOR_ERROR,
- "System_executor::get_instance_references().check_status(); fun error ");
- }
- return Error_code::SUCCESS;
- }
- //处理消息的执行函数
- Error_manager System_executor::execute_msg(Communication_message* p_msg)
- {
- if ( p_msg == NULL )
- {
- return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
- " POINTER IS NULL ");
- }
- return Error_code::SUCCESS;
- }
- //检查状态
- Error_manager System_executor::check_status()
- {
- if ( m_system_executor_status == SYSTEM_EXECUTOR_READY )
- {
- if ( m_thread_pool.thread_is_full_load() == false )
- {
- return Error_code::SUCCESS;
- }
- else
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_BUSY, Error_level::NEGLIGIBLE_ERROR,
- " System_executor::check_status error ");
- }
- }
- else
- {
- return Error_manager(Error_code::SYSTEM_EXECUTOR_STATUS_ERROR, Error_level::MINOR_ERROR,
- " System_executor::check_status error ");
- }
- }
- //定时发送状态信息
- Error_manager System_executor::encapsulate_send_status()
- {
- return Error_code::SUCCESS;
- }
- //定时发送 调度管理的状态
- Error_manager System_executor::encapsulate_send_dispatch_manager_status()
- {
- return Error_code::SUCCESS;
- }
- //判断是否为待机,如果已经准备好,则可以执行任务。
- bool System_executor::is_ready()
- {
- if ( m_system_executor_status == SYSTEM_EXECUTOR_READY && m_thread_pool.thread_is_full_load() == false )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- System_executor::System_executor_status System_executor::get_system_executor_status()
- {
- return m_system_executor_status;
- }
|