From 87774d8981ae7a079492d8949e205065ba72a8e4 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 16 Mar 2017 23:28:09 +0100 Subject: Add basic console monitor and implement monitor support --- src/monitor.hh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/monitor.hh (limited to 'src/monitor.hh') 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 +#include +#include + +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 -- cgit v1.2.3-70-g09d2