Skip to content

CPacket

Takashiro edited this page Aug 20, 2015 · 2 revisions
Cardirector Documentation: Network

CPacket

The CPacket class represents a packet transfered via the network. A packet contains one command and its corresponding parameters (possibly empty). For asynchronized communication, the sender simply sends notification (TYPE_NOTIFICATION) packets. For synchronized communication, the sender waits for a reply (TYPE_REPLY) packet after sending a request (TYPE_REQUEST) packet.

Public Types

enum Type {TYPE_NOTIFICATION, TYPE_REQUEST, TYPE_REPLY};

Public Functions

CPacket();
CPacket(int command, Type type);
CPacket(const CPacket &source);
~CPacket();

bool isValid() const;

int command() const;
void setCommand(int command);

Type type() const;
void setType(Type type);

void setData(const QVariant &data);
const QVariant &data() const;

Protected Functions

void detach();

CPacket();

Creates an invalid packet.

CPacket(int command, Type type);

Create a packet and define its command and type.

CPacket(const CPacket &source);

Copy a packet from an existing packet, source.

~CPacket();

Destroys a packet.

bool isValid() const;

Returns true if the packet is valid or false if it's invalid.

int command() const;

Returns the command of the packet.

void setCommand(int command);

Sets the command of the packet.

Type type() const;

Returns the type of the packet.

void setType(Type type);

Sets the type of the packet.

void setData(const QVariant &data);

Sets the data of the packet.

const QVariant &data() const;

Returns the data of the packet.

void detach();

CPacket is implicitly shared. Calling void detach() detachs this instance from other owners. That is, copy a new instance so it's ready to be modified.

Clone this wiki locally