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 = 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) {
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;
}
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);
}
*(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;
}