Sync with Tizen 2.4 51/51851/1 accepted/tizen/mobile/20151117.050001 accepted/tizen/tv/20151117.050030 accepted/tizen/wearable/20151117.050104 submit/tizen/20151116.132342
authorHyihong Chae <hh.chae@samsung.com>
Mon, 16 Nov 2015 13:06:19 +0000 (22:06 +0900)
committerHyihong Chae <hh.chae@samsung.com>
Mon, 16 Nov 2015 13:06:19 +0000 (22:06 +0900)
Change-Id: I279680394a83ef83a8c2d570f475180492c63271
Signed-off-by: HyiHong Chae <hh.chae@samsung.com>
packaging/mtp-initiator.manifest
packaging/mtp-initiator.spec
src/daemon/include/mtp_daemon.h
src/daemon/include/mtp_daemon_db.h
src/daemon/mtp_daemon_db.c
src/daemon/mtp_daemon_event.c
src/daemon/mtp_daemon_gdbus_manager.c

index 5b19ac755a634e41153d36fea71aacdbb188f824..8df437fc54547f8c6718ac92b526b55f7db7a541 100755 (executable)
@@ -1,5 +1,16 @@
 <manifest>
+       <define>
+               <domain name ="mtp-initiator"/>
+               <request>
+                       <smack request="device::app_logging" type="rw"/>
+                       <smack request="device::sys_logging" type="w"/>
+                       <smack request="_" type="rw"/>
+               </request>
+       </define>
+       <assign>
+               <filesystem path="/usr/bin/mtp-initiator" exec_label="mtp-initiator"/>
+       </assign>
        <request>
-               <domain name ="_" />
+               <domain name ="mtp-initiator"/>
        </request>
 </manifest>
index c00d7bcd49bdb9a34e7ad83db50592a887dfdebf..b13b12b1e535a63cf0f0fcb0a736ae1041958a4d 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       mtp-initiator
 Summary:    mtp(media transfer protocol) initiator
-Version:    1.2.1
+Version:    1.2.6
 Release:    1
 Group:      Network & Connectivity/Other
 License:    Apache-2.0
@@ -8,8 +8,8 @@ Source0:    %{name}-%{version}.tar.gz
 Source1:    %{name}.manifest
 
 # This package would be built only TV
-%if "%{?tizen_profile_name}" != "tv"
-ExcludeArch: %{arm} %ix86 x86_64
+%if "%{?profile}" != "tv"
+ExcludeArch: %arm aarch64 %ix86 x86_64
 %endif
 
 BuildRequires:  cmake
@@ -32,6 +32,7 @@ A mtp-initiator
 cp %{SOURCE1} .
 
 %build
+CFLAGS+=" -DTIZEN_EXT"
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 %cmake . -DMAJORVER=${MAJORVER} -DFULLVER=%{version} %{?ARM_DEF}
 
index 7dfbbfb245a82177c79efc681b37946f6600d82e..92a1215a6641df5d64b519ece0eec297c21d2525 100755 (executable)
@@ -104,6 +104,7 @@ typedef enum {
        MTP_INITIATOR_EVENT_OBJECT_REMOVED,
        MTP_INITIATOR_EVENT_DEVICE_ADDED,
        MTP_INITIATOR_EVENT_DEVICE_REMOVED,
+       MTP_INITIATOR_EVENT_DAEMON_TERMINATED
 } mtp_event;
 
 /* struct */
index 44eea3469795f934adb5cdf56c3f6e1b3f5a2b9b..38ae810e63147aefab1c7b6f6171e2b06d3ead6e 100755 (executable)
@@ -30,5 +30,8 @@ mtp_error_e mtp_daemon_db_update(int device_handle, int object_handle,
        MTPObjectInfo* object_info, mtp_context *mtp_ctx);
 MTPObjectInfo* mtp_daemon_db_get_object_info(int device_handle,
        int object_handle, mtp_context *mtp_ctx); //
+mtp_error_e mtp_daemon_db_begin(mtp_context *mtp_ctx);
+mtp_error_e mtp_daemon_db_commit(mtp_context *mtp_ctx);
+
 
 #endif
