24 #include <blackboard/net/interface_proxy.h>
25 #include <blackboard/internal/instance_factory.h>
26 #include <blackboard/net/messages.h>
27 #include <blackboard/internal/interface_mem_header.h>
28 #include <blackboard/internal/notifier.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>
37 #include <arpa/inet.h>
62 if ( msg->
msgid() != MSG_BB_OPEN_SUCCESS ) {
63 throw Exception(
"Expected open success message");
69 __notifier = notifier;
71 __instance_serial = ntohl(osm->
serial);
78 if ( interface->
datasize() != __data_size ) {
80 throw Exception(
"Network message does not carry chunk of expected size");
91 strncpy(ih->
type, interface->
type(), __INTERFACE_TYPE_SIZE);
92 strncpy(ih->
id, interface->
id(), __INTERFACE_ID_SIZE);
93 memcpy(ih->
hash, interface->
hash(), __INTERFACE_HASH_SIZE);
98 interface->set_instance_serial(__instance_serial);
99 interface->set_memory(0, __mem_chunk, __data_chunk);
100 interface->set_mediators(
this,
this);
101 interface->set_readwrite(writer, __rwlock);
117 if ( msg->
msgid() != MSG_BB_DATA_CHANGED ) {
119 "received message of type %u, ignoring.", msg->
msgid());
123 void *payload = msg->
payload();
125 if ( ntohl(dm->
serial) != __instance_serial ) {
127 "but got %u, ignoring.", __instance_serial, ntohl(dm->
serial));
131 if ( ntohl(dm->
data_size) != __data_size ) {
133 "but got %zu, ignoring.", __data_size, ntohl(dm->
data_size));
137 memcpy(__data_chunk, (
char *)payload +
sizeof(
bb_idata_msg_t), __data_size);
149 if ( msg->
msgid() != MSG_BB_INTERFACE_MESSAGE ) {
151 "received message of type %u, ignoring.", msg->
msgid());
155 void *payload = msg->
payload();
157 if ( ntohl(mm->
serial) != __instance_serial ) {
159 "but got %u, ignoring.", __instance_serial, ntohl(mm->
serial));
165 "is a reading instance (%s), ignoring.", __interface->
uid());
174 if (im->
hops() > 1) {
175 LibLogger::log_warn(
"BlackBoardInterfaceProxy",
"Message IDs are not stable across more than one hop, "
176 "message of type %s for interface %s has %u hops",
190 __interface->msgq_append(im);
193 e.
append(
"Failed to enqueue interface message for %s, ignoring", __interface->
uid());
215 if ( __num_readers > 0 ) {
237 __has_writer =
false;
248 return __instance_serial;
258 return __instance_serial;
281 return __num_readers;
289 void *payload = malloc(payload_size);
298 payload, payload_size);
309 void *payload = calloc(1, payload_size);
312 unsigned int msgid = next_msg_id();
313 dm->
msgid = htonl(msgid);
316 strncpy(dm->
msg_type, message->
type(), __INTERFACE_MESSAGE_TYPE_SIZE);
322 MSG_BB_INTERFACE_MESSAGE,
323 payload, payload_size);
void notify_of_reader_added(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been added.
uint32_t num_readers
number of currently existing readers
unsigned int hops() const
Get number of hops.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void writer_removed(unsigned int event_serial)
Writer has been removed.
unsigned short serial() const
Get instance serial of interface.
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
Simple Fawkes network client.
uint32_t serial
instance serial to unique identify this instance
const char * type() const
Get message type.
void notify_of_writer_added(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been added.
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
void * payload() const
Get payload buffer.
unsigned int serial() const
Get instance serial of interface.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
const unsigned char * hash() const
Get interface hash.
Representation of a message that is sent over the network.
unsigned short int msgid() const
Get message type ID.
unsigned int datasize() const
Get size of data.
void notify_of_writer_removed(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been removed.
virtual void notify_of_data_change(const Interface *interface)
Notify of data change.
Interface * interface() const
Get instance serial of interface.
void notify_of_data_change(const Interface *interface)
Notify of data change.
char msg_type[__INTERFACE_MESSAGE_TYPE_SIZE]
message type
virtual Message * create_message(const char *type) const =0
Create message based on type name.
Base class for all Fawkes BlackBoard interfaces.
const char * uid() const
Get unique identifier of interface.
const char * id() const
Get identifier of interface.
static void log_error(const char *component, const char *format,...)
Log error message.
unsigned int datasize() const
Get data size.
Base class for exceptions in Fawkes.
void set_from_chunk(const void *chunk)
Set from raw data chunk.
uint32_t has_writer
1 if the interface currently has a writer, 0 otherwise
Interface open success The serial denotes a unique instance of an interface within the (remote) Black...
void reader_removed(unsigned int event_serial)
Reader has been removed.
Read/write lock with reference counting.
uint32_t data_size
data for message
unsigned int clid() const
Get client ID of assigned client.
uint32_t data_size
size in bytes of the following data.
static void log_warn(const char *component, const char *format,...)
Log warning message.
void writer_added(unsigned int event_serial)
Writer has been added.
void reader_added(unsigned int event_serial)
Reader has been added.
uint32_t serial
interface instance serial
uint32_t serial
instance serial to unique identify this instance
~BlackBoardInterfaceProxy()
Destructor.
const void * datachunk() const
Get pointer to data.
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 ...
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
bool is_writer() const
Check if this is a writing instance.
const void * datachunk() const
Get data chunk.
virtual void transmit(Message *message)
Transmit message.
void notify_of_reader_removed(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been removed.
void set_hops(unsigned int hops)
Set number of hops.
uint32_t data_size
size in bytes of the following data.
void process_data_changed(FawkesNetworkMessage *msg)
Process MSG_BB_DATA_CHANGED message.
const char * type() const
Get type of interface.
void set_id(unsigned int message_id)
Set message ID.
void append(const char *format,...)
Append messages to the message list.
unsigned int clid() const
Get client ID.
uint32_t hops
number of hops this message already passed
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.