Line data Source code
1 : #ifndef FELIX_RECEIVER_H_ 2 : #define FELIX_RECEIVER_H_ 3 : 4 : #include <sys/uio.h> 5 : #include <cstdint> 6 : #include <functional> 7 : #include <vector> 8 : #include <string> 9 : 10 : #include "elink.hpp" 11 : #include "network/fromhost_message.hpp" 12 : 13 : /** 14 : * Interface class to any receiver implemented by the network backend. 15 : */ 16 5 : class Receiver { 17 : 18 : public: 19 : using OnMsg = std::function<void(const std::vector<ToFlxMessage>&)>; 20 : using OnConnOpen = std::function<void (const std::string &)>; 21 : using OnConnClose = std::function<void (const std::string &)>; 22 : 23 5 : virtual ~Receiver() = default; 24 : 25 : /** 26 : * @brief advertise e-links services by the receiver. 27 : * @param elinks to advertise. 28 : * @return whether the operation was succesfull. 29 : */ 30 : virtual bool declare(const std::vector<Elink> &elinks) = 0; 31 : 32 : /** 33 : * @brief application callback for new connections. 34 : * @param callback the std::function<void (std::string &)> to invoked when a 35 : * new connection is established. 36 : */ 37 : virtual void set_conn_open_callback(OnConnOpen callback) = 0; 38 : 39 : /** 40 : * @brief application callback for closed connections. 41 : * @param callback the std::function<void (std::string &)> to be invoked 42 : * when a new connection is closed. 43 : */ 44 : virtual void set_conn_close_callback(OnConnClose callback) = 0; 45 : 46 : /** 47 : * @brief application callback for received messages. 48 : * @param callback the std::function<void(uint8_t*, size_t)> to invoke when 49 : * a message is received. 50 : */ 51 : virtual void set_on_msg_callback(OnMsg callback) = 0; 52 : 53 : /** 54 : * @brief Monitor the number of open connetions. 55 : * @return the number of open connections. 56 : */ 57 : virtual int get_number_of_connections() = 0; 58 : 59 : }; 60 : 61 : #endif /* FELIX_RECEIVER_H_ */