Fix condition check macro to support multiple expression.
[platform/adaptation/spreadtrum/audio-hal-sc7727.git] / tizen-audio.c
1 /*
2  * audio-hal
3  *
4  * Copyright (c) 2015 - 2016 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
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 #include "tizen-audio-internal.h"
25
26 audio_return_t audio_init(void **audio_handle)
27 {
28     audio_hal_t *ah;
29     audio_return_t ret = AUDIO_RET_OK;
30
31     AUDIO_RETURN_VAL_IF_FAIL(audio_handle, AUDIO_ERR_PARAMETER);
32
33     if (!(ah = malloc(sizeof(audio_hal_t)))) {
34         AUDIO_LOG_ERROR("failed to malloc()");
35         return AUDIO_ERR_RESOURCE;
36     }
37
38     if ((ret = _audio_ctrl_init(ah))) {
39         AUDIO_LOG_ERROR("failed to _audio_ctrl_init(), ret(0x%x)", ret);
40         goto error_exit;
41     }
42     if ((ret = _audio_volume_init(ah))) {
43         AUDIO_LOG_ERROR("failed to _audio_volume_init(), ret(0x%x)", ret);
44         goto error_exit;
45     }
46     if ((ret = _audio_routing_init(ah))) {
47         AUDIO_LOG_ERROR("failed to _audio_routing_init(), ret(0x%x)", ret);
48         goto error_exit;
49     }
50     if ((ret = _audio_stream_init(ah))) {
51         AUDIO_LOG_ERROR("failed to _audio_stream_init(), ret(0x%x)", ret);
52         goto error_exit;
53     }
54     if ((ret = _audio_pcm_init(ah))) {
55         AUDIO_LOG_ERROR("failed to _audio_pcm_init(), ret(0x%x)", ret);
56         goto error_exit;
57     }
58     if ((ret = _audio_modem_init(ah))) {
59         AUDIO_LOG_ERROR("failed to _audio_modem_init(), ret(0x%x)", ret);
60         goto error_exit;
61     }
62     if ((ret = _audio_comm_init(ah))) {
63         AUDIO_LOG_ERROR("failed to _audio_comm_init(), ret(0x%x)", ret);
64         goto error_exit;
65     }
66
67     *audio_handle = (void *)ah;
68     return AUDIO_RET_OK;
69
70 error_exit:
71     if (ah)
72         free(ah);
73
74     return ret;
75 }
76
77 audio_return_t audio_deinit(void *audio_handle)
78 {
79     audio_hal_t *ah = (audio_hal_t *)audio_handle;
80
81     AUDIO_RETURN_VAL_IF_FAIL(ah, AUDIO_ERR_PARAMETER);
82
83     _audio_volume_deinit(ah);
84     _audio_routing_deinit(ah);
85     _audio_stream_deinit(ah);
86     _audio_pcm_deinit(ah);
87     _audio_modem_deinit(ah);
88     _audio_comm_deinit(ah);
89     _audio_ctrl_deinit(ah);
90
91     free(ah);
92     ah = NULL;
93
94     return AUDIO_RET_OK;
95 }