From: Jeon Sang-Heon Date: Fri, 3 Jul 2020 17:17:42 +0000 (+0000) Subject: Support update_control_get_property with result X-Git-Tag: submit/tizen/20200706.142233~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c89938e130db1692e8fa4f12854ab7507243ff7a;p=platform%2Fcore%2Fsystem%2Fupdate-control.git Support update_control_get_property with result - Change update_control_initialize to initialize dbus proxy - Support get_property with result Change-Id: I54832e11d6f25aa5f898d9d1427ff3ef46ba2364 Signed-off-by: Jeon Sang-Heon --- diff --git a/src/update_control.c b/src/update_control.c index 6f4ce60..1d36ff3 100644 --- a/src/update_control.c +++ b/src/update_control.c @@ -27,49 +27,31 @@ static bool initialized = false; static void *plugin_handle = NULL; +static OrgTizenUpdateManager *proxy = NULL; API int update_control_initialize(void) { CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE); + _I("update_control_initialize called"); - int ret; - int (*plugin_update_control_initialize)(void) = NULL; + GError *error = NULL; - if (initialized) { + if (proxy != NULL) { _D("Already initialized"); return UPDATE_CONTROL_ERROR_NONE; } - if (access(UPDATE_CONTROL_PLUGIN, F_OK) != 0) { - _E("update-control plugin is not found"); - return UPDATE_CONTROL_ERROR_INVALID_OPERATION; - } - - plugin_handle = dlopen(UPDATE_CONTROL_PLUGIN, RTLD_NOW); - if (!plugin_handle) { - _E("dlopen failed: %s", dlerror()); + proxy = org_tizen_update_manager_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + "org.tizen.update.manager", "/org/tizen/update/manager", NULL, &error); + if (error != NULL) { + _E("Failed get proxy for org.tizen.update.manager : %s", error->message); return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; } - plugin_update_control_initialize = dlsym(plugin_handle, - "update_control_initialize"); - if (!plugin_update_control_initialize) { - _E("dlsym failed: %s", dlerror()); - return UPDATE_CONTROL_ERROR_INVALID_OPERATION; - } - - ret = plugin_update_control_initialize(); - if (ret != UPDATE_CONTROL_ERROR_NONE) { - _E("update_control_initialize error: %d", ret); - return ret; - } - - initialized = true; - + _I("Success to get proxy for org.tizen.update.manager"); return UPDATE_CONTROL_ERROR_NONE; } - API int update_control_deinitialize(void) { CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE); @@ -169,36 +151,29 @@ API int update_control_download_package(void) API int update_control_do_update(void) { CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE); - _I("Try to start update ..."); + _I("update_control_do_update called"); - static OrgTizenUpdateManager *proxy = NULL; gint status = 0; GError *error = NULL; if (proxy == NULL) { - proxy = org_tizen_update_manager_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, - "org.tizen.update.manager", "/org/tizen/update/manager", NULL, &error); - if (error == NULL) { - _I("Success to get proxy for org.tizen.update.manager"); - } else { - _E("Failed get proxy for org.tizen.update.manager : %s", error->message); - return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; - } + _E("Not initialized"); + return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; } org_tizen_update_manager_call_install_sync(proxy, &status, NULL, &error); - if (error == NULL) { - _I("Success to call install to daemon"); - if (status < 0) { - _E("Failed to do update : %d", status); - return UPDATE_CONTROL_ERROR_INVALID_OPERATION; - } - } else { - _E("Failed to call install to daemon : %s", error->message); + if (error != NULL) { + _E("Failed to method call to dbus : %s", error->message); return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; } + _I("Success to method call to dbus"); + if (status < 0) { + _E("Failed to do update : %d", status); + return UPDATE_CONTROL_ERROR_INVALID_OPERATION; + } + + _I("Success to do update : %d", status); return UPDATE_CONTROL_ERROR_NONE; } @@ -261,27 +236,35 @@ API int update_control_cancel_reservation(void) API int update_control_get_property(update_control_property_e property, void **value) { CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE); + _I("update_control_get_property called"); - int ret; - int (*plugin_update_control_get_property)(update_control_property_e, void **) = NULL; + gint status = 0; + GError *error = NULL; - if (!plugin_handle) { - _E("plugin not opened"); - return UPDATE_CONTROL_ERROR_INVALID_OPERATION; + if (proxy == NULL) { + _E("Not initialized"); + return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; } - plugin_update_control_get_property = dlsym(plugin_handle, - "update_control_get_property"); - if (!plugin_update_control_get_property) { - _E("dlsym failed: %s", dlerror()); - return UPDATE_CONTROL_ERROR_INVALID_OPERATION; - } + switch(property) { + case UPDATE_CONTROL_PROPERTY_RESULT: + org_tizen_update_manager_call_result_sync(proxy, &status, NULL, &error); + if (error != NULL) { + _E("Failed to method call to dbus : %s", error->message); + return UPDATE_CONTROL_ERROR_SYSTEM_ERROR; + } - ret = plugin_update_control_get_property(property, value); - if (ret != UPDATE_CONTROL_ERROR_NONE) { - _E("update_control_get_property error: %d", ret); - return ret; - } + _I("Success to method call to dbus"); + if (status < 0) { + _E("Failed to get result : %d", status); + return UPDATE_CONTROL_ERROR_INVALID_OPERATION; + } - return UPDATE_CONTROL_ERROR_NONE; + _I("Success to get result : %d", status); + *value = (void *)(status); + return UPDATE_CONTROL_ERROR_NONE; + default: + _I("Unsupported property : %d", property); + return UPDATE_CONTROL_ERROR_NOT_SUPPORTED; + } }