2014-04-12 04:21:09 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
#ifndef APICLIENT_H
|
|
|
|
#define APICLIENT_H
|
2014-04-12 04:21:09 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
#include "remote/endpoint.h"
|
|
|
|
#include "base/stream.h"
|
2014-04-12 04:21:09 +02:00
|
|
|
#include "base/timer.h"
|
2014-05-03 20:02:22 +02:00
|
|
|
#include "base/array.h"
|
|
|
|
#include "remote/i2-remote.h"
|
|
|
|
#include <boost/signals2.hpp>
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
enum ClientRole
|
|
|
|
{
|
|
|
|
ClientInbound,
|
|
|
|
ClientOutbound
|
|
|
|
};
|
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
/**
|
2014-05-03 20:02:22 +02:00
|
|
|
* An API client connection.
|
2014-04-12 04:21:09 +02:00
|
|
|
*
|
2014-05-03 20:02:22 +02:00
|
|
|
* @ingroup remote
|
2014-04-12 04:21:09 +02:00
|
|
|
*/
|
2014-05-03 20:02:22 +02:00
|
|
|
class I2_REMOTE_API ApiClient : public Object
|
2014-04-12 04:21:09 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-05-03 20:02:22 +02:00
|
|
|
DECLARE_PTR_TYPEDEFS(ApiClient);
|
|
|
|
|
2014-05-08 15:00:09 +02:00
|
|
|
ApiClient(const String& identity, const Stream::Ptr& stream, ConnectionRole role);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
2014-04-12 04:21:09 +02:00
|
|
|
static void StaticInitialize(void);
|
2014-05-03 20:02:22 +02:00
|
|
|
|
|
|
|
void Start(void);
|
|
|
|
|
2014-05-08 15:00:09 +02:00
|
|
|
String GetIdentity(void) const;
|
2014-05-03 20:02:22 +02:00
|
|
|
Endpoint::Ptr GetEndpoint(void) const;
|
|
|
|
Stream::Ptr GetStream(void) const;
|
|
|
|
ConnectionRole GetRole(void) const;
|
|
|
|
|
|
|
|
void Disconnect(void);
|
|
|
|
|
|
|
|
void SendMessage(const Dictionary::Ptr& request);
|
2014-04-12 04:21:09 +02:00
|
|
|
|
|
|
|
private:
|
2014-05-08 15:00:09 +02:00
|
|
|
String m_Identity;
|
2014-05-03 20:02:22 +02:00
|
|
|
Endpoint::Ptr m_Endpoint;
|
|
|
|
Stream::Ptr m_Stream;
|
|
|
|
ConnectionRole m_Role;
|
|
|
|
double m_Seen;
|
|
|
|
bool m_Syncing;
|
|
|
|
|
|
|
|
bool ProcessMessage(void);
|
|
|
|
void MessageThreadProc(void);
|
2014-04-15 15:56:41 +02:00
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
static Timer::Ptr m_KeepAliveTimer;
|
|
|
|
static void KeepAliveTimerHandler(void);
|
2014-04-12 04:21:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-05-03 20:02:22 +02:00
|
|
|
#endif /* APICLIENT_H */
|