Fix bt-service crash on Fhub TCT
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-main.c
old mode 100755 (executable)
new mode 100644 (file)
index 3c68e78..ea8748a
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -80,7 +74,7 @@ static void __bt_core_sigterm_handler(int signo)
 static gboolean __bt_check_bt_core(void *data)
 {
        int bt_status = VCONFKEY_BT_STATUS_OFF;
-       int bt_le_status = 0;
+       int bt_le_status = VCONFKEY_BT_LE_STATUS_OFF;
        bt_status_t status = BT_DEACTIVATED;
        bt_le_status_t le_status = BT_LE_DEACTIVATED;
        int flight_mode_deactivation = 0;
@@ -91,14 +85,12 @@ static gboolean __bt_check_bt_core(void *data)
        le_status = _bt_core_get_le_status();
        BT_DBG("State: %d, LE State: %d", status, le_status);
 
-       if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0) {
+       if (vconf_get_int(VCONFKEY_BT_STATUS, &bt_status) < 0)
                BT_DBG("no bluetooth device info, so BT was disabled at previous session");
-       }
 
 #ifdef ENABLE_TIZEN_2_4
-       if (vconf_get_int(VCONFKEY_BT_LE_STATUS, &bt_le_status) < 0) {
+       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");
-       }
 #endif
 
        if (vconf_get_int(BT_OFF_DUE_TO_FLIGHT_MODE, &flight_mode_deactivation) != 0)
@@ -110,28 +102,32 @@ static gboolean __bt_check_bt_core(void *data)
        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)) {
+       if ((bt_status != VCONFKEY_BT_STATUS_OFF || bt_off_due_to_timeout) &&
+               (status == BT_DEACTIVATED)) {
                BT_DBG("Previous session was enabled.");
-
+#if 0
                /* Enable the BT */
                _bt_core_service_request_adapter(BT_ENABLE_ADAPTER);
-               _bt_enable_adapter();
+               if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                       _bt_enable_adapter();
+#endif
        } else if (bt_status == VCONFKEY_BT_STATUS_OFF &&
                        (flight_mode_deactivation == 1 || ps_mode_deactivation > 0)) {
-               _bt_core_handle_flight_mode_noti();
+               //_bt_core_handle_flight_mode_noti();
                _bt_core_handle_power_saving_mode_noti();
 
                _bt_core_set_bt_status(BT_FLIGHT_MODE, flight_mode_deactivation);
                _bt_core_set_bt_status(BT_POWER_SAVING_MODE, ps_mode_deactivation);
        }
 
-       if ((bt_le_status == 1) && (le_status == BT_LE_DEACTIVATED)) {
+       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 0
                /* Enable the BT LE */
                _bt_core_service_request_adapter(BT_ENABLE_ADAPTER_LE);
-               _bt_enable_adapter_le();
+               if (!TIZEN_FEATURE_BT_USB_DONGLE)
+                       _bt_enable_adapter_le();
+#endif
        } else {
                status = _bt_core_get_status();
                le_status = _bt_core_get_le_status();
@@ -147,51 +143,41 @@ static gboolean __bt_check_bt_core(void *data)
 
 int main(void)
 {
-       DBusGConnection *conn = NULL;
-       GError *error = NULL;
-       BtCore *bt_core = NULL;
-
-       DBusGProxy *dbus_proxy = NULL;
+       gboolean ret;
        struct sigaction sa;
 
-       g_type_init();
        BT_INFO_C("Starting bt-core daemeon");
 
-       conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
-       if (error != NULL) {
-               BT_ERR("ERROR: Can't get on system bus [%s]", error->message);
-               g_error_free(error);
-               goto fail;
-       }
-
-       bt_core = g_object_new(BT_CORE_TYPE, NULL);
+       _bt_core_update_status();
 
-       dbus_proxy = _bt_core_register_event_filter(conn, bt_core);
-       if (!dbus_proxy) {
-               BT_ERR("__bt_core_register_event_filter failed");
-               g_object_unref(bt_core);
-               bt_core = NULL;
+       ret = _bt_core_register_dbus();
+       if (!ret) {
+               BT_ERR("_bt_core_register_dbus failed");
                goto fail;
        }
 
+
        memset(&sa, 0, sizeof(sa));
        sa.sa_handler = __bt_core_sigterm_handler;
        sigaction(SIGINT, &sa, NULL);
        sigaction(SIGTERM, &sa, NULL);
 
        g_timeout_add(500, (GSourceFunc)__bt_check_bt_core, NULL);
+
        main_loop = g_main_loop_new(NULL, FALSE);
+       if (!main_loop) {
+               BT_ERR("creating main loop failed");
+               goto fail;
+       }
+
        g_main_loop_run(main_loop);
 
 fail:
-
-       _bt_unregister_event_filter(conn, bt_core, dbus_proxy);
+       _bt_core_unregister_dbus();
 
        if (main_loop)
                g_main_loop_unref(main_loop);
 
-       dbus_g_connection_unref(conn);
-
        BT_INFO_C("Terminating bt-core daemon");
 
        return 0;