Fawkes API
Fawkes Development Version
|
24 #ifndef _INTERFACE_MESSAGE_H_
25 #define _INTERFACE_MESSAGE_H_
27 #include <core/exceptions/software.h>
28 #include <core/utils/refcount.h>
29 #include <interface/field_iterator.h>
30 #include <interface/types.h>
33 #include <type_traits>
35 #define INTERFACE_MESSAGE_TYPE_SIZE_ 64
41 class InterfaceFieldIterator;
56 unsigned int id()
const;
57 void set_id(
unsigned int message_id);
65 const char *
type()
const;
75 unsigned int hops()
const;
87 template <
class MessageType>
95 template <
class MessageType>
99 unsigned int message_id_;
102 Time * time_enqueued_;
104 unsigned int recipient_interface_mem_serial;
105 unsigned int sender_interface_instance_serial;
108 char * _sender_thread_name;
109 unsigned int _sender_id;
115 unsigned int num_fields_;
125 const char * enumtype = 0,
141 template <
class MessageType>
145 return (
dynamic_cast<MessageType *
>(
this) != 0);
148 template <
class MessageType>
152 MessageType *m =
dynamic_cast<MessageType *
>(
this);
165 template <
class FieldT,
class DataT>
169 bool rv = field != value;
179 template <
class FieldT, std::
size_t Size>
183 bool change = ::strncmp(field, value, Size);
184 ::strncpy(field, value, Size - 1);
194 template <
class FieldT, std::
size_t Size,
class DataT>
195 typename std::enable_if<!std::is_same<FieldT, char>::value,
bool>::type
198 bool change = ::memcmp(field, value, Size);
199 ::memcpy(field, value,
sizeof(FieldT) * Size);
209 template <
class FieldT, std::
size_t Size,
class DataT>
211 change_field(FieldT (&field)[Size],
unsigned int index,
const DataT &value)
214 throw Exception(
"Index value %u is out of bounds (0..%u)", index, Size - 1);
215 bool change = field[index] != value;
216 field[index] = value;
bool enqueued() const
Check is message has been enqueued.
const void * datachunk() const
Get pointer to data.
interface_fieldtype_t
Interface field type.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
InterfaceFieldIterator fields_end()
Invalid iterator.
void * data_ptr
Pointer to memory that contains local data.
void set_id(unsigned int message_id)
Set message ID.
void mark_enqueued()
Mark message as being enqueued.
message_data_ts_t * data_ts
data timestamp aliasing pointer
const char * sender_thread_name() const
Get sender of message.
const Time * time_enqueued() const
Get time when message was enqueued.
Message(const char *type)
Constructor.
Interface * interface() const
Get transmitting interface.
unsigned int sender_id() const
Get ID of sender.
Timestamp data, must be present and first entries for each interface data structs!...
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
Interface field iterator.
Fawkes library namespace.
Interface field info list.
unsigned int data_size
Size of memory needed to hold all data.
Base class for all Fawkes BlackBoard interfaces.
void set_hops(unsigned int hops)
Set number of hops.
unsigned int datasize() const
Get size of data.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
const char * type() const
Get message type.
unsigned int num_fields() const
Get the number of fields in the message.
A class for handling time.
void add_fieldinfo(interface_fieldtype_t type, const char *name, size_t length, void *value, const char *enumtype=0, const interface_enum_map_t *enum_map=0)
Add an entry to the info list.
virtual ~Message()
Destructor.
Reference counting base class.
Message & operator=(const Message &m)
Assign this message to given message.
MessageType * as_type()
Cast message to given type if possible.
void set_from_chunk(const void *chunk)
Set from raw data chunk.
unsigned int hops() const
Get number of hops.
int64_t timestamp_usec
additional time microseconds
virtual Message * clone() const
Clone this message.
unsigned int id() const
Get message ID.
bool is_of_type()
Check if message has desired type.
unsigned int recipient() const
Get recipient memory serial.
int64_t timestamp_sec
time in seconds since Unix epoch
bool change_field(FieldT &field, const DataT &value)
Set a field and return whether it changed.
Base class for exceptions in Fawkes.