Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDKCOM-4606: New RemoteControl Plugin APIs #5836

Open
wants to merge 1 commit into
base: sprint/24Q4
Choose a base branch
from
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
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
Loading