Skip to content

Commit

Permalink
RDKCOM-4606: New RemoteControl Plugin APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
klu339 committed Nov 1, 2024
1 parent 4934003 commit 3e5d84b
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 0 deletions.
196 changes: 196 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 @@ -822,6 +826,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 Down
4 changes: 4 additions & 0 deletions RemoteControl/RemoteControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ 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
Expand Down

0 comments on commit 3e5d84b

Please sign in to comment.