Remove Profile Build Dependency: do it at runtime 57/101457/4
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Thu, 1 Dec 2016 07:40:20 +0000 (16:40 +0900)
committerIckhee Woo <ickhee.woo@samsung.com>
Tue, 17 Jan 2017 23:10:39 +0000 (15:10 -0800)
- 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.

Runtime profile determination is activated only for common, mobile, and
unified build. For older (to be obsolete) build projects or
non-mobile GBM build projects, it is always-off.

- patchset2: fixed AEGIS's comments on coding style

Change-Id: I7fed0b9bae2b099ca6f3e5429ca09a882c52cd4e
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
packaging/sync-manager.spec
src/sync-client/CMakeLists.txt
src/sync-client/sync_manager.c
src/sync-service/CMakeLists.txt
src/sync-service/SyncManager_DataChangeSyncScheduler.cpp
src/sync-service/SyncManager_PeriodicSyncScheduler.cpp
src/sync-service/SyncManager_SyncDefines.cpp
src/sync-service/SyncManager_SyncDefines.h
src/sync-service/SyncManager_SyncService.cpp

index 11152d6a31b102a03c3aeb633eac4ad8208c6e35..ebf9d7cb35661d20bb0a83cefa23133a1f8efbe6 100644 (file)
@@ -1,3 +1,6 @@
+# To not create auto-provides for extension replacement shared objects
+%global __provides_exclude_from ^.*\\.extension-calendar
+
 Name:      sync-service
 Version:   0.1.18
 Release:   1
@@ -13,6 +16,7 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-network-connection)
+BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(appcore-efl)
 BuildRequires: pkgconfig(dlog)
 BuildRequires: pkgconfig(pkgmgr)
@@ -29,18 +33,17 @@ BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(cynara-client)
 BuildRequires: pkgconfig(cynara-session)
 BuildRequires: pkgconfig(cynara-creds-gdbus)
-%if "%{?profile}" == "mobile"
+# If it is mobile, common, or "unified (undefined)"
+%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi"
 BuildRequires: pkgconfig(calendar-service2)
 %endif
 BuildRequires: pkgconfig(contacts-service2)
 BuildRequires: pkgconfig(capi-content-media-content)
 BuildRequires: pkgconfig(libtzplatform-config)
 
-
 %description
 sync manager service and sync framework which manages sync of registered applications
 
-
 %package -n libcore-sync-client
 Summary:    Sync manager client library
 Group:      Development/Libraries
@@ -69,10 +72,13 @@ cp %{SOURCE2} .
 %build
 _FEATURE_CONTAINER_ENABLE=OFF
 
-%if "%{?profile}" == "mobile"
-_FEATURE_CALENDAR_ENABLE=ON
+# If it is mobile, common, or "unified (undefined)"
+%if "%{?profile}" != "wearable" && "%{?profile}" != "tv" && "%{?profile}" != "ivi"
+# Support runtime feature on/off
+_RUNTIME_PROFILE_TEST=ON
 %else
-_FEATURE_CALENDAR_ENABLE=OFF
+# Always off.
+_RUNTIME_PROFILE_TEST=OFF
 %endif
 
 cmake \
@@ -82,7 +88,7 @@ cmake \
        -DLIBDIR=%{_libdir} \
        -DINCLUDEDIR=%{_includedir} \
        -D_FEATURE_CONTAINER_ENABLE:BOOL=${_FEATURE_CONTAINER_ENABLE} \
-       -D_FEATURE_CALENDAR_ENABLE:BOOL=${_FEATURE_CALENDAR_ENABLE} \
+       -D_RUNTIME_PROFILE_TEST:BOOL=${_RUNTIME_PROFILE_TEST} \
        -DVERSION=%{version}
 
 
index 8846913fbe638db0b87bcfdfd9f410652b1f0e97..3cb6558db33b4e011d5ff921b158c3abe737e656 100644 (file)
@@ -28,9 +28,9 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX})
 SET(VERSION_MAJOR 1)
 SET(FULLVER "${VERSION_MAJOR}.0")
 
-IF(_FEATURE_CALENDAR_ENABLE)
-       ADD_DEFINITIONS("-D_FEATURE_CALENDAR_ENABLE=1")
-ENDIF(_FEATURE_CALENDAR_ENABLE)
+IF(_RUNTIME_PROFILE_TEST)
+       ADD_DEFINITIONS("-D_RUNTIME_PROFILE_TEST=1")
+ENDIF(_RUNTIME_PROFILE_TEST)
 
 
 INCLUDE_DIRECTORIES(
@@ -49,6 +49,7 @@ ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE_NAME}\"")
 INCLUDE(FindPkgConfig)
 pkg_check_modules(PKGS REQUIRED
                capi-appfw-app-manager
+               capi-system-info
                dlog
                gio-unix-2.0
                bundle)
