Apply caching for bluetooth feature check 29/219929/1 accepted/tizen/unified/20191213.042503 submit/tizen/20191212.044134
authorKim Dukwoo <dukwoo7.kim@samsung.com>
Wed, 11 Dec 2019 06:40:15 +0000 (15:40 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 12 Dec 2019 01:35:25 +0000 (10:35 +0900)
Change-Id: I446d81576dda20fc662cb59a9636de30510de74a
Signed-off-by: Kim Dukwoo <dukwoo7.kim@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
include/bluetooth_private.h
src/bluetooth-common.c

index ebb5d46..18976d8 100644 (file)
@@ -575,56 +575,70 @@ typedef void (*bt_adapter_passkey_notification_cb)(const char *remote_address, c
                return BT_ERROR_INVALID_PARAMETER; \
        }
 
-#define BT_FEATURE_COMMON "tizen.org/feature/network.bluetooth"
-#define BT_FEATURE_LE "tizen.org/feature/network.bluetooth.le"
-#define BT_FEATURE_LE_5_0 "tizen.org/feature/network.bluetooth.le.5_0"
-#define BT_FEATURE_IPSP "tizen.org/feature/network.bluetooth.le.ipsp"
-#define BT_FEATURE_AUDIO_CALL "tizen.org/feature/network.bluetooth.audio.call"
-#define BT_FEATURE_AUDIO_MEDIA "tizen.org/feature/network.bluetooth.audio.media"
-#define BT_FEATURE_AUDIO_CONTROLLER "tizen.org/feature/network.bluetooth.audio.controller"
-#define BT_FEATURE_HEALTH "tizen.org/feature/network.bluetooth.health"
-#define BT_FEATURE_HID_HOST "tizen.org/feature/network.bluetooth.hid"
-#define BT_FEATURE_HID_DEVICE "tizen.org/feature/network.bluetooth.hid_device"
-#define BT_FEATURE_OPP "tizen.org/feature/network.bluetooth.opp"
-#define BT_FEATURE_MAP "tizen.org/feature/network.bluetooth.map"
-#define BT_FEATURE_TETHERING "tizen.org/feature/network.tethering.bluetooth"
-#define BT_FEATURE_PBAP_CLIENT "tizen.org/feature/network.bluetooth.phonebook.client"
-#define BT_FEATURE_OOB "tizen.org/feature/network.bluetooth.oob"
-#define BT_FEATURE_GATT_SERVER "tizen.org/feature/network.bluetooth.le.gatt.server"
-#define BT_FEATURE_GATT_CLIENT "tizen.org/feature/network.bluetooth.le.gatt.client"
-
-#define BT_CHECK_SUPPORTED_FEATURE(feature_name) \
+typedef enum {
+       BT_FEATURE_BASE = 0,
+       BT_FEATURE_COMMON = BT_FEATURE_BASE,
+       BT_FEATURE_LE,
+       BT_FEATURE_LE_5_0,
+       BT_FEATURE_IPSP,
+       BT_FEATURE_AUDIO_CALL,
+       BT_FEATURE_AUDIO_MEDIA,
+       BT_FEATURE_AUDIO_CONTROLLER,
+       BT_FEATURE_HEALTH,
+       BT_FEATURE_HID_HOST,
+       BT_FEATURE_HID_DEVICE,
+       BT_FEATURE_OPP,
+       BT_FEATURE_MAP,
+       BT_FEATURE_TETHERING,
+       BT_FEATURE_PBAP_CLIENT,
+       BT_FEATURE_OOB,
+       BT_FEATURE_GATT_SERVER,
+       BT_FEATURE_GATT_CLIENT,
+       BT_FEATURE_MAX
+} bt_feature_t;
+
+typedef struct {
+       const char *name;
+       gboolean is_check;
+       gboolean value;
+} bt_feature_table_t;
+
+int _bt_check_supported_feature(bt_feature_t feature, bool *supported);
+
+#define BT_CHECK_SUPPORTED_FEATURE(feature) \
 do     { \
        bool is_supported = false; \
-       if (!system_info_get_platform_bool(feature_name, &is_supported)) { \
+       if (!_bt_check_supported_feature(feature, &is_supported)) { \
                if (is_supported == false) { \
                        LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \
                        return BT_ERROR_NOT_SUPPORTED; \
                } \
        } else { \
-               LOGE("[%s] Fail to get the system feature: [%s]", __FUNCTION__, feature_name); \
+               LOGE("[%s] Fail to get the system feature: [%d]", __FUNCTION__, feature); \
        } \
 } while (0)
 
-#define BT_CHECK_SUPPORTED_FEATURES(feature_name1, feature_name2) \
+#define BT_CHECK_SUPPORTED_FEATURES(feature1, feature2) \
 do     { \
        bool is_supported = false; \
-       if (!system_info_get_platform_bool(feature_name1, &is_supported)) { \
-               if (is_supported == true) {\
+       if (!_bt_check_supported_feature(feature1, &is_supported)) { \
+               if (is_supported == true) { \
+                       LOGI("[%s] SUPPORTED", __FUNCTION__); \
                        break; \
                } \
        } else { \
-               LOGE("[%s] Fail to get the system feature: [%s]", __FUNCTION__, feature_name1); \
+               LOGE("[%s] Fail to get the system feature: [%d]", __FUNCTION__, feature1); \
        } \
-       if (!system_info_get_platform_bool(feature_name2, &is_supported)) { \
+       if (!_bt_check_supported_feature(feature2, &is_supported)) { \
                if (is_supported == true) { \
+                       LOGI("[%s] SUPPORTED", __FUNCTION__); \
                        break; \
                } else  {\
                        LOGE("[%s] NOT_SUPPORTED(0x%08x)", __FUNCTION__, BT_ERROR_NOT_SUPPORTED); \
                        return BT_ERROR_NOT_SUPPORTED; \
                } \
        } else { \
-               LOGE("[%s] Fail to get the system feature: [%s]", __FUNCTION__, feature_name2); \
+               LOGE("[%s] Fail to get the system feature: [%d]", __FUNCTION__, feature2); \
        } \
 } while (0)
 
index c59f074..d535ecd 100644 (file)
@@ -278,6 +278,26 @@ static bt_event2index_table_t event2index[] = {
        { 0, -1 }
 };
 
+static bt_feature_table_t feature_table[] = {
+       {"tizen.org/feature/network.bluetooth", FALSE, FALSE},                  /* BT_FEATURE_COMMON */
+       {"tizen.org/feature/network.bluetooth.le", FALSE, FALSE},               /* BT_FEATURE_LE */
+       {"tizen.org/feature/network.bluetooth.le.5_0", FALSE, FALSE},           /* BT_FEATURE_LE_5_0 */
+       {"tizen.org/feature/network.bluetooth.le.ipsp", FALSE, FALSE},          /* BT_FEATURE_IPSP */
+       {"tizen.org/feature/network.bluetooth.audio.call", FALSE, FALSE},       /* BT_FEATURE_AUDIO_CALL */
+       {"tizen.org/feature/network.bluetooth.audio.media", FALSE, FALSE},      /* BT_FEATURE_AUDIO_MEDIA */
+       {"tizen.org/feature/network.bluetooth.audio.controller", FALSE, FALSE}, /* BT_FEATURE_AUDIO_CONTROLLER */
+       {"tizen.org/feature/network.bluetooth.health", FALSE, FALSE},           /* BT_FEATURE_HEALTH */
+       {"tizen.org/feature/network.bluetooth.hid", FALSE, FALSE},              /* BT_FEATURE_HID_HOST */
+       {"tizen.org/feature/network.bluetooth.hid_device", FALSE, FALSE},       /* BT_FEATURE_HID_DEVICE */
+       {"tizen.org/feature/network.bluetooth.opp", FALSE, FALSE},              /* BT_FEATURE_OPP */
+       {"tizen.org/feature/network.bluetooth.map", FALSE, FALSE},              /* BT_FEATURE_MAP */
+       {"tizen.org/feature/network.tethering.bluetooth", FALSE, FALSE},        /* BT_FEATURE_TETHERING */
+       {"tizen.org/feature/network.bluetooth.phonebook.client", FALSE, FALSE}, /* BT_FEATURE_PBAP_CLIENT */
+       {"tizen.org/feature/network.bluetooth.oob", FALSE, FALSE},              /* BT_FEATURE_OOB */
+       {"tizen.org/feature/network.bluetooth.le.gatt.server", FALSE, FALSE},   /* BT_FEATURE_GATT_SERVER */
+       {"tizen.org/feature/network.bluetooth.le.gatt.client", FALSE, FALSE}    /* BT_FEATURE_GATT_CLIENT */
+};
+
 /*
  *  Internal Functions
  */
@@ -350,6 +370,32 @@ int bt_get_uuid_name(const char *uuid, char **name)
 /*
  *  Common Functions
  */
+int _bt_check_supported_feature(bt_feature_t feature, bool *supported)
+{
+       int ret;
+
+       if (feature < BT_FEATURE_BASE || feature >= BT_FEATURE_MAX) {
+               BT_ERR("Invalid parameter. feature [%d]", feature);
+               return BT_ERROR_INVALID_PARAMETER;
+       }
+
+       if (TRUE == feature_table[feature].is_check) {
+               *supported = feature_table[feature].value;
+               return BT_ERROR_NONE;
+       }
+
+       ret = system_info_get_platform_bool(feature_table[feature].name, supported);
+       if (SYSTEM_INFO_ERROR_NONE != ret) {
+               BT_ERR("fail to get %s", feature_table[feature].name);
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       feature_table[feature].is_check = TRUE;
+       feature_table[feature].value = *supported;
+
+       return BT_ERROR_NONE;
+}
+
 int _bt_check_init_status(void)
 {
        if (is_initialized != true) {