1/*************************************************************************
2 * libjson-rpc-cpp
3 *************************************************************************
4 * @file batchresponse.h
5 * @date 10/9/2014
6 * @author Peter Spiess-Knafl <dev@spiessknafl.at>
7 * @license See attached LICENSE.txt
8 ************************************************************************/
9
10#ifndef JSONRPC_BATCHRESPONSE_H
11#define JSONRPC_BATCHRESPONSE_H
12
13#include <jsonrpccpp/common/jsonparser.h>
14#include <map>
15
16namespace jsonrpc {
17
18 /**
19 * @brief The BatchResponse class provides a simple interface for handling batch responses.
20 */
21 class BatchResponse {
22 public:
23 BatchResponse();
24
25 /**
26 * @brief addResponse method is used only internally by the framework
27 * @param id
28 * @param response
29 * @param isError
30 */
31 void addResponse(Json::Value &id, Json::Value response, bool isError = false);
32
33 /**
34 * @brief getResult method gets the result for a given request id (returned by BatchCall::addCall.
35 * You should always invoke getErrorCode() first to check if the result is valid.
36 * @param id
37 * @return
38 */
39 Json::Value getResult(int id);
40
41 void getResult(Json::Value &id, Json::Value &result);
42
43 /**
44 * @brief getErrorCode method checks if for a given id, an error occurred in the batch request.
45 * @param id
46 */
47 int getErrorCode(Json::Value &id);
48
49 /**
50 * @brief getErrorMessage method gets the corresponding error message.
51 * @param id
52 * @return the error message in case of an error, an empty string if no error was found for the provided id.
53 */
54 std::string getErrorMessage(Json::Value &id);
55
56 std::string getErrorMessage(int id);
57
58 bool hasErrors();
59
60 private:
61 std::map<Json::Value, Json::Value> responses;
62 std::vector<Json::Value> errorResponses;
63 };
64
65} // namespace jsonrpc
66
67#endif // JSONRPC_BATCHRESPONSE_H
68