block, app: Add CheckSpeed 40/154740/5 accepted/tizen/4.0/unified/20171012.225808 submit/tizen_4.0/20171012.122106
authorpr.jung <pr.jung@samsung.com>
Wed, 11 Oct 2017 07:52:57 +0000 (16:52 +0900)
committerpr.jung <pr.jung@samsung.com>
Wed, 11 Oct 2017 08:52:19 +0000 (17:52 +0900)
- Add CheckSpeed dbus method on storaged
- App calls CheckSpeed (internal extended sdcard)

Change-Id: I90817330ce210946d9ee1a1b9fcc9895648d431c
Signed-off-by: pr.jung <pr.jung@samsung.com>
apps/extended-sd/include/dbus-call.h
apps/extended-sd/include/extended-sd-main.h
apps/extended-sd/src/dbus-call.c
apps/extended-sd/src/es-internal-storage-page.c
src/block/block.c

index 0a3a10c..fcc3659 100644 (file)
@@ -25,6 +25,8 @@
 #include "dbus_macro.h"
 #include "extended-sd-main.h"
 
+#define DBUS_REPLY_TIMEOUT     (-1)
+
 struct dbus_int {
        int *list;
        int size;
index c4d5441..b89b062 100644 (file)
@@ -51,8 +51,6 @@ typedef struct appdata {
        internal_storage_page_data_s* internal_storage_page_data;
 
        int storage_id;
-       Ecore_Timer* format_timer; //demo purpose, please remove once formatting implementation in place
-       Ecore_Timer* check_timer; //demo purpose, please remove once formatting implementation in place
 } appdata_s;
 
 #define SAFE_FREE(data) if (data) { free(data); data = NULL; }
index cdc503e..c13e210 100644 (file)
@@ -26,7 +26,6 @@
 #include "dbus-call.h"
 #include "log-util.h"
 
-#define DBUS_REPLY_TIMEOUT     (-1)
 #define DBUS_MAXIMUM_NAME_LENGTH 255
 
 struct pending_call_data {
index 3405d50..5ebc14c 100644 (file)
@@ -44,22 +44,6 @@ static Evas_Object* create_page_4(appdata_s* ad);
 static Evas_Object* create_page_5(appdata_s* ad);
 
 static void
-_format_click_cb(void *data, Evas_Object* obj, void *event_info)
-{
-       FUNC_BEGIN();
-
-       appdata_s* ad = (appdata_s*)data;
-       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");
-       EVAS_OBJECT_DEL(page_content);
-       page_content = create_page_2(ad);
-       elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
-
-       FUNC_END();
-}
-
-static void
 format_done(void *data, GVariant *result, GError *err)
 {
        appdata_s* ad = (appdata_s*)data;
@@ -99,7 +83,7 @@ format_done(void *data, GVariant *result, GError *err)
 }
 
 static void
-_continue_click_cb(void *data, Evas_Object* obj, void *event_info)
+encryption_format(void *data)
 {
        FUNC_BEGIN();
 
@@ -137,6 +121,77 @@ _continue_click_cb(void *data, Evas_Object* obj, void *event_info)
 }
 
 static void
+check_speed_done(void *data, GVariant *result, GError *err)
+{
+       appdata_s* ad = (appdata_s*)data;
+       int ret;
+
+       FUNC_BEGIN();
+       ret_if(ad == NULL);
+       ret_if(result == NULL);
+
+       g_variant_get(result, "(i)", &ret);
+       if (ret < 0) {
+               DMSG("Performance warning", ret);
+               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_3(ad);
+               elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
+               goto out;
+       } else
+               encryption_format(ad);
+
+out:
+       g_variant_unref(result);
+       FUNC_END();
+}
+
+static void
+_format_click_cb(void *data, Evas_Object* obj, void *event_info)
+{
+       FUNC_BEGIN();
+
+       appdata_s* ad = (appdata_s*)data;
+       char str_id[32];
+       char *arr[1];
+       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");
+       EVAS_OBJECT_DEL(page_content);
+       page_content = create_page_2(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;
+       ret = dbus_method_async_with_reply(STORAGED_BUS_NAME,
+                       STORAGED_PATH_BLOCK_MANAGER,
+                       STORAGED_INTERFACE_BLOCK_MANAGER,
+                       "CheckSpeed",
+                       "i",
+                       arr,
+                       check_speed_done,
+                       DBUS_REPLY_TIMEOUT,  // ms
+                       ad);
+       if (ret < 0)
+               DMSG("Failed to check speed", ret);
+
+       FUNC_END();
+}
+
+static void
+_continue_click_cb(void *data, Evas_Object* obj, void *event_info)
+{
+       FUNC_BEGIN();
+
+       appdata_s* ad = (appdata_s*)data;
+
+       encryption_format(ad);
+       FUNC_END();
+}
+
+static void
 _move_files_button_click_cb(void *data, Evas_Object* obj, void *event_info)
 {
        FUNC_BEGIN();
@@ -429,23 +484,6 @@ out:
        return page_content;
 }
 
-static Eina_Bool _check_timer_cb(void* data)
-{
-       FUNC_BEGIN();
-
-       appdata_s* ad = (appdata_s*)data;
-       retv_if(ad == NULL, ECORE_CALLBACK_CANCEL);
-
-       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_3(ad);
-       elm_object_part_content_set(ad->internal_storage_page_data->internal_storage_page_base_layout, "elm.swallow.content", page_content);
-
-       ad->check_timer = NULL;
-       FUNC_END();
-       return ECORE_CALLBACK_CANCEL;
-}
-
 static Evas_Object* create_page_2(appdata_s* ad)
 {
        FUNC_BEGIN();
@@ -505,10 +543,6 @@ static Evas_Object* create_page_2(appdata_s* ad)
 
        elm_genlist_item_class_free(extended_multiline_genlist_itc);
 
-       //demo implementation to emulate format process, please remove once formatting implementation in place
-       // prprprprprpr TODO
-       ECORE_TIMER_DEL(ad->check_timer);
-       ad->check_timer = ecore_timer_add(5, _check_timer_cb, ad);
 
 out:
        FUNC_END();
index edda2e8..c9107c9 100644 (file)
 /* Maximum number of thread */
 #define THREAD_MAX 5
 
+#define SPEEDCHECK 16
+
 #define PKGDIR_BUS_NAME                "org.tizen.pkgdir_tool"
 #define PKGDIR_PATH            "/org/tizen/pkgdir_tool"
 #define PKGDIR_INTERFACE       "org.tizen.pkgdir_tool"
@@ -3265,6 +3267,78 @@ out:
        return reply;
 }
 
+static DBusMessage *request_check_speed(dbus_method_reply_handle_h reply_handle,
+               DBusMessage *msg)
+{
+       struct timespec start_time, end_time;
+       DBusMessageIter iter;
+       DBusMessage *reply;
+       struct block_device *bdev;
+       struct block_data *data;
+       char *buf;
+       int ret = 0;
+       int id;
+       int fd;
+
+       if (!reply_handle || !msg)
+               return NULL;
+
+       ret = dbus_message_get_args(msg, NULL,
+                       DBUS_TYPE_INT32, &id,
+                       DBUS_TYPE_INVALID);
+       if (!ret) {
+               ret = -1;
+               goto out;
+       }
+
+       bdev = find_block_device_by_id(id);
+       if (!bdev) {
+               ret = -1;
+               goto out;
+       }
+       data = bdev->data;
+       if (!data) {
+               ret = -1;
+               goto out;
+       }
+
+       _D("speed check: %s", data->devnode);
+       fd = open(data->devnode, O_RDWR | O_SYNC);
+       buf = calloc(1, SPEEDCHECK * 1024 * 1024);
+       if (!buf) {
+               _E("calloc() failed");
+               close(fd);
+               ret = -1;
+               goto out;
+       }
+       clock_gettime(CLOCK_REALTIME, &start_time);
+       _I("start time: %lu.%lu", start_time.tv_sec, start_time.tv_nsec);
+       ret = write(fd, buf, SPEEDCHECK * 1024 * 1024);
+       clock_gettime(CLOCK_REALTIME, &end_time);
+       _I("end time %lu.%lu", end_time.tv_sec, end_time.tv_nsec);
+
+       free(buf);
+
+       if (SPEEDCHECK / (end_time.tv_sec - start_time.tv_sec) < 4) {
+               ret = -1;
+               close(fd);
+               goto out;
+       }
+
+       if (ret < 0) {
+               _E("write() failed %d", errno);
+               close(fd);
+               goto out;
+       }
+
+       close(fd);
+out:
+       reply = dbus_message_new_method_return(msg);
+       dbus_message_iter_init_append(reply, &iter);
+       dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &ret);
+       return reply;
+}
+
 /*
   Method name      Method call format string  Reply format string
 { "ShowDeviceList",                      NULL,               NULL, request_show_device_list },
@@ -3291,6 +3365,7 @@ static const dbus_method_s manager_methods[] = {
        { "GetMmcPrimary" ,         NULL, request_get_mmc_primary },
        { "PrivateMount",           "is", request_private_mount_block },
        { "PrivateUnmount",         "ii", request_private_unmount_block },
+       { "CheckSpeed",              "i", request_check_speed },
 };
 
 static dbus_interface_s block_interface = {