index bb993604d251fab77f48b52e45d9e135c007bd7c..54aa12d515140ef0e4455de965fc8170612fad69 100644 (file)
 #define SYNC_ADAPTER_DBUS_PATH "/org/tizen/sync/adapter"
 #define SYNC_ERROR_PREFIX "org.tizen.sync.Error"
 
+#ifdef _RUNTIME_PROFILE_TEST
+#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 inline tizen_profile_t _get_tizen_profile()
+{
+       char *profileName;
+
+       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 _FEATURE_CALENDAR_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+
+#else /* _RUNTIME_PROFILE_TEST */
+
+#define _FEATURE_CALENDAR_ENABLE (0)
+
+#endif /* _RUNTIME_PROFILE_TEST */
 
 typedef struct sync_manager_s {
        TizenSyncManager *ipcObj;
@@ -320,9 +372,7 @@ int sync_manager_add_data_change_sync_job(account_h account, const char *sync_ca
 {
        if (sync_capability != NULL) {
                if (
-#if defined(_FEATURE_CALENDAR_ENABLE)
-                       !(strcmp(sync_capability, "http://tizen.org/sync/capability/calendar")) ||
-#endif
+                       ((_FEATURE_CALENDAR_ENABLE) ? !(strcmp(sync_capability, "http://tizen.org/sync/capability/calendar")) : 0) ||
                        !(strcmp(sync_capability, "http://tizen.org/sync/capability/contact")) ||
                        !(strcmp(sync_capability, "http://tizen.org/sync/capability/image")) ||
                        !(strcmp(sync_capability, "http://tizen.org/sync/capability/video")) ||
index d953a3a4a3cc8ceda456ee77eff07e1efef72029..04fdf508d8e3270e28d9ba7859f0713d926c5ede 100644 (file)
@@ -68,9 +68,9 @@ SET(SRCS
 #      ADD_DEFINITIONS("-D_FEATURE_CONTAINER_ENABLE=1")
 #ENDIF(_FEATURE_CONTAINER_ENABLE)
 
-IF(_FEATURE_CALENDAR_ENABLE)
-       ADD_DEFINITIONS("-D_FEATURE_CALENDAR_ENABLE=1")
-ENDIF(_FEATURE_CALENDAR_ENABLE)
+IF(_RUNTIME_PROFILE_TEST)
+       ADD_DEFINITIONS("-D_RUNTIME_PROFILE_TEST=1")
+ENDIF(_RUNTIME_PROFILE_TEST)
 
 ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE_NAME}\"")
 
@@ -80,6 +80,7 @@ SET(PACKAGES
                capi-network-connection
                capi-appfw-application
                capi-appfw-app-manager
+               capi-system-info
                pkgmgr
                pkgmgr-info
                dlog
@@ -104,9 +105,9 @@ IF(_FEATURE_CONTAINER_ENABLE)
        SET(PACKAGES ${PACKAGES} vasum)
 ENDIF(_FEATURE_CONTAINER_ENABLE)
 
-IF(_FEATURE_CALENDAR_ENABLE)
+IF(_RUNTIME_PROFILE_TEST)
        SET(PACKAGES ${PACKAGES} calendar-service2)
-ENDIF(_FEATURE_CALENDAR_ENABLE)
+ENDIF(_RUNTIME_PROFILE_TEST)
 
 pkg_check_modules(PKGS REQUIRED ${PACKAGES})
 
index 49a4312a720400c9d0717678da29662ae9498a57..a76d57860b879c78fd61f266c847838e309b30c6 100644 (file)
@@ -19,7 +19,7 @@
  * @brief   This is the implementation file for the DataChangeListener class.
  */
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
+#if defined(_RUNTIME_PROFILE_TEST)
 #include <calendar.h>
 #endif
 
@@ -33,7 +33,7 @@
 
 
 /* LCOV_EXCL_START */
-#if defined(_FEATURE_CALENDAR_ENABLE)
+#if defined(_RUNTIME_PROFILE_TEST)
 void OnCalendarBookChanged(const char* view_uri, void* user_data) {
        LOG_LOGD("On Calendar Book Changed");
 
@@ -117,7 +117,7 @@ DataChangeSyncScheduler::~DataChangeSyncScheduler(void) {
 /* LCOV_EXCL_STOP */
 
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
+#if defined(_RUNTIME_PROFILE_TEST)
 int
 DataChangeSyncScheduler::SubscribeCalendarCallback(void) {
        SYNC_LOGE_RET_RES(!calendar_subscription_started, SYNC_ERROR_NONE, "Calendar Callback Already Subscribed");
@@ -226,7 +226,7 @@ DataChangeSyncScheduler::SubscribeMediaContentCallback(void) {
 
 
 /* LCOV_EXCL_START */
-#if defined(_FEATURE_CALENDAR_ENABLE)
+#if defined(_RUNTIME_PROFILE_TEST)
 int
 DataChangeSyncScheduler::UnSubscribeCalendarCallback(void) {
        SYNC_LOGE_RET_RES(calendar_subscription_started, SYNC_ERROR_NONE, "Calendar Callback Already UnSubscribed");
@@ -274,15 +274,15 @@ int
 DataChangeSyncScheduler::RegisterDataChangeListeners(void) {
        int err = SYNC_ERROR_NONE;
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
-       err = SubscribeCalendarCallback();
-       if (err != SYNC_ERROR_NONE) {
-               /* LCOV_EXCL_START */
-               LOG_LOGD("Registration of Calendar DataChangeListener Failed");
-               return SYNC_ERROR_INVALID_OPERATION;
-               /* LCOV_EXCL_STOP */
+       if (_FEATURE_CALENDAR_ENABLE) {
+               err = SubscribeCalendarCallback();
+               if (err != SYNC_ERROR_NONE) {
+                       /* LCOV_EXCL_START */
+                       LOG_LOGD("Registration of Calendar DataChangeListener Failed");
+                       return SYNC_ERROR_INVALID_OPERATION;
+                       /* LCOV_EXCL_STOP */
+               }
        }
-#endif
 
        err = SubscribeContactsCallback();
        if (err != SYNC_ERROR_NONE) {
@@ -309,13 +309,13 @@ int
 DataChangeSyncScheduler::DeRegisterDataChangeListeners(void) {
        int err = VALUE_UNDEFINED;
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
-       err = UnSubscribeCalendarCallback();
-       if (err != SYNC_ERROR_NONE) {
-               LOG_LOGD("DeRegistration of Calendar DataChangeListener Failed");
-               return SYNC_ERROR_INVALID_OPERATION;
+       if (_FEATURE_CALENDAR_ENABLE) {
+               err = UnSubscribeCalendarCallback();
+               if (err != SYNC_ERROR_NONE) {
+                       LOG_LOGD("DeRegistration of Calendar DataChangeListener Failed");
+                       return SYNC_ERROR_INVALID_OPERATION;
+               }
        }
-#endif
 
        err = UnSubscribeContactsCallback();
        if (err != SYNC_ERROR_NONE) {
index f80110ebd08633ce73619c9f13f17dfc816e3b63..ddd71623238473098718eac0c95ad7fa684d0371 100644 (file)
  * @brief   This is the implementation file for the PeriodicSyncScheduler class.
  */
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
-#include <calendar.h>
-#endif
-
 #include <contacts.h>
 #include <media_content.h>
 #include "sync-error.h"
index 8710eefb7051a3a56b0af3e4f47abed9d97b5db6..5fd276f4450f7fcad1cedf084eb695dacd93f3be 100644 (file)
@@ -15,6 +15,8 @@
  */
 
 #include "SyncManager_SyncDefines.h"
+#include <stdlib.h>
+#include <system_info.h>
 
 
 /*namespace _SyncManager
@@ -36,3 +38,36 @@ bool SyncStatus::syncTooManyTries = false;
 bool SyncStatus::syncSomeProgress = false;
 */
 //}//_SyncManager
+
+tizen_profile_t _get_tizen_profile()
+{
+       static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN;
+       if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1))
+               return profile;
+
+       char *profileName;
+       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;
+}
index 6591b79d9b24757002942fab21ec37e2ebf0d682..9285cfe836d78aaa55468c2f5b84951986296273 100644 (file)
@@ -221,4 +221,20 @@ struct Message {
 } _SyncManager
 */
 
+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;
+extern tizen_profile_t _get_tizen_profile();
+
+#ifdef _RUNTIME_PROFILE_TEST
+#define _FEATURE_CALENDAR_ENABLE (_get_tizen_profile() == TIZEN_PROFILE_MOBILE)
+#else /* _RUNTIME_PROFILE_TEST */
+#define _FEATURE_CALENDAR_ENABLE (0)
+#endif /* _RUNTIME_PROFILE_TEST */
+
 #endif /* SYNC_SERVICE_SYNC_DEFINES_H */
index 2902b2a710732ae19f4c2e41c9405354ac1285d6..0404f3f61fb638f49c2bb8be06c846708022b31d 100644 (file)
@@ -60,9 +60,7 @@ static bool check_jobs = false;
 #define SYNC_ERROR_PREFIX "org.tizen.sync.Error"
 #define PRIV_ALARM_SET "http://tizen.org/privilege/alarm.set"
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
 #define PRIV_CALENDAR_READ "http://tizen.org/privilege/calendar.read"
-#endif
 
 #define PRIV_CONTACT_READ "http://tizen.org/privilege/contact.read"
 
@@ -326,11 +324,9 @@ int _check_privilege_alarm_set(GDBusMethodInvocation *invocation) {
 }
 
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
 int _check_privilege_calendar_read(GDBusMethodInvocation *invocation) {
        return _check_privilege(invocation, PRIV_CALENDAR_READ);
 }
-#endif
 
 
 int _check_privilege_contact_read(GDBusMethodInvocation *invocation) {
@@ -909,46 +905,46 @@ sync_manager_add_data_change_job(TizenSyncManager* pObject, GDBusMethodInvocatio
 
        int ret = SYNC_ERROR_NONE;
 
-#if defined(_FEATURE_CALENDAR_ENABLE)
-       const char *capability = (char *)pCapabilityArg;
-       if (!strcmp(capability, "http://tizen.org/sync/capability/calendar") ||
-               !strcmp(capability, "http://tizen.org/sync/capability/contact")) {
-               if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
-                       ret = _check_privilege_calendar_read(pInvocation);
-               else
-                       ret = _check_privilege_contact_read(pInvocation);
-
-               if (ret != SYNC_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       GError* error = NULL;
+       if (_FEATURE_CALENDAR_ENABLE) {
+               const char *capability = (char *)pCapabilityArg;
+               if (!strcmp(capability, "http://tizen.org/sync/capability/calendar") ||
+                       !strcmp(capability, "http://tizen.org/sync/capability/contact")) {
                        if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
-                               error = g_error_new(_sync_error_quark(), ret, "sync service: calendar.read permission denied");
+                               ret = _check_privilege_calendar_read(pInvocation);
                        else
-                               error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
+                               ret = _check_privilege_contact_read(pInvocation);
 
-                       g_dbus_method_invocation_return_gerror(pInvocation, error);
-                       g_clear_error(&error);
-                       /* LCOV_EXCL_STOP */
-                       return true;
+                       if (ret != SYNC_ERROR_NONE) {
+                               /* LCOV_EXCL_START */
+                               GError* error = NULL;
+                               if (!strcmp(capability, "http://tizen.org/sync/capability/calendar"))
+                                       error = g_error_new(_sync_error_quark(), ret, "sync service: calendar.read permission denied");
+                               else
+                                       error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
+
+                               g_dbus_method_invocation_return_gerror(pInvocation, error);
+                               g_clear_error(&error);
+                               /* LCOV_EXCL_STOP */
+                               return true;
+                       }
                }
-       }
-#else
-       const char *capability = (char *)pCapabilityArg;
-       if (!strcmp(capability, "http://tizen.org/sync/capability/contact")) {
-               ret = _check_privilege_contact_read(pInvocation);
+       } else {
+               const char *capability = (char *)pCapabilityArg;
+               if (!strcmp(capability, "http://tizen.org/sync/capability/contact")) {
+                       ret = _check_privilege_contact_read(pInvocation);
 
-               if (ret != SYNC_ERROR_NONE) {
-                       /* LCOV_EXCL_START */
-                       GError* error = NULL;
-                       error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
+                       if (ret != SYNC_ERROR_NONE) {
+                               /* LCOV_EXCL_START */
+                               GError* error = NULL;
+                               error = g_error_new(_sync_error_quark(), ret, "sync service: contact.read permission denied");
 
-                       g_dbus_method_invocation_return_gerror(pInvocation, error);
-                       g_clear_error(&error);
-                       /* LCOV_EXCL_STOP */
-                       return true;
+                               g_dbus_method_invocation_return_gerror(pInvocation, error);
+                               g_clear_error(&error);
+                               /* LCOV_EXCL_STOP */
+                               return true;
+                       }
                }
        }
-#endif
 
        guint pid = get_caller_pid(pInvocation);
        string pkgIdStr;