Remove Profile Build Dependenceis: do it at runtime 02/99202/1
authorMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 22 Nov 2016 07:03:49 +0000 (16:03 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Tue, 22 Nov 2016 07:04:41 +0000 (16:04 +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.

ps. There was no code using TIZEN_WEARABLE/TIZEN_MOBILE
and there was only one effective code block for TIZEN_TV.

ps2. I really doubt whether you need capi-appfw-application
in this package.

Change-Id: Ie70acdf66e5cde1ca4932d3e30bb6f8e35a4e64f
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
CMakeLists.txt
include/network_dbus.h
include/network_interface.h
include/network_internal.h
include/wifi_internal.h
packaging/capi-network-wifi-manager.spec
src/network_dbus.c
src/network_interface.c
src/wifi_internal.c
src/wifi_manager.c

index 09f2651..8651bfc 100755 (executable)
@@ -14,17 +14,6 @@ INCLUDE_DIRECTORIES(${INC_DIR})
 SET(dependents "dlog vconf capi-base-common capi-system-info glib-2.0 gio-2.0 gthread-2.0 ")
 SET(pc_dependents "capi-base-common")
 
-IF(TIZEN_WEARABLE)
-       ADD_DEFINITIONS(-DTIZEN_WEARABLE)
-ENDIF(TIZEN_WEARABLE)
-IF(TIZEN_MOBILE)
-       ADD_DEFINITIONS(-DTIZEN_MOBILE)
-ENDIF(TIZEN_MOBILE)
-
-IF(TIZEN_TV)
-       ADD_DEFINITIONS(-DTIZEN_TV)
-ENDIF(TIZEN_TV)
-
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${dependents} ${APPFW_REQUIRED_PKGS})
 FOREACH(flag ${${fw_name}_CFLAGS})
index 58287a1..1807276 100755 (executable)
@@ -108,15 +108,12 @@ int _net_dbus_wps_scan_request(void);
 int _net_dbus_get_passpoint(int *enabled);
 int _net_dbus_set_passpoint(int enable);
 
-#if defined TIZEN_TV
 int _net_dbus_cancel_wps(void);
 int _net_dbus_open_connection_without_ssid();
 int _net_dbus_open_pin_connection_without_ssid(const char *pin);
 int _net_dbus_set_agent_wps_pbc(void);
 int _net_dbus_set_agent_wps_pin(const char *wps_pin);
 
-#endif
-
 int _net_dbus_tdls_disconnect(const char* peer_mac_addr);
 int _net_dbus_tdls_connected_peer(char** peer_mac_addr);
 
index 4095219..ba7cb4d 100755 (executable)
@@ -227,9 +227,7 @@ int net_wps_scan_wifi(void);
 int net_wifi_get_passpoint(int *enable);
 int net_wifi_set_passpoint(int enable);
 
-#if defined TIZEN_TV
 int net_wifi_cancel_wps(void);
-#endif
 
 int net_open_connection_with_wifi_info(const net_wifi_connection_info_s *wifi_info);
 int net_scan_wifi(void);
@@ -239,9 +237,7 @@ int net_wifi_enroll_wps(const char *profile_name, net_wifi_wps_info_s *wps_info)
 int net_check_get_privilege(void);
 int net_check_profile_privilege(void);
 
-#if defined TIZEN_TV
 int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_s *wps_info);
-#endif
 
 int net_wifi_tdls_disconnect(const char* peer_mac_addr);
 int net_wifi_tdls_connected_peer(char** peer_mac_addr);
