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);