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",
194 e.
append(
"Failed to enqueue interface message for %s, ignoring", __interface->
uid());
216 if ( __num_readers > 0 ) {
238 __has_writer =
false;
249 return __instance_serial;
259 return __instance_serial;
282 return __num_readers;
285 std::list<std::string>
303 void *payload = malloc(payload_size);
312 payload, payload_size);
323 void *payload = calloc(1, payload_size);
326 unsigned int msgid = next_msg_id();
327 dm->
msgid = htonl(msgid);
330 strncpy(dm->
msg_type, message->
type(), __INTERFACE_MESSAGE_TYPE_SIZE);
336 MSG_BB_INTERFACE_MESSAGE,
337 payload, payload_size);
void * payload() const
Get payload buffer.
void notify_of_reader_added(const Interface *interface, unsigned int event_instance_serial)
Notify that reader has been added.
unsigned int datasize() const
Get data size.
unsigned int clid() const
Get client ID of assigned client.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
void writer_removed(unsigned int event_serial)
Writer has been removed.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
Simple Fawkes network client.
void unref()
Decrement reference count and conditionally delete this instance.
uint32_t serial
instance serial to unique identify this instance
void notify_of_writer_added(const Interface *interface, unsigned int event_instance_serial)
Notify that writer has been added.
Fawkes library namespace.
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
unsigned int clid() const
Get client ID.
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
Called method has not been implemented.
const char * id() const
Get identifier of interface.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
unsigned int serial() const
Get instance serial of interface.
Representation of a message that is sent over the network.
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
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.
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.
void msgq_append(Message *message)
Enqueue message.
Base class for all Fawkes BlackBoard interfaces.
const void * datachunk() const
Get pointer to data.
const unsigned char * hash() const
Get interface hash.
static void log_error(const char *component, const char *format,...)
Log error message.
const char * type() const
Get type of interface.
Base class for exceptions in Fawkes.
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.
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
const char * uid() const
Get unique identifier of interface.
uint32_t data_size
size in bytes of the following data.
static void log_warn(const char *component, const char *format,...)
Log warning message.
bool is_writer() const
Check if this is a writing instance.
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
unsigned short int msgid() const
Get message type ID.
uint32_t serial
instance serial to unique identify this instance
~BlackBoardInterfaceProxy()
Destructor.
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 ...
unsigned int datasize() const
Get size of data.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
const void * datachunk() const
Get data chunk.
Interface * interface() const
Get instance serial of interface.
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 message type.
uint32_t writer_readers
combined writer reader information.
void set_id(unsigned int message_id)
Set message ID.
void append(const char *format,...)
Append messages to the message list.
uint32_t hops
number of hops this message already passed
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.