Fawkes API
Fawkes Development Version
|
24 #include <arpa/inet.h>
25 #include <blackboard/internal/instance_factory.h>
26 #include <blackboard/internal/interface_mem_header.h>
27 #include <blackboard/internal/notifier.h>
28 #include <blackboard/net/interface_proxy.h>
29 #include <blackboard/net/messages.h>
30 #include <core/threading/refc_rwlock.h>
31 #include <logging/liblogger.h>
32 #include <netcomm/fawkes/client.h>
33 #include <netcomm/fawkes/message.h>
62 if (msg->
msgid() != MSG_BB_OPEN_SUCCESS) {
63 throw Exception(
"Expected open success message");
66 void * payload = msg->
payload();
71 instance_serial_ = ntohl(osm->
serial);
80 throw Exception(
"Network message does not carry chunk of expected size");
98 interface->set_instance_serial(instance_serial_);
99 interface->set_memory(0, mem_chunk_, data_chunk_);
116 if (msg->
msgid() != MSG_BB_DATA_CHANGED) {
118 "Expected data changed BB message, but "
119 "received message of type %u, ignoring.",
124 void * payload = msg->
payload();
126 if (ntohl(dm->
serial) != instance_serial_) {
128 "Serial mismatch, expected %u, "
129 "but got %u, ignoring.",
135 if (ntohl(dm->
data_size) != data_size_) {
137 "Data size mismatch, expected %zu, "
138 "but got %zu, ignoring.",
144 memcpy(data_chunk_, (
char *)payload +
sizeof(
bb_idata_msg_t), data_size_);
155 if (msg->
msgid() != MSG_BB_INTERFACE_MESSAGE) {
157 "Expected interface BB message, but "
158 "received message of type %u, ignoring.",
163 void * payload = msg->
payload();
165 if (ntohl(mm->
serial) != instance_serial_) {
167 "Serial mismatch (msg), expected %u, "
168 "but got %u, ignoring.",
176 "Received interface message, but this"
177 "is a reading instance (%s), ignoring.",
187 if (im->
hops() > 1) {
189 "Message IDs are not stable across more than one hop, "
190 "message of type %s for interface %s has %u hops",
198 "Message data size mismatch, expected "
199 "%zu, but got %zu, ignoring.",
213 e.
append(
"Failed to enqueue interface message for %s, ignoring", interface_->
uid());
234 if (num_readers_ > 0) {
266 return instance_serial_;
275 return instance_serial_;
300 std::list<std::string>
317 void * payload = malloc(payload_size);
324 clid_, FAWKES_CID_BLACKBOARD, MSG_BB_DATA_CHANGED, payload, payload_size);
334 void * payload = calloc(1, payload_size);
337 unsigned int msgid = next_msg_id();
338 dm->
msgid = htonl(msgid);
341 strncpy(dm->
msg_type, message->
type(), INTERFACE_MESSAGE_TYPE_SIZE_ - 1);
346 clid_, FAWKES_CID_BLACKBOARD, MSG_BB_INTERFACE_MESSAGE, payload, payload_size);
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
void unref()
Decrement reference count and conditionally delete this instance.
const void * datachunk() const
Get data chunk.
virtual void notify_of_data_change(const Interface *interface)
Notify of data change.
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.
void reader_added(unsigned int event_serial)
Reader has been added.
uint32_t writer_readers
combined writer reader information.
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
uint32_t data_size
size in bytes of the following data.
const void * datachunk() const
Get pointer to data.
virtual Message * create_message(const char *type) const =0
Create message based on type name.
virtual void transmit(Message *message)
Transmit message.
Read/write lock with reference counting.
bool is_writer() const
Check if this is a writing instance.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
uint32_t data_size
size in bytes of the following data.
unsigned int serial() const
Get instance serial of interface.
static void log_error(const char *component, const char *format,...)
Log error message.
void set_id(unsigned int message_id)
Set message ID.
uint32_t serial
instance serial to unique identify this instance
const unsigned char * hash() const
Get interface hash.
uint32_t hops
number of hops this message already passed
void reader_removed(unsigned int event_serial)
Reader has been removed.
char msg_type[INTERFACE_MESSAGE_TYPE_SIZE_]
message type
const char * type() const
Get type of interface.
const char * id() const
Get identifier of interface.
bool notify_of_message_received(const Interface *interface, Message *message)
Notify of message received Notify all subscribers of the given interface of an incoming message This ...
void append(const char *format,...)
Append messages to the message list.
void notify_of_reader_removed(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been removed.
uint32_t data_size
data for message
static void log_warn(const char *component, const char *format,...)
Log warning message.
Fawkes library namespace.
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
void process_data_changed(FawkesNetworkMessage *msg)
Process MSG_BB_DATA_CHANGED message.
void * payload() const
Get payload buffer.
void msgq_append(Message *message)
Enqueue message.
Base class for all Fawkes BlackBoard interfaces.
void notify_of_reader_added(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been added.
void set_hops(unsigned int hops)
Set number of hops.
unsigned int datasize() const
Get size of data.
~BlackBoardInterfaceProxy()
Destructor.
const char * type() const
Get message type.
uint32_t serial
instance serial to unique identify this instance
const char * uid() const
Get unique identifier of interface.
unsigned int clid() const
Get client ID of assigned client.
Interface open success The serial denotes a unique instance of an interface within the (remote) Black...
void notify_of_writer_added(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been added.
void writer_added(unsigned int event_serial)
Writer has been added.
void notify_of_data_change(const Interface *interface)
Notify of data change.
Called method has not been implemented.
unsigned short serial() const
Get instance serial of interface.
void set_from_chunk(const void *chunk)
Set from raw data chunk.
unsigned int hops() const
Get number of hops.
Representation of a message that is sent over the network.
void writer_removed(unsigned int event_serial)
Writer has been removed.
unsigned int datasize() const
Get data size.
uint32_t serial
interface instance serial
Simple Fawkes network client.
unsigned int clid() const
Get client ID.
unsigned short int msgid() const
Get message type ID.
void notify_of_writer_removed(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been removed.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
Interface * interface() const
Get instance serial of interface.
Base class for exceptions in Fawkes.