diff --git a/RemoteControl/RemoteControl.cpp b/RemoteControl/RemoteControl.cpp index e0541f541f..259d885b29 100644 --- a/RemoteControl/RemoteControl.cpp +++ b/RemoteControl/RemoteControl.cpp @@ -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); @@ -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 diff --git a/RemoteControl/RemoteControl.h b/RemoteControl/RemoteControl.h index e349994bea..5b4246b122 100644 --- a/RemoteControl/RemoteControl.h +++ b/RemoteControl/RemoteControl.h @@ -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