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();
*/
#include "trex_rpc_cmds.h"
#include <iostream>
+#include <sstream>
+#include <trex_rpc_cmds_table.h>
using namespace std;
* add command
*
*/
-
-TestRpcAddMethod::TestRpcAddMethod() : TrexRpcCommand("test_rpc_add") {
-
-}
-
TrexRpcCommand::rpc_cmd_rc_e
-TestRpcAddMethod::_run(const Json::Value ¶ms, Json::Value &result) {
+TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) {
const Json::Value &x = params["x"];
const Json::Value &y = params["y"];
*
* @author imarom (16-Aug-15)
*/
-
-TestRpcSubMethod::TestRpcSubMethod() : TrexRpcCommand("test_rpc_sub") {
-
-}
-
TrexRpcCommand::rpc_cmd_rc_e
-TestRpcSubMethod::_run(const Json::Value ¶ms, Json::Value &result) {
+TrexRpcCmdTestSub::_run(const Json::Value ¶ms, Json::Value &result) {
const Json::Value &x = params["x"];
const Json::Value &y = params["y"];
return (RPC_CMD_OK);
}
+/**
+ * ping command
+ */
+TrexRpcCommand::rpc_cmd_rc_e
+TrexRpcCmdPing::_run(const Json::Value ¶ms, 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 ¶ms, 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);
+}
+
/* 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 ¶ms, 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 ¶ms, Json::Value &result);
+};
+
+class TrexRpcCmdPing : public TrexRpcCommand {
+public:
+ TrexRpcCmdPing() : TrexRpcCommand("rpc_ping") {};
+protected:
+ virtual rpc_cmd_rc_e _run(const Json::Value ¶ms, Json::Value &result);
+};
+
+class TrexRpcCmdGetReg : public TrexRpcCommand {
+public:
+ TrexRpcCmdGetReg() : TrexRpcCommand("rpc_get_reg_cmds") {};
protected:
virtual rpc_cmd_rc_e _run(const Json::Value ¶ms, Json::Value &result);
};
/************* 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() {
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);
+ }
+}
+