index b0b986109bdec9c5e91934b4e845c90980705cc3..77c328a9e5c8a04eed0bbf8f65ffaf18c50cb992 100755 (executable)
@@ -168,8 +168,8 @@ MTPObjectInfo* mtp_daemon_db_get_object_info(int device_handle,
                object_info->ModificationDate = sqlite3_column_int(stmt, 20);
                object_info->Keywords = g_strdup(sqlite3_column_text(stmt, 21));
 
-               MTP_LOGE("object_info->Filename : %s, %ld, object_info->ModificationDate : %ld",
-                       object_info->Filename, (long)object_info->CaptureDate, (long)object_info->ModificationDate);
+               /*MTP_LOGI("object_info->Filename : %s, %ld, object_info->ModificationDate : %ld",
+                       object_info->Filename, (long)object_info->CaptureDate, (long)object_info->ModificationDate);*/
 
                sqlite3_finalize(stmt);
                sqlite3_free(sql);
@@ -212,8 +212,8 @@ bool mtp_daemon_db_is_exist(int device_handle, int object_handle, mtp_context *m
 
                count = sqlite3_column_int(stmt, 0);
 
-               MTP_LOGE("device : %d, object_id : %d, count is [%d]", device_handle,
-                       object_handle, count);
+               /*MTP_LOGI("device : %d, object_id : %d, count is [%d]", device_handle,
+                       object_handle, count);*/
 
                sqlite3_finalize(stmt);
                sqlite3_free(sql);
@@ -224,6 +224,42 @@ bool mtp_daemon_db_is_exist(int device_handle, int object_handle, mtp_context *m
        return (count > 0) ? true : false;
 }
 
+mtp_error_e mtp_daemon_db_begin(mtp_context *mtp_ctx)
+{
+       int sql_ret;
+
+       if (mtp_ctx->db == NULL) {
+               MTP_LOGE("mtp_ctx->db is NULL");
+               return MTP_ERROR_DB;
+       }
+
+       sql_ret = sqlite3_exec(mtp_ctx->db, "BEGIN;", NULL, NULL, NULL);
+       if (sql_ret != SQLITE_OK) {
+               MTP_LOGE("sqlite3_exec BEGIN failed");
+               return MTP_ERROR_DB;
+       }
+
+       return MTP_ERROR_NONE;
+}
+
+mtp_error_e mtp_daemon_db_commit(mtp_context *mtp_ctx)
+{
+       int sql_ret;
+
+       if (mtp_ctx->db == NULL) {
+               MTP_LOGE("mtp_ctx->db is NULL");
+               return MTP_ERROR_DB;
+       }
+
+       sql_ret = sqlite3_exec(mtp_ctx->db, "COMMIT;", NULL, NULL, NULL);
+       if (sql_ret != SQLITE_OK) {
+               MTP_LOGE("sqlite3_exec COMMIT failed");
+               return MTP_ERROR_DB;
+       }
+
+       return MTP_ERROR_NONE;
+}
+
 /* db insert is called where get_object_handles function. */
 /* every ptp protocol "get object info" call, called this function. */
 mtp_error_e mtp_daemon_db_insert(int device_handle, int storage_id,
@@ -323,19 +359,6 @@ mtp_error_e mtp_daemon_db_init(mtp_context *mtp_ctx)
                        return MTP_ERROR_DB;
                }
 
-               sql_ret = sqlite3_exec(mtp_ctx->db, "PRAGMA journal_mode = PERSIST",
-                       NULL, NULL, &error);
-               if (sql_ret != SQLITE_OK) {
-                       MTP_LOGE("sqlite3_exec failed, [%d] : %s", sql_ret, error);
-                       if (mtp_ctx->db != NULL) {
-                                       sql_ret = sqlite3_close(mtp_ctx->db);
-                                       if (sql_ret == SQLITE_OK)
-                                               mtp_ctx->db = NULL;
-                       }
-                       sqlite3_free(error);
-                       return MTP_ERROR_DB;
-               }
-
                ret = __create_table(mtp_ctx);
        }
 
index 95c36b6bcc6461964c0c3dea415fff071663bf62..7639890ccec0c6413df33701ab0cc6908a04ecbd 100755 (executable)
@@ -324,8 +324,10 @@ static void* __event_thread(gpointer dev, gpointer data)
        /* TODO : deactivate signal to clients using g_idle_add */
        __print_device_list(mtp_ctx);
 
-       if (mtp_ctx->device_list->device_num == 0)
+       if (mtp_ctx->device_list->device_num == 0) {
+               mtp_daemon_gdbus_emit_event(MTP_INITIATOR_EVENT_DAEMON_TERMINATED, device, mtp_ctx);
                g_main_loop_quit(mtp_ctx->main_loop);
+       }
 
        return NULL;
 }
