ReplicaNet and RNLobby  1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
BaseServer Class Reference

A server base class that handles encrypted messages to and from a socket. More...

#include <BaseServer.h>

Inheritance diagram for BaseServer:
Inheritance graph
[legend]
Collaboration diagram for BaseServer:
Collaboration graph
[legend]

Public Member Functions

virtual bool StartWithSocket (t_XPSocket *socket, const bool allowDelete=true)
 
virtual bool Stop (void)
 
void SetEncryptionKey (const void *data, const int length)
 
virtual void CallbackDataReceived (DynamicMessageHelper &message, XPAddress &address)
 
virtual void CallbackDataSend (DynamicMessageHelper &message, XPAddress &address)
 
virtual void CallbackQueryReplyTime (const float seconds)
 
virtual bool CallbackPoll (void)
 
virtual void CallbackTidy (void)
 
- Public Member Functions inherited from ThreadClass
 ThreadClass ()
 
virtual ~ThreadClass ()
 
void Sleep (int milliseconds)
 
- Public Member Functions inherited from MutexClass
 MutexClass ()
 
virtual ~MutexClass ()
 
void Lock (void)
 
void UnLock (void)
 
- Public Member Functions inherited from Thread
 Thread ()
 
virtual ~Thread ()
 
void Begin (ThreadClass *threaded_class)
 
void Terminate (void)
 
bool GetTerminated (void)
 
bool GetEverTerminated (void)
 
bool GetIsRunning (void) const
 
void SetPreferredProcessor (int processor=kReplicaNetPreferredProcessorOSChoice)
 
int GetPreferredProcessor (void)
 

Static Public Member Functions

static SysTimeType FloatTime (void)
 
- Static Public Member Functions inherited from Thread
static int CallThreadEntry (ThreadClass *thread_class)
 
static int GetCurrentProcessorNumber (void)
 
static size_t GetNumAllocated (void)
 
static size_t GetNumActive (void)
 

Protected Member Functions

virtual bool CallbackParseValidMessage (DynamicMessageHelper &message, const size_t length, const XPAddress &address)
 
virtual bool PackageAndSendData (t_XPSocket *socket, const DynamicMessageHelper &message, const XPAddress &address)
 
virtual bool CallbackParsePacketData (t_XPSocket *socket, const XPAddress &addr, void *data, size_t &length, DynamicMessageHelper &result)
 
int ThreadEntry (void)
 
- Protected Member Functions inherited from ThreadClass
void DoQuitNow (const int returnCode)
 
void CheckQuit (void)
 

Protected Attributes

t_XPSocketmSocket
 
bool mAllowDelete
 
int mNOnce
 

Additional Inherited Members

- Public Types inherited from MutexClass
enum  { kNoOwnerThread = -1 }
 
- Static Protected Member Functions inherited from ThreadClass
static size_t GetNumAllocated (void)
 

Detailed Description

A server base class that handles encrypted messages to and from a socket.

Member Function Documentation

virtual void CallbackDataReceived ( DynamicMessageHelper message,
XPAddress address 
)
inlinevirtual

This callback may be used to alter data after it has been received and before the data received is processed.

Parameters
messageThe data held in a DynamicMessageHelper class.
addressThe network address for this data packet. The contents of the address may be changed if required.
virtual void CallbackDataSend ( DynamicMessageHelper message,
XPAddress address 
)
inlinevirtual

This callback may be used to alter any data in a reply, just before it gets sent by the socket.

Parameters
messageThe data held in a DynamicMessageHelper class.
addressThe network address for this data packet. The contents of the address may be changed if required.
virtual bool CallbackParsePacketData ( t_XPSocket socket,
const XPAddress addr,
void *  data,
size_t &  length,
DynamicMessageHelper result 
)
protectedvirtual

The class mutex is locked during the context of this function.

Parameters
resultThe resultant data after decrypting and length will be updated with the new packet length.
virtual bool CallbackParseValidMessage ( DynamicMessageHelper message,
const size_t  length,
const XPAddress address 
)
inlineprotectedvirtual

Called from the scope of the thread but without the class mutex being locked.

Returns
Return true to indicate this service class should continue to run. If false is returned this will stop the receiving thread and shutdown this server class.
virtual bool CallbackPoll ( void  )
inlinevirtual

Called from the scope of the thread but without the class mutex being locked.

Returns
Return true to indicate this service class should continue to run. If false is returned this will stop the receiving thread and shutdown this server class.
virtual void CallbackQueryReplyTime ( const float  seconds)
inlinevirtual

This callback reports how long an query and reply took starting from when packet data was received until the packet data is sent.

Parameters
secondsThe time in seconds.
virtual void CallbackTidy ( void  )
inlinevirtual

This callback may be used to tidy allocation of objects when the thread terminates. The class mutex is locked when executing this callback.

virtual bool PackageAndSendData ( t_XPSocket socket,
const DynamicMessageHelper message,
const XPAddress address 
)
protectedvirtual

The class mutex is locked during the context of this function.

Returns
Return true to indicate this service class should continue to run. If false is returned this will stop the receiving thread and shutdown this server class.
void SetEncryptionKey ( const void *  data,
const int  length 
)

Sets the encryption key to be used by all queries for this server. The same key must be used with any other RNLobby::BaseServer querying this server.

Parameters
dataThe data to use as a seed for the key. This can be NULL to use the default key.
lengthThe length of the data to use for creating the key.
virtual bool StartWithSocket ( t_XPSocket socket,
const bool  allowDelete = true 
)
virtual

Starts the thread. If this function is overridden then this base implementation must also be called.

Parameters
socketThe socket to poll for this class.
allowDeleteWhen true this class is responsible for deleting the socket.
Returns
Success returns true, failure returns false.
virtual bool Stop ( void  )
virtual

Stops the thread. If this function is overridden then this base implementation must also be called.

Returns
Success returns true, failure returns false.
int ThreadEntry ( void  )
protectedvirtual

The thread starts executing from here.

Implements ThreadClass.