//
// Created by huli on 2023/1/3.
//

#include "dispatch_network.h"
#include "../dispatch/dispatch_manager.h"

Dispatch_network::Dispatch_network()
{

}

Dispatch_network::~Dispatch_network()
{

}

//初始化 通信 模块。如下三选一
Error_manager Dispatch_network::network_init()
{
	return Network_base::network_init();
}

//初始化 通信 模块。如下三选一
Error_manager Dispatch_network::network_init(int dispatch_id)
{
//	return Network_base::network_init();
	switch ( dispatch_id )
	{
		case 0:
		{
			return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_A);
			break;
		}
		case 1:
		{
			return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_B);
			break;
		}
		case 2:
		{
			return Network_base::network_init_from_protobuf(NETKORK_PARAMETER_PATH_C);
			break;
		}
		default:
		{
			return Error_manager(Error_code::COMMUNICATION_READ_PROTOBUF_ERROR, Error_level::MINOR_ERROR,
								 " Dispatch_network::communication_init dispatch_id error ");
			break;
		}
	}
	return Error_code::SUCCESS;
}

//检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
Error_manager Dispatch_network::check_msg(Network_message*  p_msg)
{
return Error_code::SUCCESS;
}

//检查执行者的状态, 判断能否处理这条消息, 需要子类重载
Error_manager Dispatch_network::check_executer(Network_message*  p_msg)
{
	return Error_code::SUCCESS;
}

//处理消息, 需要子类重载
Error_manager Dispatch_network::execute_msg(Network_message* p_msg)
{
	return Dispatch_manager::get_instance_references().execute_network_message_new(p_msg);
}

//定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
Error_manager Dispatch_network::auto_encapsulate_status()
{
	return Error_code::SUCCESS;
}


























