Support update_control_get_property with result 58/237758/6
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Fri, 3 Jul 2020 17:17:42 +0000 (17:17 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Mon, 6 Jul 2020 12:59:51 +0000 (12:59 +0000)
- Change update_control_initialize to initialize dbus proxy
- Support get_property with result

Change-Id: I54832e11d6f25aa5f898d9d1427ff3ef46ba2364
Signed-off-by: Jeon Sang-Heon <sh95.jeon@samsung.com>
src/update_control.c

index 6f4ce606bbfe0949e08713c6f0e2d1a4534d5810..1d36ff37bf92bffe13beaa772934f635779a4f54 100644 (file)
 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 <install> to dbus : %s", error->message);
                return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
        }
 
+       _I("Success to method call <install> 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 <result> 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 <result> 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;
+       }
 }