SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
IProtocolHandler.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <memory>
7 #include "IProtocolMessage.h"
8 #include "common/Types.h"
9 
10 namespace ai {
11 
12 typedef uint8_t ClientId;
13 
20 public:
21  virtual ~IProtocolHandler() {
22  }
23 
24  virtual void execute(const ClientId& clientId, const IProtocolMessage& message) = 0;
25 };
26 
27 template<class T>
29 public:
30  virtual ~ProtocolHandler ()
31  {
32  }
33 
34  void execute (const ClientId& clientId, const IProtocolMessage& message) override {
35  const T *msg = ai_assert_cast<const T*>(&message);
36  execute(clientId, msg);
37  }
38 
39  virtual void execute (const ClientId& clientId, const T* message) = 0;
40 };
41 
43 public:
44  void execute(const ClientId& /*clientId*/, const IProtocolMessage& /*message*/) override {
45  }
46 };
47 
48 typedef std::shared_ptr<IProtocolHandler> ProtocolHandlerPtr;
49 
54  void operator()(IProtocolHandler* /* ptr */) {
55  }
56 };
57 
58 }
Definition: IProtocolHandler.h:28
A protocol message is used for the serialization of the ai states for remote debugging.
Definition: IProtocolMessage.h:60
Interface for the execution of assigned IProtocolMessage.
Definition: IProtocolHandler.h:19
Definition: IProtocolHandler.h:42
T ai_assert_cast(const S object)
If you compile with RTTI activated, you get additional sanity checks when using this macro to perform...
Definition: Types.h:84
Use this deleter for any handler that should not get freed by delete.
Definition: IProtocolHandler.h:53