some minor fixes
authorimarom <[email protected]>
Tue, 18 Aug 2015 07:49:59 +0000 (10:49 +0300)
committerimarom <[email protected]>
Tue, 18 Aug 2015 07:49:59 +0000 (10:49 +0300)
src/rpc-server/include/trex_rpc_cmds_table.h
src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
src/rpc-server/src/commands/trex_rpc_cmds.h
src/rpc-server/src/trex_rpc_cmds_table.cpp

index 3cf6766..a41944f 100644 (file)
@@ -43,10 +43,24 @@ public:
         return instance;
     }
 
+    /**
+     * register a new command
+     * 
+     */
     void register_command(TrexRpcCommand *command);
 
+    /**
+     * lookup for a command
+     * 
+     */
     TrexRpcCommand * lookup(const std::string &method_name);
 
+    /**
+     * query all commands registered
+     * 
+     */
+    void query(std::vector<std::string> &cmds);
+
 private:
     TrexRpcCommandsTable();
     ~TrexRpcCommandsTable();
index 913736a..f2d4121 100644 (file)
@@ -20,6 +20,8 @@ limitations under the License.
 */
 #include "trex_rpc_cmds.h"
 #include <iostream>
+#include <sstream>
+#include <trex_rpc_cmds_table.h>
 
 using namespace std;
 
@@ -27,13 +29,8 @@ using namespace std;
  * add command
  * 
  */
-
-TestRpcAddMethod::TestRpcAddMethod() : TrexRpcCommand("test_rpc_add") {
-
-}
-
 TrexRpcCommand::rpc_cmd_rc_e 
-TestRpcAddMethod::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdTestAdd::_run(const Json::Value &params, Json::Value &result) {
 
     const Json::Value &x = params["x"];
     const Json::Value &y = params["y"];
@@ -57,13 +54,8 @@ TestRpcAddMethod::_run(const Json::Value &params, Json::Value &result) {
  * 
  * @author imarom (16-Aug-15)
  */
-
-TestRpcSubMethod::TestRpcSubMethod() : TrexRpcCommand("test_rpc_sub") {
-
-}
-
 TrexRpcCommand::rpc_cmd_rc_e 
-TestRpcSubMethod::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdTestSub::_run(const Json::Value &params, Json::Value &result) {
 
     const Json::Value &x = params["x"];
     const Json::Value &y = params["y"];
@@ -82,3 +74,41 @@ TestRpcSubMethod::_run(const Json::Value &params, Json::Value &result) {
     return (RPC_CMD_OK);
 }
 
+/**
+ * ping command
+ */
+TrexRpcCommand::rpc_cmd_rc_e 
+TrexRpcCmdPing::_run(const Json::Value &params, Json::Value &result) {
+
+    /* validate count */
+    if (params.size() != 0) {
+        return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
+    }
+
+    result["result"] = "ACK";
+    return (RPC_CMD_OK);
+}
+
+/**
+ * query command
+ */
+TrexRpcCommand::rpc_cmd_rc_e 
+TrexRpcCmdGetReg::_run(const Json::Value &params, Json::Value &result) {
+    vector<string> cmds;
+    stringstream ss;
+
+    /* validate count */
+    if (params.size() != 0) {
+        return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
+    }
+
+
+    TrexRpcCommandsTable::get_instance().query(cmds);
+    for (auto cmd : cmds) {
+        ss << cmd << "\n";
+    }
+
+    result["result"] = ss.str();
+    return (RPC_CMD_OK);
+}
+
index ea6e108..44b72c4 100644 (file)
@@ -28,16 +28,30 @@ limitations under the License.
 /* all the RPC commands decl. goes here */
 
 /******************* test section ************/
-class TestRpcAddMethod : public TrexRpcCommand {
+class TrexRpcCmdTestAdd : public TrexRpcCommand {
 public:
-     TestRpcAddMethod();
+     TrexRpcCmdTestAdd() : TrexRpcCommand("rpc_test_add") {}
 protected:
      virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
 };
 
-class TestRpcSubMethod : public TrexRpcCommand {
+class TrexRpcCmdTestSub : public TrexRpcCommand {
 public:
-     TestRpcSubMethod();
+     TrexRpcCmdTestSub() : TrexRpcCommand("rpc_test_sub") {} ;
+protected:
+     virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
+};
+
+class TrexRpcCmdPing : public TrexRpcCommand {
+public:
+     TrexRpcCmdPing() : TrexRpcCommand("rpc_ping") {};
+protected:
+     virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
+};
+
+class TrexRpcCmdGetReg : public TrexRpcCommand {
+public:
+     TrexRpcCmdGetReg() : TrexRpcCommand("rpc_get_reg_cmds") {};
 protected:
      virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
 };
index 4bc1ef2..7635f14 100644 (file)
@@ -28,8 +28,10 @@ using namespace std;
 /************* table related methods ***********/
 TrexRpcCommandsTable::TrexRpcCommandsTable() {
     /* add the test command (for gtest) */
-    register_command(new TestRpcAddMethod());
-    register_command(new TestRpcSubMethod());
+    register_command(new TrexRpcCmdTestAdd());
+    register_command(new TrexRpcCmdTestSub());
+    register_command(new TrexRpcCmdPing());
+    register_command(new TrexRpcCmdGetReg());
 }
 
 TrexRpcCommandsTable::~TrexRpcCommandsTable() {
@@ -48,3 +50,9 @@ void TrexRpcCommandsTable::register_command(TrexRpcCommand *command) {
     m_rpc_cmd_table[command->get_name()] = command;
 }
 
+void TrexRpcCommandsTable::query(vector<string> &cmds) {
+    for (auto cmd : m_rpc_cmd_table) {
+        cmds.push_back(cmd.first);
+    }
+}
+