1 /******************************************************************************
3 * Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
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. *
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. *
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 ******************************************************************************/
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"
41 * An API client connection.
45 class I2_REMOTE_API ApiClient : public Object
48 DECLARE_PTR_TYPEDEFS(ApiClient);
50 ApiClient(const String& identity, bool authenticated, const TlsStream::Ptr& stream, ConnectionRole role);
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;
60 void Disconnect(void);
61 void DisconnectSync(void);
63 void SendMessage(const Dictionary::Ptr& request);
65 static void HeartbeatTimerHandler(void);
66 static Value HeartbeatAPIHandler(const MessageOrigin& origin, const Dictionary::Ptr& params);
71 Endpoint::Ptr m_Endpoint;
72 TlsStream::Ptr m_Stream;
73 ConnectionRole m_Role;
75 double m_NextHeartbeat;
77 WorkQueue m_WriteQueue;
79 bool ProcessMessage(void);
80 void MessageThreadProc(void);
81 void SendMessageSync(const Dictionary::Ptr& request);
86 #endif /* APICLIENT_H */