24 #ifndef __INTERFACE_H_
25 #define __INTERFACE_H_
27 #include <interface/message.h>
28 #include <interface/message_queue.h>
29 #include <core/exception.h>
33 #define __STD_LIMIT_MACROS
36 #define __INTERFACE_TYPE_SIZE 32
37 #define __INTERFACE_ID_SIZE 32
39 #define __INTERFACE_HASH_SIZE 16
41 #define __INTERFACE_UID_SIZE __INTERFACE_TYPE_SIZE + 2 + __INTERFACE_ID_SIZE
49 class InterfaceMediator;
50 class MessageMediator;
90 bool oftype(
const char *interface_type)
const;
91 const void * datachunk()
const;
92 unsigned int datasize()
const;
93 const char * type()
const;
94 const char * id()
const;
95 const char * uid()
const;
96 unsigned short serial()
const;
97 unsigned int mem_serial()
const;
99 const unsigned char * hash()
const;
100 size_t hash_size()
const;
101 const char * hash_printable()
const;
102 bool is_writer()
const;
103 void set_validity(
bool valid);
104 bool is_valid()
const;
106 void set_from_chunk(
void *chunk);
108 virtual Message * create_message(
const char *type)
const = 0;
109 virtual void copy_values(
const Interface *interface) = 0;
110 virtual const char * enum_tostring(
const char *enumtype,
int val)
const = 0;
112 void resize_buffers(
unsigned int num_buffers);
113 unsigned int num_buffers()
const;
114 void copy_shared_to_buffer(
unsigned int buffer);
115 void copy_private_to_buffer(
unsigned int buffer);
116 void read_from_buffer(
unsigned int buffer);
117 int compare_buffers(
unsigned int buffer);
122 bool has_writer()
const;
123 unsigned int num_readers()
const;
125 bool changed()
const;
126 const Time * timestamp()
const;
127 void set_auto_timestamping(
bool enabled);
128 void set_timestamp(
const Time *t = NULL);
129 void set_clock(
Clock *clock);
131 std::list<const char *> get_message_types();
133 unsigned int msgq_enqueue(
Message *message);
134 unsigned int msgq_enqueue_copy(
Message *message);
135 void msgq_remove(
Message *message);
136 void msgq_remove(
unsigned int message_id);
137 unsigned int msgq_size();
140 bool msgq_try_lock();
149 template <
class MessageType>
150 bool msgq_first_is();
156 template <
class MessageType>
157 MessageType * msgq_first();
165 template <
class MessageType>
166 MessageType * msgq_first(MessageType *&msg);
175 template <
class MessageType>
176 MessageType * msgq_first_safe(MessageType *&msg)
throw();
192 unsigned int num_fields();
195 static void parse_uid(
const char *uid,
char **type,
char **
id);
199 virtual bool message_valid(
const Message *message)
const = 0;
201 void set_hash(
unsigned char *ihash);
203 size_t length,
void *value,
const char *enumtype = 0);
204 void add_messageinfo(
const char *name);
219 void msgq_append(
Message *message);
220 void set_type_id(
const char *type,
const char *
id);
221 void set_instance_serial(
unsigned short instance_serial);
224 void set_memory(
unsigned int serial,
void *real_ptr,
void *data_ptr);
227 inline unsigned int next_msg_id()
229 return (__instance_serial << 16) | ++__next_message_id;
232 char __type[__INTERFACE_TYPE_SIZE + 1];
233 char __id[__INTERFACE_ID_SIZE + 1];
234 char __uid[__INTERFACE_UID_SIZE + 1];
235 unsigned char __hash[__INTERFACE_HASH_SIZE];
236 char __hash_printable[__INTERFACE_HASH_SIZE * 2 + 1];
238 unsigned short __instance_serial;
241 void * __mem_data_ptr;
242 void * __mem_real_ptr;
243 unsigned int __mem_serial;
247 unsigned int __num_buffers;
255 unsigned short __next_message_id;
258 interface_messageinfo_t *__messageinfo_list;
260 unsigned int __num_fields;
264 Time *__local_read_timestamp;
265 bool __auto_timestamping;
269 template <
class MessageType>
271 Interface::msgq_first()
273 MessageType *m =
dynamic_cast<MessageType *
>(__message_queue->first());
282 template <
class MessageType>
284 Interface::msgq_first(MessageType *&msg)
286 msg = this->msgq_first<MessageType>();
291 template <
class MessageType>
293 Interface::msgq_first_safe(MessageType *&msg)
throw()
295 msg =
dynamic_cast<MessageType *
>(__message_queue->first());
303 template <
class MessageType>
305 Interface::msgq_first_is()
307 return (dynamic_cast<MessageType *>(__message_queue->first()) != 0);
315 typedef void (* InterfaceDestroyFunc) (
Interface *interface);
324 #define INTERFACE_MGMT_FRIENDS(interface_class) \
325 friend Interface * private_new##interface_class(); \
326 friend void private_delete##interface_class(interface_class *interface);
331 #define INTERFACE_GENERATOR(interface_class) \
333 private_new##interface_class() \
335 return new interface_class(); \
342 #define INTERFACE_DELETER(interface_class) \
344 private_delete##interface_class(interface_class *interface) \
353 #define INTERFACE_FACTORY(interface_class) \
356 interface_factory() \
358 return private_new##interface_class(); \
365 #define INTERFACE_DESTROY(interface_class) \
368 interface_destroy(interface_class *interface) \
370 private_delete##interface_class(interface); \
376 #define EXPORT_INTERFACE(interface_class) \
377 INTERFACE_GENERATOR(interface_class) \
378 INTERFACE_DELETER(interface_class) \
379 INTERFACE_FACTORY(interface_class) \
380 INTERFACE_DESTROY(interface_class)
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
BlackBoard instance factory.
const char * type
the type of the message
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.
Interface field info list.
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.
A class for handling time.
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 data_changed
Indicator if data has changed.
void * data_ptr
Pointer to local memory storage.
Base class for exceptions in Fawkes.
Interface proxy for remote BlackBoard.
int64_t timestamp_usec
additional time microseconds
Read/write lock with reference counting.
Message queue used in interfaces.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
BlackBoard message manager.
interface_data_ts_t * data_ts
Pointer to data casted to timestamp struct.
Mutex mutual exclusion lock.
This exception is thrown if a write has been attempted on a read-only interface.
interface_fieldtype_t
Interface field type.
BlackBoard interface manager.