Skip to content

Commit

Permalink
RDKCOM-4606, RDKCOM-3765: New RemoteControl Plugin APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
klu339 committed Jan 3, 2025
1 parent 51d0301 commit 18a4927
Show file tree
Hide file tree
Showing 5 changed files with 714 additions and 8 deletions.
8 changes: 8 additions & 0 deletions RemoteControl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ All notable changes to this RDK Service will be documented in this file.

* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README.
* The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.5.4] - 2024-03-29
### Added
- Added four new APIs unpair and start, cancel, and statusFirmwareUpdate
- Added a new notification onFirmwareUpdateProgress

### Changed
- Changed startPairing API to also accept a list of mac addresses

## [1.4.4] - 2024-03-29
### Fixed
- Fixed coverity reported issues
Expand Down
210 changes: 210 additions & 0 deletions RemoteControl/RemoteControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ namespace WPEFramework {
Register("initializeIRDB", &RemoteControl::initializeIRDB, this);
Register("findMyRemote", &RemoteControl::findMyRemote, this);
Register("factoryReset", &RemoteControl::factoryReset, this);
Register("unpair", &RemoteControl::unpair, this);
Register("startFirmwareUpdate", &RemoteControl::startFirmwareUpdate, this);
Register("cancelFirmwareUpdate", &RemoteControl::cancelFirmwareUpdate, this);
Register("statusFirmwareUpdate", &RemoteControl::statusFirmwareUpdate, this);

m_hasOwnProcess = false;
setApiVersionNumber(1);
Expand Down Expand Up @@ -108,6 +112,7 @@ namespace WPEFramework {
m_hasOwnProcess = true;
IARM_Result_t res;
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RCU_STATUS, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_FIRMWARE_UPDATE_PROGRESS, remoteEventHandler) );
// Register for ControlMgr pairing-related events
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_BEGIN, remoteEventHandler) );
IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_KEY_PRESS, remoteEventHandler) );
Expand Down Expand Up @@ -174,6 +179,10 @@ namespace WPEFramework {
LOGWARN("Got CTRLM_RCU_IARM_EVENT event.");
onStatus(eventData);
break;
case CTRLM_RCU_IARM_EVENT_FIRMWARE_UPDATE_PROGRESS:
LOGWARN("Got CTRLM_RCU_IARM_FIRMWARE_EVENT event.");
onFirmwareUpdateProgress(eventData);
break;
default:
LOGERR("ERROR - unexpected ctrlm event: eventId: %d, data: %p, size: %d.",
(int)eventId, data, len);
Expand Down Expand Up @@ -822,6 +831,198 @@ namespace WPEFramework {

returnResponse(bSuccess);
}

uint32_t RemoteControl::unpair(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;

parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);

if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}

call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';

res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_UNPAIR, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_UNPAIR Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}

JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);

if (bSuccess)
LOGINFO("UNPAIR call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_UNPAIR returned FAILURE!");

returnResponse(bSuccess);
}

uint32_t RemoteControl::startFirmwareUpdate(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;

parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);

if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}

call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';

res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}

JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);

if (bSuccess)
LOGINFO("START FIRMWARE UPDATE call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE returned FAILURE!");

returnResponse(bSuccess);
}

uint32_t RemoteControl::cancelFirmwareUpdate(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;

parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);

if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}

call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';

res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}

JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);

if (bSuccess)
LOGINFO("CANCEL FIRMWARE UPDATE call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE returned FAILURE!");

returnResponse(bSuccess);
}

uint32_t RemoteControl::statusFirmwareUpdate(const JsonObject& parameters, JsonObject& response)
{
LOGINFOMETHOD();

ctrlm_main_iarm_call_json_t *call = NULL;
IARM_Result_t res;
string jsonParams;
bool bSuccess = false;
size_t totalsize = 0;

parameters.ToString(jsonParams);
totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1;
call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize);

if (call == NULL)
{
LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize);
bSuccess = false;
returnResponse(bSuccess);
}

call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION;
size_t len = jsonParams.copy(call->payload, jsonParams.size());
call->payload[len] = '\0';

res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE, (void *)call, totalsize);
if (res != IARM_RESULT_SUCCESS)
{
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res);
bSuccess = false;
free(call);
returnResponse(bSuccess);
}

JsonObject result;
result.FromString(call->result);
bSuccess = result["success"].Boolean();
response = result;
free(call);

if (bSuccess)
LOGINFO("STATUS FIRMWARE UPDATE call SUCCESS!");
else
LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE returned FAILURE!");

returnResponse(bSuccess);
}
//End methods

//Begin ble events
Expand All @@ -833,6 +1034,15 @@ namespace WPEFramework {

sendNotify("onStatus", params);
}

void RemoteControl::onFirmwareUpdateProgress(ctrlm_main_iarm_event_json_t* eventData)
{
JsonObject params;

params.FromString(eventData->payload);

sendNotify("onFirmwareUpdateProgress", params);
}
//End ble events

//Begin local private utility methods
Expand Down
5 changes: 5 additions & 0 deletions RemoteControl/RemoteControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ namespace WPEFramework {
uint32_t initializeIRDB(const JsonObject& parameters, JsonObject& response);
uint32_t findMyRemote(const JsonObject& parameters, JsonObject& response);
uint32_t factoryReset(const JsonObject& parameters, JsonObject& response);
uint32_t unpair(const JsonObject& parameters, JsonObject& response);
uint32_t startFirmwareUpdate(const JsonObject& parameters, JsonObject& response);
uint32_t cancelFirmwareUpdate(const JsonObject& parameters, JsonObject& response);
uint32_t statusFirmwareUpdate(const JsonObject& parameters, JsonObject& response);
//End methods

//Begin events
void onStatus(ctrlm_main_iarm_event_json_t* eventData);
void onFirmwareUpdateProgress(ctrlm_main_iarm_event_json_t* eventData);
//End events

public:
Expand Down
Loading

0 comments on commit 18a4927

Please sign in to comment.