Add on-demand storage insertion and removal for product TV 15/306815/15
authorJiyong <jiyong.min@samsung.com>
Wed, 28 Feb 2024 01:58:46 +0000 (10:58 +0900)
committerJiyong <jiyong.min@samsung.com>
Sun, 10 Mar 2024 23:35:45 +0000 (08:35 +0900)
Change-Id: I71d5144dd023254e22771e8811bf955e9eea332c

packaging/media-server.spec
src/server/include/media-server-device-block.h
src/server/include/media-server-on-demand.h
src/server/media-server-device-block.c
src/server/media-server-main.c
src/server/media-server-on-demand.c

index 1adf48941a8b7a3cbc8e521568a9c5cedc17f806..9d68074c58ca8b1469e1ca3a59b2feab54b14857 100644 (file)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.5.4
+Version:    0.5.5
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index c3a346593fcd4e7a9bd2e44bd8a0ae902d154000..b33b01f3c262b61c3dc830d744aea4e2e76674bd 100644 (file)
@@ -26,6 +26,8 @@ void ms_storage_remove_handler(const char *mount_path, const char *mount_uuid);
 #ifdef _USE_TVPD_MODE
 void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *user_data);
 int ms_check_mounted_storage(uid_t uid);
+void ms_device_handle_usb_added(const char *mount_path);
+void ms_device_handle_usb_removed(const char *mount_path);
 #else
 void ms_device_block_changed_cb(ms_block_info_s *block_info, void *user_data);
 #endif
index 482d085658989534a67ad4d735fd908befa4133a..0b99372a20e4d551b13a28f81aa9652957399a8b 100644 (file)
@@ -37,5 +37,8 @@ void ms_on_demand_finalize(void);
 void ms_on_demand_insert_storage(gpointer data, gpointer user_data);
 void ms_on_demand_remove_storage(gpointer data, gpointer user_data);
 void ms_on_demand_update_storage_list(GSList *storage_list);
+#ifdef _USE_TVPD_MODE
+void ms_on_demand_reset_storage(void);
+#endif
 
 #endif /* _MEDIA_SERVER_ON_DEMAND_H_ */
index d333f8220b8acffb862cecc7fa4bdb64822996f5..9f1394a8c6d224f0121bdd539528c331c4f9ea4c 100644 (file)
@@ -132,7 +132,7 @@ void ms_storage_remove_handler(const char *mount_path, const char *mount_uuid)
 }
 
 #ifdef _USE_TVPD_MODE
-static void __ms_usb_add_event(const char *mount_path)
+void ms_device_handle_usb_added(const char *mount_path)
 {
        int ret = MS_MEDIA_ERR_NONE;
        char *storage_id = NULL;
@@ -197,7 +197,7 @@ ERROR:
        ms_disconnect_db(handle);
 }
 
