TDME2  1.9.200
ServerClient.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
10 
11 using std::string;
12 
16 
17 namespace tdme {
18 namespace network {
19 namespace udpserver {
20 class ServerRequest;
21 };
22 };
23 };
24 
25 /**
26  * Base class for network server clients
27  * @author Andreas Drewke
28  */
30  friend class ServerWorkerThread;
31 
32 public:
34 
35  /**
36  * @brief returns client's ip
37  * @return client ip
38  */
39  virtual const string& getIp() const = 0;
40 
41  /**
42  * @brief returns client port
43  * @return client port
44  */
45  virtual const uint16_t getPort() const = 0;
46 
47  /**
48  * @brief Client identification key
49  * @return client key
50  */
51  virtual const string& getKey() const = 0;
52 
53  /**
54  * @brief sets the clients identification key
55  * @param &key client identification key
56  * @return if setting the key was succesful
57  */
58  virtual const bool setKey(const string &key) = 0;
59 
60  /**
61  * @brief Creates a packet to be used with send
62  * @return packet to be send
63  */
64  inline UDPPacket* createPacket() {
65  return new UDPPacket();
66  }
67 
68  /**
69  * @brief Shuts down this network client
70  */
71  virtual void shutdown() = 0;
72 
73 protected:
74  /**
75  * @brief To be overwritten with a request handler, will be called from worker
76  * @param packet packet
77  * @param messageId message id (udp server only)
78  * @param retries retries (udp server only)
79  */
80  virtual void onRequest(const UDPPacket* packet, const uint32_t messageId, const uint8_t retries) = 0;
81 
82  /*
83  * @brief event method called if client will be initiated, will be called from worker
84  */
85  virtual void onInit() = 0;
86 
87  /*
88  * @brief event method called if client will be closed, will be called from worker
89  */
90  virtual void onClose() = 0;
91 
92  /*
93  * @brief custom event method called if fired, will be called from worker
94  */
95  virtual void onCustom(const string& type) = 0;
96 
97  /**
98  * @brief Event, which will be called if packet has been received, defaults to worker thread pool
99  * @param packet packet
100  * @param messageId message id (upd server only)
101  * @param retries retries (udp server only)
102  */
103  virtual void onPacketReceived(const UDPPacket* packet, const uint32_t messageId = 0, const uint8_t retries = 0) = 0;
104 
105  /**
106  * @brief Shuts down this network client
107  */
108  virtual void close() = 0;
109 
110  //
111  string key;
112 };
113 
Base class for network server clients.
Definition: ServerClient.h:29
virtual const string & getKey() const =0
Client identification key.
virtual void onPacketReceived(const UDPPacket *packet, const uint32_t messageId=0, const uint8_t retries=0)=0
Event, which will be called if packet has been received, defaults to worker thread pool.
virtual void shutdown()=0
Shuts down this network client.
UDPPacket * createPacket()
Creates a packet to be used with send.
Definition: ServerClient.h:64
virtual const uint16_t getPort() const =0
returns client port
virtual const string & getIp() const =0
returns client's ip
virtual void onRequest(const UDPPacket *packet, const uint32_t messageId, const uint8_t retries)=0
To be overwritten with a request handler, will be called from worker.
virtual const bool setKey(const string &key)=0
sets the clients identification key
static STATIC_DLL_IMPEXT const char * KEY_PREFIX_UNNAMED
Definition: ServerClient.h:33
virtual void close()=0
Shuts down this network client.
virtual void onCustom(const string &type)=0
Reference counter implementation to be used with inheritance.
Definition: Reference.h:13
std::exception Exception
Exception base class.
Definition: Exception.h:18
Definition: fwd-tdme.h:4
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15