Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/thunder/ctrlm_thunder_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,29 @@ bool ctrlm_thunder_plugin_t::call_plugin(std::string method, void *params, void
return(ret);
}

bool ctrlm_thunder_plugin_t::call_plugin_boolean(std::string method, void *params, bool *response) {
bool ret = false;
auto clientObject = (JSONRPC::LinkType<Core::JSON::IElement>*)this->plugin_client;
JsonObject *jsonParams = (JsonObject *)params;
if(clientObject) {
if(!method.empty() && jsonParams && response) {
Core::JSON::Boolean jsonResponse;
uint32_t thunderRet = clientObject->Invoke<JsonObject, Core::JSON::Boolean>(CALL_TIMEOUT, _T(method), *jsonParams, jsonResponse);
if(thunderRet != Core::ERROR_NONE) {
XLOGD_ERROR("Thunder call failed <%s> <%u>", method.c_str(), thunderRet);
} else {
*response = jsonResponse.Value();
ret = true;
Comment on lines +266 to +276
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call_plugin_boolean does not implement timeout retry behavior like property_get and call_plugin (which retry on Core::ERROR_TIMEDOUT up to retries). If callers need the same robustness, consider adding an optional retries parameter and reusing the same retry loop/logging pattern to keep behavior consistent across Thunder calls.

Suggested change
auto clientObject = (JSONRPC::LinkType<Core::JSON::IElement>*)this->plugin_client;
JsonObject *jsonParams = (JsonObject *)params;
if(clientObject) {
if(!method.empty() && jsonParams && response) {
Core::JSON::Boolean jsonResponse;
uint32_t thunderRet = clientObject->Invoke<JsonObject, Core::JSON::Boolean>(CALL_TIMEOUT, _T(method), *jsonParams, jsonResponse);
if(thunderRet != Core::ERROR_NONE) {
XLOGD_ERROR("%s: Thunder call failed <%s> <%u>\n", __FUNCTION__, method.c_str(), thunderRet);
} else {
*response = jsonResponse.Value();
ret = true;
unsigned int attempts = 0;
const unsigned int retries = REGISTER_EVENTS_RETRY_MAX;
auto clientObject = (JSONRPC::LinkType<Core::JSON::IElement>*)this->plugin_client;
JsonObject *jsonParams = (JsonObject *)params;
if(clientObject) {
if(!method.empty() && jsonParams && response) {
Core::JSON::Boolean jsonResponse;
uint32_t thunderRet = Core::ERROR_TIMEDOUT;
while(thunderRet == Core::ERROR_TIMEDOUT && attempts <= retries) { // We only want to retry if return code is for TIMEDOUT
thunderRet = clientObject->Invoke<JsonObject, Core::JSON::Boolean>(CALL_TIMEOUT, _T(method), *jsonParams, jsonResponse);
if(thunderRet == Core::ERROR_NONE) {
*response = jsonResponse.Value();
ret = true;
} else {
attempts += 1;
XLOGD_ERROR("Thunder call failed <%s> <%u>, attempt %u of %u", method.c_str(), thunderRet, attempts, (thunderRet == Core::ERROR_TIMEDOUT ? retries : 0) + 1); // retries + initial attempt
}

Copilot uses AI. Check for mistakes.
}
} else {
XLOGD_ERROR("Invalid parameters");
}
} else {
XLOGD_ERROR("Client is NULL");
}
return(ret);
}

bool ctrlm_thunder_plugin_t::call_controller(std::string method, void *params, void *response) {
bool ret = false;
if(this->controller) {
Expand Down
16 changes: 13 additions & 3 deletions src/thunder/ctrlm_thunder_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class ctrlm_thunder_plugin_t {
std::string callsign_with_api();

/**
* This functions is used to get a Thunder Plugin property.
* This function is used to get a Thunder Plugin property.
* @param method The method in which the user wants to call.
* @param params The WPEFramework JsonObject containing the parameters for the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param response The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
Expand All @@ -115,7 +115,7 @@ class ctrlm_thunder_plugin_t {
bool property_get(std::string property, void *response, unsigned int retries = 0);
Comment on lines 108 to 115
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring for property_get looks incorrect: it refers to @param method and @param params, but the signature is property_get(std::string property, void *response, ...) and there is no params argument. Please update the parameter names/descriptions to match the actual API to avoid misleading callers.

Copilot uses AI. Check for mistakes.

/**
* This functions is used to call a Thunder Plugin method.
* This function is used to call a Thunder Plugin method.
* @param method The method in which the user wants to call.
* @param params The WPEFramework JsonObject containing the parameters for the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param response The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
Expand All @@ -125,7 +125,17 @@ class ctrlm_thunder_plugin_t {
bool call_plugin(std::string method, void *params, void *response, unsigned int retries = 0);

/**
* This functions is used to call a Thunder Controller method.
* This function is used to call a Thunder Plugin method.
* @param method The method in which the user wants to call.
* @param params The WPEFramework JsonObject containing the parameters for the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param response The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param retries The number of retries if the call times out.
Comment on lines +131 to +132
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call_plugin_boolean doc comment doesn’t match the function signature: it documents a JsonObject response and a retries parameter, but the signature takes bool *response and has no retries argument. Please adjust the comment (or add a retries argument) so the header accurately describes the API.

Suggested change
* @param response The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param retries The number of retries if the call times out.
* @param response A pointer to the boolean response value from the call.

Copilot uses AI. Check for mistakes.
* @return True if the call succeeded, otherwise False.
*/
bool call_plugin_boolean(std::string method, void *params, bool *response);

/**
* This function is used to call a Thunder Controller method.
* @param method The method in which the user wants to call.
* @param params The WPEFramework JsonObject containing the parameters for the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
* @param params The WPEFramework JsonObject containing the response from the call. (We can't include WPEFramework headers in controlMgr .h files as their logging macros clash)
Expand Down
12 changes: 6 additions & 6 deletions src/thunder/ctrlm_thunder_plugin_powermanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,15 @@ ctrlm_power_state_t ctrlm_thunder_plugin_powermanager_t::get_power_state() {
/* root@pioneer-uhd:~# curl --request POST --url http://127.0.0.1:9998/jsonrpc --header 'Content-Type: application/json' --data '{ "jsonrpc": "2.0", "id": 1234567890, "method": "org.rdk.PowerManager.1.getNetworkStandbyMode", "params": {} }'
{"jsonrpc":"2.0","id":1234567890,"result":true} */
bool ctrlm_thunder_plugin_powermanager_t::get_networked_standby_mode() {
JsonObject params, response;
JsonObject params;
params = {};
bool networked_standby_mode = false;

sem_wait(&this->semaphore);
if(this->call_plugin("getNetworkStandbyMode", (void *)&params, (void *)&response)) {
networked_standby_mode = response["result"].Boolean();
sem_wait(&this->semaphore);
if(this->call_plugin_boolean("getNetworkStandbyMode", (void *)&params, &networked_standby_mode)) {
XLOGD_DEBUG("networked_standby_mode is %s", networked_standby_mode?"TRUE":"FALSE");
} else {
XLOGD_ERROR("getNetworkedStandbyMode call failed");
XLOGD_ERROR("getNetworkStandbyMode call failed");
}
sem_post(&this->semaphore);

Expand All @@ -114,7 +113,8 @@ bool ctrlm_thunder_plugin_powermanager_t::get_wakeup_reason_voice() {

sem_wait(&this->semaphore);
if(this->call_plugin("getLastWakeupReason", (void *)&params, (void *)&response)) {
wakeup_reason_voice = (0 == strncmp(response["result"].String().c_str(), "VOICE", 5));
XLOGD_INFO("received <%s>", response["result"].String().c_str());
wakeup_reason_voice = (std::string(response["result"].String()) == "VOICE");
XLOGD_DEBUG("voice_wakeup is %s", wakeup_reason_voice?"TRUE":"FALSE");
} else {
XLOGD_ERROR("getLastWakeupReason call failed");
Expand Down
Loading