-static void __ms_usb_remove_event(const char *mount_path)
+void ms_device_handle_usb_removed(const char *mount_path)
 {
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
@@ -261,16 +261,29 @@ void ms_device_block_changed_cb(usb_device_h usb_device, char *action, void *use
 
        mount_path = usb_device_get_mountpath(usb_device);
 
+       ms_check_mediadb(uid, &is_reset);
+
+#ifdef _USE_ON_DEMAND
+       ms_block_info_s block_info = { mount_path, 0, NULL };
+
        if (!strcmp(action, "mounted")) {
                MS_DBG_SWARN("USB MOUNTED, mountpath : %s", mount_path);
-               ms_check_mediadb(uid, &is_reset);
-               __ms_usb_add_event(mount_path);
+               ms_on_demand_insert_storage((gpointer)&block_info, NULL);
        } else if (!strcmp(action, "blocked")) { /*unmount->blocked stop accessing usb in time*/
                MS_DBG_SWARN("USB blocked, mountpath : %s", mount_path);
-               ms_check_mediadb(uid, &is_reset);
                if (!is_reset)
-                       __ms_usb_remove_event(mount_path);
+                       ms_on_demand_remove_storage((gpointer)&block_info, NULL);
        }
+#else
+       if (!strcmp(action, "mounted")) {
+               MS_DBG_SWARN("USB MOUNTED, mountpath : %s", mount_path);
+               ms_device_handle_usb_added(mount_path);
+       } else if (!strcmp(action, "blocked")) { /*unmount->blocked stop accessing usb in time*/
+               MS_DBG_SWARN("USB blocked, mountpath : %s", mount_path);
+               if (!is_reset)
+                       ms_device_handle_usb_removed(mount_path);
+       }
+#endif
 
        free_usb_device_h(usb_device);
 
index eca6ebb8fcc204a3d1433b56f535c7a32eac2854..3ba1c50e469b335d6b86bf1139faec1df373972a 100644 (file)
@@ -55,8 +55,7 @@ extern GMutex scanner_mutex;
 GMainLoop *mainloop = NULL;
 bool power_off; /*If this is true, poweroff notification received*/
 
-
-static void __ms_check_mediadb(void);
+static void __ms_update_mediadb(bool need_checkdb);
 static void __ms_update_storage_status(void);
 static void __ms_add_signal_handler(void);
 static void __ms_add_event_receiver(void);
@@ -64,6 +63,8 @@ static void __ms_add_event_receiver(void);
 static bool __ms_is_external_supported(void);
 
 #ifdef _USE_TVPD_MODE
+static void __ms_check_mediadb(void);
+
 static bool __ms_deal_reset_status(void)
 {
        int value = 0;
@@ -121,7 +122,7 @@ static void __ms_smarthub_vconf_cb(void *data)
                        ms_config_set_int(MS_DB_RESET, 1);
                        ms_reset_ownerlist();
                        ms_reset_mediadb(uid);
-                       __ms_check_mediadb();
+                       __ms_update_mediadb(true);
                        ms_config_set_int(MS_DB_RESET, 0);
                        MS_DBG_ERR("END SMART HUB RESET");
                        smarthub_reset = false;
@@ -183,6 +184,9 @@ int main(int argc, char **argv)
 #endif
 #ifdef _USE_ON_DEMAND
        ms_start_type_e start_type = ms_on_demand_get_start_type();
+#ifdef _USE_TVPD_MODE
+       bool need_checkdb = false;
+#endif
 #endif
 
        resource_pid_t stResource = {};
@@ -221,11 +225,19 @@ int main(int argc, char **argv)
        if (db_size > MEDIA_DB_SIZE_LIMIT_2) {
                MS_DBG_ERR("THE SIZE OF MEDIA DB REACH THE LIMIT. RESET MEDIA DB.");
                ms_reset_mediadb(uid);
+#ifdef _USE_ON_DEMAND
+               need_checkdb = true;
+               ms_on_demand_reset_storage();
+#endif
        }
 
        if (ms_check_corrupt_mediadb() != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("MEDIA DB IS CORRUPTED. RESET MEDIA DB.");
                ms_reset_mediadb(uid);
+#ifdef _USE_ON_DEMAND
+               need_checkdb = true;
+               ms_on_demand_reset_storage();
+#endif
        }
 #endif
 
@@ -252,21 +264,29 @@ int main(int argc, char **argv)
 #ifdef _USE_ON_DEMAND
        switch (start_type) {
        case MS_START_TYPE_SOCKET:
-               /* do nothing */
+#ifdef _USE_TVPD_MODE
+               if (need_checkdb)
+                       __ms_update_mediadb(true);
+#endif
                break;
        case MS_START_TYPE_UDEV:
                /* improve mount/unmount performance */
                MS_DBG("ms_scanner_start [%s]", (ms_scanner_start() == MS_MEDIA_ERR_NONE) ? "success" : "fail");
-               /* fall through */
+#ifdef _USE_TVPD_MODE
+               __ms_update_mediadb(need_checkdb);
+#else
+               __ms_update_mediadb(false);
+#endif
+               break;
        case MS_START_TYPE_BOOT:
-               __ms_check_mediadb();
+               __ms_update_mediadb(true);
                break;
        default:
                MS_DBG_ERR("invalid start_type(%d)", start_type);
                break;
        }
 #else
-       __ms_check_mediadb();
+       __ms_update_mediadb(true);
 #endif
 
        /*Active flush */
@@ -378,12 +398,11 @@ static void __ms_update_storage_status(void)
        g_slist_free_full(dev_list, __ms_dev_free);
 }
 
+#ifdef _USE_TVPD_MODE
 static void __ms_check_mediadb(void)
 {
        int ret = MS_MEDIA_ERR_NONE;
-#ifdef _USE_TVPD_MODE
        uid_t uid = ms_sys_get_uid();
-
        sqlite3 *db_handle = NULL;
 
        ret = ms_connect_db(&db_handle, uid);
@@ -406,29 +425,42 @@ static void __ms_check_mediadb(void)
        if (ms_set_all_storage_validity(db_handle, 0, uid) != MS_MEDIA_ERR_NONE)
                MS_DBG_ERR("ms_set_all_storage_validity fail");
 
-/* auto scan tv interal storage */
+#ifdef _USE_ON_DEMAND
+       ms_on_demand_reset_storage();
+#endif
+
+       /* auto scan tv interal storage */
        char *internal_path = NULL;
        ms_user_get_internal_root_path(uid, &internal_path);
        ms_send_storage_scan_request(internal_path, INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);
        g_free(internal_path);
 
        ms_disconnect_db(db_handle);
+}
+#endif
+
+static void __ms_update_mediadb(bool need_checkdb)
+{
+#ifdef _USE_TVPD_MODE
+       if (need_checkdb)
+               __ms_check_mediadb();
 #endif
 
+       if (!__ms_is_external_supported())
+               return;
+
        /* update external storage */
-       if (__ms_is_external_supported()) {
 #ifdef _USE_TVPD_MODE
-               __ms_update_storage_status();
+       __ms_update_storage_status();
 #else
-               ret = ms_load_functions();
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       MS_DBG_ERR("ms_load_functions failed [%d]", ret);
-                       return;
-               }
-               __ms_update_storage_status();
-               ms_unload_functions();
-#endif
+       int ret = ms_load_functions();
+       if (ret != MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("ms_load_functions failed [%d]", ret);
+               return;
        }
+       __ms_update_storage_status();
+       ms_unload_functions();
+#endif
 }
 
 static bool __ms_is_external_supported(void)
index fc385c3f3d3f4be063c8d9db7b7a68f457cd0791..1bb524c89a6502239f2055740ce90aa1a70c1566 100644 (file)
 #include "media-server-scanner.h"
 #include "media-server-device-block.h"
 #include "media-server-on-demand.h"
+#ifndef _USE_DEVICED_DBUS
+#include "media-server-db-manage.h"
+#endif
 
 #define MS_MAIN_TIMEOUT_SEC 300
-#define BOOT_CHECK_FILE tzplatform_mkpath(TZ_SYS_TMP, "media_server_boot")
+#define BOOT_CHECK_FILE     tzplatform_mkpath(TZ_SYS_TMP, "media_server_boot")
 #define SELECT_VALID_STORAGES "SELECT storage_id, storage_path FROM storage WHERE validity=1"
 
 extern GMainLoop *mainloop;
@@ -274,7 +277,11 @@ void ms_on_demand_insert_storage(gpointer data, gpointer user_data)
        g_ms_on_demand_storage_list = g_slist_append(g_ms_on_demand_storage_list, new_storage);
 
        /* request database insertion to scanner */
+#ifdef _USE_TVPD_MODE
+       ms_device_handle_usb_added(block_info->mount_path);
+#else
        ms_storage_insert_handler(block_info->mount_path, block_info->mount_uuid);
+#endif
 }
 
 void ms_on_demand_remove_storage(gpointer data, gpointer user_data)
@@ -293,7 +300,11 @@ void ms_on_demand_remove_storage(gpointer data, gpointer user_data)
        __ms_print_storage(block_info, "Remove");
 
        /* request database removal to scanner */
+#ifdef _USE_TVPD_MODE
+       ms_device_handle_usb_removed(block_info->mount_path);
+#else
        ms_storage_remove_handler(block_info->mount_path, block_info->mount_uuid);
+#endif
 
        g_ms_on_demand_storage_list = g_slist_remove_link(g_ms_on_demand_storage_list, found);
        g_slist_free_full(found, (GDestroyNotify)__ms_free_storage);
@@ -322,3 +333,11 @@ void ms_on_demand_update_storage_list(GSList *storage_list)
 
        MS_DBG_FLEAVE();
 }
+
+#ifdef _USE_TVPD_MODE
+void ms_on_demand_reset_storage(void)
+{
+       g_slist_free_full(g_ms_on_demand_storage_list, (GDestroyNotify)__ms_free_storage);
+       g_ms_on_demand_storage_list = NULL;
+}
+#endif