1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ 2 3 #ifndef ENDPOINT_H 4 #define ENDPOINT_H 5 6 #include "remote/i2-remote.hpp" 7 #include "remote/endpoint-ti.hpp" 8 #include "base/ringbuffer.hpp" 9 #include <set> 10 11 namespace icinga 12 { 13 14 class JsonRpcConnection; 15 class Zone; 16 17 /** 18 * An endpoint that can be used to send and receive messages. 19 * 20 * @ingroup remote 21 */ 22 class Endpoint final : public ObjectImpl<Endpoint> 23 { 24 public: 25 DECLARE_OBJECT(Endpoint); 26 DECLARE_OBJECTNAME(Endpoint); 27 28 static boost::signals2::signal<void(const Endpoint::Ptr&, const intrusive_ptr<JsonRpcConnection>&)> OnConnected; 29 static boost::signals2::signal<void(const Endpoint::Ptr&, const intrusive_ptr<JsonRpcConnection>&)> OnDisconnected; 30 31 void AddClient(const intrusive_ptr<JsonRpcConnection>& client); 32 void RemoveClient(const intrusive_ptr<JsonRpcConnection>& client); 33 std::set<intrusive_ptr<JsonRpcConnection> > GetClients() const; 34 35 intrusive_ptr<Zone> GetZone() const; 36 37 bool GetConnected() const override; 38 39 static Endpoint::Ptr GetLocalEndpoint(); 40 41 void SetCachedZone(const intrusive_ptr<Zone>& zone); 42 43 void AddMessageSent(int bytes); 44 void AddMessageReceived(int bytes); 45 46 double GetMessagesSentPerSecond() const override; 47 double GetMessagesReceivedPerSecond() const override; 48 49 double GetBytesSentPerSecond() const override; 50 double GetBytesReceivedPerSecond() const override; 51 52 protected: 53 void OnAllConfigLoaded() override; 54 55 private: 56 mutable std::mutex m_ClientsLock; 57 std::set<intrusive_ptr<JsonRpcConnection> > m_Clients; 58 intrusive_ptr<Zone> m_Zone; 59 60 mutable RingBuffer m_MessagesSent{60}; 61 mutable RingBuffer m_MessagesReceived{60}; 62 mutable RingBuffer m_BytesSent{60}; 63 mutable RingBuffer m_BytesReceived{60}; 64 }; 65 66 } 67 68 #endif /* ENDPOINT_H */ 69