index cceb14d..9f77a0a 100755 (executable)
@@ -63,9 +63,7 @@ extern "C" {
 #define NETCONFIG_NETWORK_PATH                 "/net/netconfig/network"
 #define NETCONFIG_WIFI_PATH                            "/net/netconfig/wifi"
 
-#if defined TIZEN_TV
 #define NETCONFIG_TV_PROFILE_INTERFACE NETCONFIG_SERVICE ".tv_profile"
-#endif
 
 #define SUPPLICANT_SERVICE                             "fi.w1.wpa_supplicant1"
 #define SUPPLICANT_INTERFACE                   "fi.w1.wpa_supplicant1"
index 3849fba..13d2f53 100755 (executable)
@@ -235,6 +235,15 @@ int _wifi_check_feature_supported(const char *feature_name, ...);
 /* WIFI Handle Check */
 bool __wifi_check_handle_validity(wifi_manager_h wifi);
 
+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 __cplusplus
 }
 #endif /* __cplusplus */
index 1aed2c9..c47d5e7 100755 (executable)
@@ -13,13 +13,10 @@ BuildRequires:      pkgconfig(gio-2.0)
 BuildRequires: pkgconfig(gthread-2.0)
 BuildRequires: pkgconfig(capi-base-common)
 BuildRequires: pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-appfw-application)
 Requires(post):                /sbin/ldconfig
 Requires(postun):      /sbin/ldconfig
 
-%if "%{profile}" == "wearable"
-BuildRequires:  pkgconfig(capi-appfw-application)
-%endif
-
 %description
 Network Wi-Fi Manager library in Tizen C API
 
@@ -40,17 +37,6 @@ export CFLAGS+=' -Wno-unused-local-typedefs'
 MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
 cmake -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \
        -DLIB_PATH=%{_lib} \
-%if "%{profile}" == "wearable"
-       -DTIZEN_WEARABLE=1 \
-%else
-%if "%{profile}" == "mobile"
-       -DTIZEN_MOBILE=1 \
-%else
-%if "%{profile}" == "tv"
-       -DTIZEN_TV=1 \
-%endif
-%endif
-%endif
        .
 
 make %{?_smp_mflags}
index 3891dda..314a17c 100755 (executable)
@@ -1714,7 +1714,6 @@ int _net_dbus_set_passpoint(int enable)
        return Error;
 }
 
-#if defined TIZEN_TV
 static void __net_wps_cancel_reply(GObject *source_object,
                GAsyncResult *res, gpointer user_data)
 {
@@ -1922,7 +1921,6 @@ int _net_dbus_set_agent_wps_pin(const char *wps_pin)
        __NETWORK_FUNC_EXIT__;
        return NET_ERR_NONE;
 }
-#endif
 
 int _net_dbus_tdls_disconnect(const char* peer_mac_addr)
 {
index 5f48118..a8f728d 100755 (executable)
@@ -1860,7 +1860,6 @@ int net_wifi_enroll_wps(const char *profile_name, net_wifi_wps_info_s *wps_info)
        return Error;
 }
 
-#if defined TIZEN_TV
 int net_wifi_cancel_wps(void)
 {
        __NETWORK_FUNC_ENTER__;
@@ -1908,7 +1907,6 @@ int net_wifi_cancel_wps(void)
        __NETWORK_FUNC_EXIT__;
        return Error;
 }
-#endif
 
 int net_get_wifi_state(net_wifi_state_e *current_state)
 {
@@ -1993,7 +1991,6 @@ int net_check_profile_privilege()
 }
 
 //LCOV_EXCL_START
-#if defined TIZEN_TV
 int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_s *wps_info)
 {
        __NETWORK_FUNC_ENTER__;
@@ -2069,7 +2066,6 @@ int net_wifi_enroll_wps_without_ssid(net_wifi_wps_info_s *wps_info)
        __NETWORK_FUNC_EXIT__;
        return Error;
 }
-#endif
 
 int net_wifi_tdls_disconnect(const char* peer_mac_addr)
 {
index 0cc0d5f..0065eaf 100755 (executable)
@@ -18,6 +18,8 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
+#include <system_info.h>
 
 #include "wifi_internal.h"
 
@@ -1732,3 +1734,36 @@ int _wifi_check_feature_supported(const char *feature_name, ...)
        set_last_result(WIFI_MANAGER_ERROR_NONE);
        return WIFI_MANAGER_ERROR_NONE;
 }
