Remove Profile Build Dependency (1/2): do it at runtime 75/101175/5
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 30 Nov 2016 10:40:16 +0000 (19:40 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Mon, 5 Dec 2016 02:00:05 +0000 (11:00 +0900)
- This is for Tizen 4.0.

  : Tizen 4.0 Configurability and Build Blocks require
  to remove all profile-depending build options in spec files.
  (No More profile macros)

- It is recommended to distinguish features/profiles at runtime.
 unless it incurs too much overhead, which requires you to
 create multiple binaries and subpackages.

Change-Id: I015b2f10cb6bd3cb84a9c0435202bc59004e752c
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
lib/include/private.h [new file with mode: 0644]
lib/media-util-noti-internal.c
lib/media-util-noti.c
packaging/media-server.spec
src/scanner-v2/media-scanner-v2.c
src/scanner/media-scanner.c
src/server/media-server-main.c

diff --git a/lib/include/private.h b/lib/include/private.h
new file mode 100644 (file)
index 0000000..26be51f
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Media Utility / Private Header
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SERVER_PRIVATE_H_
+#define _MEDIA_SERVER_PRIVATE_H_
+#include <stdlib.h>
+#include <system_info.h>
+
+typedef enum {
+       TIZEN_PROFILE_UNKNOWN = 0,
+       TIZEN_PROFILE_MOBILE = 0x1,
+       TIZEN_PROFILE_WEARABLE = 0x2,
+       TIZEN_PROFILE_TV = 0x4,
+       TIZEN_PROFILE_IVI = 0x8,
+       TIZEN_PROFILE_COMMON = 0x10,
+} tizen_profile_t;
+
+static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+static char *profileName;
+static inline tizen_profile_t _get_tizen_profile()
+{
+       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+               return profile;
+
+       system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
+       switch (*profileName) {
+               case 'm':
+               case 'M':
+                       profile = TIZEN_PROFILE_MOBILE;
+                       break;
+               case 'w':
+               case 'W':
+                       profile = TIZEN_PROFILE_WEARABLE;
+                       break;
+               case 't':
+               case 'T':
+                       profile = TIZEN_PROFILE_TV;
+                       break;
+               case 'i':
+               case 'I':
+                       profile = TIZEN_PROFILE_IVI;
+                       break;
+               default: // common or unknown ==> ALL ARE COMMON.
+                       profile = TIZEN_PROFILE_COMMON;
+       }
+       free(profileName);
+
+       return profile;
+}
+
+#define _USE_SDCARD    (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+#define _USE_TV_PATH   (_get_tizen_profile() == TIZEN_PROFILE_TV)
+
+#endif /* _MEDIA_SERVER_PRIVATE_H_ */
index 4e21ae3..3c83e91 100755 (executable)
@@ -41,6 +41,8 @@
 #include "media-util.h"
 #include "media-util-noti-internal.h"
 
+#include "private.h"
+
 GArray *handle_list_internal;
 static GMutex mutex_internal;
 
@@ -66,7 +68,7 @@ int media_db_update_send_internal(int pid, /* mandatory */
        GDBusConnection *bus = NULL;
        GError *error = NULL;
        char repl_path[MAX_FILEPATH_LEN] = {0, };
-#if !defined(_USE_SENIOR_MODE) && !defined(_USE_TV_PATH)
+#if !defined(_USE_SENIOR_MODE)
        char *tmp_path = NULL;
 #endif
        bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
@@ -77,21 +79,24 @@ int media_db_update_send_internal(int pid, /* mandatory */
        }
 
        memset(repl_path, 0, sizeof(repl_path));
-#if !defined(_USE_SENIOR_MODE) && !defined(_USE_TV_PATH)
-       /* Need uid to change path */
-       if (strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0) {
-               snprintf(repl_path, sizeof(repl_path), "%s", path);
-       } else {
-               if (storage_get_origin_internal_path(path, MAX_FILEPATH_LEN, repl_path) != STORAGE_ERROR_NONE) {
-                       MSAPI_DBG("Failed to change internal path");
-                       return MS_MEDIA_ERR_INTERNAL;
+#if !defined(_USE_SENIOR_MODE)
+       if (!_USE_TV_PATH) {
+               /* Need uid to change path */
+               if (strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0) {
+                       snprintf(repl_path, sizeof(repl_path), "%s", path);
+               } else {
+                       if (storage_get_origin_internal_path(path, MAX_FILEPATH_LEN, repl_path) != STORAGE_ERROR_NONE) {
+                               MSAPI_DBG("Failed to change internal path");
+                               return MS_MEDIA_ERR_INTERNAL;
+                       }
                }
-       }
 
-       MSAPI_DBG("New path: [%s]", repl_path);
-#else
-       snprintf(repl_path, sizeof(repl_path), "%s", path);
+               MSAPI_DBG("New path: [%s]", repl_path);
+       } else
 #endif
+       {
+               snprintf(repl_path, sizeof(repl_path), "%s", path);
+       }
 
        if (item == MS_MEDIA_ITEM_FILE) {
                MSAPI_DBG("FILE CHANGED");
index 54ca5f3..1b07123 100755 (executable)
@@ -33,6 +33,8 @@
 #include "media-util.h"
 #include "media-util-noti.h"
 
+#include "private.h"
+
 static GDBusConnection *g_bus = NULL;
 static guint g_handler = 0;
 static void *g_data_store = NULL;
@@ -205,7 +207,7 @@ int media_db_update_send(int pid, /* mandatory */
        GDBusConnection *bus = NULL;
        GError *error = NULL;
        char repl_path[MAX_FILEPATH_LEN] = {0, };
-#if !defined(_USE_SENIOR_MODE) && !defined(_USE_TV_PATH)
+#if !defined(_USE_SENIOR_MODE)
        char *tmp_path = NULL;
 #endif
 
@@ -217,21 +219,24 @@ int media_db_update_send(int pid, /* mandatory */
        }
 
        memset(repl_path, 0, sizeof(repl_path));
-#if !defined(_USE_SENIOR_MODE) && !defined(_USE_TV_PATH)
-       /* Need uid to change path */
-       if (strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0) {
-               snprintf(repl_path, sizeof(repl_path), "%s", path);
-       } else {
-               if (storage_get_origin_internal_path(path, MAX_FILEPATH_LEN, repl_path) != STORAGE_ERROR_NONE) {
-                       MSAPI_DBG("Failed to change internal path");
-                       return MS_MEDIA_ERR_INTERNAL;
+#if !defined(_USE_SENIOR_MODE)
+       if (!_USE_TV_PATH) {
+               /* Need uid to change path */
+               if (strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0) {
+                       snprintf(repl_path, sizeof(repl_path), "%s", path);
+               } else {
+                       if (storage_get_origin_internal_path(path, MAX_FILEPATH_LEN, repl_path) != STORAGE_ERROR_NONE) {
+                               MSAPI_DBG("Failed to change internal path");
+                               return MS_MEDIA_ERR_INTERNAL;
+                       }
                }
-       }
 
-       MSAPI_DBG("New path: [%s]", repl_path);
-#else
-       snprintf(repl_path, sizeof(repl_path), "%s", path);
+               MSAPI_DBG("New path: [%s]", repl_path);
+       } else
 #endif
+       {
+               snprintf(repl_path, sizeof(repl_path), "%s", path);
+       }
 
        if (item == MS_MEDIA_ITEM_FILE) {
                MSAPI_DBG("FILE CHANGED");
index 914ee13..62f4c2f 100755 (executable)
@@ -76,16 +76,8 @@ cp po/* .
 %if 0%{?product_tv}
 export CFLAGS="$CFLAGS -D_USE_SENIOR_MODE -D_USE_RECORDED_CONTENT -D_USE_SUSPEND_MODE -D_SET_VIP_PROCESS"
 %else
-%if "%{?profile}" == "mobile"
-export CFLAGS="$CFLAGS -D_USE_MULTI_USER -D_USE_META_UPDATE -D_USE_DEVICED_DBUS -D_USE_SDCARD"
-%else
-%if "%{?profile}" == "tv"
-export CFLAGS="$CFLAGS -D_USE_MULTI_USER -D_USE_META_UPDATE -D_USE_DEVICED_DBUS -D_USE_TV_PATH"
-%else
 export CFLAGS="$CFLAGS -D_USE_MULTI_USER -D_USE_META_UPDATE -D_USE_DEVICED_DBUS"
 %endif
-%endif
-%endif
 export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE -DSYSCONFDIR=\\\"%{_sysconfdir}\\\""
 export CFLAGS+=" -DPATH_LIBDIR=\\\"%{_libdir}\\\""
 rm -rf autom4te.cache
index faea0c1..f647b60 100755 (executable)
@@ -39,6 +39,8 @@
 #include "media-scanner-socket-v2.h"
 #include "media-scanner-extract-v2.h"
 
+#include "private.h"
+
 #define APP_NAME "media-scanner-v2"
 
 #define MSC_VCONF_KEY_SCANNER_POWEROFF_STATUS "db/mediascanner/poweroff_status"
@@ -219,11 +221,9 @@ int main(int argc, char **argv)
        storage_extract_thread = g_thread_new("storage_extract_thread", (GThreadFunc)msc_storage_extract_thread, NULL);
        folder_extract_thread = g_thread_new("folder_extract_thread", (GThreadFunc)msc_folder_extract_thread, NULL);
 
-#ifdef _USE_SDCARD
-       if (ms_is_mmc_inserted()) {
+       if (_USE_SDCARD && ms_is_mmc_inserted()) {
                msc_set_mmc_status(MS_STG_INSERTED);
        }
-#endif
        MS_DBG_INFO("scanner v2 is ready");
 
        msc_send_ready();
index ffb40a1..59e3785 100755 (executable)
@@ -37,6 +37,8 @@
 #include "media-scanner-scan.h"
 #include "media-scanner-socket.h"
 
+#include "private.h"
+
 static GMainLoop *scanner_mainloop = NULL;
 
 #ifdef _USE_DEVICED_DBUS
@@ -108,11 +110,9 @@ int main(int argc, char **argv)
        scan_thread = g_thread_new("scanner_thread", (GThreadFunc)msc_directory_scan_thread, NULL);
        register_thread = g_thread_new("register_thread", (GThreadFunc)msc_register_thread, NULL);
 
-#ifdef _USE_SDCARD
-       if (ms_is_mmc_inserted()) {
+       if (_USE_SDCARD && ms_is_mmc_inserted()) {
                msc_set_mmc_status(MS_STG_INSERTED);
        }
-#endif
        MS_DBG_INFO("scanner is ready");
 
        msc_send_ready();
index 1493856..6025ae0 100755 (executable)
@@ -46,6 +46,8 @@
 #include "media-server-dcm.h"
 #include "media-server-db-manage.h"
 
+#include "private.h"
+
 #define MS_VCONF_KEY_RESET_STATUS "db/media_server/reset_status"
 extern GMutex scanner_mutex;
 
@@ -57,9 +59,7 @@ bool smarthub_reset_start;
 bool smarthub_reset;
 
 static void __ms_check_mediadb(void);
-#ifdef _USE_SDCARD
 static int __ms_check_mmc_status(void);
-#endif
 static int __ms_check_usb_status(void);
 static void __ms_add_signal_handler(void);
 static void __ms_add_event_receiver(GIOChannel *channel);
@@ -614,7 +614,6 @@ static void __ms_add_signal_handler(void)
 }
 
 ////////////////////////////////////////////////////////////////////
-#ifdef _USE_SDCARD
 static int __ms_check_mmc_status(void)
 {
        int ret = MS_MEDIA_ERR_NONE;
@@ -645,7 +644,6 @@ static int __ms_check_mmc_status(void)
 
        return MS_MEDIA_ERR_NONE;
 }
-#endif
 
 static int __ms_check_usb_status(void)
 {
@@ -730,9 +728,8 @@ static void __ms_check_mediadb(void)
        ms_send_storage_scan_request(ms_get_path(uid), INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);
 */
        /* update external storage */
-#ifdef _USE_SDCARD
-       __ms_check_mmc_status();
-#endif
+       if (_USE_SDCARD)
+               __ms_check_mmc_status();
        __ms_check_usb_status();
 }