apply FSL(Flora Software License)
[apps/home/call.git] / call-engine / voice-call-service.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include "voice-call-service.h"
19 #include "voice-call-dbus.h"
20 #include "vc-core-util.h"
21 #include "voice-call-core.h"
22 #include "voice-call-sound.h"
23 #include "voice-call-bt.h"
24
25 /**
26  * This function on the loud speaker state
27  *
28  * @return              gboolean
29  * @param[in]           pcall_core              Handle to voicecall core                
30  */
31 gboolean voicecall_service_loudspeaker_on(call_vc_core_state_t *pcall_core)
32 {
33         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core != NULL);
34         
35         gboolean bloud_speaker = FALSE;
36         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
37         gboolean ret = FALSE;
38         int total_call_member = -1;
39
40         CALL_ENG_DEBUG(ENG_DEBUG, "\n");
41
42         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
43         if (total_call_member == 0) {
44                 CALL_ENG_DEBUG(ENG_DEBUG, "There are not active calls hence it should not work \n");
45                 return FALSE;
46         }
47
48         /* Toggle the LoudSpeaker Status */
49 #ifdef _NEW_SND_
50         if (voicecall_snd_get_path_status(pcall_core->papp_snd) != VOICE_CALL_SND_PATH_SPEAKER) {
51                 if (TRUE == _vc_bt_is_bt_connected(pcall_core) && 
52                 (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_BT)) {
53                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_SPEAKER);
54 /*                      _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
55                         _vc_bt_request_switch_headset_path(pcall_core, FALSE);
56                 } else {
57                         voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_SPEAKER);
58                         voicecall_snd_change_path(papp_snd);
59                 }
60         } else {
61                 CALL_ENG_DEBUG(ENG_DEBUG, "loudspeacker is already on.\n");
62                 ret = FALSE;
63         }
64 #else
65         bloud_speaker = voicecall_snd_get_status(papp_snd, VOICE_CALL_AUDIO_SPEAKER);
66         if (bloud_speaker == FALSE) {
67                 CALL_ENG_DEBUG(ENG_DEBUG, "Change to Speaker On. \n");
68
69                 /*If current Path is Set to BT Headset, Change Path from Headset to Phone */
70                 if (TRUE == _vc_bt_is_bt_connected(pcall_core)) {
71                         if (TRUE == voicecall_snd_get_status(papp_snd, VOICE_CALL_AUDIO_HEADSET)) {
72                                 voicecall_snd_set_status(papp_snd, VOICE_CALL_AUDIO_HEADSET, FALSE);
73 /*                              _vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_PHONE, -1, NULL);*/
74                                 _vc_bt_request_switch_headset_path(pcall_core, FALSE);
75                                 voicecall_snd_change_path(papp_snd);
76                         }
77                 }
78
79                 voicecall_snd_set_status(papp_snd, VOICE_CALL_AUDIO_SPEAKER, TRUE);
80
81                 /* Change Audio Path according to the current status */
82                 voicecall_snd_change_path(papp_snd);
83                 ret = TRUE;
84         } else {
85                 CALL_ENG_DEBUG(ENG_DEBUG, "loudspeacker is already on.\n");
86                 ret = FALSE;
87         }
88 #endif
89         return ret;
90 }
91
92 /**
93  * This function off the loud speaker state
94  *
95  * @return              gboolean
96  * @param[in]           pcall_core              Handle to voicecall core                
97  */
98 gboolean voicecall_service_loudspeaker_off(call_vc_core_state_t *pcall_core)
99 {
100         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core != NULL);
101
102         gboolean bloud_speaker = FALSE;
103         gboolean ret = FALSE;
104         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
105         int total_call_member = -1;
106         voicecall_core_get_total_call_member(pcall_core->pcall_engine, &total_call_member);
107         if (total_call_member == 0) {
108                 CALL_ENG_DEBUG(ENG_DEBUG, "There are not active calls hence it should not work \n");
109                 return FALSE;
110         }
111
112         CALL_ENG_DEBUG(ENG_DEBUG, "\n");
113
114 #ifdef _NEW_SND_
115                 if (voicecall_snd_get_path_status(pcall_core->papp_snd) == VOICE_CALL_SND_PATH_SPEAKER) {
116                         if (TRUE == _vc_bt_is_bt_connected(pcall_core)) {
117                                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_BT);
118                                 /*_vc_bt_send_response_to_bt(pcall_core, BT_AG_RES_SWITCH_TO_HEADSET, -1, NULL);*/
119                                 _vc_bt_request_switch_headset_path(pcall_core, TRUE);
120                         } else {
121                                 voicecall_snd_set_path_status(pcall_core->papp_snd, VOICE_CALL_SND_PATH_RECEIVER);
122                                 voicecall_snd_change_path(papp_snd);
123                         }
124                 } else {
125                         CALL_ENG_DEBUG(ENG_DEBUG, "loudspeacker is already on.\n");
126                         ret = FALSE;
127                 }
128 #else
129
130         /* Toggle the LoudSpeaker Status */
131         bloud_speaker = voicecall_snd_get_status(papp_snd, VOICE_CALL_AUDIO_SPEAKER);
132         if (bloud_speaker == TRUE) {
133                 CALL_ENG_DEBUG(ENG_DEBUG, "Change to Speaker Off. \n");
134
135                 voicecall_snd_set_status(papp_snd, VOICE_CALL_AUDIO_SPEAKER, FALSE);
136
137                 /* Change Audio Path according to the current status */
138                 voicecall_snd_change_path(papp_snd);
139
140                 ret = TRUE;
141         } else {
142                 CALL_ENG_DEBUG(ENG_DEBUG, "loudspeacker is already off.\n");
143                 ret = FALSE;
144         }
145 #endif
146
147         return ret;
148 }
149
150 /**
151  * This function is mute on
152  *
153  * @return              void
154  * @param[in]           pcall_core              Handle to voicecall core                
155  */
156
157 gboolean voicecall_service_mute_status_on(call_vc_core_state_t *pcall_core)
158 {
159         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core != NULL);
160
161         gboolean bactive_calls = FALSE;
162         gboolean bheld_calls = FALSE;
163
164         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
165         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
166
167         CALL_ENG_DEBUG(ENG_DEBUG, "..\n");
168
169         voicecall_core_is_call_exists(pcall_engine, &bactive_calls, &bheld_calls);
170
171         if (FALSE == bactive_calls && TRUE == bheld_calls) {
172                 CALL_ENG_DEBUG(ENG_DEBUG, "nothing to do.\n");
173                 /*Mute button should not be handled if only held calls exists */
174                 return TRUE;
175         }
176
177         if (FALSE == papp_snd->bmute_status) {
178                 CALL_ENG_DEBUG(ENG_DEBUG, "Setting Voice Audio Mute Status On. \n");
179                 voicecall_core_set_audio_mute_status(pcall_engine, TRUE);
180                 papp_snd->bmute_status = TRUE;
181                 return TRUE;
182         } else {
183                 CALL_ENG_DEBUG(ENG_DEBUG, "mute status is already on.\n");
184                 return FALSE;
185         }
186
187 }
188
189 /**
190  * This function is mute off
191  *
192  * @return              void
193  * @param[in]           pcall_core              Handle to voicecall core                
194  */
195 gboolean voicecall_service_mute_status_off(call_vc_core_state_t *pcall_core)
196 {
197         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core != NULL);
198
199         gboolean bactive_calls = FALSE;
200         gboolean bheld_calls = FALSE;
201
202         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
203         voicecall_engine_t *pcall_engine = pcall_core->pcall_engine;
204
205         CALL_ENG_DEBUG(ENG_DEBUG, "..\n");
206
207         voicecall_core_is_call_exists(pcall_engine, &bactive_calls, &bheld_calls);
208
209         if (FALSE == bactive_calls && TRUE == bheld_calls) {
210                 CALL_ENG_DEBUG(ENG_DEBUG, "nothing to do.\n");
211                 /*Mute button should not be handled if only held calls exists */
212                 return TRUE;
213         }
214
215         if (TRUE == papp_snd->bmute_status) {
216                 CALL_ENG_DEBUG(ENG_DEBUG, "Setting Voice Audio Mute Status Off. \n");
217                 voicecall_core_set_audio_mute_status(pcall_engine, FALSE);
218                 papp_snd->bmute_status = FALSE;
219                 return TRUE;
220         } else {
221                 CALL_ENG_DEBUG(ENG_DEBUG, "mute status is already off.\n");
222                 return FALSE;
223         }
224
225 }
226
227 /**
228  * This function set volume level.
229  *
230  * @return              Returns TRUE on success or FALSE on failure
231  * @param[in]           pcall_core                      Handle to voicecall core                
232  * @param[in]           vol_alert_type                  volume alert type
233  * @param[in]           volume_level                    volume level to be set
234  */
235 gboolean voicecall_service_set_volume(call_vc_core_state_t *pcall_core, voicecall_snd_volume_alert_type_t vol_alert_type, int volume_level)
236 {
237         VOICECALL_RETURN_FALSE_IF_FAIL(pcall_core != NULL);
238
239         voicecall_snd_mgr_t *papp_snd = pcall_core->papp_snd;
240
241         voicecall_snd_set_volume(papp_snd, vol_alert_type, volume_level);
242
243         return TRUE;
244 }