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;
109 virtual const char *
enum_tostring(
const char *enumtype,
int val)
const = 0;
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) void copy_private_to_buffer(unsigned int buffer)
Copy data from private memory to buffer.
Interface field iterator.
This exception is thrown if an interface is invalid and it is attempted to call read()/write().
int64_t timestamp_sec
time in seconds since Unix epoch
const char * owner() const
Get owner of interface.
bool operator==(Interface &comp) const
Check equality of two interfaces.
BlackBoard instance factory.
const char * type
the type of the message
std::string writer() const
Get owner name of writing interface instance.
MessageQueue::MessageIterator msgq_begin()
Get start iterator for message queue.
unsigned int datasize() const
Get data size.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
This exception is thrown if a write has been attempted on a read-only interface.
bool msgq_empty()
Check if queue is empty.
InterfaceInvalidMessageException(const Interface *interface, const Message *message)
Constructor.
void set_hash(unsigned char *ihash)
Set hash.
Interface field info list.
unsigned int msgq_enqueue_copy(Message *message)
Enqueue copy of message at end of queue.
void set_auto_timestamping(bool enabled)
Enable or disable automated timestamping.
Fawkes library namespace.
void msgq_unlock()
Unlock message queue.
interface_messageinfo_t * next
the next field, NULL if last
unsigned int data_size
Minimal data size to hold data storage.
This is supposed to be the central clock in Fawkes.
void msgq_remove(Message *message)
Remove message from queue.
const char * id() const
Get identifier of interface.
A class for handling time.
InterfaceMessageEnqueueException(const char *type, const char *id)
Constructor.
void write()
Write from local copy into BlackBoard memory.
virtual Message * create_message(const char *type) const =0
Create message based on type name.
void msgq_append(Message *message)
Enqueue message.
Base class for all Fawkes BlackBoard interfaces.
This exception is thrown if a message has been queued in the interface which is not recognized by the...
bool msgq_try_lock()
Try to lock message queue.
bool is_valid() const
Check validity of interface.
unsigned int msgq_size()
Get size of message queue.
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.
Time buffer_timestamp(unsigned int buffer)
Get time of a buffer.
unsigned int num_fields()
Get the number of fields in the interface.
unsigned int mem_serial() const
Get memory serial of interface.
const unsigned char * hash() const
Get interface hash.
void add_messageinfo(const char *name)
Add an entry to the message info list.
void msgq_pop()
Erase first message from queue.
bool data_changed
Indicator if data has changed.
const char * type() const
Get type of interface.
void * data_ptr
Pointer to local memory storage.
void read_from_buffer(unsigned int buffer)
Copy data from buffer to private memory.
Base class for exceptions in Fawkes.
Message * msgq_first()
Get the first message from the message queue.
InterfaceWriteDeniedException(const char *type, const char *id, const char *msg)
Constructor.
virtual bool message_valid(const Message *message) const =0
Check if the message is valid and can be enqueued.
unsigned short serial() const
Get instance serial of interface.
void read()
Read from BlackBoard into local copy.
Interface proxy for remote BlackBoard.
virtual ~Interface()
Destructor.
int64_t timestamp_usec
additional time microseconds
Read/write lock with reference counting.
Message queue used in interfaces.
InterfaceInvalidException(const Interface *interface, const char *method)
Constructor.
bool has_writer() const
Check if there is a writer for the interface.
Timestamp data, must be present and first entries for each interface data structs!...
void copy_shared_to_buffer(unsigned int buffer)
Copy data from private memory to buffer.
const char * uid() const
Get unique identifier of interface.
bool oftype(const char *interface_type) const
Check if interface is of given type.
size_t hash_size() const
Get size of interface hash.
bool msgq_first_is()
Check if first message has desired type.
const Time * timestamp() const
Get timestamp of last write.
bool is_writer() const
Check if this is a writing instance.
bool changed() const
Check if data has been changed.
unsigned int msgq_enqueue(Message *message)
Enqueue message at end of queue.
void(* InterfaceDestroyFunc)(Interface *interface)
Interface destructor function for the shared library.
virtual const char * enum_tostring(const char *enumtype, int val) const =0
Convert arbitrary enum value to string.
InterfaceFieldIterator fields_end()
Invalid iterator.
void set_clock(Clock *clock)
Set clock to use for timestamping.
void resize_buffers(unsigned int num_buffers)
Resize buffer array.
static void parse_uid(const char *uid, std::string &type, std::string &id)
Parse UID to type and ID strings.
MessageType * msgq_first_safe(MessageType *&msg)
Get first message casted to the desired type without exceptions.
BlackBoard message manager.
void msgq_flush()
Flush all messages.
void msgq_lock()
Lock message queue.
int compare_buffers(unsigned int buffer)
Compare buffer to private memory.
unsigned int num_buffers() const
Get number of buffers.
void set_validity(bool valid)
Mark this interface invalid.
const void * datachunk() const
Get data chunk.
unsigned int num_readers() const
Get the number of readers.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
InterfaceFieldIterator fields()
Get iterator over all fields of this interface instance.
Message * first()
Get first message from queue.
Mutex mutual exclusion lock.
void set_from_chunk(void *chunk)
Set from a raw data chunk.
This exception is thrown if a write has been attempted on a read-only interface.
interface_fieldtype_t
Interface field type.
std::list< std::string > readers() const
Get owner names of reading interface instances.
virtual void copy_values(const Interface *interface)=0
Copy values from another interface.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
BlackBoard interface manager.
void set_timestamp(const Time *t=NULL)
Set timestamp.
std::list< const char * > get_message_types()
Obtain a list of textual representations of the message types available for this interface.
void mark_data_changed()
Mark data as changed.
const char * hash_printable() const
Get printable interface hash.
MessageQueue::MessageIterator msgq_end()
Get end iterator for message queue.