From 54f8323b3938bf4ab672cde01a06711bfc522a2e Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 9 Sep 2015 18:06:12 +0300 Subject: added ownership to RPC server --- src/rpc-server/commands/trex_rpc_cmd_general.cpp | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'src/rpc-server/commands/trex_rpc_cmd_general.cpp') 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 ¶ms, 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 ¶ms, Json::Value &result) { + Json::Value §ion = result["result"]; + + section["owner"] = TrexRpcServer::get_owner(); + + return (TREX_RPC_CMD_OK); +} + +/** + * acquire device + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdAcquire::_run(const Json::Value ¶ms, 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 ¶ms, Json::Value &result) { + TrexRpcServer::clear_owner(); + + result["result"] = "ACK"; + + return (TREX_RPC_CMD_OK); +} -- cgit 1.2.3-korg