Support audio_set_message_cb() and call the callback with variables for loopback
[platform/adaptation/hawkp/audio-hal-hawkp.git] / tizen-audio-comm.c
1 /*
2  * audio-hal
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  */
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include "tizen-audio-internal.h"
24
25 audio_return_t _audio_comm_send_message(audio_hal_t *ah, const char *name, int value)
26 {
27     audio_return_t audio_ret = AUDIO_RET_OK;
28
29     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
30     AUDIO_RETURN_VAL_IF_FAIL(name, AUDIO_ERR_PARAMETER);
31
32     AUDIO_LOG_DEBUG("send message : name(%s), value(%d)", name, value);
33     if (ah->comm.msg_cb) {
34         ah->comm.msg_cb(name, value, ah->comm.user_data);
35     }
36
37     return audio_ret;
38 }
39
40 audio_return_t _audio_comm_set_message_callback(audio_hal_t *ah, message_cb callback, void *user_data)
41 {
42     audio_return_t audio_ret = AUDIO_RET_OK;
43
44     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
45     AUDIO_RETURN_VAL_IF_FAIL(callback, AUDIO_ERR_PARAMETER);
46
47     ah->comm.msg_cb = callback;
48     ah->comm.user_data = user_data;
49
50     AUDIO_LOG_DEBUG("message callback is set, callback(%p), user_data(%p)", ah->comm.msg_cb, ah->comm.user_data);
51
52     return audio_ret;
53 }
54
55 audio_return_t _audio_comm_unset_message_callback(audio_hal_t *ah)
56 {
57     audio_return_t audio_ret = AUDIO_RET_OK;
58
59     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
60
61     ah->comm.msg_cb = NULL;
62     ah->comm.user_data = NULL;
63
64     AUDIO_LOG_DEBUG("message callback is unset");
65
66     return audio_ret;
67 }
68
69 audio_return_t _audio_comm_init(audio_hal_t *ah)
70 {
71     audio_return_t audio_ret = AUDIO_RET_OK;
72
73     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
74
75     ah->comm.msg_cb = NULL;
76     ah->comm.user_data = NULL;
77
78     return audio_ret;
79 }
80
81 audio_return_t _audio_comm_deinit(audio_hal_t *ah)
82 {
83     audio_return_t audio_ret = AUDIO_RET_OK;
84
85     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
86
87     ah->comm.msg_cb = NULL;
88     ah->comm.user_data = NULL;
89
90     return audio_ret;
91 }