ReplicaNet and RNLobby  1
BaseServer.h
1 /* START_LICENSE_HEADER
2 
3 Copyright (C) 2000 Martin Piper, original design and program code
4 Copyright (C) 2001 Replica Software
5 
6 This program file is copyright (C) Replica Software and can only be used under license.
7 For more information visit: http://www.replicanet.com/
8 Or email: info@replicanet.com
9 
10 END_LICENSE_HEADER */
11 #include "RNPlatform/Inc/MemoryTracking.h"
12 #ifndef _BASESERVER_H_
13 #define _BASESERVER_H_
14 #include "RNLobby/Inc/CommonServer.h"
15 #include "RNPlatform/Inc/SysTime.h"
16 
17 namespace RNReplicaNet
18 {
19 
20 namespace RNLobby
21 {
22 
24 class BaseServer : private CommonServer , public ThreadClass , public Thread
25 {
26 public:
27  BaseServer();
28  virtual ~BaseServer();
29 
34  virtual bool StartWithSocket(t_XPSocket *socket,const bool allowDelete = true);
35 
38  virtual bool Stop(void);
39 
43  void SetEncryptionKey(const void *data,const int length);
44 
48  virtual void CallbackDataReceived(DynamicMessageHelper &message,XPAddress &address) {}
49 
53  virtual void CallbackDataSend(DynamicMessageHelper &message,XPAddress &address) {}
54 
57  virtual void CallbackQueryReplyTime(const float seconds) {}
58 
61  virtual bool CallbackPoll(void) { return true; }
62 
63  static SysTimeType FloatTime(void);
64 
67  virtual void CallbackTidy(void) {}
68 
69 protected:
72  virtual bool CallbackParseValidMessage(DynamicMessageHelper &message,const size_t length,const XPAddress &address) { return true; }
73 
76  virtual bool PackageAndSendData(t_XPSocket *socket,const DynamicMessageHelper &message,const XPAddress &address);
77 
80  virtual bool CallbackParsePacketData(t_XPSocket *socket,const XPAddress &addr,void *data,size_t &length,DynamicMessageHelper &result);
81 
82  int ThreadEntry(void);
83 
84 private:
85 
86  void ThreadExiting(const int returnCode);
87  void Tidy(void);
88 
89 protected:
90  t_XPSocket *mSocket;
91  bool mAllowDelete;
92 
93  int mNOnce;
94 };
95 
96 } // namespace RNLobby
97 
98 } // namespace RNReplicaNet
99 
100 #endif
virtual void CallbackTidy(void)
Definition: BaseServer.h:67
Definition: XPSocket.h:91
virtual void CallbackQueryReplyTime(const float seconds)
Definition: BaseServer.h:57
virtual void CallbackDataSend(DynamicMessageHelper &message, XPAddress &address)
Definition: BaseServer.h:53
A common server support class.
Definition: CommonServer.h:27
virtual void CallbackDataReceived(DynamicMessageHelper &message, XPAddress &address)
Definition: BaseServer.h:48
virtual bool StartWithSocket(t_XPSocket *socket, const bool allowDelete=true)
virtual bool CallbackPoll(void)
Definition: BaseServer.h:61
Definition: XPSocket.h:167
virtual bool PackageAndSendData(t_XPSocket *socket, const DynamicMessageHelper &message, const XPAddress &address)
Definition: MessageHelper.h:211
virtual bool CallbackParseValidMessage(DynamicMessageHelper &message, const size_t length, const XPAddress &address)
Definition: BaseServer.h:72
virtual bool CallbackParsePacketData(t_XPSocket *socket, const XPAddress &addr, void *data, size_t &length, DynamicMessageHelper &result)
void SetEncryptionKey(const void *data, const int length)
A server base class that handles encrypted messages to and from a socket.
Definition: BaseServer.h:24
Definition: ThreadClass.h:96
Definition: Thread.h:29