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 31e9358..581c1b6 100644 (file)
@@ -75,14 +75,8 @@ typedef struct {
 static bt_adapter_timer_t visible_timer;
 
 static guint timer_id = 0;
-static guint le_timer_id = 0;
 
 static gboolean a2dp_init_pending = FALSE;
-static GDBusProxy *core_proxy = NULL;
-
-#define BT_CORE_NAME "org.projectx.bt_core"
-#define BT_CORE_PATH "/org/projectx/bt_core"
-#define BT_CORE_INTERFACE "org.projectx.btcore"
 
 /* Adapter default states */
 static bt_status_t adapter_state = BT_DEACTIVATED;
@@ -109,38 +103,6 @@ static gboolean __bt_is_service_request_present(int service_function);
 
 static void __bt_set_visible_mode(void);
 static void __bt_set_local_name(void);
-void _bt_adapter_start_enable_timer(void);
-void _bt_adapter_start_le_enable_timer(void);
-
-GDBusProxy *_bt_init_core_proxy(void)
-{
-       GDBusProxy *proxy;
-       GDBusConnection *conn;
-
-       conn = _bt_gdbus_get_system_gconn();
-       if (!conn)
-               return NULL;
-
-       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
-                                       NULL,
-                                       BT_CORE_NAME,
-                                       BT_CORE_PATH,
-                                       BT_CORE_INTERFACE,
-                                       NULL, NULL);
-
-       if (!proxy)
-               return NULL;
-
-       core_proxy = proxy;
-
-       return proxy;
-}
-
-static GDBusProxy *__bt_get_core_proxy(void)
-{
-       return (core_proxy) ? core_proxy : _bt_init_core_proxy();
-}
-
 
 /* Initialize BT stack (Initialize OAL layer) */
 int _bt_stack_init(void)
@@ -178,34 +140,9 @@ int _bt_enable_adapter(void)
 
 int _bt_enable_core(void)
 {
-       BT_INFO("Implemented");
-       GDBusProxy *proxy;
-       GVariant *result;
-       GError *error = NULL;
-
-       proxy = __bt_get_core_proxy();
-       retv_if(!proxy, BLUETOOTH_ERROR_INTERNAL);
-
-       /* Clean up the process */
-       result = g_dbus_proxy_call_sync(proxy,
-                               "EnableCore",
-                               NULL,
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &error);
-
-       if (!result) {
-               if (error != NULL) {
-                       BT_ERR("Bt core call failed(Error: %s)", error->message);
-                       g_clear_error(&error);
-               } else
-                       BT_ERR("Bt core call failed");
-        return BLUETOOTH_ERROR_INTERNAL;
-}
-
-g_variant_unref(result);
-return BLUETOOTH_ERROR_NONE;
+       /* TODO_40 : 4.0 merge  */
+       BT_INFO("Not Supported");
+       return BLUETOOTH_ERROR_NOT_SUPPORT;
 }
 
 int _bt_recover_adapter(void)
@@ -230,30 +167,6 @@ int _bt_reset_adapter(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
-void _bt_set_le_disabled(int result)
-{
-       int power_off_status;
-       int ret;
-
-       ret = vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &power_off_status);
-       BT_DBG("ret : %d", ret);
-       BT_DBG("power_off_status : %d", power_off_status);
-
-       /* Update Bluetooth Status to notify other modules */
-       BT_DBG("Update vconf for BT LE normal Deactivation");
-       if (vconf_set_int(VCONFKEY_BT_LE_STATUS, VCONFKEY_BT_LE_STATUS_OFF) != 0)
-               BT_ERR("Set vconf failed\n");
-                       _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
-
-       if (_bt_eventsystem_set_value(SYS_EVENT_BT_STATE, EVT_KEY_BT_LE_STATE,
-                                               EVT_VAL_BT_LE_OFF) != ES_R_OK)
-                       BT_ERR("Fail to set value");
-
-       /* Send disabled event */
-       _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_LE_DISABLED,
-                       g_variant_new("(i)", result));
-}
-
 int _bt_check_adapter(int *status)
 {
        BT_INFO("+");
@@ -304,170 +217,6 @@ gboolean _bt_is_discovering(void)
                return FALSE;
 }
 