@@ -361,14 +363,6 @@ mtp_error_e __device_list_init(mtp_context *mtp_ctx)
                        continue;
                }
 
-               /* get all storages for this device */
-               ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED);
-               if (ret != 0) {
-                       MTP_LOGE("get storage is failed!!!");
-                       LIBMTP_Release_Device(device);
-                       continue;
-               }
-
                device_info->device = device;
                device_info->bus_location = rawdevices[i].bus_location;
                device_info->model_name = LIBMTP_Get_Modelname(device);
index 22833488c143cc936d5cdd9c3af2d3d35eb18940..c0d4a23d1f2381e1f8037d909616c28f84ac7316 100755 (executable)
@@ -200,7 +200,7 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
        g_assert(param->invocation != NULL);
        g_assert(param->mtp_ctx != NULL);
 
-       MTP_LOGI("%s", __func__);
+       /*MTP_LOGI("%s", __func__);*/
 
        /* parameter unpacking */
 
@@ -209,9 +209,9 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
        format = param->param3;
        parent_object_handle = param->param4;
 
-       MTP_LOGE("storage id : %d", param->param2);
-       MTP_LOGE("format : %d", param->param3);
-       MTP_LOGE("parent : %d", param->param4);
+       MTP_LOGI("storage id : %d", param->param2);
+       MTP_LOGI("format : %d", param->param3);
+       MTP_LOGI("parent : %d", param->param4);
 
        ret = LIBMTP_Get_Object_Handles(device, storage_id, format, parent_object_handle,
                &object_list, &temp);
@@ -219,31 +219,41 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
        if (ret < 0)
                MTP_LOGE("LIBMTP_Get_Object_Handles is failed : %d", ret);
 
-       MTP_LOGE("Total Object number : %d", temp);
+       /*MTP_LOGI("Total Object number : %d", temp);*/
 
        /* loop over storages */
        g_variant_builder_init(&b, G_VARIANT_TYPE("aa{sv}"));
 
