Merge "Fix ASAN issue multiple definition of variable" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / adapter / bt-service-core-adapter.c
index 2134858..581c1b6 100644 (file)
@@ -78,7 +78,6 @@ static guint timer_id = 0;
 
 static gboolean a2dp_init_pending = FALSE;
 
-
 /* Adapter default states */
 static bt_status_t adapter_state = BT_DEACTIVATED;
 static bt_adapter_discovery_state_t adapter_discovery_state = ADAPTER_DISCOVERY_STOPPED;
@@ -507,7 +506,7 @@ int _bt_set_discoverable_mode(int discoverable_mode, int timeout)
        _bt_dpm_get_bluetooth_limited_discoverable_state(&discoverable_state);
        if (discoverable_mode != BLUETOOTH_DISCOVERABLE_MODE_CONNECTABLE &&
                 discoverable_state == DPM_RESTRICTED) {
-               if (headed_plugin_info->plugin_headed_enabled) // TODO: There is no definition headed_plugin_info
+               if (headed_plugin_info->plugin_headed_enabled)
                        headed_plugin_info->headed_plugin->bt_launch_dpmpopup("DPM_POLICY_DISABLE_BT_HANDSFREE");
                return BLUETOOTH_ERROR_ACCESS_DENIED;
        }
@@ -1003,6 +1002,11 @@ int _bt_init_profiles()
        if (ret != BLUETOOTH_ERROR_NONE)
                BT_ERR("_bt_gatt_init Failed");
 
+       /* Initialize HF Client */
+       ret = _bt_audio_initialize(BT_HFP_MODULE);
+       if (ret != BLUETOOTH_ERROR_NONE)
+               BT_ERR("_bt_audio_initialize(BT_HFP_MODULE) Failed");
+
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -1095,8 +1099,9 @@ static void __bt_adapter_handle_pending_requests(int service_function, void *use
        BT_INFO("+");
 
        /* Get method invocation context */
-       for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) {
+       for (l = _bt_get_invocation_list(); l != NULL; ) {
                req_info = l->data;
+               l = g_slist_next(l);
                if (req_info == NULL || req_info->service_function != service_function)
                        continue;
 
@@ -1175,21 +1180,21 @@ static gboolean __bt_adapter_post_set_enabled(gpointer user_data)
 {
        BT_INFO("__bt_adapter_post_set_enabled>>");
 
-       if (!TIZEN_PROFILE_TV) {
-               __bt_set_visible_mode();
-
-               /* add the vconf noti handler */
-               if (0 != vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
-                               (vconf_callback_fn)__bt_phone_name_changed_cb, NULL))
-                       BT_ERR("DEVICE_NAME key changed notification registration failed");
-
-               __bt_set_local_name();
-       } else {
+       if (TIZEN_PROFILE_TV || !headed_plugin_info->plugin_headed_enabled) {
                if (BLUETOOTH_ERROR_NONE != _bt_set_discoverable_mode(
                                BLUETOOTH_DISCOVERABLE_MODE_GENERAL_DISCOVERABLE, 0))
                        BT_ERR("Fail to set discoverable mode");
+       } else {
+               __bt_set_visible_mode();
        }
 
+       /* add the vconf noti handler */
+       if (0 != vconf_notify_key_changed(VCONFKEY_SETAPPL_DEVICE_NAME_STR,
+                       (vconf_callback_fn)__bt_phone_name_changed_cb, NULL))
+               BT_ERR("DEVICE_NAME key changed notification registration failed");
+
+       __bt_set_local_name();
+
        /* Get All properties */
        if (OAL_STATUS_SUCCESS != adapter_get_properties())
                BT_ERR("adapter_get_properties failed");
@@ -1321,6 +1326,16 @@ static void __bt_adapter_state_change_callback(int bt_status)
        }
 }
 
+int _bt_set_adapter_request_state(int enable)
+{
+       return oal_set_adapter_request_state(enable);
+}
+
+int _bt_set_le_request_state(int enable)
+{
+       return oal_set_le_request_state(enable);
+}
+
 static int __bt_adapter_state_handle_request(gboolean enable)
 {
        int result = BLUETOOTH_ERROR_NONE;
@@ -1460,19 +1475,10 @@ static int __bt_adapter_state_discovery_request(gboolean enable,
        case ADAPTER_DISCOVERY_STARTING: {
                BT_INFO("Adapter is currently in discovery starting state, state [%d]",
                                adapter_discovery_state);
-               if (enable) {
-                       return BLUETOOTH_ERROR_IN_PROGRESS;
-               } else {
-                       result = adapter_stop_inquiry();
-                       if (result != OAL_STATUS_SUCCESS) {
-                               BT_ERR("Discover stop failed: %d", result);
-                               result = BLUETOOTH_ERROR_INTERNAL;
-                       } else {
-                               BT_ERR("Stop Discovery Triggered successfully");
-                               __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STOPPING);
-                               result = BLUETOOTH_ERROR_NONE;
-                       }
-               }
+
+               result = enable ?  BLUETOOTH_ERROR_IN_PROGRESS :
+                                       BLUETOOTH_ERROR_DEVICE_BUSY;
+
                break;
        }
        case ADAPTER_DISCOVERY_STOPPED: {
@@ -1502,23 +1508,10 @@ static int __bt_adapter_state_discovery_request(gboolean enable,
        case ADAPTER_DISCOVERY_STOPPING: {
                BT_INFO("Adapter is currently in discovery stopping state, state [%d]",
                                adapter_discovery_state);
-               if (!enable)
-                       return BLUETOOTH_ERROR_NOT_IN_OPERATION;
-               else {
-                       BT_DBG("max_resp: %u, duration: %u, cod: 0x%X", max_response, duration, mask);
-                       if (!is_custom)
-                               result = adapter_start_inquiry(duration);
-                       else
-                               result = adapter_start_custom_inquiry(role);
-                       if (result != OAL_STATUS_SUCCESS) {
-                               BT_ERR("Start Discovery failed: %d", result);
-                               result = BLUETOOTH_ERROR_INTERNAL;
-                       } else {
-                               BT_ERR("Start Discovery Triggered successfully");
-                       __bt_adapter_update_discovery_status(ADAPTER_DISCOVERY_STARTING);
-                               result = BLUETOOTH_ERROR_NONE;
-                       }
-               }
+
+               result = enable ?  BLUETOOTH_ERROR_DEVICE_BUSY :
+                                       BLUETOOTH_ERROR_NOT_IN_OPERATION;
+
                break;
        }
        default: