summaryrefslogtreecommitdiff
path: root/common/connectionbase.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/connectionbase.h')
-rw-r--r--common/connectionbase.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/common/connectionbase.h b/common/connectionbase.h
new file mode 100644
index 0000000..1bfc437
--- /dev/null
+++ b/common/connectionbase.h
@@ -0,0 +1,40 @@
+#ifndef CONNECTIONBASE_H
+#define CONNECTIONBASE_H
+
+#include <stdint.h>
+#include <cstdlib>
+
+// Poor excuse for a real Message class.
+class Message {
+ public:
+ typedef Message* p;
+};
+
+class ConnectionBase {
+ protected:
+ //! Signal that connection is established and ready to transfer data.
+ void connected();
+
+ //! 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;
+
+ public:
+ //! Send a message.
+ void send(const Message::p& msg);
+
+ //! Get received message or null if queue empty.
+ Message::p recv();
+};
+
+#endif