defs/si_sha/autopkt.h File Reference

General Packet data container. More...

#include <si_sys/defs.h>
#include <si_std/ptrh.h>
#include <si_std/listt.h>
#include <pthread.h>

Go to the source code of this file.

Classes

struct  sc_automationPacket
 Packet data container object. More...
struct  sc_automationPacketPool
 A pool of packets for constant time allocation and release. More...

Functions

sc_status sc_automationPacket_construct (sc_automationPacket *ppkt, s_int32 capacity, s_uint8 *pbuffer)
sc_status sc_automationPacket_serializeToFd (sc_automationPacket *pkt, int fd)
sc_status sc_automationPacket_deserializeFromFd (sc_automationPacket *pkt, int fd)
sc_status sc_automationPacket_tell (sc_automationPacket *pkt, s_uint32 *ppos)
sc_status sc_automationPacket_setPos (sc_automationPacket *pkt, s_uint32 pos)
sc_status sc_automationPacket_clear (sc_automationPacket *pkt)
 sm_ptrhDecl (sc_automationPacket)
 Declares sc_automationPacketPtrh, a packet pointer-handle.
 sm_listDecl (sc_automationPacketPtrh)
 Declares sc_automationPacketPtrhList, a list of packet pointer-handles.
sc_status sc_automationPacketPool_construct (sc_automationPacketPool *ppool, s_int32 pktSize, s_int32 initialCapacity, s_int32 maxCapacity)
sc_status sc_automationPacketPool_destruct (sc_automationPacketPool *ppool)
sc_status sc_automationPacketPool_allocate (sc_automationPacketPool *ppool, sc_automationPacketPtrh *pptrh)
sc_status sc_automationPacketPool_free (sc_automationPacketPool *ppool, sc_automationPacketPtrh *pptrh)
Functions for moving data into and out of packets.
These functions push/pop byte or integer data into/out of the packet.

sc_status sc_automationPacket_pushUInt8 (sc_automationPacket *pkt, s_uint8 val)
sc_status sc_automationPacket_popUInt8 (sc_automationPacket *pkt, s_uint8 *val)
sc_status sc_automationPacket_pushInt8 (sc_automationPacket *pkt, s_int8 val)
sc_status sc_automationPacket_popInt8 (sc_automationPacket *pkt, s_int8 *val)
sc_status sc_automationPacket_pushUInt16 (sc_automationPacket *pkt, s_uint16 v)
sc_status sc_automationPacket_popUInt16 (sc_automationPacket *pkt, s_uint16 *v)
sc_status sc_automationPacket_pushInt16 (sc_automationPacket *pkt, s_int16 v)
sc_status sc_automationPacket_popInt16 (sc_automationPacket *pkt, s_int16 *v)
sc_status sc_automationPacket_pushUInt32 (sc_automationPacket *pkt, s_uint32 v)
sc_status sc_automationPacket_popUInt32 (sc_automationPacket *pkt, s_uint32 *v)
sc_status sc_automationPacket_pushInt32 (sc_automationPacket *pkt, s_int32 v)
sc_status sc_automationPacket_popInt32 (sc_automationPacket *pkt, s_int32 *v)
sc_status sc_automationPacket_pushUInt64 (sc_automationPacket *pkt, s_uint64 v)
sc_status sc_automationPacket_popUInt64 (sc_automationPacket *pkt, s_uint64 *v)
sc_status sc_automationPacket_pushInt64 (sc_automationPacket *pkt, s_int64 v)
sc_status sc_automationPacket_popInt64 (sc_automationPacket *pkt, s_int64 *v)
sc_status sc_automationPacket_pushBinary (sc_automationPacket *ppkt, const s_uint8 *pdata, s_int32 nbytes)
sc_status sc_automationPacket_popBinary (sc_automationPacket *ppkt, s_uint8 *pdata, s_int32 nbytes)


Detailed Description

General Packet data container.

