Fawkes API
Fawkes Development Version
|
#include <netcomm/fawkes/message.h>
Public Member Functions | |
FawkesNetworkMessage (unsigned int clid, fawkes_message_t &msg) | |
Constructor to set message and client ID. More... | |
FawkesNetworkMessage (fawkes_message_t &msg) | |
Constructor that only sets message. More... | |
FawkesNetworkMessage (unsigned int clid, unsigned short int cid, unsigned short int msg_id, void *payload, size_t payload_size) | |
Constructor to set single fields and client ID. More... | |
FawkesNetworkMessage (unsigned int clid, unsigned short int cid, unsigned short int msg_id) | |
Constructor to set single fields and client ID without payload. More... | |
FawkesNetworkMessage (unsigned short int cid, unsigned short int msg_id, void *payload, size_t payload_size) | |
Constructor to set single fields. More... | |
FawkesNetworkMessage (unsigned int clid, unsigned short int cid, unsigned short int msg_id, FawkesNetworkMessageContent *content) | |
Constructor to set single fields and client ID. More... | |
FawkesNetworkMessage (unsigned short int cid, unsigned short int msg_id, FawkesNetworkMessageContent *content) | |
Constructor to set single fields. More... | |
FawkesNetworkMessage (unsigned short int cid, unsigned short int msg_id, size_t payload_size) | |
Constructor to set single fields and allocate memory. More... | |
FawkesNetworkMessage (unsigned short int cid, unsigned short int msg_id) | |
Constructor to set single fields without payload. More... | |
FawkesNetworkMessage () | |
Constructor. More... | |
virtual | ~FawkesNetworkMessage () |
Destructor. More... | |
unsigned int | clid () const |
Get client ID. More... | |
unsigned short int | cid () const |
Get component ID. More... | |
unsigned short int | msgid () const |
Get message type ID. More... | |
size_t | payload_size () const |
Get payload size. More... | |
void * | payload () const |
Get payload buffer. More... | |
const fawkes_message_t & | fmsg () const |
Get message reference. More... | |
template<typename MT > | |
MT * | msg () const |
Get correctly casted payload. More... | |
template<typename MT > | |
MT * | msgge () const |
Get correctly casted payload. More... | |
template<typename MT > | |
MT * | msgc () const |
Get correctly parsed output. More... | |
void | set_client_id (unsigned int clid) |
Set client ID. More... | |
void | set_component_id (unsigned short int cid) |
Set component ID. More... | |
void | set_message_id (unsigned short int msg_id) |
Set message type ID. More... | |
void | set_payload (void *payload, size_t payload_size) |
Set payload. More... | |
void | set (fawkes_message_t &msg) |
Set from message. More... | |
void | set_content (FawkesNetworkMessageContent *content) |
Set complex message content. More... | |
void | pack () |
Pack data for sending. More... | |
![]() | |
RefCount () | |
Constructor. More... | |
virtual | ~RefCount () |
Destructor. More... | |
void | ref () |
Increment reference count. More... | |
void | unref () |
Decrement reference count and conditionally delete this instance. More... | |
unsigned int | refcount () |
Get reference count for this instance. More... | |
Representation of a message that is sent over the network.
For the basic format of a message see fawkes_message_t. This class provides access to all of the fields in a convenient manner. Additionally it can handle the client ID, which is either the sender or the recipient of a message (depending if it's in an inbound or outbound queue).
Note that the message takes over ownership of the payload. This means that it is internally held and freed (using free()) if the message is deleted (if the reference count reaches zero). Because of this you can NOT supply a local variable. The following code is illegal:
Rather you have to use the following code:
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned int | clid, |
fawkes_message_t & | msg | ||
) |
Constructor to set message and client ID.
clid | client ID |
msg | reference to message, deep-copied into local message. |
Definition at line 104 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | fawkes_message_t & | msg | ) |
Constructor that only sets message.
The client ID is zero.
msg | reference to message, deep-copied into local message. |
Definition at line 115 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned int | clid, |
unsigned short int | cid, | ||
unsigned short int | msg_id, | ||
void * | payload, | ||
size_t | payload_size | ||
) |
Constructor to set single fields and client ID.
clid | client ID |
cid | component ID |
msg_id | message type ID |
payload | pointer to payload buffer |
payload_size | size of payload buffer |
Definition at line 227 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned int | clid, |
unsigned short int | cid, | ||
unsigned short int | msg_id | ||
) |
Constructor to set single fields and client ID without payload.
clid | client ID |
cid | component ID |
msg_id | message type ID |
Definition at line 250 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned short int | cid, |
unsigned short int | msg_id, | ||
void * | payload, | ||
size_t | payload_size | ||
) |
Constructor to set single fields.
The client ID is set to zero.
cid | component ID |
msg_id | message type ID |
payload | pointer to payload buffer |
payload_size | size of payload buffer |
Definition at line 129 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned int | clid, |
unsigned short int | cid, | ||
unsigned short int | msg_id, | ||
FawkesNetworkMessageContent * | content | ||
) |
Constructor to set single fields and client ID.
clid | client ID |
cid | component ID |
msg_id | message type ID |
content | complex content object |
Definition at line 207 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned short int | cid, |
unsigned short int | msg_id, | ||
FawkesNetworkMessageContent * | content | ||
) |
Constructor to set single fields.
The client ID is set to zero.
cid | component ID |
msg_id | message type ID |
content | complex content object |
Definition at line 189 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned short int | cid, |
unsigned short int | msg_id, | ||
size_t | payload_size | ||
) |
Constructor to set single fields and allocate memory.
The client ID is set to zero. The payload memory is allocated on the heap.
cid | component ID |
msg_id | message type ID |
payload_size | size of payload buffer |
Definition at line 152 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | unsigned short int | cid, |
unsigned short int | msg_id | ||
) |
Constructor to set single fields without payload.
The client ID is set to zero.
cid | component ID |
msg_id | message type ID |
Definition at line 173 of file message.cpp.
fawkes::FawkesNetworkMessage::FawkesNetworkMessage | ( | ) |
Constructor.
Plain constructor. All values initialized to zero, including the client ID.
Definition at line 93 of file message.cpp.
|
virtual |
Destructor.
This destructor also frees the payload buffer if set!
Definition at line 265 of file message.cpp.
unsigned short int fawkes::FawkesNetworkMessage::cid | ( | ) | const |
Get component ID.
Definition at line 291 of file message.cpp.
Referenced by fawkes::FawkesNetworkClient::enqueue(), and fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator().
unsigned int fawkes::FawkesNetworkMessage::clid | ( | ) | const |
Get client ID.
Definition at line 282 of file message.cpp.
Referenced by fawkes::FawkesNetworkServerThread::broadcast(), and ExampleNetworkThread::handle_network_message().
const fawkes_message_t & fawkes::FawkesNetworkMessage::fmsg | ( | ) | const |
Get message reference.
Definition at line 327 of file message.cpp.
|
inline |
Get correctly casted payload.
Use this method to cast the payload to a specific type. The size is check as a sanity check and a TypeMismatchException is thrown if the size does not match.
TypeMismatchException | payload size does not match requested type |
|
inline |
Get correctly parsed output.
Use this method to cast the payload to a specific complex type. You can use this routine to parse complex messages that are derived from FawkesNetworkMessageContent. Note that the class must provide a constructor that takes four parameters: The component ID, message ID, a pointer to the payload and the payload size. From this the class shall parse the output and throw an exception if that for whatever reason fails.
TypeMismatchException | payload size does not match requested type |
|
inline |
Get correctly casted payload.
Use this method to cast the payload to a specific type. The size is check as a sanity check and a TypeMismatchException is thrown if the size does not match. The size of the received message must be greater or equal to the size of the message type. Useful if message contains a variable length string.
TypeMismatchException | payload size does not match requested type |
Definition at line 145 of file message.h.
Referenced by fawkes::NetworkConfiguration::get_bool(), fawkes::NetworkConfiguration::NetConfValueIterator::get_bool(), fawkes::NetworkConfiguration::NetConfValueIterator::get_bools(), fawkes::NetworkConfiguration::get_comment(), fawkes::NetworkConfiguration::NetConfValueIterator::get_comment(), fawkes::NetworkConfiguration::get_default_comment(), fawkes::NetworkConfiguration::get_float(), fawkes::NetworkConfiguration::NetConfValueIterator::get_float(), fawkes::NetworkConfiguration::NetConfValueIterator::get_floats(), fawkes::NetworkConfiguration::get_int(), fawkes::NetworkConfiguration::NetConfValueIterator::get_int(), fawkes::NetworkConfiguration::NetConfValueIterator::get_ints(), fawkes::NetworkConfiguration::NetConfValueIterator::get_list_size(), fawkes::NetworkConfiguration::get_string(), fawkes::NetworkConfiguration::NetConfValueIterator::get_string(), fawkes::NetworkConfiguration::NetConfValueIterator::get_strings(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::NetConfValueIterator::get_uint(), fawkes::NetworkConfiguration::NetConfValueIterator::get_uints(), fawkes::NetworkConfiguration::NetConfValueIterator::is_default(), and fawkes::NetworkConfiguration::NetConfValueIterator::is_list().
unsigned short int fawkes::FawkesNetworkMessage::msgid | ( | ) | const |
Get message type ID.
Definition at line 300 of file message.cpp.
Referenced by fawkes::NetworkConfiguration::NetConfValueIterator::get_as_string(), fawkes::NetworkConfiguration::NetConfValueIterator::get_bool(), fawkes::NetworkConfiguration::NetConfValueIterator::get_bools(), fawkes::NetworkConfiguration::NetConfValueIterator::get_comment(), fawkes::NetworkConfiguration::NetConfValueIterator::get_float(), fawkes::NetworkConfiguration::NetConfValueIterator::get_floats(), fawkes::NetworkConfiguration::NetConfValueIterator::get_int(), fawkes::NetworkConfiguration::NetConfValueIterator::get_ints(), fawkes::NetworkConfiguration::NetConfValueIterator::get_string(), fawkes::NetworkConfiguration::NetConfValueIterator::get_strings(), fawkes::NetworkConfiguration::NetConfValueIterator::get_uint(), fawkes::NetworkConfiguration::NetConfValueIterator::get_uints(), ExampleNetworkThread::handle_network_message(), fawkes::NetworkConfiguration::NetConfValueIterator::is_bool(), fawkes::NetworkConfiguration::NetConfValueIterator::is_default(), fawkes::NetworkConfiguration::NetConfValueIterator::is_float(), fawkes::NetworkConfiguration::NetConfValueIterator::is_int(), fawkes::NetworkConfiguration::NetConfValueIterator::is_string(), fawkes::NetworkConfiguration::NetConfValueIterator::is_uint(), fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator(), fawkes::NetworkConfiguration::NetConfValueIterator::type(), and fawkes::BlackBoardInterfaceProxy::~BlackBoardInterfaceProxy().
void fawkes::FawkesNetworkMessage::pack | ( | ) |
Pack data for sending.
If complex message sending is required (message content object has been set) then serialize() is called for the content and the message is prepared for sending.
Definition at line 398 of file message.cpp.
void * fawkes::FawkesNetworkMessage::payload | ( | ) | const |
Get payload buffer.
Definition at line 318 of file message.cpp.
Referenced by fawkes::NetworkConfiguration::get_bool(), fawkes::NetworkConfiguration::NetConfValueIterator::get_bool(), fawkes::NetworkConfiguration::get_float(), fawkes::NetworkConfiguration::NetConfValueIterator::get_float(), fawkes::NetworkConfiguration::get_int(), fawkes::NetworkConfiguration::NetConfValueIterator::get_int(), fawkes::NetworkConfiguration::get_string(), fawkes::NetworkConfiguration::NetConfValueIterator::get_string(), fawkes::NetworkConfiguration::get_uint(), fawkes::NetworkConfiguration::NetConfValueIterator::get_uint(), ExampleNetworkThread::handle_network_message(), and fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator().
size_t fawkes::FawkesNetworkMessage::payload_size | ( | ) | const |
Get payload size.
Definition at line 309 of file message.cpp.
Referenced by ExampleNetworkThread::handle_network_message(), and fawkes::NetworkConfiguration::NetConfValueIterator::NetConfValueIterator().
void fawkes::FawkesNetworkMessage::set | ( | fawkes_message_t & | msg | ) |
Set from message.
msg | reference to message. Content is deep-copied. |
Definition at line 378 of file message.cpp.
void fawkes::FawkesNetworkMessage::set_client_id | ( | unsigned int | clid | ) |
Set client ID.
clid | client ID |
Definition at line 336 of file message.cpp.
References fawkes::fawkes_message_header_t::cid, and fawkes::fawkes_message_t::header.
Referenced by fawkes::FawkesNetworkServerClientThread::set_clid().
void fawkes::FawkesNetworkMessage::set_component_id | ( | unsigned short int | cid | ) |
void fawkes::FawkesNetworkMessage::set_content | ( | FawkesNetworkMessageContent * | content | ) |
Set complex message content.
content | complex message content. |
Definition at line 387 of file message.cpp.
References fawkes::FawkesNetworkMessageContent::serialize().
void fawkes::FawkesNetworkMessage::set_message_id | ( | unsigned short int | msg_id | ) |
void fawkes::FawkesNetworkMessage::set_payload | ( | void * | payload, |
size_t | payload_size | ||
) |
Set payload.
payload | pointer to payload buffer |
payload_size | size of payload buffer |
Definition at line 364 of file message.cpp.