-static void __bt_service_flight_ps_mode_cb(keynode_t *node, void *data)
-{
-       gboolean flight_mode = FALSE;
-       int type;
-
-       DBG_SECURE("key=%s", vconf_keynode_get_name(node));
-       type = vconf_keynode_get_type(node);
-       if (type == VCONF_TYPE_BOOL) {
-               flight_mode = vconf_keynode_get_bool(node);
-               if (flight_mode != TRUE) {
-                       BT_ERR("Ignore the event");
-                       return;
-               }
-               else {
-                       BT_ERR("Flight Mode == TRUE");
-               }
-       } else {
-               BT_ERR("Invaild vconf key type : %d", type);
-               return;
-       }
-
-       _bt_enable_core();
-}
-
-void _bt_service_register_vconf_handler(void)
-{
-       BT_DBG("+");
-
-       if (vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
-                       BT_ERR("Unable to register key handler");
-       BT_DBG("Telephony is disabled");
-       if (vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
-               (vconf_callback_fn)__bt_service_flight_ps_mode_cb, NULL) < 0)
-                       BT_ERR("Unable to register key handler");
-}
-
-void _bt_service_unregister_vconf_handler(void)
-{
-       BT_DBG("+");
-
-       vconf_ignore_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE,
-                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-
-       vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
-                       (vconf_callback_fn)__bt_service_flight_ps_mode_cb);
-}
-
-static gboolean __bt_enable_timeout_cb(gpointer user_data)
-{
-       GDBusProxy *proxy;
-       GVariant *result;
-       GError *error = NULL;
-
-       timer_id = 0;
-
-       retv_if(_bt_adapter_get_status() == BT_ACTIVATED, FALSE);
-
-       BT_ERR("EnableAdapter is failed");
-
-       proxy = __bt_get_core_proxy();
-       if (!proxy)
-               return FALSE;
-
-       /* Clean up the process */
-       result = g_dbus_proxy_call_sync(proxy,
-                               "DisableAdapter",
-                               NULL,
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &error);
-
-       if (!result) {
-               if (error != NULL) {
-                       BT_ERR("Bt core call failed(Error: %s)", error->message);
-                       g_clear_error(&error);
-               } else {
-                       BT_ERR("Bt core call failed");
-               }
-               return FALSE;
-       }
-
-       g_variant_unref(result);
-       _bt_set_disabled(BLUETOOTH_ERROR_TIMEOUT);
-
-#ifndef USB_BLUETOOTH
-       _bt_terminate_service(NULL);
-#endif
-
-       return FALSE;
-}
-
-void _bt_adapter_start_enable_timer(void)
-{
-       if (timer_id > 0) {
-               g_source_remove(timer_id);
-               timer_id = 0;
-       }
-
-       timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
-                       __bt_enable_timeout_cb, NULL);
-
-       return;
-}
-
-static gboolean __bt_enable_le_timeout_cb(gpointer user_data)
-{
-       GDBusProxy *proxy;
-       GVariant *result;
-       GError *error = NULL;
-
-       le_timer_id = 0;
-
-       retv_if(_bt_adapter_get_le_status() == BT_LE_ACTIVATED, FALSE);
-
-       BT_ERR("EnableAdapterLE is failed");
-
-       proxy = __bt_get_core_proxy();
-       if (!proxy)
-               return FALSE;
-
-       /* Clean up the process */
-       result = g_dbus_proxy_call_sync(proxy,
-                               "DisableAdapterLe",
-                               NULL,
-                               G_DBUS_CALL_FLAGS_NONE,
-                               -1,
-                               NULL,
-                               &error);
-
-       if (!result) {
-               if (error != NULL) {
-                       BT_ERR("Bt core call failed(Error: %s)", error->message);
-                       g_clear_error(&error);
-               } else
-                       BT_ERR("Bt core call failed");
-               return FALSE;
-       }
-
-       g_variant_unref(result);
-       _bt_adapter_set_le_status(BT_LE_DEACTIVATED);
-
-       _bt_set_le_disabled(BLUETOOTH_ERROR_TIMEOUT);
-
-       if (_bt_adapter_get_status() == BT_DEACTIVATED)
-               _bt_terminate_service(NULL);
-
-       return FALSE;
-}
-
-void _bt_adapter_start_le_enable_timer(void)
-{
-       if (le_timer_id > 0) {
-               g_source_remove(le_timer_id);
-               le_timer_id = 0;
-       }
-
-       le_timer_id = g_timeout_add(BT_ENABLE_TIMEOUT,
-                       __bt_enable_le_timeout_cb, NULL);
-
-       return;
-}
-
 int _bt_get_local_address(void)
 {
        int result;
@@ -1253,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;
 }
 
@@ -1345,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;
 
@@ -1431,14 +1186,14 @@ static gboolean __bt_adapter_post_set_enabled(gpointer user_data)
                        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");
+       /* 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();
-       }
+       __bt_set_local_name();
 
        /* Get All properties */
        if (OAL_STATUS_SUCCESS != adapter_get_properties())
@@ -1571,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;
@@ -1710,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: {
@@ -1752,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: