Make TIZEN 2.0
[apps/home/call.git] / call-engine / voice-call-engine.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-engine.h"
19 #include "voice-call-core.h"
20 #include "voice-call-service.h"
21 #include "voice-call-dbus.h"
22 #include "voice-call-device.h"
23 #include "vc-core-util.h"
24 #include "vc-core-engine-types.h"
25 #include "vc-core-engine-status.h"
26 #include "vc-core-engine-group.h"
27
28 typedef struct {
29         void *puser_data;
30         vcall_engine_app_cb cb_func;
31 } app_cb_t;
32
33 call_vc_core_state_t *global_pcall_core = NULL;
34
35 static app_cb_t *app_client_data = NULL;
36
37 /**
38  * This function send events to client.
39  *
40  * @return      int     API Result Code.
41  * @param[in]
42 */
43 gboolean vcall_engine_send_event_to_client(int event, void *pdata)
44 {
45         CALL_ENG_DEBUG(ENG_DEBUG, "..");
46         if (app_client_data->cb_func != NULL) {
47                 CALL_ENG_DEBUG(ENG_DEBUG, "Sending Event to APP Client");
48                 app_client_data->cb_func(event, pdata, app_client_data->puser_data);
49         }
50         CALL_ENG_DEBUG(ENG_ERR, "End..");
51         return TRUE;
52 }
53
54 /**
55  * This function initialize voice call engine.
56  *
57  * @return      int     API Result Code.
58  * @param[in]
59 */
60 int vcall_engine_init(vcall_engine_app_cb pcb_func, void *puser_data)
61 {
62         CALL_ENG_DEBUG(ENG_WARN, "..");
63
64         global_pcall_core = (call_vc_core_state_t *)calloc(1, sizeof(call_vc_core_state_t));
65         if (global_pcall_core == NULL) {
66                 CALL_ENG_DEBUG(ENG_ERR, "Memory Allocation Failed");
67                 return VCALL_ENGINE_API_FAILED;
68         }
69         CALL_ENG_DEBUG(ENG_DEBUG, "global_pcall_core alloctated memory:[%d],global_pcall_core(0x%x)", sizeof(call_vc_core_state_t), global_pcall_core);
70
71         if (FALSE == voicecall_core_init(global_pcall_core)) {
72                 CALL_ENG_DEBUG(ENG_DEBUG, "voicecall_core_init() failed");
73                 return VCALL_ENGINE_API_FAILED;
74         }
75
76         app_client_data = (app_cb_t *) calloc(1, sizeof(app_cb_t));
77         if (app_client_data == NULL) {
78                 CALL_ENG_DEBUG(ENG_ERR, "Memory Allocation Failed");
79                 return VCALL_ENGINE_API_FAILED;
80         }
81         app_client_data->cb_func = pcb_func;
82         app_client_data->puser_data = puser_data;
83
84         CALL_ENG_DEBUG(ENG_DEBUG, "Init dbus connection");
85         vc_engine_dbus_receiver_setup();
86         return VCALL_ENGINE_API_SUCCESS;
87
88 }
89
90 /**
91  * This function processes mo nomal call.
92  *
93  * @return      int     API Result Code.
94  * @param[in]
95 */
96 int vcall_engine_process_normal_call(char *number, int ct_index, gboolean b_download_call)
97 {
98         CALL_ENG_DEBUG(ENG_DEBUG, " number is (%s)", number);
99         voicecall_engine_t *pcall_engine = global_pcall_core->pcall_engine;
100         vc_engine_outgoing_type event_data;
101         char number_after_removal[VC_PHONE_NUMBER_LENGTH_MAX] = {"\0",};
102         int io_state;
103
104         if (number == NULL || pcall_engine == NULL)
105                 return VCALL_ENGINE_API_FAILED;
106
107         _vc_core_engine_status_set_download_call(pcall_engine, b_download_call);
108
109         /* check the call-engine state before proceeding with call processing */
110         _vc_core_engine_status_get_engine_iostate(pcall_engine, &io_state);
111         if (io_state != VC_INOUT_STATE_NONE) {
112                 CALL_ENG_DEBUG(ENG_DEBUG, "IO State [%d] not NONE, cannot proceed with the call", io_state);
113                 voicecall_core_set_status(global_pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
114                 vc_engine_msg_box_type mbox_event_data;
115
116                 memset(&mbox_event_data, 0, sizeof(mbox_event_data));
117                 mbox_event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
118                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&mbox_event_data);
119                 return VCALL_ENGINE_API_FAILED;
120         }
121
122         memset(&(global_pcall_core->call_setup_info), 0, sizeof(global_pcall_core->call_setup_info));
123         global_pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
124         global_pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_NORMAL;
125
126         memset(&event_data, 0, sizeof(event_data));
127
128         _vc_core_util_remove_invalid_chars(number, number_after_removal);
129         snprintf(global_pcall_core->call_setup_info.source_tel_number, VC_PHONE_NUMBER_LENGTH_MAX, "%s", number_after_removal);
130         voicecall_core_extract_phone_number(number_after_removal, event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX);
131
132         if (strlen(event_data.call_num) >= VC_PHONE_NUMBER_LENGTH_MAX) {
133                 CALL_ENG_DEBUG(ENG_ERR, " WARNING!! number is larger than max num length!!");
134                 memcpy(global_pcall_core->call_setup_info.tel_number, event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX-1);
135         } else {
136                 memcpy(global_pcall_core->call_setup_info.tel_number, event_data.call_num, strlen(event_data.call_num));
137         }
138         CALL_ENG_DEBUG(ENG_DEBUG, "number:[%s]", number);
139         CALL_ENG_DEBUG(ENG_DEBUG, "number_after_removal:[%s]", number_after_removal);
140         CALL_ENG_DEBUG(ENG_DEBUG, "global_pcall_core->call_setup_info.source_tel_number:[%s]", global_pcall_core->call_setup_info.source_tel_number);
141         CALL_ENG_DEBUG(ENG_DEBUG, "global_pcall_core->call_setup_info.tel_number:[%s]", global_pcall_core->call_setup_info.tel_number);
142         CALL_ENG_DEBUG(ENG_DEBUG, "event_data.call_num:[%s]", event_data.call_num);
143
144         {
145                 voicecall_contact_info_t ct_info;
146                 memset(&ct_info, 0, sizeof(ct_info));
147
148                 ct_info.ct_index = ct_index;
149
150                 voicecall_service_contact_info_by_number(event_data.call_num, &ct_info);
151                 event_data.contact_index = ct_info.ct_index;
152                 event_data.phone_type = ct_info.phone_type;
153                 event_data.bday_remaining_days = ct_info.bday_remaining_days;
154
155                 _vc_core_util_strcpy(event_data.call_name, sizeof(event_data.call_name), ct_info.display_name);
156                 _vc_core_util_strcpy(event_data.call_file_path, sizeof(event_data.call_file_path), ct_info.caller_id_path);
157                 _vc_core_util_strcpy(event_data.call_full_file_path, sizeof(event_data.call_full_file_path), ct_info.caller_full_id_path);
158                 CALL_ENG_DEBUG(ENG_DEBUG, " contact copy ended!!");
159         }
160         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_TO_UI, (void *)&event_data);
161
162         if (voicecall_core_setup_call(global_pcall_core, FALSE)) {
163                 CALL_ENG_DEBUG(ENG_DEBUG, " success!!");
164         } else {
165                 CALL_ENG_DEBUG(ENG_DEBUG, " failed!!");
166         }
167         return VCALL_ENGINE_API_SUCCESS;
168
169 }
170
171 /**
172  * This function processes mo emergency call.
173  *
174  * @return      int     API Result Code.
175  * @param[in]
176 */
177 int vcall_engine_process_emergency_call(char *number)
178 {
179         CALL_ENG_DEBUG(ENG_DEBUG, " number is : [%s]", number);
180         voicecall_engine_t *pcall_engine = global_pcall_core->pcall_engine;
181         gboolean bDefaultNumber = FALSE;
182         vc_engine_outgoing_type event_data;
183         int io_state;
184
185         /* check the call-engine state before proceeding with emergency call processing */
186         _vc_core_engine_status_get_engine_iostate(pcall_engine, &io_state);
187         if (io_state != VC_INOUT_STATE_NONE) {
188                 CALL_ENG_DEBUG(ENG_DEBUG, "IO State [%d] not NONE, cannot proceed with the call", io_state);
189                 voicecall_core_set_status(global_pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
190                 vc_engine_msg_box_type mbox_event_data;
191
192                 memset(&mbox_event_data, 0, sizeof(mbox_event_data));
193                 mbox_event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
194                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&mbox_event_data);
195                 return VCALL_ENGINE_API_FAILED;
196         }
197
198         memset(&event_data, 0, sizeof(event_data));
199
200         memset(&(global_pcall_core->call_setup_info), 0, sizeof(global_pcall_core->call_setup_info));
201
202         bDefaultNumber = strlen(number) ? FALSE : TRUE;
203         if (bDefaultNumber == TRUE) {
204                 global_pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
205                 global_pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_EMERGENCY;
206                 if (strlen("911") < sizeof(event_data.call_num))
207                         _vc_core_util_strcpy(event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX, "911");
208
209                 memcpy(global_pcall_core->call_setup_info.tel_number, "911", strlen("911"));
210         } else {
211                 global_pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
212                 global_pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_PINLOCK;
213                 voicecall_core_extract_phone_number(number, event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX);
214                 if (strlen(number) > VC_PHONE_NUMBER_LENGTH_MAX) {
215                         CALL_ENG_DEBUG(ENG_ERR, " WARNING!! number is larger than max num length!!");
216                         memcpy(global_pcall_core->call_setup_info.source_tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
217                         memcpy(global_pcall_core->call_setup_info.tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
218                 } else {
219                         memcpy(global_pcall_core->call_setup_info.source_tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
220                         memcpy(global_pcall_core->call_setup_info.tel_number, number, strlen(number));
221                 }
222         }
223
224         event_data.contact_index = -1;
225         event_data.phone_type = -1;
226         event_data.bday_remaining_days = -1;
227
228         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_TO_UI, (void *)&event_data);
229
230         if (voicecall_core_setup_call(global_pcall_core, TRUE)) {
231                 CALL_ENG_DEBUG(ENG_DEBUG, " success!!");
232         } else {
233                 CALL_ENG_DEBUG(ENG_DEBUG, " failed!!");
234         }
235         return VCALL_ENGINE_API_SUCCESS;
236 }
237
238 /**
239  * This function processes emergency call for testing purpose.
240  *
241  * @return      int     API Result Code.
242  * @param[in]
243 */
244 int vcall_engine_process_emergency_call_test(char *number)
245 {
246         CALL_ENG_DEBUG(ENG_DEBUG, " number is : [%s]", number);
247         voicecall_engine_t *pcall_engine = global_pcall_core->pcall_engine;
248         gboolean bDefaultNumber = FALSE;
249         vc_engine_outgoing_type event_data;
250         int io_state;
251
252         /* check the call-engine state before proceeding with emergency call processing */
253         _vc_core_engine_status_get_engine_iostate(pcall_engine, &io_state);
254         if (io_state != VC_INOUT_STATE_NONE) {
255                 CALL_ENG_DEBUG(ENG_DEBUG, "IO State [%d] not NONE, cannot proceed with the call", io_state);
256                 voicecall_core_set_status(global_pcall_core, CALL_VC_CORE_FLAG_SETUPCALL_FAIL, TRUE);
257                 vc_engine_msg_box_type mbox_event_data;
258
259                 memset(&mbox_event_data, 0, sizeof(mbox_event_data));
260                 mbox_event_data.string_id = IDS_CALL_POP_CALLNOTCALLOWED;
261                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_MESSAGE_BOX_TO_UI, (void *)&mbox_event_data);
262                 return VCALL_ENGINE_API_FAILED;
263         }
264
265         memset(&event_data, 0, sizeof(event_data));
266
267         memset(&(global_pcall_core->call_setup_info), 0, sizeof(global_pcall_core->call_setup_info));
268
269         bDefaultNumber = strlen(number) ? FALSE : TRUE;
270         if (bDefaultNumber == TRUE) {
271                 global_pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
272                 global_pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_EMERGENCY;
273                 if (strlen("911") < sizeof(event_data.call_num))
274                         _vc_core_util_strcpy(event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX, "911");
275
276                 memcpy(global_pcall_core->call_setup_info.tel_number, "911", strlen("911"));
277         } else {
278                 global_pcall_core->call_setup_info.call_setup_by = VC_CALL_SETUP_BY_NORMAL;
279                 global_pcall_core->call_setup_info.call_type = VC_CALL_ORIG_TYPE_PINLOCK;
280                 voicecall_core_extract_phone_number(number, event_data.call_num, VC_PHONE_NUMBER_LENGTH_MAX);
281                 if (strlen(number) > VC_PHONE_NUMBER_LENGTH_MAX) {
282                         CALL_ENG_DEBUG(ENG_ERR, " WARNING!! number is larger than max num length!!");
283                         memcpy(global_pcall_core->call_setup_info.source_tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
284                         memcpy(global_pcall_core->call_setup_info.tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
285                 } else {
286                         memcpy(global_pcall_core->call_setup_info.source_tel_number, number, VC_PHONE_NUMBER_LENGTH_MAX);
287                         memcpy(global_pcall_core->call_setup_info.tel_number, number, strlen(number));
288                 }
289         }
290
291         event_data.contact_index = -1;
292         event_data.phone_type = -1;
293         event_data.bday_remaining_days = -1;
294
295         vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_TO_UI, (void *)&event_data);
296
297         {
298                 int call_handle = 1;
299                 vc_engine_outgoing_orig_type orig_event_data;
300
301                 memset(&orig_event_data, 0, sizeof(orig_event_data));
302                 orig_event_data.call_handle = call_handle;
303                 orig_event_data.bemergency = TRUE;
304
305                 CALL_ENG_DEBUG(ENG_DEBUG, "Call Handle = %d, bemergency:[%d]", orig_event_data.call_handle, orig_event_data.bemergency);
306                 vcall_engine_send_event_to_client(VC_ENGINE_MSG_OUTGOING_ORIG_TO_UI_TEST, (void *)&orig_event_data);
307         }
308
309         return VCALL_ENGINE_API_SUCCESS;
310 }
311
312 /**
313  * This function processes sat setup call.
314  *
315  * @return      int     API Result Code.
316  * @param[in]
317 */
318 int vcall_engine_process_sat_setup_call(vcall_engine_sat_setup_call_info_t *sat_setup_call_info)
319 {
320         CALL_ENG_DEBUG(ENG_WARN, "..");
321         voicecall_core_process_sat_setup_call(sat_setup_call_info);
322         return VCALL_ENGINE_API_SUCCESS;
323 }
324
325 /**
326  * This function processes incoming call.
327  *
328  * @return      int     API Result Code.
329  * @param[in]
330 */
331 int vcall_engine_process_incoming_call(vcall_engine_incoming_info_t *incoming_call_info)
332 {
333         call_vc_core_incoming_info_t tmp_incom_info = { 0, };
334
335         CALL_ENG_DEBUG(ENG_WARN, "..");
336
337         tmp_incom_info.call_handle = incoming_call_info->call_handle;
338         tmp_incom_info.call_type = incoming_call_info->call_type;
339         tmp_incom_info.cli_presentation_indicator = incoming_call_info->cli_presentation_indicator;
340         _vc_core_util_strcpy(tmp_incom_info.call_num, sizeof(tmp_incom_info.call_num), incoming_call_info->call_num);
341         tmp_incom_info.calling_name_mode = incoming_call_info->calling_name_mode;
342         _vc_core_util_strcpy(tmp_incom_info.calling_name, sizeof(tmp_incom_info.calling_name), incoming_call_info->calling_name);
343         _vc_core_util_strcpy(tmp_incom_info.redirected_number, sizeof(tmp_incom_info.redirected_number), incoming_call_info->redirected_number);
344         _vc_core_util_strcpy(tmp_incom_info.redirected_sub_address, sizeof(tmp_incom_info.redirected_sub_address), incoming_call_info->redirected_sub_address);
345         tmp_incom_info.cli_cause = incoming_call_info->cli_cause;
346         tmp_incom_info.bfwded = incoming_call_info->bfwded;
347         tmp_incom_info.active_line = incoming_call_info->active_line;
348
349         voicecall_core_process_incoming_call(&tmp_incom_info);
350         return VCALL_ENGINE_API_SUCCESS;
351 }
352
353 /**
354  * This function answers an incoming call
355  *
356  * @return      int     API Result Code.
357  * @param[in]           none
358 */
359 int vcall_engine_answer_call(void)
360 {
361         CALL_ENG_DEBUG(ENG_WARN, "..");
362         int ret = VCALL_ENGINE_API_FAILED;
363
364         ret = voicecall_core_answer_call(global_pcall_core, FALSE);
365         CALL_ENG_DEBUG(ENG_DEBUG, " ret:[%d]", ret);
366         return ret;
367 }
368
369 /**
370  * This function answers an incoming call  according to the given type
371  *
372  * @return      int     API Result Code.
373  * @param[in]           answer_type             answer type
374  */
375 int vcall_engine_answer_call_by_type(vcall_engine_answer_type_t answer_type)
376 {
377         CALL_ENG_DEBUG(ENG_WARN, "..");
378         CALL_ENG_DEBUG(ENG_DEBUG, "answer_type:[%d]", answer_type);
379
380         if (TRUE == voicecall_core_answer_call_bytype(global_pcall_core, answer_type)) {
381                 return VCALL_ENGINE_API_SUCCESS;
382         } else {
383                 return VCALL_ENGINE_API_FAILED;
384         }
385
386 }
387
388 /**
389  * This function cancel outgoing call
390  *
391  * @return      int     API Result Code.
392  * @param[in]           none
393  */
394 int vcall_engine_cancel_call(void)
395 {
396         CALL_ENG_DEBUG(ENG_WARN, "..");
397
398         if (TRUE == voicecall_core_cancel_call(global_pcall_core)) {
399                 return VCALL_ENGINE_API_SUCCESS;
400         } else {
401                 return VCALL_ENGINE_API_FAILED;
402         }
403 }
404
405 /**
406  * This function reject incoming call
407  *
408  * @return      int     API Result Code.
409  * @param[in]           none
410  */
411 int vcall_engine_reject_call(void)
412 {
413         CALL_ENG_DEBUG(ENG_WARN, "..");
414
415         if (TRUE == voicecall_core_reject_mt(global_pcall_core, TRUE)) {
416                 return VCALL_ENGINE_API_SUCCESS;
417         } else {
418                 return VCALL_ENGINE_API_FAILED;
419         }
420 }
421
422 /**
423  * This function release a active or held call
424  *
425  * @return      int     API Result Code.
426  * @param[in]           none
427  */
428 int vcall_engine_release_call(void)
429 {
430         CALL_ENG_DEBUG(ENG_WARN, "..");
431
432         if (TRUE == voicecall_core_end_call(global_pcall_core)) {
433                 return VCALL_ENGINE_API_SUCCESS;
434         } else {
435                 return VCALL_ENGINE_API_FAILED;
436         }
437 }
438
439 /**
440  * This function release a call by handle
441  *
442  * @return      int     API Result Code.
443  * @param[in]   int     call_handle
444  */
445 int vcall_engine_release_call_by_handle(int call_handle)
446 {
447         CALL_ENG_DEBUG(ENG_WARN, "..");
448         CALL_ENG_DEBUG(ENG_DEBUG, "call_handle:[%d]", call_handle);
449
450         if (TRUE == voicecall_core_end_call_by_handle(global_pcall_core, call_handle)) {
451                 return VCALL_ENGINE_API_SUCCESS;
452         } else {
453                 return VCALL_ENGINE_API_FAILED;
454         }
455 }
456
457 /**
458  * This function release calls by type
459  *
460  * @return      int     API Result Code.
461  * @param[in]           release_type release_type
462  */
463 int vcall_engine_release_call_by_type(vcall_engine_release_type_t release_type)
464 {
465         CALL_ENG_DEBUG(ENG_WARN, "..");
466         int ret = FALSE;
467
468         CALL_ENG_DEBUG(ENG_DEBUG, " release_type : [%d]", release_type);
469         switch (release_type) {
470         case VCALL_ENGINE_RELEASE_ALL_ACTIVE_CALLS:
471                 {
472                         ret = voicecall_core_end_all_active_calls(global_pcall_core);
473                 }
474                 break;
475
476         case VCALL_ENGINE_RELEASE_ALL_HELD_CALLS:
477                 {
478                         ret = voicecall_core_end_all_held_calls(global_pcall_core);
479                 }
480                 break;
481
482         case VCALL_ENGINE_RELEASE_ALL_CALLS:
483                 {
484                         ret = voicecall_core_end_all_calls(global_pcall_core);
485                 }
486                 break;
487
488         default:
489                 CALL_ENG_DEBUG(ENG_DEBUG, " Unknown release_type : [%d]", release_type);
490                 break;
491
492         }
493
494         if (ret == TRUE) {
495                 return VCALL_ENGINE_API_SUCCESS;
496         } else {
497                 return VCALL_ENGINE_API_FAILED;
498         }
499 }
500
501 /**
502  * This function processes hold/retrive/swap calls.
503  *
504  * @return      int     API Result Code.
505  * @param[in]           none
506  */
507 int vcall_engine_process_hold_call(void)
508 {
509         CALL_ENG_DEBUG(ENG_WARN, "..");
510         int ret = FALSE;
511
512         ret = voicecall_core_process_hold_call(global_pcall_core);
513         if (ret == TRUE) {
514                 return VCALL_ENGINE_API_SUCCESS;
515         } else {
516                 return VCALL_ENGINE_API_FAILED;
517         }
518 }
519
520 /**
521  * This function processes in call SS code..
522  *
523  * @return      int     API Result Code.
524  * @param[in]           none
525  */
526 void vcall_engine_process_incall_ss(char *number)
527 {
528         CALL_ENG_DEBUG(ENG_WARN, "number(%s)");
529
530         voicecall_core_process_incall_ss(global_pcall_core, number);
531 }
532
533 /**
534  * This function sets up a conference calls
535  *
536  * @return      int     API Result Code.
537  * @param[in]           none
538  */
539 int vcall_engine_join_call(void)
540 {
541         CALL_ENG_DEBUG(ENG_WARN, "..");
542         int ret = FALSE;
543
544         ret = voicecall_core_setup_conference(global_pcall_core);
545         if (ret == TRUE) {
546                 return VCALL_ENGINE_API_SUCCESS;
547         } else {
548                 return VCALL_ENGINE_API_FAILED;
549         }
550 }
551
552 /**
553  * This function make a private call in conference calls.
554  *
555  * @return      int     API Result Code.
556  * @param[in]   int     call_handle
557  */
558 int vcall_engine_split_call(int call_handle)
559 {
560         CALL_ENG_DEBUG(ENG_WARN, "..");
561         int ret = FALSE;
562
563         ret = voicecall_core_make_private_call(global_pcall_core, call_handle);
564         if (ret == TRUE) {
565                 return VCALL_ENGINE_API_SUCCESS;
566         } else {
567                 return VCALL_ENGINE_API_FAILED;
568         }
569 }
570
571 /**
572  * This function transfers the call from active call to the held call
573  *
574  * @return      int     API Result Code.
575  * @param[in]   int     call_handle
576  */
577 int vcall_engine_transfer_call(void)
578 {
579         CALL_ENG_DEBUG(ENG_WARN, "..");
580         int ret = FALSE;
581
582         ret = voicecall_core_transfer_calls(global_pcall_core);
583         if (ret == TRUE) {
584                 return VCALL_ENGINE_API_SUCCESS;
585         } else {
586                 return VCALL_ENGINE_API_FAILED;
587         }
588 }
589
590 /**
591  * This function processed loud speaker.
592  *
593  * @return      int     API Result Code.
594  * @param[in]   int     bstatus
595  */
596 int vcall_engine_process_loudspeaker(int bstatus)
597 {
598         CALL_ENG_DEBUG(ENG_WARN, "..");
599         int ret = FALSE;
600
601         CALL_ENG_DEBUG(ENG_DEBUG, " bstatus : [%d]", bstatus);
602         if (bstatus) {
603                 ret = voicecall_service_loudspeaker_on(global_pcall_core);
604         } else {
605                 ret = voicecall_service_loudspeaker_off(global_pcall_core);
606         }
607
608         if (ret == TRUE) {
609                 return VCALL_ENGINE_API_SUCCESS;
610         } else {
611                 return VCALL_ENGINE_API_FAILED;
612         }
613 }
614
615 /**
616  * This function processed voice mute status.
617  *
618  * @return      int     API Result Code.
619  * @param[in]   int     bstatus
620  */
621 int vcall_engine_process_voice_mute(int bstatus)
622 {
623         CALL_ENG_DEBUG(ENG_WARN, "..");
624         int ret = FALSE;
625
626         CALL_ENG_DEBUG(ENG_DEBUG, " bstatus : [%d]", bstatus);
627         if (bstatus) {
628                 ret = voicecall_service_mute_status_on(global_pcall_core);
629         } else {
630                 ret = voicecall_service_mute_status_off(global_pcall_core);
631         }
632
633         if (ret == TRUE) {
634                 return VCALL_ENGINE_API_SUCCESS;
635         } else {
636                 return VCALL_ENGINE_API_FAILED;
637         }
638 }
639
640 /**
641  * This function gets the volume level
642  *
643  * @return      int     API Result Code.
644  * @param[in]           vcall_engine_vol_type_t vol_type
645  * @param[in]           voicecall_snd_volume_alert_type_t vol_alert_type
646  */
647 int vcall_engine_get_volume_level(vcall_engine_vol_type_t vol_type)
648 {
649         CALL_ENG_DEBUG(ENG_WARN, "..");
650
651         CALL_ENG_DEBUG(ENG_DEBUG, " vol_type : [%d]", vol_type);
652         /* jspark 201007 decide to sync or async. */
653
654         return voicecall_snd_get_volume(global_pcall_core->papp_snd, vol_type);
655
656 }
657
658 /**
659  * This function sets the volume level
660  *
661  * @return      int     API Result Code.
662  * @param[in]           vcall_engine_vol_type_t vol_type
663  * @param[in]           int vol_level
664  */
665 int vcall_engine_set_volume_level(vcall_engine_vol_type_t vol_type, int vol_level)
666 {
667         CALL_ENG_DEBUG(ENG_WARN, "..");
668         int ret = FALSE;
669
670         CALL_ENG_DEBUG(ENG_DEBUG, " vol_type : [%d], vol_level:[%d]", vol_type, vol_level);
671         ret = voicecall_service_set_volume(global_pcall_core, vol_type, vol_level);
672         if (ret == TRUE) {
673                 return VCALL_ENGINE_API_SUCCESS;
674         } else {
675                 return VCALL_ENGINE_API_FAILED;
676         }
677 }
678
679 /**
680  * This function stop alert
681  *
682  * @return      int     API Result Code.
683  * @param[in]           none
684  */
685 int vcall_engine_stop_alert(void)
686 {
687         CALL_ENG_DEBUG(ENG_WARN, "..");
688         int ret = FALSE;
689
690         ret = voicecall_core_stop_alert(global_pcall_core);
691         if (ret == TRUE) {
692                 return VCALL_ENGINE_API_SUCCESS;
693         } else {
694                 return VCALL_ENGINE_API_FAILED;
695         }
696 }
697
698 /**
699  * This function mute alert.
700  *
701  * @return int  API Result Code.
702  * @param[in]           none
703  */
704 int vcall_engine_mute_alert(void)
705 {
706         CALL_ENG_DEBUG(ENG_WARN, "..");
707         int ret = FALSE;
708
709         ret = voicecall_snd_mute_alert(global_pcall_core->papp_snd);
710         if (ret == TRUE) {
711                 return VCALL_ENGINE_API_SUCCESS;
712         } else {
713                 return VCALL_ENGINE_API_FAILED;
714         }
715 }
716
717 /**
718  * This function process auto redial.
719  *
720  * @return      int     API Result Code.
721  * @param[in]           int bstatus
722  */
723 int vcall_engine_process_auto_redial(int bstatus)
724 {
725         CALL_ENG_DEBUG(ENG_WARN, "..");
726         int ret = FALSE;
727
728         CALL_ENG_DEBUG(ENG_DEBUG, " bstatus : [%d]", bstatus);
729         if (bstatus) {
730                 ret = voicecall_core_start_redial(global_pcall_core, TRUE);
731         } else {
732                 ret = voicecall_core_stop_redial(global_pcall_core);
733         }
734         if (ret == TRUE) {
735                 return VCALL_ENGINE_API_SUCCESS;
736         } else {
737                 return VCALL_ENGINE_API_FAILED;
738         }
739 }
740
741 /**
742  * This function send the DTMF number
743  *
744  * @return      int     API Result Code.
745  * @param[in]           char* dtmf_number
746  */
747 int vcall_engine_send_dtmf_number(char *dtmf_number)
748 {
749         CALL_ENG_DEBUG(ENG_WARN, "..");
750         int ret = FALSE;
751
752         ret = voicecall_core_send_dtmf(global_pcall_core, dtmf_number);
753
754         if (ret == TRUE) {
755                 return VCALL_ENGINE_API_SUCCESS;
756         } else {
757                 return VCALL_ENGINE_API_FAILED;
758         }
759 }
760
761 /**
762  * This function processed sound path
763  *
764  * @return      int     API Result Code.
765  * @param[in]   int     sound_path
766  */
767 int vcall_engine_change_sound_path(vcall_engine_audio_type_t sound_path)
768 {
769         CALL_ENG_DEBUG(ENG_WARN, "..");
770         int ret = FALSE;
771
772         ret = voicecall_core_change_sound_path(global_pcall_core, sound_path);
773
774         if (ret == TRUE) {
775                 return VCALL_ENGINE_API_SUCCESS;
776         } else {
777                 return VCALL_ENGINE_API_FAILED;
778         }
779 }
780
781 /**
782  * This function get sound path
783  *
784  * @return      int     API Result Code.
785  * @param[out]  int     sound_path
786  */
787 int vcall_engine_get_sound_path(int *sound_path)
788 {
789         CALL_ENG_DEBUG(ENG_WARN, "..");
790         int ret = FALSE;
791         int snd_path = 0;
792
793         ret = voicecall_core_get_sound_path(global_pcall_core, &snd_path);
794
795         if (snd_path == VOICE_CALL_AUDIO_SPEAKER) {
796                 *sound_path = VCALL_ENGINE_AUDIO_SPEAKER;
797         } else if (snd_path == VOICE_CALL_AUDIO_HEADSET) {
798                 *sound_path = VCALL_ENGINE_AUDIO_HEADSET;
799         } else if (snd_path == VOICE_CALL_AUDIO_RECEIVER_EARJACK) {
800                 *sound_path = VCALL_ENGINE_AUDIO_RECEIVER_EARJACK;
801         } else {
802                 *sound_path = VCALL_ENGINE_AUDIO_RECEIVER_EARJACK;
803         }
804
805         if (ret == TRUE) {
806                 return VCALL_ENGINE_API_SUCCESS;
807         } else {
808                 return VCALL_ENGINE_API_FAILED;
809         }
810 }
811
812 /**
813  * This function set call engine to default
814  *
815  * @return      int     API Result Code.
816  * @param[in]
817  */
818 int vcall_engine_set_to_default()
819 {
820         CALL_ENG_DEBUG(ENG_WARN, "..");
821         int ret = FALSE;
822
823         ret = voicecall_core_set_to_default(global_pcall_core);
824
825         if (ret == TRUE) {
826                 return VCALL_ENGINE_API_SUCCESS;
827         } else {
828                 return VCALL_ENGINE_API_FAILED;
829         }
830 }
831
832 gpointer vcall_engine_get_core_state(void)
833 {
834         return global_pcall_core;
835 }
836
837 /**
838  * This function is interface to call-utility to perform string copy
839  *
840  * @return      instance of the core state
841  * @param[out]  pbuffer         Target Buffer
842  * @param[in]   buf_count       Size of Target Buffer
843  * @param[in]   pstring         Source String
844  */
845 gboolean vcall_engine_util_strcpy(char *pbuffer, int buf_count, const char *pstring)
846 {
847         return _vc_core_util_strcpy(pbuffer, buf_count, pstring);
848 }
849
850 /**
851  * This function returns the number of groups
852  *
853  * @param[in]           pcount          count of the groups
854  */
855 gboolean vcall_engine_get_group_count(int *pcount)
856 {
857         CALL_ENG_DEBUG(ENG_DEBUG, "..");
858         return _vc_core_engine_group_get_enabled_group_count(global_pcall_core->pcall_engine, pcount);
859 }
860
861 /**
862  * This function is interface to call-utility to perform string copy
863  *
864  * @return      instance of the core state
865  * @param[out]  pbuffer         Target Buffer
866  * @param[in]   time            time
867  */
868 char *vcall_engine_util_get_date_time(time_t time)
869 {
870         CALL_ENG_DEBUG(ENG_DEBUG, "..");
871         return _vc_core_util_get_date_time(time);
872 }
873
874 /**
875  * This function is force reset all engine status.
876  *
877  * @return      void
878  * @param[in] void
879  */
880 void vcall_engine_force_reset(void)
881 {
882         CALL_ENG_DEBUG(ENG_DEBUG, "..");
883
884         voicecall_snd_unregister_cm(global_pcall_core->papp_snd);
885
886         _vc_core_util_set_call_status(VCONFKEY_CALL_OFF);
887
888         voicecall_core_end_all_calls(global_pcall_core);
889 }
890
891 /**
892  * This function will process the dtmf send request from UI
893  * It is executed when wait(w/W/;) is finished while sending a dtmf string
894  *
895  * @return      void
896  * @param[in] void
897  */
898 void vcall_engine_send_dtmf(gboolean bsuccess)
899 {
900         CALL_ENG_DEBUG(ENG_DEBUG, "..");
901
902         voicecall_core_process_dtmf_send_status(global_pcall_core, bsuccess);
903 }
904
905 /**
906  * This function is interface to call-utility to check for ss string
907  *
908  * @return      TRUE or FALSE if success/failure
909  * @param[in]   call_number     pointer to the number
910  */
911 gboolean vcall_engine_check_incall_ss_string(char *call_number)
912 {
913         CALL_ENG_DEBUG(ENG_DEBUG, "..");
914         return _vc_core_util_check_incall_ss_string(call_number);
915 }
916
917 /**
918  * This function checks whether a given number is a SS string or not
919  *
920  * @return      TRUE or FALSE if success/failure
921  * @param[in]   call_number     pointer to the number
922  */
923 gboolean vcall_engine_check_ss_string(char *call_number)
924 {
925         CALL_ENG_DEBUG(ENG_DEBUG, "..");
926         return _vc_core_util_check_ss_string(call_number);
927 }
928
929 /**
930  * This function controls the lcd state
931  *
932  * @return void
933  * @param[in]   lcd_state       state of the lcd control
934  */
935 void vcall_engine_device_control_lcd_state(voicecall_lcd_control_t lcd_state)
936 {
937         CALL_ENG_DEBUG(ENG_DEBUG, "..");
938         _voicecall_dvc_control_lcd_state(lcd_state);
939 }
940