#ifndef CONNECTIONBASE_H #define CONNECTIONBASE_H #include #include #include #include "message.h" class ConnectionBase { private: Message::Type pending_type; std::size_t pending_size; protected: //! Initiate reception of a message. void start_recv(); //! Deliver received data. //! \param data Pointer to received data. Ownership is retained by caller. //! \param bytes Size of data. void got_data(uint8_t* data, std::size_t bytes); //! Called to request data. //! \param bytes Amount of data requested. virtual void request_data(std::size_t bytes) = 0; //! Called to write data. //! \param data Pointer to data to send. Ownership is transferred to callee. //! \param bytes Size of data. virtual void write_data(uint8_t* data, std::size_t bytes) = 0; //! Called when a message is received. //! \param msg Received message. virtual void got_message(const Message::p& msg) = 0; //! Called upon error (lost connection or failed deserialization). //! \param msg Error message. virtual void error(const std::string& msg) = 0; public: ConnectionBase(); virtual ~ConnectionBase(); //! Send a message. void send(const Message::p& msg); }; #endif