release tizen_2.0 beta
[framework/telephony/tel-plugin-socket_communicator.git] / plugin / src / socket_call.c
1 /*
2  * tel-plugin-socket-communicator
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <glib-object.h>
26
27 #include <aul.h>
28 #include <bundle.h>
29 #include <tcore.h>
30 #include <server.h>
31 #include <plugin.h>
32 #include <hal.h>
33 #include <communicator.h>
34 #include <core_object.h>
35 #include <queue.h>
36 #include <user_request.h>
37 #include <util.h>
38 #include <co_call.h>
39
40 #include "sipc.h"
41 #include "tapi_common.h"
42 #include "module_req.h"
43
44 static void _launch_voice_call( struct tnoti_call_status_incoming* incoming );
45 static void _launch_video_call( struct tnoti_call_status_incoming* incoming );
46
47 gboolean scomm_service_reqeust_call(unsigned int ch_id, Communicator *c, TcorePlugin *plugin, tapi_service_command_e cmd, gchar *data, void **outparam)
48 {
49         int ret = 0;
50         gboolean result = TRUE; int err_cause = 0;
51         int s_data_len = 0;
52         gchar *serial_d = NULL;
53
54         GSList *co_list = NULL;
55         CoreObject *co_call = NULL;
56         UserRequest *ur = NULL;
57         struct tcore_user_info ui = { 0, 0, 0, NULL,0,0, NULL };
58
59         struct _sipc_marshal_object *out_obj;
60         struct _sipc_marshal_object *in_obj;
61
62         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_CALL);
63         if (!co_list) {
64                 return FALSE;
65         }
66
67         co_call = (CoreObject *)co_list->data;
68         if (!co_call) {
69                 return FALSE;
70         }
71         g_slist_free(co_list);
72
73         in_obj = sipc_util_marshal_object_deserializer(data);
74         if(in_obj){
75                 return FALSE;
76         }
77
78         ui.channel_id = ch_id;
79         ui.client_cmd = (unsigned int)cmd;
80         ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
81         if (!ur) {
82                 return FALSE;
83         }
84         tcore_user_request_set_user_info(ur, &ui);
85
86         switch (cmd) {
87                 case TAPI_SERVICE_CALL_DIAL: {
88                         struct treq_call_dial data;
89                         gchar *type = 0;
90                         gchar *number = 0;
91                         
92                         type = sipc_util_marshal_object_get_string(in_obj, "call_type");
93                         number = sipc_util_marshal_object_get_string(in_obj, "call_number");
94
95                         data.type = (enum telephony_call_type)*type;
96
97                         if ( !number ) {
98                                 dbg("[ error ] number : 0");
99                                 result = FALSE;
100                                 goto RETURN;
101                         }
102
103                         memcpy( data.number, number, MAX_CALL_DIAL_NUM_LEN );
104
105                         tcore_user_request_set_data(ur, sizeof( struct treq_call_dial ), &data);
106                         tcore_user_request_set_command(ur, TREQ_CALL_DIAL);
107
108                 } break;
109
110                 case TAPI_SERVICE_CALL_ANSWER: {
111                         struct treq_call_answer data;
112
113                         gchar *id = 0;
114                         gchar *type = 0;
115                         
116                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
117                         type = sipc_util_marshal_object_get_string(in_obj, "answer_type");
118
119                         data.id         = (unsigned int)*id;
120                         data.type       = (enum telephony_call_answer_type)*type;
121
122                         tcore_user_request_set_data(ur, sizeof( struct treq_call_answer ), &data);
123                         tcore_user_request_set_command(ur, TREQ_CALL_ANSWER);
124                 }break;
125
126                 case TAPI_SERVICE_CALL_END: {
127                         struct treq_call_end data;
128
129                         gchar *id = 0;
130                         gchar *type = 0;
131
132                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
133                         type = sipc_util_marshal_object_get_string(in_obj, "end_type");
134
135                         data.id         = (unsigned int)*id;
136                         data.type       = (enum telephony_call_end_type)*type;
137
138                         tcore_user_request_set_data(ur, sizeof( struct treq_call_end ), &data);
139                         tcore_user_request_set_command(ur, TREQ_CALL_END);
140                 }break;
141
142                 case TAPI_SERVICE_CALL_SEND_DTMF: {
143                         struct treq_call_dtmf data;
144                         gchar *str;
145
146                         str = sipc_util_marshal_object_get_string(in_obj, "call_dtmf");
147
148                         if ( str ) {
149                                 strncpy( data.digits, str, MAX_CALL_DTMF_DIGITS_LEN );
150                         } else {
151                                 dbg("[ error ] str : 0");
152                                 result = FALSE;
153                                 goto RETURN;
154                         }
155
156                         tcore_user_request_set_data(ur, sizeof( struct treq_call_dtmf ), &data);
157                         tcore_user_request_set_command(ur, TREQ_CALL_SEND_DTMF);
158                 }break;
159
160                 case TAPI_SERVICE_CALL_HOLD: {
161                         gchar *id = 0;
162                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
163
164                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
165                         tcore_user_request_set_command(ur, TREQ_CALL_HOLD);
166                 }break;
167
168                 case TAPI_SERVICE_CALL_ACTIVE: {
169                         gchar *id = 0;
170                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
171
172                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
173                         tcore_user_request_set_command(ur, TREQ_CALL_ACTIVE);
174                 }break;
175
176                 case TAPI_SERVICE_CALL_SWAP: {
177                         gchar *id = 0;
178                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
179
180                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
181                         tcore_user_request_set_command(ur, TREQ_CALL_SWAP);
182                 }break;
183
184                 case TAPI_SERVICE_CALL_JOIN: {
185                         gchar *id = 0;
186                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
187
188                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
189                         tcore_user_request_set_command(ur, TREQ_CALL_JOIN);
190                 }break;
191
192                 case TAPI_SERVICE_CALL_SPLIT: {
193                         gchar *id = 0;
194                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
195
196                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
197                         tcore_user_request_set_command(ur, TREQ_CALL_SPLIT);
198                 }break;
199
200                 case TAPI_SERVICE_CALL_DEFLECT: {
201                         gchar *number = 0;
202                         number = sipc_util_marshal_object_get_string(in_obj, "call_number");
203
204                         if ( !number ) {
205                                 dbg("[ error ] number : 0");
206                                 result = FALSE;
207                                 goto RETURN;
208                         }
209
210                         tcore_user_request_set_data(ur, MAX_CALL_NUMBER_LEN, (char*)number);
211                         tcore_user_request_set_command(ur, TREQ_CALL_DEFLECT);
212                 }break;
213
214                 case TAPI_SERVICE_CALL_TRANSFER: {
215                         gchar *id = 0;
216                         id = sipc_util_marshal_object_get_string(in_obj, "call_id");
217
218                         tcore_user_request_set_data(ur, sizeof( unsigned int ), id);
219                         tcore_user_request_set_command(ur, TREQ_CALL_TRANSFER);
220                 }break;
221
222                 //TAPI_CS_CALL_GETACTIVELINE
223                 //TAPI_CS_CALL_SETACTIVELINE
224
225                 case TAPI_SERVICE_CALL_SET_SOUND_PATH: {
226                         struct treq_call_sound_set_path data;
227                         gchar *path = 0;
228
229                         path = sipc_util_marshal_object_get_string(in_obj, "sound_path");
230
231                         data.path = (enum telephony_call_sound_path)*path;
232
233                         tcore_user_request_set_data(ur, sizeof( struct treq_call_sound_set_path ), &data);
234                         tcore_user_request_set_command(ur, TREQ_CALL_SET_SOUND_PATH );
235
236             }break;
237
238                 case TAPI_SERVICE_CALL_GET_SOUND_VOLUME_LEVEL: {
239                         struct treq_call_sound_get_volume_level data;
240                         gchar *sound_device = 0;
241                         gchar *sound_type = 0;
242
243                         sound_type = sipc_util_marshal_object_get_string(in_obj, "sound_type");
244                         sound_device = sipc_util_marshal_object_get_string(in_obj, "sound_device");
245
246                         data.sound = (enum telephony_call_sound_type)sound_type;
247                         data.device = (enum telephony_call_sound_device)sound_device;
248
249                         tcore_user_request_set_data(ur, sizeof( struct treq_call_sound_get_volume_level ), &data);
250                         tcore_user_request_set_command(ur, TREQ_CALL_GET_SOUND_VOLUME_LEVEL );
251                 }break;
252
253                 case TAPI_SERVICE_CALL_SET_SOUND_VOLUME_LEVEL: {
254                         struct treq_call_sound_set_volume_level data;
255                         gchar *sound_type = 0;
256                         gchar *sound_device = 0;
257                         gchar *sound_volume = 0;
258
259                         sound_type = sipc_util_marshal_object_get_string(in_obj, "sound_type");
260                         sound_device = sipc_util_marshal_object_get_string(in_obj, "sound_device");
261                         sound_volume = sipc_util_marshal_object_get_string(in_obj, "sound_volume");
262
263                         data.sound = (enum telephony_call_sound_type)sound_type;
264                         data.device = (enum telephony_call_sound_device)sound_device;
265                         data.volume = (enum telephony_call_sound_volume_level)sound_volume;
266
267                         tcore_user_request_set_data(ur, sizeof( struct treq_call_sound_set_volume_level ), &data);
268                         tcore_user_request_set_command(ur, TREQ_CALL_SET_SOUND_VOLUME_LEVEL );
269
270                 }break;
271
272                 case TAPI_SERVICE_CALL_MUTE: {
273
274                         tcore_user_request_set_command(ur, TREQ_CALL_MUTE);
275                                                                  
276                 }break;
277
278                 case TAPI_SERVICE_CALL_UNMUTE: {
279
280                         tcore_user_request_set_command(ur, TREQ_CALL_UNMUTE);
281
282                 }break;
283
284                 case TAPI_SERVICE_CALL_GET_MUTE_STATUS: {
285
286                         tcore_user_request_set_command(ur, TREQ_CALL_GET_MUTE_STATUS);
287
288                 }break;
289
290                 case TAPI_SERVICE_CALL_SET_ACTIVE_LINE: {}break;
291                 case TAPI_SERVICE_CALL_GET_ACTIVE_LINE: {}break;
292                 case TAPI_SERVICE_CALL_ACTIVATE_CCBS: {}break;
293         }
294
295 RETURN:
296
297         sipc_util_marshal_object_destory(in_obj);
298         out_obj = sipc_util_marshal_object_create();
299         sipc_util_marshal_object_add_data(out_obj, "result", &result, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
300
301         dbg("result = %d", result);
302
303         *outparam = sipc_util_marshal_object_serializer(out_obj);
304         sipc_util_marshal_object_destory(out_obj);
305
306         if (result == FALSE) {
307                 tcore_user_request_unref(ur);
308                 return FALSE;
309         }
310
311         ret = tcore_communicator_dispatch_request(c, ur);
312         if (ret != TCORE_RETURN_SUCCESS) {
313                 return FALSE;
314         }
315
316         return TRUE;
317 }
318
319 gboolean scomm_service_response_call(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
320 {
321         int ret = 0;
322
323         gboolean result = TRUE; int err_cause = 0;
324         gchar *out_d= NULL, *serial_d = NULL;
325         struct custom_data *ctx = NULL;
326         const struct tcore_user_info *ui;
327
328         sipc_server_t *s = NULL;
329         struct _tapi_header hdr;
330         struct _sipc_marshal_object* out_obj = NULL;
331
332         memset(&hdr, 0, sizeof(struct _tapi_header));
333
334         ctx = tcore_communicator_ref_user_data(comm);
335         if (!ctx) {
336                 dbg("user_data is NULL");
337                 return FALSE;
338         }
339
340         ui = tcore_user_request_ref_user_info(ur);
341         s = ctx->sk_server;
342
343         dbg("application channel id(%d), Command = [0x%x], data_len = %d", ui->channel_id, command, data_len);
344         hdr.cmd = (tapi_service_command_e)ui->client_cmd;
345
346         out_obj = sipc_util_marshal_object_create();
347
348         switch (command) {
349                 case TRESP_CALL_DIAL: {
350                         struct tresp_call_general* resp_data = 0;
351                         resp_data = (struct tresp_call_general*)data;
352
353                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
354                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
355                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
356
357                 } break;
358
359                 case TRESP_CALL_ANSWER: {
360                         struct tresp_call_general* resp_data = 0;
361                         resp_data = (struct tresp_call_general*)data;
362
363                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
364                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
365                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
366
367                 } break;
368
369                 case TRESP_CALL_END: {
370                         struct tresp_call_general* resp_data = 0;
371                         resp_data = (struct tresp_call_general*)data;
372
373                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
374                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
375                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
376
377                 } break;
378                 case TRESP_CALL_END_ALL: {
379                         struct tresp_call_general* resp_data = 0;
380                         resp_data = (struct tresp_call_general*)data;
381
382                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
383                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
384                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
385
386                 } break;
387                 case TRESP_CALL_END_ALL_ACTIVE: {
388                         struct tresp_call_general* resp_data = 0;
389                         resp_data = (struct tresp_call_general*)data;
390
391                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
392                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
393                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
394
395                 } break;
396                 case TRESP_CALL_END_ALL_HELD: {
397                         struct tresp_call_general* resp_data = 0;
398                         resp_data = (struct tresp_call_general*)data;
399
400                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
401                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
402                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
403
404                 } break;
405                 case TRESP_CALL_HOLD: {
406                         struct tresp_call_general* resp_data = 0;
407                         resp_data = (struct tresp_call_general*)data;
408
409                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
410                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
411                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
412
413                 } break;
414                 case TRESP_CALL_ACTIVE: {
415                         struct tresp_call_general* resp_data = 0;
416                         resp_data = (struct tresp_call_general*)data;
417
418                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
419                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
420                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
421
422                 } break;
423                 case TRESP_CALL_SWAP: {
424                         struct tresp_call_general* resp_data = 0;
425                         resp_data = (struct tresp_call_general*)data;
426
427                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
428                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
429                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
430
431                 } break;
432                 case TRESP_CALL_JOIN: {
433                         struct tresp_call_general* resp_data = 0;
434                         resp_data = (struct tresp_call_general*)data;
435
436                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
437                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
438                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
439
440                 } break;
441                 case TRESP_CALL_SPLIT: {
442                         struct tresp_call_general* resp_data = 0;
443                         resp_data = (struct tresp_call_general*)data;
444
445                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
446                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
447                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
448
449                 } break;
450                 case TRESP_CALL_DEFLECT: {
451
452                 } break;
453                 case TRESP_CALL_TRANSFER: {
454                         struct tresp_call_general* resp_data = 0;
455                         resp_data = (struct tresp_call_general*)data;
456
457                         sipc_util_marshal_object_add_data(out_obj, "call_id", &resp_data->id, SIPC_MARSHAL_DATA_INT_TYPE);
458                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
459                         sipc_util_marshal_object_add_data(out_obj, "err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
460
461                 } break;
462                 case TRESP_CALL_SEND_DTMF: {
463
464                 } break;
465                 case TRESP_CALL_SET_SOUND_PATH: {
466                         struct tresp_call_sound_general* resp_data = 0;
467                         resp_data = (struct tresp_call_sound_general*)data;
468
469                         out_obj = sipc_util_marshal_object_create();
470                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
471                         sipc_util_marshal_object_add_data(out_obj, "sound_err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
472
473                 } break;
474
475                 case TRESP_CALL_SET_SOUND_VOLUME_LEVEL: {
476                         struct tresp_call_sound_general* resp_data = 0;
477                         resp_data = (struct tresp_call_sound_general*)data;
478
479                         out_obj = sipc_util_marshal_object_create();
480                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
481                         sipc_util_marshal_object_add_data(out_obj, "sound_err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
482
483                 } break;
484
485                 case TRESP_CALL_GET_SOUND_VOLUME_LEVEL: {
486
487                 } break;
488
489                 case TRESP_CALL_MUTE:
490                 case TRESP_CALL_UNMUTE: {
491                         struct tresp_call_sound_general* resp_data = 0;
492                         resp_data = (struct tresp_call_sound_general*)data;
493
494                         out_obj = sipc_util_marshal_object_create();
495                         sipc_util_marshal_object_add_data(out_obj, "err", &resp_data->err, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
496                         sipc_util_marshal_object_add_data(out_obj, "sound_err_cause", &resp_data->cause, SIPC_MARSHAL_DATA_INT_TYPE);
497
498                 } break;
499
500                 case TRESP_CALL_GET_MUTE_STATUS: {
501
502                 } break;
503
504                 default:
505                         break;
506         }
507
508         if(out_obj){
509                 serial_d = sipc_util_marshal_object_serializer(out_obj);
510                 hdr.data_len = strlen(serial_d);
511                 sipc_util_marshal_object_destory(out_obj);
512         }
513
514         out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
515         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
516         if(serial_d){
517                 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
518                 g_free(serial_d);
519         }
520
521         ret = sipc_server_send(s, ui->channel_id, out_d, sizeof(struct _tapi_header)+hdr.data_len, SIPC_SEND_DATA_ASYNC);
522         g_free(out_d);
523
524         if(ret < 0){
525                 return FALSE;
526         }
527
528         return TRUE;
529 }
530
531 gboolean scomm_service_notification_call(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
532 {
533         int ret = 0;
534         gboolean result = TRUE; int err_cause = 0;
535         gchar *out_d= NULL, *serial_d = NULL;
536
537         struct custom_data *ctx = NULL;
538
539         struct _tapi_header hdr;
540         struct _sipc_marshal_object* out_obj = NULL;
541
542         memset(&hdr, 0, sizeof(struct _tapi_header));
543
544         ctx = tcore_communicator_ref_user_data(comm);
545         if (!ctx) {
546                 dbg("user_data is NULL");
547                 return FALSE;
548         }
549
550         dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
551
552         out_obj = sipc_util_marshal_object_create();
553
554         switch (command) {
555                 case TNOTI_CALL_STATUS_IDLE: {
556                         struct tnoti_call_status_idle *status;
557                         status = (struct tnoti_call_status_idle*)data;
558
559                         sipc_util_marshal_object_add_data(out_obj, "call_type", &status->type, SIPC_MARSHAL_DATA_INT_TYPE);
560                         sipc_util_marshal_object_add_data(out_obj, "call_id", &status->id, SIPC_MARSHAL_DATA_INT_TYPE);
561                         sipc_util_marshal_object_add_data(out_obj, "end_cause", &status->cause, SIPC_MARSHAL_DATA_INT_TYPE);
562
563                 } break;
564
565                 case TNOTI_CALL_STATUS_DIALING: {
566                         struct tnoti_call_status_dialing *status;
567                         status = (struct tnoti_call_status_dialing*)data;
568
569                         sipc_util_marshal_object_add_data(out_obj, "call_type", &status->type, SIPC_MARSHAL_DATA_INT_TYPE);
570                         sipc_util_marshal_object_add_data(out_obj, "call_id", &status->id, SIPC_MARSHAL_DATA_INT_TYPE);
571
572                 } break;
573
574                 case TNOTI_CALL_STATUS_ALERT: {
575                         struct tnoti_call_status_alert *status;
576                         status = (struct tnoti_call_status_alert*)data;
577
578                         sipc_util_marshal_object_add_data(out_obj, "call_type", &status->type, SIPC_MARSHAL_DATA_INT_TYPE);
579                         sipc_util_marshal_object_add_data(out_obj, "call_id", &status->id, SIPC_MARSHAL_DATA_INT_TYPE);
580
581                 } break;
582
583                 case TNOTI_CALL_STATUS_ACTIVE: {
584                         struct tnoti_call_status_active *status = 0;
585                         status = (struct tnoti_call_status_active*)data;
586
587                         sipc_util_marshal_object_add_data(out_obj, "call_type", &status->type, SIPC_MARSHAL_DATA_INT_TYPE);
588                         sipc_util_marshal_object_add_data(out_obj, "call_id", &status->id, SIPC_MARSHAL_DATA_INT_TYPE);
589
590             } break;
591
592                 case TNOTI_CALL_STATUS_HELD: {
593                         struct tnoti_call_status_held *status;
594                         status = (struct tnoti_call_status_held*)data;
595
596                         sipc_util_marshal_object_add_data(out_obj, "call_type", &status->type, SIPC_MARSHAL_DATA_INT_TYPE);
597                         sipc_util_marshal_object_add_data(out_obj, "call_id", &status->id, SIPC_MARSHAL_DATA_INT_TYPE);
598
599                 } break;
600
601                 case TNOTI_CALL_STATUS_INCOMING: {
602                         struct tnoti_call_status_incoming *incoming = 0;
603                         incoming = (struct tnoti_call_status_incoming*)data;
604
605                         dbg("incoming noti publish");
606
607                         if ( incoming->type == CALL_TYPE_VOICE )
608                                 _launch_voice_call( incoming );
609                         else
610                                 _launch_video_call( incoming );
611
612
613                 } break;
614
615                 case TNOTI_CALL_STATUS_WAITING:
616                 default:
617                         dbg("unknown notification");
618                         return FALSE;
619                         break;
620         }
621
622         if (out_obj) {
623                 serial_d = sipc_util_marshal_object_serializer(out_obj);
624                 hdr.data_len = strlen(serial_d);
625                 sipc_util_marshal_object_destory(out_obj);
626         }
627
628         out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
629         memcpy(out_d, &hdr, sizeof(struct _tapi_header));
630         if (serial_d) {
631                 memcpy(out_d + sizeof(struct _tapi_header), serial_d, hdr.data_len);
632                 g_free(serial_d);
633         }
634
635         ret = sipc_server_broadcast(ctx->sk_server, out_d, sizeof(struct _tapi_header) + hdr.data_len);
636         dbg("ret = %d", ret);
637         g_free(out_d);
638
639         if (ret < 0) {
640                 return FALSE;
641         }
642
643         return TRUE;
644 }
645
646 static void _launch_voice_call( struct tnoti_call_status_incoming* incoming )
647 {
648         char id[2] = {0, };
649         char cli[2] = {0, };
650         char forward[2] = {0, };
651         char active_line[2] = {0, };
652         char cna[2] = {0, };
653         char number[83] = {0, };
654         char name[83] = {0, };
655         int ret = 0;
656
657         bundle *kb  = 0;
658
659         snprintf( id, 2, "%d", incoming->id );
660         dbg("id : [%s]", id );
661         snprintf( cli, 2, "%d", incoming->cli.mode );
662         dbg("cli : [%s]", id );
663         snprintf( number, 83, "%s", incoming->cli.number );
664         dbg("number : [%s]", number );
665         snprintf( forward, 2, "%d", incoming->forward );
666         dbg("forward : [%s]", forward );
667         snprintf( active_line, 2, "%d", incoming->active_line );
668         dbg("active_line : [%s]", active_line );
669
670 #if 0
671         if ( incoming->cna.mode == CALL_CNA_MODE_PRESENT )
672                 snprintf( cna, 2, "%d", TAPI_CALL_NAME_AVAIL );
673         else
674                 snprintf( cna, 2, "%d", TAPI_CALL_NAME_RESTRICTED );
675 #endif
676
677         snprintf( cna, 2, "%d", incoming->cna.mode );
678         dbg("cna : [%s]", cna );
679         snprintf( name, 83, "%s", incoming->cna.name );
680         dbg("name : [%s]", name );
681
682         kb = bundle_create();
683         bundle_add(kb, "launch-type", "MT");
684         bundle_add(kb, "handle", id);
685         bundle_add(kb, "number", number);
686         bundle_add(kb, "name_mode", cna);
687         bundle_add(kb, "name", name);
688         bundle_add(kb, "clicause", cli);
689         bundle_add(kb, "fwded", forward);
690         bundle_add(kb, "activeline", active_line);
691
692         ret = aul_launch_app("com.samsung.call", kb);
693         bundle_free(kb);
694
695         dbg("aul_launch_app [ voice call ] : %d", ret );
696 }
697
698 static void _launch_video_call( struct tnoti_call_status_incoming* incoming )
699 {
700         char id[2] = {0, };
701         char cli[2] = {0, };
702         char forward[2] = {0, };
703         char number[83] = {0, };
704         int ret = 0;
705
706         bundle *kb  = 0;
707
708         dbg("Func Entrance");
709
710         snprintf( id, 2, "%d", incoming->id );
711         dbg("id : [%s]", id );
712         snprintf( number, 83, "%s", incoming->cli.number );
713         dbg("number : [%s]", number );
714         snprintf( cli, 2, "%d", incoming->cli.mode );
715         dbg("cli : [%s]", id );
716         snprintf( forward, 2, "%d", incoming->forward );
717         dbg("forward : [%s]", forward );
718
719         kb = bundle_create();
720         bundle_add(kb, "KEY_CALL_TYPE", "mt");
721         bundle_add(kb, "KEY_CALL_HANDLE", id);
722         bundle_add(kb, "KEY_CALLING_PARTY_NUMBER", number);
723         bundle_add(kb, "KEY_CLI_CAUSE", cli);
724         bundle_add(kb, "KEY_FORWARDED", forward);
725
726         ret = aul_launch_app("com.samsung.vtmain", kb);
727         bundle_free(kb);
728
729         dbg("VT AUL return %d",ret);
730 }
731