1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2 
3 #ifndef JSONRPC_H
4 #define JSONRPC_H
5 
6 #include "base/stream.hpp"
7 #include "base/dictionary.hpp"
8 #include "base/tlsstream.hpp"
9 #include "remote/i2-remote.hpp"
10 #include <memory>
11 #include <boost/asio/spawn.hpp>
12 
13 namespace icinga
14 {
15 
16 /**
17  * A JSON-RPC connection.
18  *
19  * @ingroup remote
20  */
21 class JsonRpc
22 {
23 public:
24 	static size_t SendMessage(const Shared<AsioTlsStream>::Ptr& stream, const Dictionary::Ptr& message);
25 	static size_t SendMessage(const Shared<AsioTlsStream>::Ptr& stream, const Dictionary::Ptr& message, boost::asio::yield_context yc);
26 	static size_t SendRawMessage(const Shared<AsioTlsStream>::Ptr& stream, const String& json, boost::asio::yield_context yc);
27 
28 	static String ReadMessage(const Shared<AsioTlsStream>::Ptr& stream, ssize_t maxMessageLength = -1);
29 	static String ReadMessage(const Shared<AsioTlsStream>::Ptr& stream, boost::asio::yield_context yc, ssize_t maxMessageLength = -1);
30 
31 	static Dictionary::Ptr DecodeMessage(const String& message);
32 
33 private:
34 	JsonRpc();
35 };
36 
37 }
38 
39 #endif /* JSONRPC_H */
40