Protocols::Generics::PacketFactory Class Reference

#include <PacketFactory.h> [code]

Inherited by Protocols::Generics::Testing::PacketFactoryStub.

Inheritance diagram for Protocols::Generics::PacketFactory:

Inheritance graph
[legend]
List of all members.

Detailed Description

Extracts and creates objects of Packet derived classes from raw bytes.

This is an abstract base class for Packet helper classes, which would provide functions for extracting packets from a raw bytes buffer or for creating objects of Packet derived classes from the extracted raw data.

According to the design of PacketFactory, extractPacket() looks into the raw bytes, which are probably read from a Connection, and tries to figure out the header/payload/trailer lengths of the first packet available in the raw buffer. After the packet is extracted, createPacket() can be called with the corresponding data. If it is possible to identify the type of the packet from the raw data, then a default-constructed Packet object of the correct dynamic type is created. After that PacketFactory tries to Packet::parse() the packet and if that fails a packet of type BadPacket is created and returned. A BadPacket object contains just the bad raw bytes, which could be dumped for debugging or diagnostic purposes.

Todo:
See how this one fits with PacketProtocol!

Definition at line 51 of file PacketFactory.h.

Public Member Functions

 PacketFactory ()
 Default constructor.
virtual ~PacketFactory ()
 Destructor.
bool extractPacket (const QByteArray &rawBytes, int &headerLength, int &payloadLength, int &trailerLength)
 Tells whether a packet can be extracted from rawBytes.
Packet createPacket (const QByteArray &rawHeader, const QByteArray &rawPayload, const QByteArray &rawTrailer)
 Creates an object of a Packet derive class after parsing the raw data bytes.

Protected Member Functions

virtual bool doExtractPacket (const QByteArray &rawBytes, int &headerLength, int &payloadLength, int &trailerLength)=0
virtual Packet doCreatePacket (const QByteArray &rawHeader, const QByteArray &rawPayload, const QByteArray &rawTrailer)=0


Constructor & Destructor Documentation

PacketFactory::PacketFactory  ) 
 

Default constructor.

Definition at line 30 of file PacketFactory.cpp.

PacketFactory::~PacketFactory  )  [virtual]
 

Destructor.

Definition at line 35 of file PacketFactory.cpp.


Member Function Documentation

Packet PacketFactory::createPacket const QByteArray &  rawHeader,
const QByteArray &  rawPayload,
const QByteArray &  rawTrailer
 

Creates an object of a Packet derive class after parsing the raw data bytes.

The function tries to parse rawHeader, rawPayload and rawTrailer. If parsing them succeeds, an object of the corresponding dynamic type will be created and returned from the function. The caller owns the new object.

If parsing fails, then an object of dynamic type BadPacket is created. It contains the raw bytes, which the caller may decide to dump, for example.

Definition at line 64 of file PacketFactory.cpp.

virtual Packet Protocols::Generics::PacketFactory::doCreatePacket const QByteArray &  rawHeader,
const QByteArray &  rawPayload,
const QByteArray &  rawTrailer
[protected, pure virtual]
 

Implemented in Protocols::Generics::Testing::PacketFactoryStub.

virtual bool Protocols::Generics::PacketFactory::doExtractPacket const QByteArray &  rawBytes,
int &  headerLength,
int &  payloadLength,
int &  trailerLength
[protected, pure virtual]
 

Implemented in Protocols::Generics::Testing::PacketFactoryStub.

bool PacketFactory::extractPacket const QByteArray &  rawBytes,
int &  headerLength,
int &  payloadLength,
int &  trailerLength
 

Tells whether a packet can be extracted from rawBytes.

Returns:
false if a complete packet cannot be extracted from rawBytes.

true if a complete packet can be extracted, in which case headerLength, payloadLength and trailerLength would be set accordingly.

Definition at line 46 of file PacketFactory.cpp.


The documentation for this class was generated from the following files: