4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Anupam Roy <anupam.r@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "bt-hal-log.h"
30 #include "bt-hal-msg.h"
31 #include "bt-hal-utils.h"
33 #include "bt-hal-av-dbus-handler.h"
35 static const btav_callbacks_t *bt_hal_av_cbacks;
37 static bool interface_ready(void)
39 return bt_hal_av_cbacks != NULL;
42 static bt_status_t av_connect(bt_bdaddr_t *bd_addr)
45 return _bt_hal_dbus_handler_av_connect(bd_addr);
48 static bt_status_t av_disconnect(bt_bdaddr_t *bd_addr)
51 return _bt_hal_dbus_handler_av_disconnect(bd_addr);
54 static void __bt_hal_handle_av_conn_state(void *buf, uint16_t len)
56 struct hal_ev_a2dp_conn_state *ev = buf;
58 if (bt_hal_av_cbacks->connection_state_cb)
59 bt_hal_av_cbacks->connection_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
62 static void __bt_hal_handle_av_audio_conn_state(void *buf, uint16_t len)
64 struct hal_ev_a2dp_audio_state *ev = buf;
66 if (bt_hal_av_cbacks->audio_state_cb)
67 bt_hal_av_cbacks->audio_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
70 static void __bt_hal_handle_av_events(int message, void *buf, uint16_t len)
73 if (!interface_ready())
76 case HAL_EV_A2DP_CONN_STATE:
77 DBG("Event: HAL_EV_A2DP_CONN_STATE");
78 __bt_hal_handle_av_conn_state(buf, len);
80 case HAL_EV_A2DP_AUDIO_STATE:
81 DBG("Event: HAL_EV_A2DP_AUDIO_STATE");
82 __bt_hal_handle_av_audio_conn_state(buf, len);
85 DBG("Event Currently not handled!!");
91 static bt_status_t init(btav_callbacks_t* callbacks)
95 int ret = BT_STATUS_SUCCESS;
97 if (interface_ready())
98 return BT_STATUS_DONE;
100 ret = _bt_hal_dbus_handler_enable_a2dp_source();
102 if (ret != BT_STATUS_SUCCESS && ret != BT_STATUS_DONE) {
103 ERR("_bt_hal_dbus_handler_enable_a2dp_source failed");
104 return BT_STATUS_FAIL;
107 bt_hal_av_cbacks = callbacks;
108 DBG("Register A2DP Src events callback function");
109 _bt_hal_register_av_dbus_handler_cb(__bt_hal_handle_av_events);
110 _bt_hal_register_event_handler_cb(HAL_A2DP_SRC, __bt_hal_handle_av_events);
111 return BT_STATUS_SUCCESS;
114 static void cleanup(void)
118 if (!interface_ready())
121 _bt_hal_unregister_event_handler_cb(HAL_A2DP_SRC);
122 bt_hal_av_cbacks = NULL;
125 static btav_interface_t av_if = {
126 .size = sizeof(av_if),
128 .connect = av_connect,
129 .disconnect = av_disconnect,
133 btav_interface_t *bt_get_av_interface(void)
135 DBG("Get A2DP Src Profile Interface");