Fawkes API
Fawkes Development Version
|
25 #include "blackboard_manager.h"
27 #include "protobuf_to_bb.h"
29 namespace protoboard {
43 message_handler_(msg_handler),
44 bb_receiving_interfaces_(make_receiving_interfaces_map()),
45 on_message_waker_(nullptr),
54 pb_sender_.reset(sender);
65 for (pb_conversion_map::value_type &c : bb_receiving_interfaces_)
72 delete on_message_waker_;
73 bb_receiving_interfaces_.clear();
74 pb_sender_->finalize();
82 on_interface<ProtobufPeerInterface>{peer_iface_,
this}
89 pb_sender_->process_sending_interfaces();
94 pb_conversion_map::iterator it;
96 if ((it = bb_receiving_interfaces_.find(inc.
msg->GetTypeName()))
97 == bb_receiving_interfaces_.end()) {
99 "Received message of unregistered type `%s'",
100 inc.
msg->GetTypeName().c_str());
104 it->second->handle(inc.
msg);
105 }
catch (std::exception &e) {
107 "Exception while handling %s: %s",
108 inc.
msg->GetTypeName().c_str(),
125 "Maximum number of peers reached. Can't create new peer with index %d!",
129 iface->
set_peers(next_peer_idx_++, peer_id);
Receive incoming ProtoBuf messages and pass them on to the BlackboardManager for publication to the a...
virtual void init() override
Initialize the thread.
char * crypto_key() const
Get crypto_key value.
long int peer_create_local(const std::string &host, int send_to_port, int recv_on_port)
Enable protobuf peer.
virtual void loop() override
Code to execute in the thread.
char * cipher() const
Get cipher value.
AbstractProtobufSender(BlackboardManager *bb_mgr)
Constructor.
long int peer_create(const std::string &host, int port)
Enable protobuf peer.
int32_t recv_on_port() const
Get recv_on_port value.
char * address() const
Get address value.
The BlackBoard abstract class.
void set_peers(unsigned int index, const int64_t new_peers)
Set peers value at given index.
int32_t send_to_port() const
Get send_to_port value.
long int peer_create_local_crypto(const std::string &host, int send_to_port, int recv_on_port, const std::string &crypto_key="", const std::string &cipher="")
Enable protobuf peer.
const char * name() const
Get name of thread.
char * address() const
Get address value.
void set_protobuf_sender(AbstractProtobufSender *sender)
The ProtoBuf sender must be initialized after construction to beak a dependency loop.
Abstract superclass for sending out ProtoBuf messages.
std::shared_ptr< google::protobuf::Message > msg
The message itself.
The main thread that is woken each time a message arrives on any of the interfaces watched by a bb_if...
CreatePeerMessage Fawkes BlackBoard Interface Message.
int32_t send_to_port() const
Get send_to_port value.
char * cipher() const
Get cipher value.
ProtobufPeerInterface Fawkes BlackBoard Interface.
Logger * logger
This is the Logger member used to access the logger.
Wrapper for a ProtoBuf message and its metadata.
virtual void close(Interface *interface)=0
Close interface.
void set_coalesce_wakeups(bool coalesce=true)
Set wakeup coalescing.
virtual void log_error(const char *component, const char *format,...)=0
Log error message.
fawkes::BlackBoard * get_blackboard()
Helper for other classes to get access to the blackboard.
virtual void finalize() override
Finalize the thread.
CreatePeerLocalMessage Fawkes BlackBoard Interface Message.
size_t maxlenof_peers() const
Get maximum length of peers value.
Fawkes library namespace.
char * address() const
Get address value.
virtual ~AbstractProtobufSender()
Destructor.
int32_t port() const
Get port value.
int32_t recv_on_port() const
Get recv_on_port value.
char * address() const
Get address value.
void handle_message(InterfaceT *iface, MessageT *msg)
Act on a given message on a given blackboard interface.
Thread class encapsulation of pthreads.
BlackBoard * blackboard
This is the BlackBoard instance you can use to interact with the BlackBoard.
int32_t port() const
Get port value.
Wake threads on receiving a blackboard message.
incoming_message pb_queue_pop()
CreatePeerLocalCryptoMessage Fawkes BlackBoard Interface Message.
BlackboardManager(ProtobufThead *msg_handler)
Main thread constructor.
CreatePeerCryptoMessage Fawkes BlackBoard Interface Message.
void write()
Write from local copy into BlackBoard memory.
long int peer_create_crypto(const std::string &host, int port, const std::string &crypto_key="", const std::string &cipher="")
Enable protobuf peer.
virtual Interface * open_for_writing(const char *interface_type, const char *identifier, const char *owner=NULL)=0
Open interface for writing.
char * crypto_key() const
Get crypto_key value.