PacketHandler.hh File Reference
#include "tools.hh"
#include "Packet.hh"
#include "EventProcess.hh"
Go to the source code of this file.
Detailed Description
Define Documentation
| #define DECLARE_PACKET |
( |
Cst, |
|
|
PClass |
|
) |
|
Value:struct PClass; \
template <typename T> \
class PacketHandler<Cst, T> : public BasePacketHandler \
{ \
public: \
typedef void (T::*fct_t)(const PClass*); \
PacketHandler<Cst, T>(T* obj, fct_t f) \
: obj_(obj), f_(f) {} \
virtual void handle(const Packet* p) \
{ \
LOG5("<- `" #Cst "' (id: %1)", \
p->client_id); \
(obj_->*f_)(reinterpret_cast<const PClass*>(p)); \
} \
virtual int getCstValue() const { return Cst; } \
virtual void dispatchUIEvent(const EventProcess* evp, \
const Packet& pkt) \
{ \
evp->dispatch(reinterpret_cast<const PClass&>(pkt)); \
} \
private: \
T* obj_; \
fct_t f_; \
}; \
struct PClass : public Packet \
{ \
PClass(int client_id = -1) \
: Packet(Cst, client_id) { data_size = sizeof(*this); }
Declare a structure for a packet.
- Parameters:
-
| Cst | One message constant, as defined in Constants.hh. |
| PClass | The struct name, derived from Packet, to create. |
The following code snippet declare a new struct derived from Packet, and the required code for automatic message handling.
- Note:
- Please take some care if you overwrite the default constructor.
- Author:
- victor
- Date:
- 10/01/2006