PIP 5.5.3
Platform-Independent Primitives
Public Member Functions | Protected Member Functions | List of all members
PIStreamPacker Class Reference

Simple packet wrap aroud any PIIODevice. More...

Inheritance diagram for PIStreamPacker:
Inheritance graph
[legend]

Public Member Functions

 PIStreamPacker (PIIODevice *dev=nullptr)
 Contructs packer and try to assign "dev".
 
int receivePacketProgress () const
 Returns progress of current packet receive in bytes.
 
void send (const PIByteArray &data)
 Prepare data for send and raise sendRequest() events.
 
void received (const PIByteArray &data)
 Receive data part. If packet is ready, raise packetReceiveEvent() event and packetReceived() virtual method.
 
void assignDevice (PIIODevice *dev)
 Connect "dev" PIIODevice::threadedReadEvent() event to received() handler and sendRequest() event to "dev" PIIODevice::write() handler.
 
- Public Member Functions inherited from PIObject
 PIObject (const PIString &name=PIString())
 Contructs PIObject with name "name".
 
PIString name () const
 Returns object name.
 
virtual const char * className () const
 Returns object class name.
 
virtual const char * parentClassName () const
 Returns parent class name.
 
bool debug () const
 Return if piCoutObj of this object is active.
 
void setName (const PIString &name)
 Set object name.
 
void setDebug (bool debug)
 Set object piCoutObj active.
 
PIVariant property (const char *name) const
 Returns property with name "name".
 
void setProperty (const char *name, const PIVariant &value)
 Set property with name "name" to "value". If there is no such property in object it will be added.
 
bool isPropertyExists (const char *name) const
 Returns if property with name "name" exists.
 
PIStringList scopeList () const
 Returns subclass scope of this object (including this class name)
 
void piDisconnect (const PIString &sig, PIObject *dest, void *ev_h)
 Disconnect object from all connections with event name "sig", connected to destination object "dest" and handler "ev_h".
 
void piDisconnect (const PIString &sig, PIObject *dest)
 Disconnect object from all connections with event name "sig", connected to destination object "dest".
 
void piDisconnect (const PIString &sig)
 Disconnect object from all connections with event name "sig".
 
bool isPIObject () const
 Returns if this is valid PIObject (check signature)
 
template<typename T >
bool isTypeOf () const
 Returns if this is valid PIObject subclass "T" (check signature and classname)
 
template<typename T >
T * cast () const
 Returns cast to T if this is valid subclass "T" (check by isTypeOf()) or "nullptr".
 
void callQueuedEvents ()
 Execute all posted events from CONNECTU_QUEUED connections.
 
bool maybeCallQueuedEvents ()
 Check if any CONNECTU_QUEUED connections to this object and execute them. More...
 
void deleteLater ()
 Mark object to delete. More...
 
void deleted (PIObject *o)
 Raise before object delete. More...
 

Protected Member Functions

virtual void packetReceived (PIByteArray data)
 Packet successfully received, by default does nothing.
 
- Protected Member Functions inherited from PIObject
PIObjectemitter () const
 Returns PIObject* which has raised an event. This value is correct only in definition of some event handler.
 
virtual void propertyChanged (const char *name)
 Virtual function executes after property with name "name" has been changed.
 

Events

void packetReceiveEvent (PIByteArray &data)
 Raise on packet successfully received.
 
void startPacketReceive (int size)
 Raise on start receive packet with overall size "size".
 
void endPacketReceive ()
 Raise on finish receive packet.
 
void sendRequest (PIByteArray data)
 Raise from send() function. This data should be directly sended to your device. You can connect this event to PIIODevice::write() handler.
 

Additional Inherited Members

- Static Public Member Functions inherited from PIObject
static void piDisconnect (PIObject *src, const PIString &sig, PIObject *dest, void *ev_h)
 Disconnect object "src" from all connections with event name "sig", connected to destination object "dest" and handler "ev_h".
 
static void piDisconnect (PIObject *src, const PIString &sig, PIObject *dest)
 Disconnect object "src" from all connections with event name "sig", connected to destination object "dest".
 
static void piDisconnect (PIObject *src, const PIString &sig)
 Disconnect object "src" from all connections with event name "sig".
 
static PIObjectfindByName (const PIString &name)
 Returns PIObject* with name "name" or 0, if there is no object found.
 
static bool isPIObject (const PIObject *o)
 Returns if "o" is valid PIObject (check signature)
 
template<typename T >
static bool isTypeOf (const PIObject *o)
 Returns if "o" is valid PIObject subclass "T" (check signature and classname)
 

Detailed Description

Simple packet wrap aroud any PIIODevice.

Synopsis

PIStreamPacker provides simple pack/unpack logic for any data packets.

When you call send() function data splited into several parts, packetSign() prepended to first part and sendRequest() event raised several times.

When your device receive some data, call received() function. packetReceiveEvent() event will be raised when packet will be collected.

Use assignDevice() to connect device to this PIStreamPacker.