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