26 #include <core/exception.h>
27 #include <interface/message.h>
28 #include <interface/message_queue.h>
34 #define INTERFACE_TYPE_SIZE_ 48
35 #define INTERFACE_ID_SIZE_ 64
37 #define INTERFACE_HASH_SIZE_ 16
39 #define INTERFACE_UID_SIZE_ INTERFACE_TYPE_SIZE_ + 2 + INTERFACE_ID_SIZE_
44 class InterfaceMediator;
45 class MessageMediator;
49 class BlackBoardInterfaceManager;
50 class BlackBoardInstanceFactory;
51 class BlackBoardMessageManager;
52 class BlackBoardInterfaceProxy;
88 bool oftype(
const char *interface_type)
const;
91 const char *
type()
const;
92 const char *
id()
const;
93 const char *
uid()
const;
94 unsigned short serial()
const;
97 const unsigned char *
hash()
const;
103 const char *
owner()
const;
125 std::string
writer()
const;
126 std::list<std::string>
readers()
const;
154 template <
class MessageType>
161 template <
class MessageType>
170 template <
class MessageType>
180 template <
class MessageType>
215 void set_hash(
unsigned char *ihash);
220 const char * enumtype = 0,
231 void set_type_id(
const char *
type,
const char *
id);
232 void set_instance_serial(
unsigned short instance_serial);
234 void set_memory(
unsigned int serial,
void *real_ptr,
void *
data_ptr);
236 void set_owner(
const char *
owner);
241 return (instance_serial_ << 16) | ++next_message_id_;
244 char type_[INTERFACE_TYPE_SIZE_ + 1];
245 char id_[INTERFACE_ID_SIZE_ + 1];
246 char uid_[INTERFACE_UID_SIZE_ + 1];
247 unsigned char hash_[INTERFACE_HASH_SIZE_];
248 char hash_printable_[INTERFACE_HASH_SIZE_ * 2 + 1];
251 unsigned short instance_serial_;
254 void * mem_data_ptr_;
255 void * mem_real_ptr_;
256 unsigned int mem_serial_;
260 unsigned int num_buffers_;
268 unsigned short next_message_id_;
271 interface_messageinfo_t *messageinfo_list_;
273 unsigned int num_fields_;
277 Time * local_read_timestamp_;
278 bool auto_timestamping_;
281 template <
class MessageType>
285 MessageType *m =
dynamic_cast<MessageType *
>(message_queue_->
first());
293 template <
class MessageType>
297 msg = this->msgq_first<MessageType>();
301 template <
class MessageType>
305 msg =
dynamic_cast<MessageType *
>(message_queue_->first());
312 template <
class MessageType>
316 return (
dynamic_cast<MessageType *
>(message_queue_->
first()) != 0);
331 #define INTERFACE_MGMT_FRIENDS(interface_class) \
332 friend Interface *private_new##interface_class(); \
333 friend void private_delete##interface_class(interface_class *interface);
338 #define INTERFACE_GENERATOR(interface_class) \
339 Interface *private_new##interface_class() \
341 return new interface_class(); \
347 #define INTERFACE_DELETER(interface_class) \
348 void private_delete##interface_class(interface_class *interface) \
356 #define INTERFACE_FACTORY(interface_class) \
357 extern "C" Interface *interface_factory() \
359 return private_new##interface_class(); \
365 #define INTERFACE_DESTROY(interface_class) \
366 extern "C" void interface_destroy(interface_class *interface) \
368 private_delete##interface_class(interface); \
374 #define EXPORT_INTERFACE(interface_class) \
375 INTERFACE_GENERATOR(interface_class) \
376 INTERFACE_DELETER(interface_class) \
377 INTERFACE_FACTORY(interface_class) \
378 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.
void set_auto_timestamping(bool enabled)
Enable or disable automated timestamping.
virtual ~Interface()
Destructor.
MessageType * msgq_first_safe(MessageType *&msg)
Get first message casted to the desired type without exceptions.
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.
bool changed() const
Check if data has been changed.
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.
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 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 data has changed.
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.
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.
unsigned short serial() const
Get instance serial 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.
unsigned int num_buffers() const
Get number of buffers.
bool has_writer() const
Check if there is a writer for the interface.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
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.
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.
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.
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.