CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::ControlMessage Class Reference

Wrapper class managing a single flat ControlMessage memory block. More...

#include <ControlMessage.h>

Public Member Functions

 ControlMessage (uint16 command, uint64 from, uint64 to, char *data=NULL, uint32 dataSize=0)
 Create a new control message.
 ControlMessage (char *data)
 Wrap an existing binary control message block without copying.
 ~ControlMessage ()
 Destructor.
uint32 getSize ()
uint16 getCommand ()
uint64 getTime ()
uint64 getFrom ()
uint64 getTo ()
uint16 getStatus ()
bool setStatus (uint16 status)
 Set the status/result code.

Static Public Member Functions

static bool UnitTest ()
 Run the built-in self test.

Public Attributes

char * data
 The flat message block (ControlMessageHeader + payload); see class notes on ownership.

Detailed Description

Wrapper class managing a single flat ControlMessage memory block.

Provides typed access to the header fields of the underlying block pointed to by data. Ownership: the (command, from, to, ...) constructor allocates a new block (payload bytes are copied); the char* constructor merely wraps the supplied block without copying.

Warning
The destructor does NOT free data — it only clears the pointer. Whoever allocated the block (this class's first constructor, or the caller for the wrapping constructor) is responsible for releasing it, typically via the surrounding memory-management layer.

Definition at line 49 of file ControlMessage.h.

Constructor & Destructor Documentation

◆ ControlMessage() [1/2]

cmlabs::ControlMessage::ControlMessage ( uint16 command,
uint64 from,
uint64 to,
char * data = NULL,
uint32 dataSize = 0 )

Create a new control message.

Parameters
commandcommand code for the receiver
fromsender id
toaddressee id
dataoptional payload bytes (copied), NULL for none
dataSizepayload size in bytes

Definition at line 12 of file ControlMessage.cpp.

References CONTROLMESSAGEID, data, cmlabs::GetTimeNow(), and cmlabs::ControlMessageHeader::size.

Referenced by UnitTest().

◆ ControlMessage() [2/2]

cmlabs::ControlMessage::ControlMessage ( char * data)

Wrap an existing binary control message block without copying.

Parameters
datathe binary block to wrap; caller retains ownership

Definition at line 25 of file ControlMessage.cpp.

References data.

◆ ~ControlMessage()

cmlabs::ControlMessage::~ControlMessage ( )

Destructor.

Warning
Does not free data (see class notes on ownership).

Definition at line 29 of file ControlMessage.cpp.

References data.

Member Function Documentation

◆ getCommand()

uint16 cmlabs::ControlMessage::getCommand ( )
Returns
the command code, 0 if invalid.

Definition at line 38 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ getFrom()

uint64 cmlabs::ControlMessage::getFrom ( )
Returns
sender id, 0 if invalid.

Definition at line 48 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ getSize()

uint32 cmlabs::ControlMessage::getSize ( )
Returns
total block size in bytes, 0 if invalid.

Definition at line 33 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ getStatus()

uint16 cmlabs::ControlMessage::getStatus ( )
Returns
the status/result code, 0 if invalid.

Definition at line 58 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ getTime()

uint64 cmlabs::ControlMessage::getTime ( )
Returns
creation time in microseconds, 0 if invalid.

Definition at line 43 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ getTo()

uint64 cmlabs::ControlMessage::getTo ( )
Returns
addressee id, 0 if invalid.

Definition at line 53 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ setStatus()

bool cmlabs::ControlMessage::setStatus ( uint16 status)

Set the status/result code.

Parameters
statusnew status value
Returns
true if successful, false if the message is invalid

Definition at line 63 of file ControlMessage.cpp.

References data, and VerObj.

Referenced by UnitTest().

◆ UnitTest()

bool cmlabs::ControlMessage::UnitTest ( )
static

Member Data Documentation

◆ data

char* cmlabs::ControlMessage::data

The flat message block (ControlMessageHeader + payload); see class notes on ownership.

Definition at line 80 of file ControlMessage.h.

Referenced by ControlMessage(), ControlMessage(), getCommand(), getFrom(), getSize(), getStatus(), getTime(), getTo(), setStatus(), UnitTest(), and ~ControlMessage().


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