parser.h File Reference

Interface for ED2KParser class which performs ED2K network stream parsing. More...

#include <hn/log.h>
#include <hn/utils.h>
#include "opcodes.h"
#include "packets.h"
#include "zutils.h"
#include "factories.h"

Go to the source code of this file.


Defines

#define DECLARE_PACKET_HANDLER(Target, Packet)   static Factory_##Packet < Target > s_packetFactory##Packet
 Declares a new packet handler within this parser.
#define DECLARE_PACKET_HANDLER2(Parent, Target, Packet)   static Factory_##Packet < Parent, Target > s_packetFactory##Packet
 Special version, allowing Parent and Target to differ.
#define FRIEND_PARSER(Class, Packet)   friend class Factory_##Packet<Class>
 Use this macro in your class's interface to allow parser factories to access the packet handler functions, if they are declared private.
#define DECLARE_PACKET_FACTORY(Proto, PacketType, Opcode)
 This macro is used by the implementation to declare a new packet parser factory.

Detailed Description

Interface for ED2KParser class which performs ED2K network stream parsing.

This is the main header for ED2KParser system, and should be included by user code. The support headers, "packets.h" and "opcodes.h" should generally not be included by user code.

Definition in file parser.h.


Define Documentation

#define DECLARE_PACKET_HANDLER Target,
Packet   )     static Factory_##Packet < Target > s_packetFactory##Packet
 

Declares a new packet handler within this parser.

Parameters:
Target Class which will handle this packet type.
Packet Packet type to be handled.
Note:
The class must also declare a member function with the following prototype in order to receive the notifiations: void onPacket(const Packet &); The name of the function is hardcoded. Failure to implement this function will result in compile-time errors. If the function is private, additional macro must be used in the class interface in order to make the function accessible to the parser. See below.

Definition at line 302 of file parser.h.

#define DECLARE_PACKET_HANDLER2 Parent,
Target,
Packet   )     static Factory_##Packet < Parent, Target > s_packetFactory##Packet
 

Special version, allowing Parent and Target to differ.

Parameters:
Parent Parent parser
Target Target which will receive the events

Definition at line 311 of file parser.h.

#define FRIEND_PARSER Class,
Packet   )     friend class Factory_##Packet<Class>
 

Use this macro in your class's interface to allow parser factories to access the packet handler functions, if they are declared private.

Definition at line 318 of file parser.h.

#define DECLARE_PACKET_FACTORY Proto,
PacketType,
Opcode   ) 
 

Value:

template<class Parent, class Target = Parent>                                 \
class Factory_##PacketType : public ED2KParser<Parent>::PacketFactory {       \
public:                                                                       \
        Factory_##PacketType()                                                \
        : ED2KParser<Parent>::PacketFactory(Proto, Opcode) {}                 \
        virtual void create(Parent *parent, std::istringstream &i) {          \
                parent->onPacket(ED2KPacket::PacketType(i));                  \
        }                                                                     \
}
This macro is used by the implementation to declare a new packet parser factory.

This should not be used by client code.

Parameters:
PacketType Type of packet this parser supports. Must be fully-qualified type name.
Opcode The opcode of the packet this factory is capable of creating. This factory will be called when this opcode is encountered in stream. Overlapping opcodes go against the logic and thus are not allowed.

Definition at line 332 of file parser.h.