summaryrefslogtreecommitdiff
path: root/src/monitor.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/monitor.hh')
-rw-r--r--src/monitor.hh68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/monitor.hh b/src/monitor.hh
new file mode 100644
index 0000000..83652ee
--- /dev/null
+++ b/src/monitor.hh
@@ -0,0 +1,68 @@
+// -*- mode: c++; c-basic-offset: 2; -*-
+
+#ifndef MONITOR_HH
+#define MONITOR_HH
+
+#include <cstdint>
+#include <memory>
+#include <string>
+
+class Looper;
+class Resolver;
+
+class Monitor {
+public:
+ enum State {
+ // Default state, if a connection is broken this is the new state
+ DISCONNECTED = 0,
+ // After connect() is called but before the connection is truly setup
+ CONNECTING,
+ // Connect() succeeded, not attached
+ CONNECTED,
+ // Connected and attached.
+ ATTACHED,
+ };
+
+ struct Package {
+ uint32_t id;
+ struct timespec timestamp;
+ uint16_t flags;
+ std::string source_host;
+ uint16_t source_port;
+ std::string target_host;
+ uint16_t target_port;
+ };
+
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ virtual void state(Monitor* monitor, State state) = 0;
+ virtual void error(Monitor* monitor, std::string const& error) = 0;
+ virtual void package(Monitor* monitor, Package const& package) = 0;
+ virtual void package_data(Monitor* monitor, uint32_t id,
+ char const* data, size_t size, bool last) = 0;
+
+ protected:
+ Delegate() {}
+ };
+
+ virtual ~Monitor() {}
+
+ static Monitor* create(
+ Looper* looper, Resolver* resolver, Delegate* delegate);
+
+ virtual void connect(std::string const& host, uint16_t port) = 0;
+ virtual void disconnect() = 0;
+
+ virtual void attach() = 0;
+ virtual void detach() = 0;
+
+ virtual State state() const = 0;
+
+protected:
+ Monitor() {}
+ Monitor(Monitor const&) = delete;
+};
+
+#endif // MONITOR_HH