Change to use storage UUID from filesystem 50/55450/3 accepted/tizen/mobile/20151224.064227 accepted/tizen/tv/20151224.064246 accepted/tizen/wearable/20151224.064301 submit/tizen/20151224.030204 submit/tizen_common/20151229.144031 submit/tizen_common/20151229.154718
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Dec 2015 00:48:33 +0000 (09:48 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Dec 2015 02:55:37 +0000 (11:55 +0900)
Change-Id: I5d89619f426b2d98e87c1ef47b54db5a082d3280
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/media-server.spec
src/common/include/media-common-system.h
src/common/media-common-system.c
src/server/include/media-server-device-block.h
src/server/media-server-device-block.c
src/server/media-server-main.c

index d0e23ba..4f4791d 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    File manager service server.
-Version:    0.2.64
+Version:    0.2.65
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index ca0e274..c7d657c 100755 (executable)
@@ -40,6 +40,7 @@ typedef struct ms_block_info_s{
        char *mount_path;
        int state;
        int block_type;
+       char *mount_uuid;
 } ms_block_info_s;
 
 typedef void (*block_changed_cb)(ms_block_info_s *block_info, void *user_data);
index 6510a5f..4961c02 100755 (executable)
@@ -78,6 +78,7 @@ static void __ms_block_changed(GDBusConnection* connection,
 {
        const char *devnode = NULL;
        const char *mount_path = NULL;
+       const char *mount_uuid = NULL;
        GVariant *tmp;
        gsize size = 0;
        block_cb_data *cb_data = (block_cb_data *)user_data;
@@ -99,6 +100,13 @@ static void __ms_block_changed(GDBusConnection* connection,
        devnode = g_variant_get_string(tmp, &size);
        MS_DBG_ERR("devnode : %s", devnode);
 
+       tmp = g_variant_get_child_value(parameters, 6);
+       mount_uuid = g_variant_get_string(tmp, &size);
+       if (mount_uuid != NULL) {
+               block_info->mount_uuid = strdup(mount_uuid);
+               MS_DBG_ERR("mount_uuid : %s", block_info->mount_uuid);
+       }
+
        tmp = g_variant_get_child_value(parameters, 8);
        mount_path = g_variant_get_string(tmp, &size);
        if (mount_path != NULL) {
@@ -112,6 +120,7 @@ static void __ms_block_changed(GDBusConnection* connection,
 
        ((block_changed_cb)usr_cb)(block_info, usr_data);
        MS_SAFE_FREE(block_info->mount_path);
+       MS_SAFE_FREE(block_info->mount_uuid);
        MS_SAFE_FREE(block_info);
 
        MS_DBG_ERR("user callback done");
@@ -275,6 +284,7 @@ static int __ms_gdbus_method_sync(const char *dest, const char *path, const char
                data->block_type = val_int[0];
                data->mount_path = strdup(val_str[6]);
                data->state = val_int[2];
+               data->mount_uuid = strdup(val_str[5]);
 
                if (*dev_list == NULL) {
                        MS_DBG_ERR("DEV LIST IS NULL");
@@ -343,6 +353,7 @@ int ms_sys_release_device_list(GArray **dev_list)
                        g_array_remove_index(*dev_list, 0);
                        MS_DBG("MOUNT PATH [%s] RELEASED", data->mount_path);
                        MS_SAFE_FREE(data->mount_path);
+                       MS_SAFE_FREE(data->mount_uuid);
                        MS_SAFE_FREE(data);
                }
                g_array_free(*dev_list, FALSE);
index 2df9203..446c62e 100755 (executable)
@@ -25,8 +25,8 @@
 
 int ms_mmc_insert_handler(const char *mount_path);
 int ms_mmc_remove_handler(const char *mount_path);
-int ms_usb_insert_handler(const char *mount_path);
-int ms_usb_remove_handler(const char *mount_path);
+int ms_usb_insert_handler(const char *mount_path, const char *mount_uuid);
+int ms_usb_remove_handler(const char *mount_path, const char *mount_uuid);
 void ms_device_block_changed_cb(ms_block_info_s *block_info, void *user_data);
 
 #endif
\ No newline at end of file
index daae85f..0ea134d 100755 (executable)
@@ -28,6 +28,7 @@
 #include "media-server-socket.h"
 #include "media-server-device-block.h"
 
+#if 0
 static int __ms_get_added_stroage_path(void **handle, const char *add_path, char **device_id)
 {
        int ret = MS_MEDIA_ERR_NONE;
@@ -53,11 +54,11 @@ static int __ms_get_added_stroage_path(void **handle, const char *add_path, char
 
        return ret;
 }
+#endif
 
-int ms_usb_insert_handler(const char *mount_path)
+int ms_usb_insert_handler(const char *mount_path, const char *mount_uuid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       char *storage_id = NULL;
        char *storage_path = NULL;
        void **handle = NULL;
        int validity = 0;
@@ -73,46 +74,35 @@ int ms_usb_insert_handler(const char *mount_path)
        ms_sys_get_uid(&uid);
        ms_connect_db(&handle, uid);
 
-       if (mount_path != NULL) {
-               MS_DBG_ERR("added path [%s]", mount_path);
-
-               __ms_get_added_stroage_path(handle, mount_path, &storage_id);
-
-               if (storage_id != NULL) {
-                       /* update storage information into media DB */
-                       ret = ms_check_storage(handle, storage_id, NULL, &storage_path, &validity);
-                       if (ret == 0) {
-                               if (validity == 1) {
-                                       MS_DBG_ERR("This storage is already updated. So ignore this event.");
-                                       ret = MS_MEDIA_ERR_NONE;
-                                       goto ERROR;
-                               }
-
-                               if (strcmp(mount_path, storage_path)) {
-                                       /* update storage path */
-                                       ret = ms_update_storage(handle, storage_id, mount_path, uid);
-                               }
-                               scan_type = MS_SCAN_PART;
-                               ms_set_storage_validity(handle, storage_id, 1, uid);
-                               if (ms_set_storage_scan_status(handle, storage_id, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) {
-                                       MS_DBG_ERR("ms_set_storage_scan_status failed");
-                               }
-                       } else {
-                               /* there is no information of this storage in Media DB */
-                               ret = ms_insert_storage(handle, storage_id, NULL, mount_path, uid);
+       if (mount_path != NULL && mount_uuid != NULL) {
+               /* update storage information into media DB */
+               ret = ms_check_storage(handle, mount_uuid, NULL, &storage_path, &validity);
+               if (ret == 0) {
+                       if (validity == 1) {
+                               MS_DBG_ERR("This storage is already updated. So ignore this event.");
+                               ret = MS_MEDIA_ERR_NONE;
+                               goto ERROR;
+                       }
+
+                       if (strcmp(mount_path, storage_path)) {
+                               /* update storage path */
+                               ret = ms_update_storage(handle, mount_uuid, mount_path, uid);
+                       }
+                       scan_type = MS_SCAN_PART;
+                       ms_set_storage_validity(handle, mount_uuid, 1, uid);
+                       if (ms_set_storage_scan_status(handle, mount_uuid, MEDIA_SCAN_PREPARE, uid) != MS_MEDIA_ERR_NONE) {
+                               MS_DBG_ERR("ms_set_storage_scan_status failed");
                        }
                } else {
-                       MS_DBG_ERR("STORAGE ID IS NUILL");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto ERROR;
+                       /* there is no information of this storage in Media DB */
+                       ret = ms_insert_storage(handle, mount_uuid, NULL, mount_path, uid);
                }
 
                /* request to update media db */
-               ms_send_storage_otg_scan_request(mount_path, storage_id, scan_type, uid);
+               ms_send_storage_otg_scan_request(mount_path, mount_uuid, scan_type, uid);
        }
 
 ERROR:
-       MS_SAFE_FREE(storage_id);
        MS_SAFE_FREE(storage_path);
 
        ms_disconnect_db(&handle);
@@ -122,14 +112,13 @@ ERROR:
        return ret;
 }
 
-int ms_usb_remove_handler(const char *mount_path)
+int ms_usb_remove_handler(const char *mount_path, const char *mount_uuid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        void **handle = NULL;
-       char device_id[MS_UUID_SIZE] = {0,};
        uid_t uid;
 
-       if (mount_path != NULL) {
+       if (mount_path != NULL && mount_uuid != NULL) {
                ret = ms_load_functions();
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_load_functions failed [%d]", ret);
@@ -137,23 +126,9 @@ int ms_usb_remove_handler(const char *mount_path)
                }
 
                ms_sys_get_uid(&uid);
-
                ms_connect_db(&handle, uid);
-
-               while (1) {
-                       memset(device_id, 0x0, sizeof(device_id));
-                       ms_get_storage_id(handle, mount_path, device_id);
-
-                       MS_DBG_ERR("removed path [%s %s]", mount_path, device_id);
-
-                       if (strlen(device_id) == (MS_UUID_SIZE-1)) {
-                               ms_set_storage_validity(handle, device_id, 0, uid);
-                               ms_send_storage_otg_scan_request(mount_path, device_id, MS_SCAN_INVALID, uid);
-                       } else {
-                               MS_DBG_ERR("Device ID is INVALID");
-                               break;
-                       }
-               }
+               ms_set_storage_validity(handle, mount_uuid, 0, uid);
+               ms_send_storage_otg_scan_request(mount_path, mount_uuid, MS_SCAN_INVALID, uid);
 
                ms_disconnect_db(&handle);
 
@@ -349,13 +324,24 @@ void _ms_mmc_changed_event(const char *mount_path, ms_stg_status_e mount_status)
        return;
 }
 
-void _ms_usb_changed_event(const char *mount_path, ms_stg_status_e mount_status)
+void _ms_usb_changed_event(const char *mount_path, const char *mount_uuid, ms_stg_status_e mount_status)
 {
        if (mount_status == MS_STG_INSERTED) {
-               ms_usb_insert_handler(mount_path);
+               if (mount_path != NULL && mount_uuid != NULL) {
+                       MS_DBG("usb_mount_path[%s], usb_mount_uuid[%s]", mount_path, mount_uuid);
+                       ms_usb_insert_handler(mount_path, mount_uuid);
+               } else {
+                       MS_DBG_ERR("usb_mount_path[%s] or usb_mount_uuid[%s] is NULL", mount_path, mount_uuid);
+                       return;
+               }
        } else if (mount_status == MS_STG_REMOVED) {
-               /*remove added watch descriptors */
-               ms_usb_remove_handler(mount_path);
+               if (mount_path != NULL && mount_uuid != NULL) {
+                       MS_DBG("usb_mount_path[%s], usb_mount_uuid[%s]", mount_path, mount_uuid);
+                       ms_usb_remove_handler(mount_path, mount_uuid);
+               } else {
+                       MS_DBG_ERR("usb_mount_path[%s] or usb_mount_uuid[%s] is NULL", mount_path, mount_uuid);
+                       return;
+               }
        }
 
        return;
@@ -365,7 +351,7 @@ void ms_device_block_changed_cb(ms_block_info_s *block_info, void *user_data)
 {
        if (block_info->block_type == 0) {
                MS_DBG_ERR("GET THE USB EVENT");
-               _ms_usb_changed_event(block_info->mount_path, block_info->state);
+               _ms_usb_changed_event(block_info->mount_path, block_info->mount_uuid, block_info->state);
        } else {
                MS_DBG_ERR("GET THE MMC EVENT");
                _ms_mmc_changed_event(block_info->mount_path, block_info->state);
index 3c7e3e1..0657512 100755 (executable)
@@ -415,7 +415,7 @@ static int __ms_check_usb_status(void)
 
                        for (i = 0; i < dev_num; i++) {
                                block_info = (ms_block_info_s *)g_array_index(dev_list , ms_stg_type_e*, i);
-                               ms_usb_insert_handler(block_info->mount_path);
+                               ms_usb_insert_handler(block_info->mount_path, block_info->mount_uuid);
                        }
 
                        ms_sys_release_device_list(&dev_list);