⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket_create_message_protocol_handler.cpp

📁 程序实现了在ip协议之上加一层RUDP协议
💻 CPP
字号:
// Socket_Create_Message_Protocol_Handler.cpp: implementation of the Socket_Create_Message_Protocol_Handler class.
//
//////////////////////////////////////////////////////////////////////

#include "Socket_Create_Message_Protocol_Handler.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

Socket_Create_Message_Protocol_Handler* Socket_Create_Message_Protocol_Handler::pinstance = NULL;// 初始化指针

Socket_Create_Message_Protocol_Handler::Socket_Create_Message_Protocol_Handler()
{

}

Socket_Create_Message_Protocol_Handler::~Socket_Create_Message_Protocol_Handler()
{

}


/*
  factory pattern, make sure there is only one object of this class
*/
Socket_Create_Message_Protocol_Handler* Socket_Create_Message_Protocol_Handler::get_instance ()
{
	if (pinstance == NULL)
	{
	pinstance = new Socket_Create_Message_Protocol_Handler; 
	}
	return pinstance;
}


/*
  once socket layer receive an legal packet,need to 
  return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_App_Packet_Receive(char* buf, unsigned int deviceID, int RUDPTag,int packet_length)
{
	Message  msg;   
	msg.Device = DEVICE_TRANSMIT;
	msg.Event = App_Receive_Success;
	msg.SubMsg = RUDPTag;
	msg.DataPtr = buf + sizeof(RUDP);
	msg.Length = packet_length;
	msg.Data[0] = deviceID;
	msg.Data[1] = 0;
	return msg;
}


/*
  once socket layer receive ack from the peer side, need to 
  return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_App_Send_Success(Message *msgptr)
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = App_Send_Success;
	msg.SubMsg = msgptr->SubMsg;
	msg.Length = msgptr->Length;
	msg.DataPtr = msgptr->DataPtr;
	msg.Data[0] = msgptr->Data[0];
	msg.Data[1] = msgptr->Data[1];
	return msg;
}


/*
  once socket layer send packet failure, need to 
  return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_App_Send_Failure(Message* msgptr)
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = App_Send_Failure;
	msg.SubMsg = msgptr->SubMsg;
	msg.Length = msgptr->Length;
	msg.DataPtr = msgptr->DataPtr;
	msg.Data[0] = msgptr->Data[0];
	msg.Data[1] = msgptr->Data[1];
	return msg;
}


/*
  once socket layer receive RUDP of illegal user or peer side is unreachable,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_App_Request_Conn_Failure(unsigned int deviceID, unsigned int failure_id)
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = App_Request_Conn_Failure;
	msg.SubMsg = failure_id;
	msg.Length = 0;
	msg.DataPtr = NULL;
	msg.Data[0] = deviceID;
	msg.Data[1] = 0;
	return msg;
}


/*
  once socket layer receive legal user login,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_App_Connected_Notify(unsigned int d_deviceID)
{
  Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = App_Connected_Notify;
	msg.SubMsg = d_deviceID;
	msg.Length = 0;
	msg.DataPtr = NULL;
	msg.Data[0] = d_deviceID;
	msg.Data[1] = 0;
	return msg;
}


/*
  once socket layer can not send RUDP successflly,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_Socket_Link_Lost(Message *msgptr)
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = Socket_Link_Lost;
	msg.SubMsg = 0;
	msg.Length = 0;
	msg.DataPtr = NULL;
	msg.Data[0] = msgptr->Data[0];
	msg.Data[1] = msgptr->Data[1];
	return msg;
}


/*
  once socket buffer is no enough,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_Socket_Buff_No_Enough()
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = Socket_Buff_Not_Enough;
	msg.SubMsg = 80;
	msg.Length = 0;
	msg.DataPtr = NULL;
	msg.Data[0] = 0;
	msg.Data[1] = 0;
	return msg;
}


/*
  once socket buffer is full,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_Socket_Buff_Full()
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = Socket_Buff_Full;
	msg.SubMsg =100;
	msg.Length =0;
	msg.DataPtr = NULL;
	msg.Data[0] = 0;
	msg.Data[1] = 0;
	return msg;
}


/*
  once socket buffer is enough,
  need to return such message to notify application
*/
Message Socket_Create_Message_Protocol_Handler::f_SOCKET_Socket_Buff_Enough()
{
	Message  msg;
	msg.Device = DEVICE_SYSTEM;
	msg.Event = Socket_Buff_Enough;
	msg.SubMsg = 30;
	msg.Length = 0;
	msg.DataPtr = NULL;
	msg.Data[0] = 0;
	msg.Data[1] = 0;
	return msg;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -