summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-08-24 17:28:25 +0300
committerimarom <imarom@cisco.com>2015-08-24 17:28:25 +0300
commite094ae7c761a7d5a3b93f489f5ff9b4ed70ae9a3 (patch)
tree00376c2acbaca93f01b657417b6e5a3b3fe1fb07
parent2adc8696b8f1a9f9038a1e6377ac23e1bfd03ceb (diff)
syntatic sugar for adding cmds
-rwxr-xr-xlinux/ws_main.py1
-rwxr-xr-xlinux_dpdk/ws_main.py1
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp14
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h61
4 files changed, 23 insertions, 54 deletions
diff --git a/linux/ws_main.py b/linux/ws_main.py
index 7d9aae3b..659d4921 100755
--- a/linux/ws_main.py
+++ b/linux/ws_main.py
@@ -149,6 +149,7 @@ rpc_server_src = SrcGroup(dir='src/rpc-server/',
'commands/trex_rpc_cmd_test.cpp',
'commands/trex_rpc_cmd_general.cpp',
+ 'commands/trex_rpc_cmd_stream.cpp',
])
diff --git a/linux_dpdk/ws_main.py b/linux_dpdk/ws_main.py
index aef36244..aa270e69 100755
--- a/linux_dpdk/ws_main.py
+++ b/linux_dpdk/ws_main.py
@@ -147,6 +147,7 @@ rpc_server_src = SrcGroup(dir='src/rpc-server/',
'commands/trex_rpc_cmd_test.cpp',
'commands/trex_rpc_cmd_general.cpp',
+ 'commands/trex_rpc_cmd_stream.cpp',
])
# JSON package
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index a5b358d0..88b50089 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -29,19 +29,13 @@ using namespace std;
*
*/
trex_rpc_cmd_rc_e
-TrexRpcCmdGetStatus::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdAddStream::_run(const Json::Value &params, Json::Value &result) {
- /* validate count */
- if (params.size() != 1) {
- generate_err_param_count(result, 0, params.size());
- return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
- }
+ check_param_count(params, 1, result);
+ check_field_type(params, "stream", FIELD_TYPE_OBJ, result);
Json::Value &stream = result["stream"];
- if (stream == Json::Value::null) {
- generate_err_param_count
- }
- return (RPC_CMD_OK);
+ return (TREX_RPC_CMD_OK);
}
diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h
index 39ccf27a..5c425856 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -30,60 +30,33 @@ limitations under the License.
/******************* test section ************/
/**
- * add
- *
+ * syntactic sugar for creating a simple command
*/
-class TrexRpcCmdTestAdd : public TrexRpcCommand {
-public:
- TrexRpcCmdTestAdd() : TrexRpcCommand("test_add") {}
-protected:
- virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
-};
+#define TREX_RPC_CMD_DEFINE(class_name, cmd_name) \
+ class class_name : public TrexRpcCommand { \
+ public: \
+ class_name () : TrexRpcCommand(cmd_name) {} \
+ protected: \
+ virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result); \
+ }
-/**
- * sub
- *
- */
-class TrexRpcCmdTestSub : public TrexRpcCommand {
-public:
- TrexRpcCmdTestSub() : TrexRpcCommand("test_sub") {} ;
-protected:
- virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
-};
/**
- * ping
- *
+ * test cmds
*/
-class TrexRpcCmdPing : public TrexRpcCommand {
-public:
- TrexRpcCmdPing() : TrexRpcCommand("ping") {};
-protected:
- virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
-};
+TREX_RPC_CMD_DEFINE(TrexRpcCmdTestAdd, "test_add");
+TREX_RPC_CMD_DEFINE(TrexRpcCmdTestSub, "test_sub");
/**
- * get all registered commands
- *
+ * general cmds
*/
-class TrexRpcCmdGetReg : public TrexRpcCommand {
-public:
- TrexRpcCmdGetReg() : TrexRpcCommand("get_reg_cmds") {};
-protected:
- virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
-};
+TREX_RPC_CMD_DEFINE(TrexRpcCmdPing, "ping");
+TREX_RPC_CMD_DEFINE(TrexRpcCmdGetReg, "get_reg_cmds");
+TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStatus, "get_status");
/**
- * get status
- *
+ * stream cmds
*/
-class TrexRpcCmdGetStatus : public TrexRpcCommand {
-public:
- TrexRpcCmdGetStatus() : TrexRpcCommand("get_status") {};
-protected:
- virtual trex_rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
-};
-
+TREX_RPC_CMD_DEFINE(TrexRpcCmdAddStream, "add_stream");
-/**************** test section end *************/
#endif /* __TREX_RPC_CMD_H__ */