23 #ifndef __INTERFACE_H_ 24 #define __INTERFACE_H_ 26 #include <interface/message.h> 27 #include <interface/message_queue.h> 28 #include <core/exception.h> 32 #define __STD_LIMIT_MACROS 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 48 class InterfaceMediator;
49 class MessageMediator;
89 bool oftype(
const char *interface_type)
const;
90 const void * datachunk()
const;
91 unsigned int datasize()
const;
92 const char * type()
const;
93 const char * id()
const;
94 const char * uid()
const;
95 unsigned short serial()
const;
96 unsigned int mem_serial()
const;
98 const unsigned char * hash()
const;
99 size_t hash_size()
const;
100 const char * hash_printable()
const;
101 bool is_writer()
const;
102 void set_validity(
bool valid);
103 bool is_valid()
const;
104 const char * owner()
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);
118 Time buffer_timestamp(
unsigned int buffer);
119 void buffer_timestamp(
unsigned int buffer,
Time *timestamp);
124 bool has_writer()
const;
125 unsigned int num_readers()
const;
126 std::string writer()
const;
127 std::list<std::string> readers()
const;
129 bool changed()
const;
130 const Time * timestamp()
const;
131 void set_auto_timestamping(
bool enabled);
132 void set_timestamp(
const Time *t = NULL);
133 void set_clock(
Clock *clock);
134 void mark_data_changed();
136 std::list<const char *> get_message_types();
138 unsigned int msgq_enqueue(
Message *message);
139 unsigned int msgq_enqueue_copy(
Message *message);
140 void msgq_remove(
Message *message);
141 void msgq_remove(
unsigned int message_id);
142 unsigned int msgq_size();
145 bool msgq_try_lock();
150 void msgq_append(
Message *message);
155 template <
class MessageType>
156 bool msgq_first_is();
162 template <
class MessageType>
163 MessageType * msgq_first();
171 template <
class MessageType>
172 MessageType * msgq_first(MessageType *&msg);
181 template <
class MessageType>
182 MessageType * msgq_first_safe(MessageType *&msg)
throw();
205 unsigned int num_fields();
208 static void parse_uid(
const char *uid, std::string &type, std::string &
id);
212 virtual bool message_valid(
const Message *message)
const = 0;
214 void set_hash(
unsigned char *ihash);
216 size_t length,
void *value,
218 void add_messageinfo(
const char *name);
227 void set_type_id(
const char *type,
const char *
id);
228 void set_instance_serial(
unsigned short instance_serial);
231 void set_memory(
unsigned int serial,
void *real_ptr,
void *data_ptr);
233 void set_owner(
const char *owner);
235 inline unsigned int next_msg_id()
237 return (__instance_serial << 16) | ++__next_message_id;
240 char __type[__INTERFACE_TYPE_SIZE + 1];
241 char __id[__INTERFACE_ID_SIZE + 1];
242 char __uid[__INTERFACE_UID_SIZE + 1];
243 unsigned char __hash[__INTERFACE_HASH_SIZE];
244 char __hash_printable[__INTERFACE_HASH_SIZE * 2 + 1];
247 unsigned short __instance_serial;
250 void * __mem_data_ptr;
251 void * __mem_real_ptr;
252 unsigned int __mem_serial;
256 unsigned int __num_buffers;
264 unsigned short __next_message_id;
269 unsigned int __num_fields;
273 Time *__local_read_timestamp;
274 bool __auto_timestamping;
278 template <
class MessageType>
282 MessageType *m =
dynamic_cast<MessageType *
>(__message_queue->first());
291 template <
class MessageType>
295 msg = this->msgq_first<MessageType>();
300 template <
class MessageType>
304 msg =
dynamic_cast<MessageType *
>(__message_queue->first());
312 template <
class MessageType>
316 return (dynamic_cast<MessageType *>(__message_queue->first()) != 0);
333 #define INTERFACE_MGMT_FRIENDS(interface_class) \ 334 friend Interface * private_new##interface_class(); \ 335 friend void private_delete##interface_class(interface_class *interface); 340 #define INTERFACE_GENERATOR(interface_class) \ 342 private_new##interface_class() \ 344 return new interface_class(); \ 351 #define INTERFACE_DELETER(interface_class) \ 353 private_delete##interface_class(interface_class *interface) \ 362 #define INTERFACE_FACTORY(interface_class) \ 365 interface_factory() \ 367 return private_new##interface_class(); \ 374 #define INTERFACE_DESTROY(interface_class) \ 377 interface_destroy(interface_class *interface) \ 379 private_delete##interface_class(interface); \ 385 #define EXPORT_INTERFACE(interface_class) \ 386 INTERFACE_GENERATOR(interface_class) \ 387 INTERFACE_DELETER(interface_class) \ 388 INTERFACE_FACTORY(interface_class) \ 389 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.
Fawkes library namespace.
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.
Message * msgq_first()
Get the first message from the message queue.
InterfaceWriteDeniedException(const char *type, const char *id, const char *msg)
Constructor.
Interface proxy for remote BlackBoard.
int64_t timestamp_usec
additional time microseconds
Read/write lock with reference counting.
void(* InterfaceDestroyFunc)(Interface *interface)
Interface destructor function for the shared library.
Message queue used in interfaces.
Timestamp data, must be present and first entries for each interface data structs! This leans on time...
bool msgq_first_is()
Check if first message has desired type.
MessageType * msgq_first_safe(MessageType *&msg)
Get first message casted to the desired type without exceptions.
BlackBoard message manager.
void set_type_id(const char *id)
Set exception type ID.
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.
std::map< int, std::string > interface_enum_map_t
Map of enum integer to string values.
BlackBoard interface manager.