Rollback plugin to API 05/238005/1 accepted/tizen/unified/20200713.094510 submit/tizen/20200710.163409
authorJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 7 Jul 2020 17:56:49 +0000 (17:56 +0000)
committerJeon Sang-Heon <sh95.jeon@samsung.com>
Tue, 7 Jul 2020 17:56:49 +0000 (17:56 +0000)
- We need to use plugin except do_update and get_property(result)
- So, rollback plugin to initialize and get_property
- Add deinitialize logic for dbus

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

index e406ff25c613dba5f70ebe75aeb24dae9a245e5c..78bfcfda052c8f50824c7ef7d312990dd900b3f1 100644 (file)
@@ -26,7 +26,6 @@
 
 static bool initialized = false;
 static void *plugin_handle = NULL;
-
 static OrgTizenUpdateManager *proxy = NULL;
 
 API int update_control_initialize(void)
@@ -34,29 +33,59 @@ API int update_control_initialize(void)
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
        _I("update_control_initialize called");
 
+       int ret = 0;
+       int (*plugin_update_control_initialize)(void) = NULL;
        GError *error = NULL;
 
-       if (proxy != NULL) {
+       if (initialized) {
                _D("Already initialized");
                return UPDATE_CONTROL_ERROR_NONE;
        }
 
-       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;
+       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) {
+                       _E("Failed get proxy for org.tizen.update.manager : %s", error->message);
+                       return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+               }
+               _I("Success to get proxy for org.tizen.update.manager");
        }
 
-       _I("Success to get proxy for org.tizen.update.manager");
+       if (access(UPDATE_CONTROL_PLUGIN, F_OK) == 0) {
+               _I("Success to find update control plugin");
+
+               plugin_handle = dlopen(UPDATE_CONTROL_PLUGIN, RTLD_NOW);
+               if (!plugin_handle) {
+                       _E("dlopen failed: %s", dlerror());
+                       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;
+               }
+       } else {
+               _I("Failed to find update control plugin, passed");
+       }
+
+       initialized = true;
        return UPDATE_CONTROL_ERROR_NONE;
 }
 
 API int update_control_deinitialize(void)
 {
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
+       _I("update_control_deinitialize called");
 
-       int ret;
+       int ret = 0;
        int (*plugin_update_control_deinitialize)(void) = NULL;
 
        if (!initialized) {
@@ -64,31 +93,34 @@ API int update_control_deinitialize(void)
                return UPDATE_CONTROL_ERROR_NONE;
        }
 
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
+       if (proxy != NULL) {
+               g_object_unref(proxy);
+               proxy = NULL;
+               _I("Success to unref proxy");
        }
 
-       plugin_update_control_deinitialize = dlsym(plugin_handle,
-                       "update_control_deinitialize");
-       if (!plugin_update_control_deinitialize) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       if (plugin_handle) {
+               _I("Success to find initialized plugin");
 
-       ret = plugin_update_control_deinitialize();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_deinitialize error: %d", ret);
-               return ret;
-       }
+               plugin_update_control_deinitialize = dlsym(plugin_handle, "update_control_deinitialize");
+               if (!plugin_update_control_deinitialize) {
+                       _E("dlsym failed: %s", dlerror());
+                       return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
+               }
+
+               ret = plugin_update_control_deinitialize();
+               if (ret != UPDATE_CONTROL_ERROR_NONE) {
+                       _E("update_control_deinitialize error: %d", ret);
+                       return ret;
+               }
 
-       if (plugin_handle) {
                dlclose(plugin_handle);
                plugin_handle = NULL;
+       } else {
+               _I("Failed to find initialized plugin, passed");
        }
 
        initialized = false;
-
        return UPDATE_CONTROL_ERROR_NONE;
 }
 
@@ -238,16 +270,18 @@ API int update_control_get_property(update_control_property_e property, void **v
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
        _I("update_control_get_property called");
 
+       int ret = 0;
+       int (*plugin_update_control_get_property)(update_control_property_e, void **) = NULL;
        gint status = 0;
        GError *error = NULL;
 
-       if (proxy == NULL) {
-               _E("Not initialized");
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-       }
-
        switch(property) {
        case UPDATE_CONTROL_PROPERTY_RESULT:
+               if (proxy == NULL) {
+                       _E("Not initialized");
+                       return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
+               }
+
                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);
@@ -268,9 +302,25 @@ API int update_control_get_property(update_control_property_e property, void **v
                }
 
                *(int *)(*value) = status;
-               return UPDATE_CONTROL_ERROR_NONE;
+               break;
        default:
-               _I("Unsupported property : %d", property);
-               return UPDATE_CONTROL_ERROR_NOT_SUPPORTED;
+               if (!plugin_handle) {
+                       _E("plugin not opened");
+                       return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
+               }
+
+               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;
+               }
+
+               ret = plugin_update_control_get_property(property, value);
+               if (ret != UPDATE_CONTROL_ERROR_NONE) {
+                       _E("update_control_get_property error: %d", ret);
+                       return ret;
+               }
        }
+
+       return UPDATE_CONTROL_ERROR_NONE;
 }