This packet object is a general purpose data container for the various types of automation networks. It functions like a stack (LIFO), and access to the object and the data it contains is available from both JavaScript and C.


Function Documentation

sc_status sc_automationPacket_clear ( sc_automationPacket pkt  ) 

Empties the given packet. Resets top and sets size to 0.

Parameters:
[in,out] pkt The packet to clear.

sc_status sc_automationPacket_construct ( sc_automationPacket ppkt,
s_int32  capacity,
s_uint8 *  pbuffer 
)

Constructs a new packet with the given capacity and buffer.

If pbuffer is NULL then a new buffer is allocated with the given capacity in the constructor, and the own_ member is set to true. Otherwise, pbuffer is used directly, assumed to have capacity, and own_ is set to false. On destruct, if own_ is true, then the buffer_ member is freed.

Parameters:
[in,out] ppkt The packet object to construct.
[in] capacity The capacity the packet will have.
[in] pbuffer If not NULL, this buffer is used directly. Otherwise, a buffer of size capacity is allocated in the constructor.

sc_status sc_automationPacket_deserializeFromFd ( sc_automationPacket pkt,
int  fd 
)

De-serializes the given packet from the file descriptor fd.

Parameters:
[in,out] pkt The packet of interest.
[in] fd The file descriptor to serialize from.
See also:
sc_automationPacket_serializeToFd for pushing a packet into a file descriptor.

sc_status sc_automationPacket_serializeToFd ( sc_automationPacket pkt,
int  fd 
)

Serializes the given packet to the file descriptor fd.

Parameters:
[in,out] pkt The packet of interest.
[in] fd The file descriptor to serialize to.
See also:
sc_automationPacket_deserializeFromFd for pulling a packet out of a file descriptor.

sc_status sc_automationPacket_setPos ( sc_automationPacket pkt,
s_uint32  pos 
)

Sets the given packet to a previously found position.

Note that many positions would not result in a usable packet. To get a useable position, call sc_automationPacket_tell when the packet is in a good state.

Parameters:
[in,out] pkt The packet of interest.
[in] pos The position to move to.

sc_status sc_automationPacket_tell ( sc_automationPacket pkt,
s_uint32 *  ppos 
)

Returns the position of the packet in ppos.

This position can be returned to by using the setPos method.

Parameters:
[in,out] pkt The packet of interest.
[out] ppos The current position of the packet.

sc_status sc_automationPacketPool_allocate ( sc_automationPacketPool ppool,
sc_automationPacketPtrh *  pptrh 
)

Allocates a packet from the packet pool.

Parameters:
[in,out] ppool The packet pool to allocate from.
[out] pptrh The pointer-handle to assign the allocated packet to.

sc_status sc_automationPacketPool_construct ( sc_automationPacketPool ppool,
s_int32  pktSize,
s_int32  initialCapacity,
s_int32  maxCapacity 
)

Constructs a packet pool with the given initialCapacity of packets (each with pktSize bytes) growable up to maxCapacity.

Packet pools are typically used by bridges to minimize packet allocation latency. With a pool, the allocation is done in amortized constant time. When all references to an allocated packet have been released, the packet is automatically returned to the free list in the pool it came from.

Parameters:
[in,out] ppool The packet pool to construct.
[in] pktSize The size of packets in the pool.
[in] initialCapacity The number of packets to ready on construction.
[in] maxCapacity The maximum number of packets to allow the pool to grow to. Can be used to simulate low memory conditions.

sc_status sc_automationPacketPool_destruct ( sc_automationPacketPool ppool  ) 

Destructs the given packet pool.

Parameters:
[in,out] ppool The packet pool to destruct.
Note:
All packets must be returned to the pool before destruction.

sc_status sc_automationPacketPool_free ( sc_automationPacketPool ppool,
sc_automationPacketPtrh *  pptrh 
)

Releases a packet back to the packet pool.

Parameters:
[in,out] ppool The pool to return the packet to.
[in] pptrh The pointer-handle to the packet being returned.


doxygen