]> granicus.if.org Git - icinga2/blob - lib/remote/apiclient.hpp
Make sure we don't include zones.d directories for zones which were removed
[icinga2] / lib / remote / apiclient.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org)    *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef APICLIENT_H
21 #define APICLIENT_H
22
23 #include "remote/endpoint.hpp"
24 #include "base/tlsstream.hpp"
25 #include "base/timer.hpp"
26 #include "base/workqueue.hpp"
27 #include "remote/i2-remote.hpp"
28
29 namespace icinga
30 {
31
32 enum ClientRole
33 {
34         ClientInbound,
35         ClientOutbound
36 };
37
38 struct MessageOrigin;
39
40 /**
41  * An API client connection.
42  *
43  * @ingroup remote
44  */
45 class I2_REMOTE_API ApiClient : public Object
46 {
47 public:
48         DECLARE_PTR_TYPEDEFS(ApiClient);
49
50         ApiClient(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role);
51
52         void Start(void);
53
54         String GetIdentity(void) const;
55         bool IsAuthenticated(void) const;
56         Endpoint::Ptr GetEndpoint(void) const;
57         TlsStream::Ptr GetStream(void) const;
58         ConnectionRole GetRole(void) const;
59
60         void Disconnect(void);
61         void DisconnectSync(void);
62
63         void SendMessage(const Dictionary::Ptr& request);
64
65         static void HeartbeatTimerHandler(void);
66         static Value HeartbeatAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
67
68 private:
69         String m_Identity;
70         bool m_Authenticated;
71         Endpoint::Ptr m_Endpoint;
72         TlsStream::Ptr m_Stream;
73         ConnectionRole m_Role;
74         double m_Seen;
75         double m_NextHeartbeat;
76
77         WorkQueue m_WriteQueue;
78
79         bool ProcessMessage(void);
80         void MessageThreadProc(void);
81         void SendMessageSync(const Dictionary::Ptr& request);
82 };
83
84 }
85
86 #endif /* APICLIENT_H */