+
+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 9e23c75..40ef736 100755 (executable)
@@ -264,44 +264,44 @@ EXPORT_API int wifi_manager_get_mac_address(wifi_manager_h wifi, char **mac_addr
                return WIFI_MANAGER_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
        }
 
-#if defined TIZEN_TV
-       FILE *fp = NULL;
-       char buf[WIFI_MAC_ADDR_LENGTH + 1];
-       if (0 == access(WIFI_MAC_ADDR_PATH, F_OK))
-               fp = fopen(WIFI_MAC_ADDR_PATH, "r");
-
-       if (fp == NULL) {
-               WIFI_LOG(WIFI_ERROR, "Failed to open file" //LCOV_EXCL_LINE
-                               " %s\n", WIFI_MAC_ADDR_PATH);
-               return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
+       if (_get_tizen_profile() == TIZEN_PROFILE_TV) {
+               FILE *fp = NULL;
+               char buf[WIFI_MAC_ADDR_LENGTH + 1];
+               if (0 == access(WIFI_MAC_ADDR_PATH, F_OK))
+                       fp = fopen(WIFI_MAC_ADDR_PATH, "r");
+
+               if (fp == NULL) {
+                       WIFI_LOG(WIFI_ERROR, "Failed to open file" //LCOV_EXCL_LINE
+                                       " %s\n", WIFI_MAC_ADDR_PATH);
+                       return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+               }
 
-       if (fgets(buf, sizeof(buf), fp) == NULL) {
-               WIFI_LOG(WIFI_ERROR, "Failed to get MAC"
-                               " info from %s\n", WIFI_MAC_ADDR_PATH); //LCOV_EXCL_LINE
-               fclose(fp); //LCOV_EXCL_LINE
-               return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
-       }
+               if (fgets(buf, sizeof(buf), fp) == NULL) {
+                       WIFI_LOG(WIFI_ERROR, "Failed to get MAC"
+                                       " info from %s\n", WIFI_MAC_ADDR_PATH); //LCOV_EXCL_LINE
+                       fclose(fp); //LCOV_EXCL_LINE
+                       return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+               }
 
-       WIFI_LOG(WIFI_INFO, "%s : %s\n", WIFI_MAC_ADDR_PATH, buf);
+               WIFI_LOG(WIFI_INFO, "%s : %s\n", WIFI_MAC_ADDR_PATH, buf);
 
-       *mac_address = strndup(buf, WIFI_MAC_ADDR_LENGTH + 1);
-       if (*mac_address == NULL) {
-               WIFI_LOG(WIFI_ERROR, "strndup() failed"); //LCOV_EXCL_LINE
-               fclose(fp); //LCOV_EXCL_LINE
-               return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
-       }
+               *mac_address = strndup(buf, WIFI_MAC_ADDR_LENGTH + 1);
+               if (*mac_address == NULL) {
+                       WIFI_LOG(WIFI_ERROR, "strndup() failed"); //LCOV_EXCL_LINE
+                       fclose(fp); //LCOV_EXCL_LINE
+                       return WIFI_MANAGER_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE
+               }
 
-       fclose(fp);
-#else
-       *mac_address = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+               fclose(fp);
+       } else {
+               *mac_address = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
 
-       if (*mac_address == NULL) {
-               WIFI_LOG(WIFI_ERROR, "Failed to get vconf" //LCOV_EXCL_LINE
-                       " from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
-               return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+               if (*mac_address == NULL) {
+                       WIFI_LOG(WIFI_ERROR, "Failed to get vconf" //LCOV_EXCL_LINE
+                               " from %s", VCONFKEY_WIFI_BSSID_ADDRESS);
+                       return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
+               }
        }
-#endif
 
        return WIFI_MANAGER_ERROR_NONE;
 }