2013-12-11 21:45:43 +01:00
|
|
|
#ifndef NETWORK_API_NETWORK_CALLBACK_HELPER_H
|
|
|
|
#define NETWORK_API_NETWORK_CALLBACK_HELPER_H
|
|
|
|
|
|
|
|
/////////////////////////////////////
|
|
|
|
// Created by Dennis Andersen 2013 //
|
|
|
|
/////////////////////////////////////
|
|
|
|
|
2013-12-12 10:36:55 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2013-12-11 21:45:43 +01:00
|
|
|
namespace Oyster
|
|
|
|
{
|
|
|
|
namespace Network
|
|
|
|
{
|
|
|
|
enum NetworkProtocolCallbackType
|
|
|
|
{
|
|
|
|
NetworkProtocolCallbackType_Function,
|
|
|
|
NetworkProtocolCallbackType_Object,
|
|
|
|
NetworkProtocolCallbackType_Unknown = -1,
|
|
|
|
};
|
|
|
|
enum NetworkClientCallbackType
|
|
|
|
{
|
|
|
|
NetworkClientCallbackType_Function,
|
|
|
|
NetworkClientCallbackType_Object,
|
|
|
|
NetworkClientCallbackType_Unknown = -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
class NetworkClient;
|
|
|
|
class CustomNetProtocol;
|
2013-12-17 10:25:34 +01:00
|
|
|
typedef void (*ClientConnectCallbackMethod)(NetworkClient*);
|
2013-12-11 21:45:43 +01:00
|
|
|
typedef void(*ProtocolRecieverFunction)(CustomNetProtocol& protocol);
|
|
|
|
struct ClientConnectedObject
|
|
|
|
{
|
2013-12-17 10:25:34 +01:00
|
|
|
virtual void ClientConnectCallback(NetworkClient* client) = 0;
|
2013-12-11 21:45:43 +01:00
|
|
|
};
|
|
|
|
struct ProtocolRecieverObject
|
|
|
|
{
|
|
|
|
virtual void ProtocolRecievedCallback(CustomNetProtocol& protocol) = 0;
|
2013-12-17 14:15:20 +01:00
|
|
|
virtual void DisconnectedCallback(CustomNetProtocol& protocol) { };
|
2013-12-11 21:45:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
union RecieverObject
|
|
|
|
{
|
2013-12-12 10:36:55 +01:00
|
|
|
ClientConnectCallbackMethod clientConnectFnc; // !< A function pointer for sending or recieving NetworkClient
|
|
|
|
ProtocolRecieverFunction protocolRecieverFnc; // !< A function pointer for sending or recieving CustomNetProtocol
|
|
|
|
ClientConnectedObject *clientConnectObject; // !< An object for sending or recieving NetworkClient
|
|
|
|
ProtocolRecieverObject *protocolRecievedObject; // !< An object for sending or recieving CustomNetProtocol
|
|
|
|
|
|
|
|
RecieverObject() { memset(this, 0, sizeof(RecieverObject)); }
|
|
|
|
RecieverObject(ClientConnectCallbackMethod o) { clientConnectFnc = o; }
|
|
|
|
RecieverObject(ProtocolRecieverFunction o) { protocolRecieverFnc = o; }
|
|
|
|
RecieverObject(ClientConnectedObject* o) { clientConnectObject = o; }
|
|
|
|
RecieverObject(ProtocolRecieverObject* o) { protocolRecievedObject = o; }
|
2013-12-11 21:45:43 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|