Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-12692
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Oct 19, 2023
1 parent ab95733 commit 525f53a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/CommandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,16 @@ namespace OpenWifi {
poco_warning(Logger(), fmt::format("{}: Failed to send command. ID: {}", UUID, RPC_ID));
return nullptr;
}

bool CommandManager::FireAndForget(const std::string &SerialNumber, const std::string &Method, const Poco::JSON::Object &Params) {
Poco::JSON::Object CompleteRPC;
CompleteRPC.set(uCentralProtocol::JSONRPC, uCentralProtocol::JSONRPC_VERSION);
CompleteRPC.set(uCentralProtocol::ID, 0);
CompleteRPC.set(uCentralProtocol::METHOD, Method);
CompleteRPC.set(uCentralProtocol::PARAMS, Params);
std::stringstream ToSend;
CompleteRPC.stringify(ToSend);
poco_debug(Logger(), fmt::format("{}: Fire and forget command {}.", SerialNumber, Method));
return AP_WS_Server()->SendFrame(SerialNumber, ToSend.str())>0;
}
} // namespace OpenWifi
2 changes: 2 additions & 0 deletions src/CommandManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ namespace OpenWifi {
inline auto CommandTimeout() const { return commandTimeOut_; }
inline auto CommandRetry() const { return commandRetry_; }

bool FireAndForget(const std::string &SerialNumber, const std::string &Method,
const Poco::JSON::Object &Params);
private:
mutable std::recursive_mutex LocalMutex_;
std::atomic_bool Running_ = false;
Expand Down
15 changes: 11 additions & 4 deletions src/RESTAPI/RESTAPI_device_commandHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1398,10 +1398,17 @@ namespace OpenWifi {
Cmd.RunAt = 0;
Cmd.ErrorCode = 0;
Cmd.WaitingForFile = 0;

return RESTAPI_RPC::WaitForCommand(CMD_RPC, APCommands::Commands::rrm, false, Cmd,
Params, *Request, *Response, timeout, nullptr, this,
Logger_);
Cmd.Status= "completed";
if(CommandManager()->FireAndForget(SerialNumber_, uCentralProtocol::RRM, Params)) {
StorageService()->AddCommand(SerialNumber_, Cmd,
Storage::CommandExecutionType::COMMAND_COMPLETED);
Cmd.Status= "completed";
return OK();
}
Cmd.Status= "failed"; // should never happen
StorageService()->AddCommand(SerialNumber_, Cmd,
Storage::CommandExecutionType::COMMAND_COMPLETED);
return BadRequest(RESTAPI::Errors::CouldNotPerformCommand);
}

void RESTAPI_device_commandHandler::Transfer(
Expand Down
3 changes: 2 additions & 1 deletion test_scripts/curl/cli
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ certupdate() {
}

rrm_kick() {
payload="$(printf '[{ "action": "kick", "addr": "%s", "reason": %s, "ban_time": %s}' "$2" "$3" "$4")"
payload="$(printf '{ "actions" : [{ "action": "kick", "addr": "%s", "reason": %s, "ban_time": %s}] }' "$2" "$3" "$4")"
echo "$payload"
curl ${FLAGS} -X POST "https://${OWGW}/api/v1/device/$1/rrm" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
Expand Down

0 comments on commit 525f53a

Please sign in to comment.