X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=bt-service%2Fbt-service-main.c;h=e4a29d234b612860599ee4f47e52e842775b163c;hb=604fbd7fc8b48cc594017fb6d8b77c378f3e0cca;hp=9a622da192759cef06320634003c1aa9f6d19d6b;hpb=ebf6c718979c3fea4040b338154b1eb3b5c28f96;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git diff --git a/bt-service/bt-service-main.c b/bt-service/bt-service-main.c index 9a622da..e4a29d2 100644 --- a/bt-service/bt-service-main.c +++ b/bt-service/bt-service-main.c @@ -45,6 +45,7 @@ static void __on_log_glib(const gchar *log_domain, GLogLevelFlags log_level, static void __bt_release_service(void) { _bt_service_unregister_vconf_handler(); + _bt_service_unregister_poweroff_event(); _bt_service_adapter_le_deinit(); _bt_deinit_service_event_sender(); @@ -70,7 +71,7 @@ static void __bt_sigterm_handler(int signo, siginfo_t *info, void *data) { BT_INFO("signal [%d] is sent by [%d]", signo, info->si_pid); -#ifndef TIZEN_PROFILE_TV +#ifndef TIZEN_TV int ret; ret = _bt_recover_adapter(); if (ret != BLUETOOTH_ERROR_NONE) @@ -123,70 +124,83 @@ gboolean _bt_reliable_terminate_service(gpointer user_data) static gboolean __bt_check_bt_service(void *data) { - bt_status_t status = BT_DEACTIVATED; - bt_le_status_t le_status = BT_LE_DEACTIVATED; -#ifndef TIZEN_PROFILE_TV - int bt_status = VCONFKEY_BT_STATUS_OFF; - int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF; - int flight_mode_deactivation = 0; - int bt_off_due_to_timeout = 0; -#endif + bt_status_t status = BT_DEACTIVATED; + bt_le_status_t le_status = BT_LE_DEACTIVATED; + int bt_status = VCONFKEY_BT_STATUS_OFF; + int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF; + int flight_mode_deactivation = 0; + int bt_off_due_to_timeout = 0; #if 0 - int ps_mode_deactivation = 0; + int ps_mode_deactivation = 0; #endif - status = _bt_adapter_get_status(); - le_status = _bt_adapter_get_le_status(); - BT_DBG("State: %d, LE State: %d", status, le_status); + if (_is_name_acquired() == FALSE) { + BT_ERR("dbus name is NOT acquired yet"); + return TRUE; + } -#ifdef TIZEN_PROFILE_TV - if (_bt_get_enable_timer_id() == 0) - _bt_enable_adapter(); -#else - if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) - BT_DBG("no bluetooth device info, so BT was disabled at previous session"); + status = _bt_adapter_get_status(); + le_status = _bt_adapter_get_le_status(); + BT_DBG("State: %d, LE State: %d", status, le_status); - if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) - BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); + if (TIZEN_PROFILE_TV) { + if (_bt_get_enable_timer_id() == 0) + _bt_enable_adapter(); + } else { + if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) + BT_DBG("no bluetooth device info, so BT was disabled at previous session"); - if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0) - BT_ERR("Fail to get the flight_mode_deactivation value"); + if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) + BT_ERR("no bluetooth le info, so BT LE was disabled at previous session"); + + if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0) + BT_ERR("Fail to get the flight_mode_deactivation value"); #if 0 - if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_deactivation) != 0) - BT_ERR("Fail to get the ps_mode_deactivation value"); + if (vconf_get_int(BT_OFF_DUE_TO_POWER_SAVING_MODE, &ps_mode_deactivation) != 0) + BT_ERR("Fail to get the ps_mode_deactivation value"); + } #endif - if (vconf_get_int(BT_OFF_DUE_TO_TIMEOUT, &bt_off_due_to_timeout) != 0) - BT_ERR("Fail to get BT_OFF_DUE_TO_TIMEOUT"); + if (vconf_get_int(BT_OFF_DUE_TO_TIMEOUT, &bt_off_due_to_timeout) != 0) + BT_ERR("Fail to get BT_OFF_DUE_TO_TIMEOUT"); - if ((bt_status != VCONFKEY_BT_STATUS_OFF || bt_off_due_to_timeout) && - (status == BT_DEACTIVATED)) { - BT_DBG("Previous session was enabled."); + if (bt_off_due_to_timeout) { + /* Set the vconf flag to 0 here, if BT need to be enabled + bt_off_due_to_timeout variable already hold the old value */ - /* Enable the BT */ - _bt_enable_adapter(); - } else if (bt_status == VCONFKEY_BT_STATUS_OFF && flight_mode_deactivation == 1) { - _bt_enable_core(); - } + if (vconf_set_int(BT_OFF_DUE_TO_TIMEOUT, 0) != 0) + BT_ERR("Set vconf failed"); + } - if ((bt_le_status == VCONFKEY_BT_LE_STATUS_ON) && (le_status == BT_LE_DEACTIVATED)) { - BT_DBG("Previous session was le enabled. Turn BT LE on automatically."); - /* Enable the BT LE */ - _bt_enable_adapter_le(); - } else { - status = _bt_adapter_get_status(); - le_status = _bt_adapter_get_le_status(); - BT_DBG("State: %d, LE State: %d", status, le_status); + if ((bt_status != VCONFKEY_BT_STATUS_OFF || bt_off_due_to_timeout) && + (status == BT_DEACTIVATED)) { + BT_DBG("Previous session was enabled."); + + /* Enable the BT */ + _bt_enable_adapter(); + } else if (bt_status == VCONFKEY_BT_STATUS_OFF && flight_mode_deactivation == 1) { + _bt_enable_core(); + } + + if ((bt_le_status == VCONFKEY_BT_LE_STATUS_ON) && (le_status == BT_LE_DEACTIVATED)) { + BT_DBG("Previous session was le enabled. Turn BT LE on automatically."); - if ((status != BT_ACTIVATING && status != BT_ACTIVATED) && - (le_status != BT_LE_ACTIVATING && le_status != BT_LE_ACTIVATED)) { - _bt_terminate_service(NULL); + /* Enable the BT LE */ + _bt_enable_adapter_le(); + } else { + status = _bt_adapter_get_status(); + le_status = _bt_adapter_get_le_status(); + BT_DBG("State: %d, LE State: %d", status, le_status); + + if ((status != BT_ACTIVATING && status != BT_ACTIVATED) && + (le_status != BT_LE_ACTIVATING && le_status != BT_LE_ACTIVATED)) { + _bt_terminate_service(NULL); + } + } } - } -#endif - return FALSE; + return FALSE; } int _bt_service_initialize(void) @@ -203,6 +217,7 @@ int _bt_service_initialize(void) } _bt_service_register_vconf_handler(); + _bt_service_register_poweroff_event(); /* Event reciever Init */ ret = _bt_init_service_event_receiver();