int size;
};
-int register_signal_handler(appdata_s *);
-int unregister_signal_handler(void);
-
int dbus_method_sync(const char *dest, const char *path,
const char *interface, const char *method,
const char *sig, char *param[]);
const char *method, const char *sig,
char *param[], GVariant **info);
+typedef void (*dbus_pending_cb)(void *data, GVariant *result, GError *err);
+
+int dbus_method_async_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[], dbus_pending_cb cb, int timeout, void *data);
+
+int register_signal_handler(appdata_s *);
+int unregister_signal_handler(void);
+
/**
* If result is NULL, err is set.
* Do not invoke g_variant_unref() with result.
#define DBUS_REPLY_TIMEOUT (-1)
#define DBUS_MAXIMUM_NAME_LENGTH 255
+struct pending_call_data {
+ dbus_pending_cb func;
+ void *data;
+};
+
struct proxy_node {
GDBusProxy *proxy;
char *dest;
return 0;
}
+static void cb_pending(GDBusProxy *proxy,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ struct pending_call_data *data = user_data;
+ GError *err = NULL;
+ GVariant *output;
+
+ output = g_dbus_proxy_call_finish(proxy,
+ res, /* GAsyncResult */
+ &err);
+ if (!output)
+ DMSG_ERR("g_dbus_proxy_call_finish error : %d-%s",
+ err->code, err->message);
+
+ if (data && data->func)
+ data->func(data->data, output, err);
+ free(data);
+
+ if (err)
+ g_clear_error(&err);
+ if (output)
+ g_variant_unref(output);
+}
+
+int dbus_method_async_with_reply(const char *dest, const char *path,
+ const char *interface, const char *method,
+ const char *sig, char *param[],
+ dbus_pending_cb cb, int timeout, void *data)
+{
+ GDBusProxy *proxy;
+ GError *err = NULL;
+ struct pending_call_data *pdata;
+ int result;
+
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+ g_type_init();
+#endif
+
+ pthread_mutex_lock(&dmutex);
+ proxy = get_proxy_from_proxy_pool(dest, path, interface, &err);
+ if (!proxy) {
+ pthread_mutex_unlock(&dmutex);
+ DMSG_ERR("fail to get proxy from proxy pool : %s-%s (%d-%s)",
+ interface, method, err->code, err->message);
+ result = g_dbus_error_to_errno(err->code);
+ g_clear_error(&err);
+ return result;
+ }
+
+ pdata = malloc(sizeof(struct pending_call_data));
+ if (!pdata) {
+ pthread_mutex_unlock(&dmutex);
+ DMSG_ERR("malloc error : %s-%s",
+ interface, method);
+ return -ENOMEM;
+ }
+
+ pdata->func = cb;
+ pdata->data = data;
+
+ g_dbus_proxy_call(proxy,
+ method, /* method name */
+ append_g_variant(sig, param), /* parameters */
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_REPLY_TIMEOUT, /* timeout */
+ NULL, /* GCancellable */
+ (GAsyncReadyCallback)cb_pending, /* GAsyncReadyCallback */
+ pdata); /* user data */
+ pthread_mutex_unlock(&dmutex);
+
+ return 0;
+}
+
static GDBusConnection *get_dbus_connection(void)
{
GError *err = NULL;
}
static void
+format_done(void *data, GVariant *result, GError *err)
+{
+ appdata_s* ad = (appdata_s*)data;
+ char str_id[32];
+ char *arr[2];
+ int ret;
+
+ FUNC_BEGIN();
+ ret_if(ad == NULL);
+ ret_if(result == NULL);
+
+ g_variant_get(result, "(i)", &ret);
+ if (ret < 0) {
+ DMSG("Failed to format sd card as portable storage: %d", ret);
+ return;
+ }
+
+ snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
+ arr[0] = str_id;
+ arr[1] = "ExtendedInternalSD";
+
+ ret = dbus_method_sync(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", "is", arr);
+ if (ret < 0) {
+ DMSG("Failed to mount sd card as extended internal storage: %d", ret);
+ return;
+ }
+
+ Evas_Object* page_content = elm_object_part_content_unset(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content");
+ EVAS_OBJECT_DEL(page_content);
+ page_content = create_page_5(ad);
+ elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
+
+
+ g_variant_unref(result);
+ FUNC_END();
+}
+
+static void
_continue_click_cb(void *data, Evas_Object* obj, void *event_info)
{
FUNC_BEGIN();
appdata_s* ad = (appdata_s*)data;
+ char str_id[32];
+ char str_option[32];
+ char *arr[3];
+ int ret;
+
ret_if(ad == NULL);
Evas_Object* page_content = elm_object_part_content_unset(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content");
page_content = create_page_4(ad);
elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
+ snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
+ arr[0] = str_id;
+ snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE);
+ arr[1] = str_option;
+ arr[2] = "ext4";
+ ret = dbus_method_async_with_reply(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ "FormatwithType",
+ "iis",
+ arr,
+ format_done,
+ -1,
+ ad);
+ if (ret < 0)
+ DMSG("Failed to format", ret);
+
FUNC_END();
}
FUNC_BEGIN();
Elm_Genlist_Item_Class *extended_multiline_genlist_itc;
- Evas_Object *page_content;
genlist_item_s *item;
- char str_id[32];
- char str_option[32];
- char *arr[3];
- char *arr2[2];
- int ret;
extended_multiline_genlist_itc = elm_genlist_item_class_new();
extended_multiline_genlist_itc->item_style = "extended-multiline";
elm_genlist_item_class_free(extended_multiline_genlist_itc);
- snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
- arr[0] = str_id;
- arr2[0] = str_id;
- snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE);
- arr[1] = str_option;
- arr[2] = "ext4";
- ret = dbus_method_sync(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "FormatwithType", "iis", arr);
- if (ret < 0)
- DMSG("Failed to format sd card as extended internal storage: %d", ret);
-
- arr2[1] = "ExtendedInternalSD";
- ret = dbus_method_sync(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", "is", arr2);
- if (ret < 0)
- DMSG("Failed to mount sd card as extended internal storage: %d", ret);
-
- page_content = elm_object_part_content_unset(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content");
- EVAS_OBJECT_DEL(page_content);
- page_content = create_page_5(ad);
- elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
-
- FUNC_END();
- return page_content;
-
out:
FUNC_END();
return genlist;
static Evas_Object* create_page_3(appdata_s* ad);
static void
+format_done(void *data, GVariant *result, GError *err)
+{
+ appdata_s* ad = (appdata_s*)data;
+ char str_id[32];
+ char *arr[2];
+ int ret;
+
+ FUNC_BEGIN();
+ ret_if(ad == NULL);
+ ret_if(result == NULL);
+
+ g_variant_get(result, "(i)", &ret);
+ if (ret < 0) {
+ DMSG("Failed to format sd card as portable storage: %d", ret);
+ return;
+ }
+
+ snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
+ arr[0] = str_id;
+ arr[1] = "";
+
+ ret = dbus_method_sync(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", "is", arr);
+ if (ret < 0) {
+ DMSG("Failed to mount sd card as portable storage: %d", ret);
+ return;
+ }
+
+ Evas_Object* page_content = elm_object_part_content_unset(ad->portable_storage_page_data->portable_storage_page_base_layout, "elm.swallow.content");
+ EVAS_OBJECT_DEL(page_content);
+ page_content = create_page_3(ad);
+ elm_object_part_content_set(ad->portable_storage_page_data->portable_storage_page_base_layout, "elm.swallow.content", page_content);
+
+ g_variant_unref(result);
+ FUNC_END();
+}
+
+static void
_format_click_cb(void *data, Evas_Object* obj, void *event_info)
{
FUNC_BEGIN();
+ char str_id[32];
+ char str_option[32];
+ char *arr[3];
+ int ret;
+
appdata_s* ad = (appdata_s*)data;
ret_if(ad == NULL);
page_content = create_page_2(ad);
elm_object_part_content_set(ad->portable_storage_page_data->portable_storage_page_base_layout, "elm.swallow.content", page_content);
+
+ snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
+ arr[0] = str_id;
+ snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE);
+ arr[1] = str_option;
+ arr[2] = "vfat";
+ ret = dbus_method_async_with_reply(STORAGED_BUS_NAME,
+ STORAGED_PATH_BLOCK_MANAGER,
+ STORAGED_INTERFACE_BLOCK_MANAGER,
+ "FormatwithType",
+ "iis",
+ arr,
+ format_done,
+ -1,
+ ad);
+ if (ret < 0)
+ DMSG("Failed to format", ret);
+
FUNC_END();
+
}
static void
FUNC_BEGIN();
Elm_Genlist_Item_Class *extended_multiline_genlist_itc;
- Evas_Object *page_content;
genlist_item_s *item;
- char str_id[32];
- char str_option[32];
- char *arr[3];
- char *arr2[2];
- int ret;
extended_multiline_genlist_itc = elm_genlist_item_class_new();
extended_multiline_genlist_itc->item_style = "extended-multiline";
elm_genlist_item_class_free(extended_multiline_genlist_itc);
- snprintf(str_id, sizeof(str_id), "%d", ad->storage_id);
- arr[0] = str_id;
- arr2[0] = str_id;
- snprintf(str_option, sizeof(str_option), "%d", UNMOUNT_FORCE);
- arr[1] = str_option;
- arr[2] = "vfat";
- ret = dbus_method_sync(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "FormatwithType", "iis", arr);
- if (ret < 0)
- _D("Failed to format sd card as portable storage: %d", ret);
-
- arr2[1] = "";
- ret = dbus_method_sync(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER, STORAGED_INTERFACE_BLOCK_MANAGER, "Mount", "is", arr2);
- if (ret < 0)
- _D("Failed to mount sd card as portable storage: %d", ret);
-
- page_content = elm_object_part_content_unset(ad->portable_storage_page_data->portable_storage_page_base_layout, "elm.swallow.content");
- EVAS_OBJECT_DEL(page_content);
- page_content = create_page_3(ad);
- elm_object_part_content_set(ad->portable_storage_page_data->portable_storage_page_base_layout, "elm.swallow.content", page_content);
-
- FUNC_END();
- return page_content;
out:
FUNC_END();
return genlist;