4 * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Nilesh Trimbake <t.shripati@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"
32 #include "bt-hal-a2dp-sink-dbus-handler.h"
34 static const btav_callbacks_t *bt_hal_a2dp_sink_cbacks;
36 static bool interface_ready(void)
38 return bt_hal_a2dp_sink_cbacks != NULL;
41 static bt_status_t a2dp_sink_connect(bt_bdaddr_t *bd_addr)
44 return _bt_hal_dbus_handler_a2dp_sink_connect(bd_addr);
47 static bt_status_t a2dp_sink_disconnect(bt_bdaddr_t *bd_addr)
50 return _bt_hal_dbus_handler_a2dp_sink_disconnect(bd_addr);
53 static void __bt_hal_handle_a2dp_sink_conn_state(void *buf, uint16_t len)
55 struct hal_ev_a2dp_conn_state *ev = buf;
57 if (bt_hal_a2dp_sink_cbacks->connection_state_cb)
58 bt_hal_a2dp_sink_cbacks->connection_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
61 static void __bt_hal_handle_a2dp_sink_audio_conn_state(void *buf, uint16_t len)
63 struct hal_ev_a2dp_audio_state *ev = buf;
65 if (bt_hal_a2dp_sink_cbacks->audio_state_cb)
66 bt_hal_a2dp_sink_cbacks->audio_state_cb(ev->state, (bt_bdaddr_t *) ev->bdaddr);
69 static void __bt_hal_handle_a2dp_sink_events(int message, void *buf, uint16_t len)
72 if (!interface_ready())
75 case HAL_EV_A2DP_SOURCE_CONN_STATE:
76 DBG("Event: HAL_EV_A2DP_SOURCE_CONN_STATE");
77 __bt_hal_handle_a2dp_sink_conn_state(buf, len);
79 case HAL_EV_A2DP_AUDIO_STATE:
80 DBG("Event: HAL_EV_A2DP_AUDIO_STATE");
81 __bt_hal_handle_a2dp_sink_audio_conn_state(buf, len);
84 DBG("Event Currently not handled!!");
90 static bt_status_t init(btav_callbacks_t* callbacks)
94 int ret = BT_STATUS_SUCCESS;
96 if (interface_ready())
97 return BT_STATUS_DONE;
99 ret = _bt_hal_dbus_handler_enable_a2dp_sink();
101 if (ret != BT_STATUS_SUCCESS && ret != BT_STATUS_DONE) {
102 ERR("_bt_hal_dbus_handler_enable_a2dp_sink failed");
103 return BT_STATUS_FAIL;
106 bt_hal_a2dp_sink_cbacks = callbacks;
107 DBG("Register A2DP Sink events callback function");
108 _bt_hal_register_a2dp_sink_dbus_handler_cb(__bt_hal_handle_a2dp_sink_events);
109 _bt_hal_register_event_handler_cb(HAL_A2DP_SNK, __bt_hal_handle_a2dp_sink_events);
110 return BT_STATUS_SUCCESS;
113 static void cleanup(void)
117 if (!interface_ready())
120 bt_hal_a2dp_sink_cbacks = NULL;
121 _bt_hal_unregister_event_handler_cb(HAL_A2DP_SNK);
124 static btav_interface_t a2dp_sink_if = {
125 .size = sizeof(a2dp_sink_if),
127 .connect = a2dp_sink_connect,
128 .disconnect = a2dp_sink_disconnect,
132 btav_interface_t *bt_get_a2dp_sink_interface(void)
134 DBG("Get A2DP Sink Profile Interface");
135 return &a2dp_sink_if;