summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/include
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-08-16 16:46:47 +0300
committerimarom <imarom@cisco.com>2015-08-16 16:46:47 +0300
commit47eeee1f5c8c2f08b06dbb02bd1400fd246e3f8b (patch)
tree100687b0e3fd69eb7f815ecf8e13100689514f44 /src/rpc-server/include
parent7827e4de667c58517bb8ae4cfbcd7e9ae41910dc (diff)
draft
Diffstat (limited to 'src/rpc-server/include')
-rw-r--r--src/rpc-server/include/trex_rpc_commands.h34
-rw-r--r--src/rpc-server/include/trex_rpc_jsonrpc_v2.h17
2 files changed, 38 insertions, 13 deletions
diff --git a/src/rpc-server/include/trex_rpc_commands.h b/src/rpc-server/include/trex_rpc_commands.h
index 4a445dac..ef9f5eaa 100644
--- a/src/rpc-server/include/trex_rpc_commands.h
+++ b/src/rpc-server/include/trex_rpc_commands.h
@@ -25,6 +25,7 @@ limitations under the License.
#include <unordered_map>
#include <string>
#include <vector>
+#include <json/json.h>
/**
* interface for RPC command
@@ -33,17 +34,36 @@ limitations under the License.
*/
class TrexRpcCommand {
public:
- TrexRpcCommand(const std::string &method_name, const std::vector<std::string> &params);
/**
- * implemented by the derived class
- *
- * @author imarom (13-Aug-15)
+ * describe different types of rc for run()
+ */
+ enum rpc_cmd_rc_e {
+ RPC_CMD_OK,
+ RPC_CMD_PARAM_COUNT_ERR = 1,
+ RPC_CMD_PARAM_PARSE_ERR
+ };
+
+ /**
+ * method name and params
*/
- virtual void run() = 0;
+ TrexRpcCommand(const std::string &method_name);
+
+ rpc_cmd_rc_e run(const Json::Value &params, std::string &output);
+
+ const std::string &get_name();
+
+ virtual ~TrexRpcCommand() {}
protected:
- std::vector<std::string> params;
+
+ /**
+ * implemented by the dervied class
+ *
+ */
+ virtual rpc_cmd_rc_e _run(const Json::Value &params, std::string &output) = 0;
+
+ std::string m_name;
};
/**
@@ -60,7 +80,7 @@ public:
return instance;
}
- void register_command(const TrexRpcCommand &command);
+ void register_command(TrexRpcCommand *command);
TrexRpcCommand * lookup(const std::string &method_name);
diff --git a/src/rpc-server/include/trex_rpc_jsonrpc_v2.h b/src/rpc-server/include/trex_rpc_jsonrpc_v2.h
index ac04fb99..963dab7b 100644
--- a/src/rpc-server/include/trex_rpc_jsonrpc_v2.h
+++ b/src/rpc-server/include/trex_rpc_jsonrpc_v2.h
@@ -26,15 +26,17 @@ limitations under the License.
#include <vector>
#include <json/json.h>
+class TrexRpcCommand;
+
/**
- * JSON RPC V2 command
+ * JSON RPC V2 parsed object
*
* @author imarom (12-Aug-15)
*/
-class TrexJsonRpcV2Command {
+class TrexJsonRpcV2ParsedObject {
public:
- TrexJsonRpcV2Command(const Json::Value &msg_id);
+ TrexJsonRpcV2ParsedObject(const Json::Value &msg_id, bool force);
/**
* main function to execute the command
@@ -46,11 +48,14 @@ protected:
/**
* instance private implementation
- *
+ * should provide implementation with response
+ * and without response value
*/
virtual void _execute(Json::Value &response) = 0;
+ virtual void _execute() = 0;
Json::Value m_msg_id;
+ bool m_respond;
};
/**
@@ -76,7 +81,7 @@ public:
*
* @author imarom (12-Aug-15)
*/
- void parse(std::vector<TrexJsonRpcV2Command *> &commands);
+ void parse(std::vector<TrexJsonRpcV2ParsedObject *> &commands);
private:
@@ -84,7 +89,7 @@ private:
* handle a single request
*
*/
- void parse_single_request(Json::Value &request, std::vector<TrexJsonRpcV2Command *> &commands);
+ void parse_single_request(Json::Value &request, std::vector<TrexJsonRpcV2ParsedObject *> &commands);
std::string m_msg;
};