26#include <core/exception.h>
27#include <interface/message.h>
28#include <interface/message_queue.h>
29#include <utils/uuid.h>
35#define INTERFACE_TYPE_SIZE_ 48
36#define INTERFACE_ID_SIZE_ 64
38#define INTERFACE_HASH_SIZE_ 16
40#define INTERFACE_UID_SIZE_ INTERFACE_TYPE_SIZE_ + 2 + INTERFACE_ID_SIZE_
45class InterfaceMediator;
50class BlackBoardInterfaceManager;
51class BlackBoardInstanceFactory;
52class BlackBoardMessageManager;
53class BlackBoardInterfaceProxy;
89 bool oftype(
const char *interface_type)
const;
92 const char *
type()
const;
93 const char *
id()
const;
94 const char *
uid()
const;
98 const unsigned char *
hash()
const;
104 const char *
owner()
const;
126 std::string
writer()
const;
127 std::list<std::string>
readers()
const;
157 template <
class MessageType>
164 template <
class MessageType>
173 template <
class MessageType>
183 template <
class MessageType>
218 void set_hash(
unsigned char *ihash);
223 const char * enumtype = 0,
232 template <
class FieldT,
class DataT>
233 void set_field(FieldT &field, DataT &data);
241 template <
class FieldT,
class DataT>
242 void set_field(FieldT &field,
unsigned int index, DataT &data);
252 void set_type_id(
const char *
type,
const char *
id);
255 void set_memory(
unsigned int serial,
void *real_ptr,
void *
data_ptr);
257 void set_owner(
const char *
owner);
262 return ++next_message_id_;
265 char type_[INTERFACE_TYPE_SIZE_ + 1];
266 char id_[INTERFACE_ID_SIZE_ + 1];
267 char uid_[INTERFACE_UID_SIZE_ + 1];
268 unsigned char hash_[INTERFACE_HASH_SIZE_];
269 char hash_printable_[INTERFACE_HASH_SIZE_ * 2 + 1];
272 Uuid instance_serial_;
275 void * mem_data_ptr_;
276 void * mem_real_ptr_;
277 unsigned int mem_serial_;
281 unsigned int num_buffers_;
289 unsigned short next_message_id_;
292 interface_messageinfo_t *messageinfo_list_;
294 unsigned int num_fields_;
298 Time * local_read_timestamp_;
299 bool auto_timestamping_;
302template <
class FieldT,
class DataT>
310template <
class FieldT,
class DataT>
318template <
class MessageType>
322 MessageType *m =
dynamic_cast<MessageType *
>(message_queue_->
first());
330template <
class MessageType>
334 msg = this->msgq_first<MessageType>();
338template <
class MessageType>
342 msg =
dynamic_cast<MessageType *
>(message_queue_->first());
349template <
class MessageType>
353 return (
dynamic_cast<MessageType *
>(message_queue_->
first()) != 0);
368#define INTERFACE_MGMT_FRIENDS(interface_class) \
369 friend Interface *private_new##interface_class(); \
370 friend void private_delete##interface_class(interface_class *interface);
375#define INTERFACE_GENERATOR(interface_class) \
376 Interface *private_new##interface_class() \
378 return new interface_class(); \
384#define INTERFACE_DELETER(interface_class) \
385 void private_delete##interface_class(interface_class *interface) \
393#define INTERFACE_FACTORY(interface_class) \
394 extern "C" Interface *interface_factory() \
396 return private_new##interface_class(); \
402#define INTERFACE_DESTROY(interface_class) \
403 extern "C" void interface_destroy(interface_class *interface) \
405 private_delete##interface_class(interface); \
411#define EXPORT_INTERFACE(interface_class) \
412 INTERFACE_GENERATOR(interface_class) \
413 INTERFACE_DELETER(interface_class) \
414 INTERFACE_FACTORY(interface_class) \
415 INTERFACE_DESTROY(interface_class)
BlackBoard instance factory.
BlackBoard interface manager.
Interface proxy for remote BlackBoard.
BlackBoard message manager.
This is supposed to be the central clock in Fawkes.
Base class for exceptions in Fawkes.
Interface field iterator.
This exception is thrown if an interface is invalid and it is attempted to call read()/write().
InterfaceInvalidException(const Interface *interface, const char *method)
Constructor.
This exception is thrown if a message has been queued in the interface which is not recognized by the...
InterfaceInvalidMessageException(const Interface *interface, const Message *message)
Constructor.
This exception is thrown if a write has been attempted on a read-only interface.
InterfaceMessageEnqueueException(const char *type, const char *id)
Constructor.
This exception is thrown if a write has been attempted on a read-only interface.
InterfaceWriteDeniedException(const char *type, const char *id, const char *msg)
Constructor.
Base class for all Fawkes BlackBoard interfaces.
std::list< std::string > readers() const
Get owner names of reading interface instances.
bool msgq_try_lock()
Try to lock message queue.
bool msgq_first_is()
Check if first message has desired type.
void copy_shared_to_buffer(unsigned int buffer)
Copy data from private memory to buffer.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
const char * hash_printable() const
Get printable interface hash.
const void * datachunk() const
Get data chunk.
void mark_data_changed()
Mark data as changed.
bool operator==(Interface &comp) const
Check equality of two interfaces.
void set_validity(bool valid)
Mark this interface invalid.
unsigned int msgq_enqueue_copy(Message *message)
Enqueue copy of message at end of queue.
void copy_private_to_buffer(unsigned int buffer)
Copy data from private memory to buffer.
const char * type() const
Get type of interface.
bool data_refreshed
Indicator if data can be considered "current", i.e.
void set_auto_timestamping(bool enabled)
Enable or disable automated timestamping.
virtual ~Interface()
Destructor.
void msgq_pop()
Erase first message from queue.
void read_from_buffer(unsigned int buffer)
Copy data from buffer to private memory.
std::string writer() const
Get owner name of writing interface instance.
void * data_ptr
Pointer to local memory storage.
const Time * timestamp() const
Get timestamp of last write.
Message * msgq_first()
Get the first message from the message queue.
Time buffer_timestamp(unsigned int buffer)
Get time of a buffer.
void resize_buffers(unsigned int num_buffers)
Resize buffer array.
InterfaceFieldIterator fields_end()
Invalid iterator.
size_t hash_size() const
Get size of interface hash.
unsigned int msgq_enqueue(Message *message, bool proxy=false)
Enqueue message at end of queue.
virtual Message * create_message(const char *type) const =0
Create message based on type name.
bool is_writer() const
Check if this is a writing instance.
void set_field(FieldT &field, DataT &data)
Set a field, set data_changed to true and update data_changed accordingly.
void msgq_remove(Message *message)
Remove message from queue.
const unsigned char * hash() const
Get interface hash.
void msgq_append(Message *message)
Enqueue message.
MessageQueue::MessageIterator msgq_end()
Get end iterator for message queue.
unsigned int msgq_size()
Get size of message queue.
void write()
Write from local copy into BlackBoard memory.
const char * id() const
Get identifier of interface.
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 field info list.
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
void set_hash(unsigned char *ihash)
Set hash.
bool data_changed
Indicator if the current data is different from the last call to write() This must is automatically u...
unsigned int data_size
Minimal data size to hold data storage.
unsigned int mem_serial() const
Get memory serial of interface.
virtual const char * enum_tostring(const char *enumtype, int val) const =0
Convert arbitrary enum value to string.
Uuid serial() const
Get instance serial of interface.
bool msgq_empty()
Check if queue is empty.
virtual void copy_values(const Interface *interface)=0
Copy values from another interface.
void set_from_chunk(void *chunk)
Set from a raw data chunk.
void msgq_lock()
Lock message queue.
const char * uid() const
Get unique identifier of interface.
bool is_valid() const
Check validity of interface.
void msgq_flush()
Flush all messages.
unsigned int num_readers() const
Get the number of readers.
void read()
Read from BlackBoard into local copy.
int compare_buffers(unsigned int buffer)
Compare buffer to private memory.
void msgq_unlock()
Unlock message queue.
static void parse_uid(const char *uid, std::string &type, std::string &id)
Parse UID to type and ID strings.
void set_clock(Clock *clock)
Set clock to use for timestamping.
unsigned int num_fields()
Get the number of fields in the interface.
unsigned int datasize() const
Get data size.
std::list< const char * > get_message_types()
Obtain a list of textual representations of the message types available for this interface.
MessageType * msgq_first_safe(MessageType *&msg) noexcept
Get first message casted to the desired type without exceptions.
unsigned int num_buffers() const
Get number of buffers.
bool has_writer() const
Check if there is a writer for the interface.
void mark_data_refreshed()
Mark data as refreshed.
void add_messageinfo(const char *name)
Add an entry to the message info list.
const char * owner() const
Get owner of interface.
bool oftype(const char *interface_type) const
Check if interface is of given type.
MessageQueue::MessageIterator msgq_begin()
Get start iterator for message queue.
void set_timestamp(const Time *t=NULL)
Set timestamp.
bool refreshed() const
Check if data has been refreshed.
virtual bool message_valid(const Message *message) const =0
Check if the message is valid and can be enqueued.
Message queue used in interfaces.
Message * first()
Get first message from queue.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
Mutex mutual exclusion lock.
Read/write lock with reference counting.
A class for handling time.
A convenience class for universally unique identifiers (UUIDs).
Fawkes library namespace.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
void(* InterfaceDestroyFunc)(Interface *interface)
Interface destructor function for the shared library.
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_usec
additional time microseconds
int64_t timestamp_sec
time in seconds since Unix epoch
const char * type
the type of the message
interface_messageinfo_t * next
the next field, NULL if last
Interface field info list.