]> granicus.if.org Git - icinga2/blob - lib/remote/httpserverconnection.hpp
Fix missing stats for current_concurrent_checks via REST API
[icinga2] / lib / remote / httpserverconnection.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef HTTPSERVERCONNECTION_H
4 #define HTTPSERVERCONNECTION_H
5
6 #include "remote/apiuser.hpp"
7 #include "base/string.hpp"
8 #include "base/tlsstream.hpp"
9 #include <memory>
10 #include <boost/asio/deadline_timer.hpp>
11 #include <boost/asio/io_service.hpp>
12 #include <boost/asio/io_service_strand.hpp>
13 #include <boost/asio/spawn.hpp>
14
15 namespace icinga
16 {
17
18 /**
19  * An API client connection.
20  *
21  * @ingroup remote
22  */
23 class HttpServerConnection final : public Object
24 {
25 public:
26         DECLARE_PTR_TYPEDEFS(HttpServerConnection);
27
28         HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream);
29
30         void Start();
31         void Disconnect();
32         void StartStreaming();
33
34         bool Disconnected();
35
36 private:
37         ApiUser::Ptr m_ApiUser;
38         std::shared_ptr<AsioTlsStream> m_Stream;
39         double m_Seen;
40         String m_PeerAddress;
41         boost::asio::io_service::strand m_IoStrand;
42         bool m_ShuttingDown;
43         bool m_HasStartedStreaming;
44         boost::asio::deadline_timer m_CheckLivenessTimer;
45
46         HttpServerConnection(const String& identity, bool authenticated, const std::shared_ptr<AsioTlsStream>& stream, boost::asio::io_service& io);
47
48         void ProcessMessages(boost::asio::yield_context yc);
49         void CheckLiveness(boost::asio::yield_context yc);
50 };
51
52 }
53
54 #endif /* HTTPSERVERCONNECTION_H */