summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/commands/trex_rpc_cmd_general.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-09 18:06:12 +0300
committerimarom <imarom@cisco.com>2015-09-09 18:56:11 +0300
commit54f8323b3938bf4ab672cde01a06711bfc522a2e (patch)
tree3454351e53499c2051715641e1b87b3e32f9a333 /src/rpc-server/commands/trex_rpc_cmd_general.cpp
parente33befcf222fd2108d589dede11069d4256bb21a (diff)
added ownership to RPC server
Diffstat (limited to 'src/rpc-server/commands/trex_rpc_cmd_general.cpp')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index 32952b1a..d5aa3a90 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -63,3 +63,56 @@ TrexRpcCmdGetStatus::_run(const Json::Value &params, Json::Value &result) {
return (TREX_RPC_CMD_OK);
}
+/**
+ * returns the current owner of the device
+ *
+ * @author imarom (08-Sep-15)
+ *
+ * @param params
+ * @param result
+ *
+ * @return trex_rpc_cmd_rc_e
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdGetOwner::_run(const Json::Value &params, Json::Value &result) {
+ Json::Value &section = result["result"];
+
+ section["owner"] = TrexRpcServer::get_owner();
+
+ return (TREX_RPC_CMD_OK);
+}
+
+/**
+ * acquire device
+ *
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdAcquire::_run(const Json::Value &params, Json::Value &result) {
+
+ const string &new_owner = parse_string(params, "user", result);
+ bool force = parse_bool(params, "force", result);
+
+ /* if not free and not you and not force - fail */
+ if ( (!TrexRpcServer::is_free_to_aquire()) && (TrexRpcServer::get_owner() != new_owner) && (!force)) {
+ generate_execute_err(result, "device is already taken by '" + TrexRpcServer::get_owner() + "'");
+ }
+
+ string handle = TrexRpcServer::set_owner(new_owner);
+
+ result["result"] = handle;
+
+ return (TREX_RPC_CMD_OK);
+}
+
+/**
+ * release device
+ *
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdRelease::_run(const Json::Value &params, Json::Value &result) {
+ TrexRpcServer::clear_owner();
+
+ result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
+}