PacketHandler.hh File Reference

#include "tools.hh"
#include "EventProcess.hh"

Include dependency graph for PacketHandler.hh:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  BasePacketHandler
 Base packet handler. More...
class  PacketHandler< N, T >
 Packet Handler. More...

Defines

#define DECLARE_PACKET(Cst, PClass)
 Declare a structure for a packet.
#define define
#define HANDLE_WITH(Token, Class, Object, Method, When)   handleWith(new PacketHandler<Token, Class>(Object, &Class::Method), When)
 Declare a Packet without additional attributes.


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.

 DECLARE_PACKET(MSG_BALLPOS, MsgBallPos)
   int row;
   int col;
 };

Note:
Please take some care if you overwrite the default constructor.
Author:
victor
Date:
10/01/2006

#define define

Value:

DECLARE_EMPTY_PACKET(Cst, PClass)      \
  DECLARE_PACKET(Cst, PClass)                   \
  };


Generated on Sat Jun 23 16:08:02 2007 for Stechec/TBT by  doxygen 1.4.7