1 | /************************************************************************* |
---|---|
2 | * libjson-rpc-cpp |
3 | ************************************************************************* |
4 | * @file batchcall.cpp |
5 | * @date 15.10.2013 |
6 | * @author Peter Spiess-Knafl <dev@spiessknafl.at> |
7 | * @license See attached LICENSE.txt |
8 | ************************************************************************/ |
9 | |
10 | #include "batchcall.h" |
11 | #include "rpcprotocolclient.h" |
12 | |
13 | using namespace jsonrpc; |
14 | using namespace std; |
15 | |
16 | BatchCall::BatchCall() : id(1) {} |
17 | |
18 | int BatchCall::addCall(const string &methodname, const Json::Value ¶ms, bool isNotification) { |
19 | Json::Value call; |
20 | call[RpcProtocolClient::KEY_PROTOCOL_VERSION] = "2.0"; |
21 | call[RpcProtocolClient::KEY_PROCEDURE_NAME] = methodname; |
22 | |
23 | if (params.isNull() || !params.empty()) |
24 | call[RpcProtocolClient::KEY_PARAMETER] = params; |
25 | |
26 | if (!isNotification) { |
27 | call[RpcProtocolClient::KEY_ID] = this->id++; |
28 | } |
29 | result.append(call); |
30 | |
31 | if (isNotification) |
32 | return -1; |
33 | return call[RpcProtocolClient::KEY_ID].asInt(); |
34 | } |
35 | |
36 | string BatchCall::toString(bool fast) const { |
37 | string result; |
38 | if (fast) { |
39 | Json::StreamWriterBuilder wbuilder; |
40 | wbuilder["indentation"] = ""; |
41 | result = Json::writeString(wbuilder, this->result); |
42 | } else { |
43 | Json::StreamWriterBuilder wbuilder; |
44 | result = Json::writeString(wbuilder, this->result); |
45 | } |
46 | return result; |
47 | } |
48 |