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_ = 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 && msg->
msgid() != MSG_BB_DATA_REFRESHED) {
118 "Expected data changed BB message, but "
119 "received message of type %u, ignoring.",
124 void * payload = msg->
payload();
126 if (dm->
serial != instance_serial_) {
128 "Serial mismatch, expected %s, "
129 "but got %s, 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 (mm->
serial != instance_serial_) {
167 "Serial mismatch (msg), expected %s, "
168 "but got %s, ignoring.",
176 "Received interface message, but this"
177 "is a reading instance (%s), ignoring.",
189 "Setting sender id to %s, source id to %s",
193 if (im->
hops() > 1) {
195 "Message IDs are not stable across more than one hop, "
196 "message of type %s for interface %s has %u hops",
204 "Message data size mismatch, expected "
205 "%zu, but got %zu, ignoring.",
219 e.
append(
"Failed to enqueue interface message for %s, ignoring", interface_->
uid());
240 if (num_readers_ > 0) {
272 return instance_serial_;
281 return instance_serial_;
306std::list<std::string>
323 void * payload = malloc(payload_size);
331 FAWKES_CID_BLACKBOARD,
332 has_changed ? MSG_BB_DATA_CHANGED : MSG_BB_DATA_REFRESHED,
344 void * payload = calloc(1, payload_size);
348 unsigned int msgid = next_msg_id();
349 dm->
msgid = htonl(msgid);
352 strncpy(dm->
msg_type, message->
type(), INTERFACE_MESSAGE_TYPE_SIZE_ - 1);
357 clid_, FAWKES_CID_BLACKBOARD, MSG_BB_INTERFACE_MESSAGE, payload, payload_size);
virtual void transmit(Message *message)
Transmit message.
Uuid clid() const
Get client ID of assigned client.
Interface * interface() const
Get instance serial of interface.
void process_interface_message(FawkesNetworkMessage *msg)
Process MSG_BB_INTERFACE message.
~BlackBoardInterfaceProxy()
Destructor.
virtual bool exists_writer(const Interface *interface) const
Check if a writer exists for the given interface.
void reader_removed(Uuid event_serial)
Reader has been removed.
void reader_added(Uuid event_serial)
Reader has been added.
Uuid serial() const
Get instance serial of interface.
void process_data_refreshed(FawkesNetworkMessage *msg)
Process MSG_BB_DATA_CHANGED/REFRESHED message.
virtual void notify_of_data_refresh(const Interface *interface, bool has_changed)
Notify of data change.
virtual unsigned int num_readers(const Interface *interface) const
Get number of readers.
BlackBoardInterfaceProxy(FawkesNetworkClient *client, FawkesNetworkMessage *msg, BlackBoardNotifier *notifier, Interface *interface, bool readwrite)
Constructor.
virtual std::list< std::string > readers(const Interface *interface) const
Get owners of interfaces who opened for reading.
virtual std::string writer(const Interface *interface) const
Get writer of interface.
void writer_added(Uuid event_serial)
Writer has been added.
void writer_removed(Uuid event_serial)
Writer has been removed.
void notify_of_writer_added(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that writer has been added.
void notify_of_writer_removed(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that writer has been removed.
void notify_of_reader_added(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that reader has been added.
void notify_of_reader_removed(const Interface *interface, Uuid event_instance_serial) noexcept
Notify that reader has been removed.
void notify_of_data_refresh(const Interface *interface, bool has_changed)
Notify of data change.
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 ...
Base class for exceptions in Fawkes.
void append(const char *format,...) noexcept
Append messages to the message list.
Simple Fawkes network client.
void enqueue(FawkesNetworkMessage *message)
Enqueue message to send.
Representation of a message that is sent over the network.
unsigned short int msgid() const
Get message type ID.
unsigned int clid() const
Get client ID.
void * payload() const
Get payload buffer.
Base class for all Fawkes BlackBoard interfaces.
const void * datachunk() const
Get data chunk.
const char * type() const
Get type of interface.
virtual Message * create_message(const char *type) const =0
Create message based on type name.
bool is_writer() const
Check if this is a writing instance.
const unsigned char * hash() const
Get interface hash.
void msgq_append(Message *message)
Enqueue message.
const char * id() const
Get identifier of interface.
Uuid serial() const
Get instance serial of interface.
const char * uid() const
Get unique identifier of interface.
unsigned int datasize() const
Get data size.
static void log_warn(const char *component, const char *format,...)
Log warning message.
static void log_error(const char *component, const char *format,...)
Log error message.
static void log_debug(const char *component, const char *format,...)
Log debug message.
Base class for all messages passed through interfaces in Fawkes BlackBoard.
const char * type() const
Get message type.
const void * datachunk() const
Get pointer to data.
unsigned int datasize() const
Get size of data.
Uuid source_id() const
Get ID of the original source of the message.
void set_source_id(const Uuid &id)
Set source ID.
void set_from_chunk(const void *chunk)
Set from raw data chunk.
void set_id(unsigned int message_id)
Set message ID.
void set_hops(unsigned int hops)
Set number of hops.
unsigned int hops() const
Get number of hops.
void set_sender_id(const Uuid &id)
Set sender ID.
Called method has not been implemented.
Read/write lock with reference counting.
void unref()
Decrement reference count and conditionally delete this instance.
A convenience class for universally unique identifiers (UUIDs).
std::string get_string() const
Get the string representation of the Uuid.
Fawkes library namespace.
uint32_t data_size
size in bytes of the following data.
Uuid serial
instance serial to unique identify this instance
Uuid serial
interface instance serial
Uuid source
serial of the original message source
uint32_t data_size
data for message
char msg_type[INTERFACE_MESSAGE_TYPE_SIZE_]
message type
uint32_t hops
number of hops this message already passed
Interface open success The serial denotes a unique instance of an interface within the (remote) Black...
Uuid serial
instance serial to unique identify this instance
uint32_t data_size
size in bytes of the following data.
uint32_t writer_readers
combined writer reader information.