From: Lukasz Bardeli Date: Wed, 28 Jun 2017 06:24:32 +0000 (+0200) Subject: [Application][Alarm] Free app_control_h using app_control_destroy X-Git-Tag: submit/tizen/20170628.112919^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8cce89cd15716deacefede58942ea342009ad928;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Application][Alarm] Free app_control_h using app_control_destroy [Verification] Code compiles without error. TCT passrate Alarm 100% AppControl 100% Application 100% Change-Id: I5c32e2307d9b7e8b36df0919c670c97b5828a572 --- diff --git a/src/alarm/alarm_utils.cc b/src/alarm/alarm_utils.cc index 1c9ee9d5..ba8872c3 100755 --- a/src/alarm/alarm_utils.cc +++ b/src/alarm/alarm_utils.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include + #include "alarm_utils.h" #include "common/logger.h" @@ -34,9 +36,19 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."); } - app_control_create(app_control); + app_control_h app_control_tmp = nullptr; + int result = app_control_create(&app_control_tmp); + + if (APP_CONTROL_ERROR_NONE != result) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Creation AppControl failed.", + ("Problem with create handle.")); + } + + std::unique_ptr::type, int(*)(app_control_h)> app_control_ptr( + app_control_tmp, &app_control_destroy); + - int ret = app_control_set_operation(*app_control, it_operation->second.get().c_str()); + int ret = app_control_set_operation(app_control_tmp, it_operation->second.get().c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting operation.", ("Failed app_control_set_operation(): %d (%s)", ret, get_error_message(ret))); @@ -44,7 +56,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a const auto it_uri = obj.find("uri"); if (it_end != it_uri && it_uri->second.is()) { - ret = app_control_set_uri(*app_control, it_uri->second.get().c_str()); + ret = app_control_set_uri(app_control_tmp, it_uri->second.get().c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting uri.", ("Failed app_control_set_uri(): %d (%s)", ret, get_error_message(ret))); @@ -53,7 +65,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a const auto it_mime = obj.find("mime"); if (it_end != it_mime && it_mime->second.is()) { - ret = app_control_set_mime(*app_control, it_mime->second.get().c_str()); + ret = app_control_set_mime(app_control_tmp, it_mime->second.get().c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting mime.", ("Failed app_control_set_mime(): %d (%s)", ret, get_error_message(ret))); @@ -62,7 +74,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a const auto it_category = obj.find("category"); if (it_end != it_category && it_category->second.is()) { - ret = app_control_set_category(*app_control, it_category->second.get().c_str()); + ret = app_control_set_category(app_control_tmp, it_category->second.get().c_str()); if (APP_CONTROL_ERROR_NONE != ret) { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error while setting category.", ("Failed app_control_set_category(): %d (%s)", ret, get_error_message(ret))); @@ -75,7 +87,7 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a PlatformResult result = PlatformResult(ErrorCode::NO_ERROR); for (auto iter = data.begin(); iter != data.end(); ++iter) { - result = AppControlToServiceExtraData(iter->get(), app_control); + result = AppControlToServiceExtraData(iter->get(), &app_control_tmp); if (!result) { LoggerE("Failed AppControlToServiceExtraData()"); return result; @@ -83,6 +95,8 @@ PlatformResult AppControlToService(const picojson::object& obj, app_control_h *a } } + *app_control = app_control_ptr.release(); + return PlatformResult(ErrorCode::NO_ERROR); } diff --git a/src/application/application_utils.cc b/src/application/application_utils.cc index a7860c1e..8d56999c 100644 --- a/src/application/application_utils.cc +++ b/src/application/application_utils.cc @@ -207,24 +207,33 @@ PlatformResult ApplicationUtils::ApplicationControlToService( return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter was passed."); } - app_control_create(app_control); + app_control_h app_control_tmp = nullptr; + int result = app_control_create(&app_control_tmp); + + if (APP_CONTROL_ERROR_NONE != result) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Creation AppControl failed.", + ("Problem with create handle.")); + } + + std::unique_ptr::type, int(*)(app_control_h)> app_control_ptr( + app_control_tmp, &app_control_destroy); // operation - app_control_set_operation(*app_control, it_operation->second.get().c_str()); + app_control_set_operation(app_control_tmp, it_operation->second.get().c_str()); // uri if (it_uri->second.is()) { - app_control_set_uri(*app_control, it_uri->second.get().c_str()); + app_control_set_uri(app_control_tmp, it_uri->second.get().c_str()); } // mime if (it_mime->second.is()) { - app_control_set_mime(*app_control, it_mime->second.get().c_str()); + app_control_set_mime(app_control_tmp, it_mime->second.get().c_str()); } // category if (it_category->second.is()) { - app_control_set_category(*app_control, it_category->second.get().c_str()); + app_control_set_category(app_control_tmp, it_category->second.get().c_str()); } // ApplicationControlData @@ -233,7 +242,7 @@ PlatformResult ApplicationUtils::ApplicationControlToService( for (auto iter = data.begin(); iter != data.end(); ++iter) { if (iter->is()) { PlatformResult ret = - ApplicationControlDataToServiceExtraData(iter->get(), *app_control); + ApplicationControlDataToServiceExtraData(iter->get(), app_control_tmp); if (ret.IsError()) { LoggerE("Failed ApplicationControlDataToServiceExtraData()"); return ret; @@ -241,6 +250,8 @@ PlatformResult ApplicationUtils::ApplicationControlToService( } } + *app_control = app_control_ptr.release(); + return PlatformResult(ErrorCode::NO_ERROR); }