2 * Copyright (c) 2015 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Anupam Roy <anupam.r@samsung.com>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include <vconf-internal-keys.h>
27 #include <syspopup_caller.h>
29 #include <eventsystem.h>
30 #include <bundle_internal.h>
32 /*bt-service headers */
33 #include "bt-internal-types.h"
34 #include "bt-service-common.h"
35 #include "bt-service-util.h"
36 #include "bt-service-main.h"
37 #include "bt-service-core-adapter.h"
38 #include "bt-service-event-receiver.h"
39 #include "bt-request-handler.h"
40 #include "bt-service-event.h"
43 #include <oal-event.h>
44 #include <oal-manager.h>
45 #include <oal-adapter-mgr.h>
47 #define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
49 /*This file will contain state machines related to adapter and remote device */
51 /* Forward declarations */
52 static void __bt_adapter_event_handler(int event_type, gpointer event_data);
53 static void __bt_post_oal_init(void);
54 static void __bt_handle_oal_initialisation(oal_event_t event);
56 /* Initialize BT stack (Initialize OAL layer) */
57 int _bt_stack_init(void)
61 BT_INFO("[bt-service] Start to initialize BT stack");
62 /* Adapter enable request is successful, setup event handlers */
63 _bt_service_register_event_handler_callback(
64 BT_ADAPTER_MODULE, __bt_adapter_event_handler);
66 ret = oal_bt_init(_bt_service_oal_event_receiver);
68 if (OAL_STATUS_PENDING == ret) {
69 BT_INFO("OAL Initialisation Pending, Profiles Init will be done once oal initialised...");
70 return BLUETOOTH_ERROR_NONE;
71 } else if (OAL_STATUS_SUCCESS != ret) {
72 _bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
73 return BLUETOOTH_ERROR_INTERNAL;
77 return BLUETOOTH_ERROR_NONE;
80 static void __bt_adapter_event_handler(int event_type, gpointer event_data)
85 case OAL_EVENT_OAL_INITIALISED_SUCCESS:
86 case OAL_EVENT_OAL_INITIALISED_FAILED:
87 __bt_handle_oal_initialisation(event_type);
90 BT_ERR("Unhandled event..");
95 /* OAL post initialization handler */
96 static void __bt_post_oal_init(void)
98 BT_DBG("OAL initialized, Init profiles..");
103 /* OAL initialization handler */
104 static void __bt_handle_oal_initialisation(oal_event_t event)
109 case OAL_EVENT_OAL_INITIALISED_SUCCESS:
110 __bt_post_oal_init();
112 case OAL_EVENT_OAL_INITIALISED_FAILED:
113 BT_ERR("OAL Initialisation Failed, terminate bt-service daemon..");
114 g_idle_add(_bt_terminate_service, NULL);
117 BT_ERR("Unknown Event");