summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-08-13 09:13:37 +0300
committerimarom <imarom@cisco.com>2015-08-13 09:13:37 +0300
commit583ef32a82dcd52cce9c1320f5141f91e40a0056 (patch)
tree4521469aadf46f46136ccf75bd3c63a019851dc2 /src/rpc-server
parent877eba6c21febeafd1122b60768c5ca5f4a69945 (diff)
just a few enums
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/src/trex_rpc_jsonrpc_v2.cpp20
-rw-r--r--src/rpc-server/src/trex_rpc_req_resp.cpp5
2 files changed, 14 insertions, 11 deletions
diff --git a/src/rpc-server/src/trex_rpc_jsonrpc_v2.cpp b/src/rpc-server/src/trex_rpc_jsonrpc_v2.cpp
index d4895557..2083ab2a 100644
--- a/src/rpc-server/src/trex_rpc_jsonrpc_v2.cpp
+++ b/src/rpc-server/src/trex_rpc_jsonrpc_v2.cpp
@@ -25,6 +25,17 @@ limitations under the License.
#include <iostream>
+/**
+ * error as described in the RFC
+ */
+enum {
+ JSONRPC_V2_ERR_PARSE = -32700,
+ JSONRPC_V2_ERR_INVALID_REQ = -32600,
+ JSONRPC_V2_ERR_METHOD_NOT_FOUND = -32601,
+ JSONRPC_V2_ERR_INVALID_PARAMS = -32602,
+ JSONRPC_V2_ERR_INTERNAL_ERROR = -32603
+};
+
/* dummy command */
class DumymCommand : public TrexJsonRpcV2Command {
public:
@@ -56,7 +67,6 @@ public:
/* encode to string */
response = writer.write(response_json);
-
}
private:
@@ -77,24 +87,22 @@ TrexJsonRpcV2Command * TrexJsonRpcV2Parser::parse() {
/* basic JSON parsing */
bool rc = reader.parse(m_msg, request, false);
if (!rc) {
- return new JsonRpcError(Json::Value::null, -32700, "Bad JSON Format");
+ return new JsonRpcError(Json::Value::null, JSONRPC_V2_ERR_PARSE, "Bad JSON Format");
}
Json::Value msg_id = request["id"];
/* check version */
if (request["jsonrpc"] != "2.0") {
- return new JsonRpcError(msg_id, -32600, "Invalid JSONRPC Version");
+ return new JsonRpcError(msg_id, JSONRPC_V2_ERR_INVALID_REQ, "Invalid JSONRPC Version");
}
/* check method name */
std::string method_name = request["method"].asString();
if (method_name == "") {
- return new JsonRpcError(msg_id, -32600, "Missing Method Name");
+ return new JsonRpcError(msg_id, JSONRPC_V2_ERR_INVALID_REQ, "Missing Method Name");
}
- std::cout << "method name: " << method_name << "\n";
-
TrexJsonRpcV2Command *command = new DumymCommand();
return (command);
diff --git a/src/rpc-server/src/trex_rpc_req_resp.cpp b/src/rpc-server/src/trex_rpc_req_resp.cpp
index 5c28d90d..b423c8e7 100644
--- a/src/rpc-server/src/trex_rpc_req_resp.cpp
+++ b/src/rpc-server/src/trex_rpc_req_resp.cpp
@@ -57,8 +57,6 @@ void TrexRpcServerReqRes::_rpc_thread_cb() {
throw TrexRpcException("Unable to start ZMQ server at: " + ss.str());
}
- printf("listening on %s\n", ss.str().c_str());
-
/* server main loop */
while (m_is_running) {
int msg_size = zmq_recv (m_socket, m_msg_buffer, sizeof(m_msg_buffer), 0);
@@ -89,9 +87,6 @@ void TrexRpcServerReqRes::_stop_rpc_thread() {
void TrexRpcServerReqRes::handle_request(const std::string &request) {
std::string response;
- /* debug */
- std::cout << request << std::endl;
-
TrexJsonRpcV2Parser rpc_request(request);
TrexJsonRpcV2Command *rpc_command = rpc_request.parse();