+       mtp_daemon_db_begin(param->mtp_ctx);
+
        for (i = 0; i < temp; i++) {
                MTPObjectInfo *object_info = NULL;
+               object_info = LIBMTP_Get_Object_Info(device, object_list[i]);
 
-               if (mtp_daemon_db_is_exist((int)device, object_list[i], param->mtp_ctx) == false) {
-                       MTP_LOGE("Objectinfo is not stored. %d, %d", device, object_list[i]);
+               if (object_info != NULL)
+                       mtp_daemon_db_insert(device, storage_id, object_list[i], object_info, param->mtp_ctx);
+
+               /*if (mtp_daemon_db_is_exist((int)device, object_list[i], param->mtp_ctx) == false) {
+                       MTP_LOGI("Objectinfo is not stored. %d, %d", device, object_list[i]);
                        object_info = LIBMTP_Get_Object_Info(device, object_list[i]);
 
                        if (object_info != NULL)
                                mtp_daemon_db_insert(device, storage_id, object_list[i], object_info, param->mtp_ctx);
                } else {
-                       MTP_LOGE("Objectinfo is stored. ");
+                       MTP_LOGI("Objectinfo is stored. ");
                        object_info = mtp_daemon_db_get_object_info(device, object_list[i], param->mtp_ctx);
-               }
+               }*/
 
                if (object_info != NULL) {
-                       MTP_LOGE("object id : %d, format : %d, filename : %s", object_list[i],
-                                                       object_info->ObjectFormat, object_info->Filename);
-
-                       if (format == LIBMTP_FILETYPE_ALL || format == object_info->ObjectFormat ||
-                               (format == LIBMTP_FILETYPE_ALL_IMAGE && LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat))) {
+                       /*MTP_LOGI("object id : %d, format : %d, filename : %s", object_list[i],
+                                                       object_info->ObjectFormat, object_info->Filename);*/
+
+                       if ((format == LIBMTP_FILETYPE_ALL &&
+                                       (object_info->ObjectFormat == LIBMTP_FILETYPE_FOLDER ||
+                                       LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat))) ||
+                               (format == LIBMTP_FILETYPE_ALL_IMAGE &&
+                                       LIBMTP_FILETYPE_IS_IMAGE(object_info->ObjectFormat)) ||
+                               (format == object_info->ObjectFormat)) {
                                g_variant_builder_open(&b, G_VARIANT_TYPE("a{sv}"));
 
                                g_variant_builder_add(&b, "{sv}", "object_handle",
@@ -257,9 +267,11 @@ static void __manager_get_object_handles_thread_func(gpointer user_data)
                g_free(object_info);
        }
 
+       mtp_daemon_db_commit(param->mtp_ctx);
+
        gv = g_variant_builder_end(&b);
 
-       MTP_LOGE("Real object_num : %d", object_num);
+       /*MTP_LOGE("Real object_num : %d", object_num);*/
 
        mtp_gdbuslib_manager_complete_get_object_handles(param->object,
                param->invocation, object_num, gv, result);
@@ -290,7 +302,7 @@ static void __manager_get_object_thread_func(gpointer user_data)
        g_assert(param->invocation != NULL);
        g_assert(param->mtp_ctx != NULL);
 
-       MTP_LOGI("%s", __func__);
+       /*MTP_LOGI("%s", __func__);*/
 
        /* parameter unpacking */
        device = (LIBMTP_mtpdevice_t *)(param->param1);
@@ -301,12 +313,15 @@ static void __manager_get_object_thread_func(gpointer user_data)
        fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
 
        if (fd < 0) {
+               MTP_LOGE("%s file open fail - fd : %d, dest_path : %s", __func__, fd, dest_path);
                result = MTP_ERROR_GENERAL;
        } else {
                ret = LIBMTP_Get_File_To_File_Descriptor(device, object_handle, fd, NULL, NULL);
 
-               if (ret != 0)
+               if (ret != 0) {
+                       MTP_LOGE("get descriptor fail - ret : %d", ret);
                        result = MTP_ERROR_PLUGIN;
+               }
 
                close(fd);
        }
@@ -342,19 +357,20 @@ static void __manager_get_thumbnail_thread_func(gpointer user_data)
        g_assert(param->invocation != NULL);
        g_assert(param->mtp_ctx != NULL);
 
-       MTP_LOGI("%s", __func__);
+       /*MTP_LOGI("%s", __func__);*/
 
        /* parameter unpacking */
        device = (LIBMTP_mtpdevice_t *)(param->param1);
        object_handle = param->param2;
        dest_path = param->char_param1;
 
-       MTP_LOGE("dest_path : %s", dest_path);
+       /*MTP_LOGI("dest_path : %s", dest_path);*/
 
        /* file open */
        fd = open(dest_path, O_WRONLY | O_CREAT | O_EXCL, 0644);
 
        if (fd < 0) {
+               MTP_LOGE("%s file open fail - fd : %d, dest_path : %s", __func__, fd, dest_path);
                result = MTP_ERROR_GENERAL;
        } else {
                ret = LIBMTP_Get_Thumbnail(device, object_handle, &thumb_data, &thumb_size);
@@ -364,6 +380,7 @@ static void __manager_get_thumbnail_thread_func(gpointer user_data)
                        if (ret == 0)
                                result = MTP_ERROR_ALLOC_FAIL;
                } else {
+                       MTP_LOGE("get thumbnail fail - ret : %d", ret);
                        result = MTP_ERROR_PLUGIN;
                }
 
@@ -572,8 +589,8 @@ gboolean manager_get_object_handles(
        mtp_param *param = NULL;
        gint result = MTP_ERROR_NONE;
 
-       MTP_LOGE(">>> REQUEST from [%s]",
-               g_dbus_method_invocation_get_sender(invocation));
+       /*MTP_LOGI(">>> REQUEST from [%s]",
+               g_dbus_method_invocation_get_sender(invocation));*/
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
@@ -626,8 +643,8 @@ gboolean manager_get_object(
        mtp_param *param = NULL;
        gint result = MTP_ERROR_NONE;
 
-       MTP_LOGE(">>> REQUEST from [%s]",
-               g_dbus_method_invocation_get_sender(invocation));
+       /*MTP_LOGI(">>> REQUEST from [%s]",
+               g_dbus_method_invocation_get_sender(invocation));*/
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {
@@ -678,8 +695,8 @@ gboolean manager_get_thumbnail(
        mtp_param *param = NULL;
        gint result = MTP_ERROR_NONE;
 
-       MTP_LOGE(">>> REQUEST from [%s]",
-               g_dbus_method_invocation_get_sender(invocation));
+       /*MTP_LOGI(">>> REQUEST from [%s]",
+               g_dbus_method_invocation_get_sender(invocation));*/
 
        param = g_try_new0(mtp_param, 1);
        if (param == NULL) {