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;
Base class for exceptions in Fawkes.
Interface field iterator.
Base class for all Fawkes BlackBoard interfaces.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
unsigned int sender_id() const
Get ID of sender.
unsigned int recipient() const
Get recipient memory serial.
virtual ~Message()
Destructor.
const char * type() const
Get message type.
const void * datachunk() const
Get pointer to data.
void mark_enqueued()
Mark message as being enqueued.
unsigned int datasize() const
Get size of data.
Message(const char *type)
Constructor.
bool enqueued() const
Check is message has been enqueued.
MessageType * as_type()
Cast message to given type if possible.
bool is_of_type()
Check if message has desired type.
Interface * interface() const
Get transmitting interface.
void set_from_chunk(const void *chunk)
Set from raw data chunk.
void set_id(unsigned int message_id)
Set message ID.
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.
void * data_ptr
Pointer to memory that contains local data.
message_data_ts_t * data_ts
data timestamp aliasing pointer
const Time * time_enqueued() const
Get time when message was enqueued.
unsigned int num_fields() const
Get the number of fields in the message.
void set_hops(unsigned int hops)
Set number of hops.
Message & operator=(const Message &m)
Assign this message to given message.
virtual Message * clone() const
Clone this message.
InterfaceFieldIterator fields_end()
Invalid iterator.
const char * sender_thread_name() const
Get sender of message.
unsigned int id() const
Get message ID.
unsigned int hops() const
Get number of hops.
unsigned int data_size
Size of memory needed to hold all data.
Reference counting base class.
A class for handling time.
Fawkes library namespace.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
interface_fieldtype_t
Interface field type.
bool change_field(FieldT &field, const DataT &value)
Set a field and return whether it changed.
Timestamp data, must be present and first entries for each interface data structs!...
int64_t timestamp_sec
time in seconds since Unix epoch
int64_t timestamp_usec
additional time microseconds
Interface field info list.