Initialize Tizen 2.3
[framework/telephony/libslp-tapi.git] / mobile / src / tapi_common.c
1 /*
2  * libslp-tapi
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 #define _GNU_SOURCE
22 #include <errno.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 #include <glib.h>
28 #include <glib-object.h>
29 #include <gio/gio.h>
30
31 #include "tapi_common.h"
32 #include "TapiUtility.h"
33
34 //
35 #include "ITapiPS.h"
36 #include "TelNetwork.h"
37 #include "TelSms.h"
38 #include "TelSat.h"
39 #include "TelSs.h"
40 #include "TelCall.h"
41
42 //
43 #include "common.h"
44 #include "tapi_log.h"
45
46 #define CALLBACK_CALL(data) \
47         if (evt_cb_data->cb_fn) { \
48                 evt_cb_data->cb_fn(handle, noti_id, (data), evt_cb_data->user_data); \
49         } \
50
51 extern char *g_cookie_name;
52 extern int g_cookie_size;
53
54 TelSatEventDownloadType_t g_event_list[TAPI_SAT_EVENT_LIST_MAX_COUNT] = {-1};
55
56 /*static void _cookie_deinit(void)
57 {
58         if (g_cookie_name)
59                 free(g_cookie_name);
60
61         g_cookie_name = NULL;
62         g_cookie_size = 0;
63 }*/
64
65 static void _process_network_event(const gchar *sig, GVariant *param,
66         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
67 {
68         if (!evt_cb_data)
69                 return;
70
71         if (!g_strcmp0(sig, "RegistrationStatus")) {
72                 struct tel_noti_network_registration_status noti;
73
74                 g_variant_get(param, "(iiib)", &noti.cs, &noti.ps, &noti.type, &noti.is_roaming);
75
76                 CALLBACK_CALL(&noti);
77         }
78         else if (!g_strcmp0(sig, "Info")) {
79                 struct tel_noti_network_info noti;
80
81                 memset(&noti, 0, sizeof(struct tel_noti_network_info));
82                 g_variant_get(param, "(ii)", &noti.rssi, &noti.battery);
83
84                 CALLBACK_CALL(&noti);
85         }
86         else if (!g_strcmp0(sig, "CellInfo")) {
87                 struct tel_noti_network_cell_info noti;
88
89                 memset(&noti, 0, sizeof(struct tel_noti_network_cell_info));
90                 g_variant_get(param, "(ii)", &noti.lac, &noti.cell_id);
91
92                 CALLBACK_CALL(&noti);
93         }
94         else if (!g_strcmp0(sig, "Change")) {
95                 struct tel_noti_network_change noti;
96                 char *plmn = NULL;
97                 int act;
98                 memset(&noti, 0, sizeof(struct tel_noti_network_change));
99
100                 g_variant_get(param, "(isi)", &act, &plmn, &noti.lac);
101
102                 switch (act) {
103                         case 0x1:
104                                 noti.act = TAPI_NETWORK_SYSTEM_GSM;
105                                 break;
106                         case 0x2:
107                                 noti.act = TAPI_NETWORK_SYSTEM_GPRS;
108                                 break;
109                         case 0x3:
110                                 noti.act = TAPI_NETWORK_SYSTEM_EGPRS;
111                                 break;
112                         case 0x4:
113                                 noti.act = TAPI_NETWORK_SYSTEM_UMTS;
114                                 break;
115                         case 0x5:
116                                 noti.act = TAPI_NETWORK_SYSTEM_GSM_AND_UMTS;
117                                 break;
118                         case 0x11:
119                                 noti.act = TAPI_NETWORK_SYSTEM_IS95A;
120                                 break;
121                         case 0x12:
122                                 noti.act = TAPI_NETWORK_SYSTEM_IS95B;
123                                 break;
124                         case 0x13:
125                                 noti.act = TAPI_NETWORK_SYSTEM_CDMA_1X;
126                                 break;
127                         case 0x14:
128                                 noti.act = TAPI_NETWORK_SYSTEM_EVDO_REV_0;
129                                 break;
130                         case 0x15:
131                                 noti.act = TAPI_NETWORK_SYSTEM_1X_EVDO_REV_0_HYBRID;
132                                 break;
133                         case 0x16:
134                                 noti.act = TAPI_NETWORK_SYSTEM_EVDO_REV_A;
135                                 break;
136                         case 0x17:
137                                 noti.act = TAPI_NETWORK_SYSTEM_1X_EVDO_REV_A_HYBRID;
138                                 break;
139                         case 0x18:
140                                 noti.act = TAPI_NETWORK_SYSTEM_EVDV;
141                                 break;
142                         case 0x21:
143                                 noti.act = TAPI_NETWORK_SYSTEM_LTE;
144                                 break;
145                         default:
146                                 noti.act = TAPI_NETWORK_SYSTEM_NO_SRV;
147                                 break;
148                 }
149
150                 if (plmn) {
151                         snprintf(noti.plmn, 7, "%s", plmn);
152                 }
153
154                 CALLBACK_CALL(&noti);
155         }
156         else if (!g_strcmp0(sig, "TimeInfo")) {
157                 struct tel_noti_network_time_info noti;
158                 char *plmn = NULL;
159
160                 memset(&noti, 0, sizeof(struct tel_noti_network_time_info));
161                 g_variant_get(param, "(iiiiiiiiibs)", &noti.year, &noti.month, &noti.day,
162                                 &noti.hour, &noti.minute, &noti.second,
163                                 &noti.wday, &noti.gmtoff, &noti.dstoff, &noti.isdst,
164                                 &plmn);
165
166                 if (plmn) {
167                         snprintf(noti.plmn, 7, "%s", plmn);
168                 }
169
170                 CALLBACK_CALL(&noti);
171         }
172         else if (!g_strcmp0(sig, "Identity")) {
173                 struct tel_noti_network_identity noti;
174                 char *plmn = NULL, *s_name = NULL, *f_name = NULL;
175
176                 memset(&noti, 0, sizeof(struct tel_noti_network_identity));
177
178                 g_variant_get(param, "(sss)", &plmn, &s_name, &f_name);
179
180                 if (plmn) {
181                         snprintf(noti.plmn, 7, "%s", plmn);
182                 }
183                 if (s_name) {
184                         snprintf(noti.short_name, 17, "%s", s_name);
185                 }
186                 if (f_name) {
187                         snprintf(noti.full_name, 33, "%s", f_name);
188                 }
189
190                 CALLBACK_CALL(&noti);
191         }
192         else {
193                 dbg("not handled Network noti[%s]", sig);
194         }
195 }
196
197 static void _process_sms_event(const gchar *sig, GVariant *param,
198         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
199 {
200         if (!evt_cb_data)
201                 return;
202
203         if (!g_strcmp0(sig, "IncommingMsg")) {
204                 struct tel_noti_sms_incomming_msg noti;
205
206                 const char *sca = NULL;
207                 const char *tpdu = NULL;
208                 gsize length;
209                 guchar *decoded_sca = NULL;
210                 guchar *decoded_tpdu = NULL;
211
212                 memset(&noti, 0, sizeof(struct tel_noti_sms_incomming_msg));
213
214                 g_variant_get(param, "(sis)", &sca, &noti.MsgLength, &tpdu);
215
216                 decoded_sca = g_base64_decode(sca, &length);
217                 if (decoded_sca) {
218                         memcpy(&(noti.Sca[0]), decoded_sca, TAPI_SMS_ENCODED_SCA_LEN_MAX);
219                         g_free(decoded_sca);
220                 }
221
222                 decoded_tpdu = g_base64_decode(tpdu, &length);
223                 if (decoded_tpdu) {
224                         memcpy(&(noti.szData[0]), decoded_tpdu, TAPI_NETTEXT_SMDATA_SIZE_MAX + 1);
225                         g_free(decoded_tpdu);
226                 }
227
228                 CALLBACK_CALL(&noti);
229         }
230         else if (!g_strcmp0(sig, "IncommingCbMsg")) {
231                 struct tel_noti_sms_incomming_cb_msg noti;
232
233                 const char *cbMsg = NULL;
234                 gsize length;
235                 guchar *decoded_cbMsg = NULL;
236
237                 memset(&noti, 0, sizeof(struct tel_noti_sms_incomming_cb_msg));
238                 g_variant_get(param, "(iis)", &noti.CbMsgType, &noti.Length, &cbMsg);
239
240                 decoded_cbMsg = g_base64_decode(cbMsg, &length);
241                 if (decoded_cbMsg) {
242                         memcpy(&(noti.szMsgData[0]), decoded_cbMsg, TAPI_NETTEXT_CB_SIZE_MAX + 1);
243                         g_free(decoded_cbMsg);
244                 }
245
246                 CALLBACK_CALL(&noti);
247         }
248         else if (!g_strcmp0(sig, "IncommingEtwsMsg")) {
249                 struct tel_noti_sms_incomming_etws_msg noti;
250
251                 const char *etwsMsg = NULL;
252                 gsize length;
253                 guchar *decoded_etwsMsg = NULL;
254
255                 memset(&noti, 0, sizeof(struct tel_noti_sms_incomming_etws_msg));
256                 g_variant_get(param, "(iis)", &noti.EtwsMsgType, &noti.Length, &etwsMsg);
257
258                 decoded_etwsMsg = g_base64_decode(etwsMsg, &length);
259                 if (decoded_etwsMsg) {
260                         memcpy(&(noti.szMsgData[0]), decoded_etwsMsg, TAPI_NETTEXT_ETWS_SIZE_MAX + 1);
261                         g_free(decoded_etwsMsg);
262                 }
263
264                 CALLBACK_CALL(&noti);
265         }
266         else if (!g_strcmp0(sig, "MemoryStatus")) {
267                 int noti = 0;
268
269                 g_variant_get(param, "(i)", &noti);
270                 CALLBACK_CALL(&noti);
271         }
272         else if (!g_strcmp0(sig, "SmsReady")) {
273                 gboolean noti = 0;
274
275                 g_variant_get(param, "(b)", &noti);
276                 CALLBACK_CALL(&noti);
277         }
278         else {
279                 dbg("not handled Sms noti[%s]", sig);
280         }
281 }
282
283 static void _process_call_event(const gchar *sig, GVariant *param,
284         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
285 {
286         if (!evt_cb_data)
287                 return;
288
289         if (!g_strcmp0(sig, "VoiceCallStatusIdle") || !g_strcmp0(sig, "VideoCallStatusIdle") ) {
290                 TelCallStatusIdleNoti_t data;
291                 int start_time = 0, end_time = 0;
292                 g_variant_get(param, "(iiii)", &data.id, &data.cause, &start_time, &end_time);
293                 dbg("[ check ] %s : call_id(%d), end_cause(0x%x)", "Status Idle noti", data.id, data.cause);
294                 CALLBACK_CALL(&data);
295         }
296         else if (!g_strcmp0(sig, "VoiceCallStatusDialing") || !g_strcmp0(sig, "VideoCallStatusDialing")) {
297                 TelCallStatusDialingNoti_t data;
298                 g_variant_get(param, "(i)", &data.id);
299                 dbg("[ check ] %s : call_id(%d)", "Status Dialing noti", data.id);
300                 CALLBACK_CALL(&data);
301         }
302         else if (!g_strcmp0(sig, "VoiceCallStatusAlert") || !g_strcmp0(sig, "VideoCallStatusAlert")) {
303                 TelCallStatusAlertNoti_t data;
304                 g_variant_get(param, "(i)", &data.id);
305                 dbg("[ check ] %s : call_id(%d)", "Status Alert noti", data.id);
306                 CALLBACK_CALL(&data);
307         }
308         else if (!g_strcmp0(sig, "VoiceCallStatusActive") || !g_strcmp0(sig, "VideoCallStatusActive")) {
309                 TelCallStatusActiveNoti_t data;
310                 g_variant_get(param, "(i)", &data.id);
311                 dbg("[ check ] %s : call_id(%d)", "Status Active noti", data.id);
312                 CALLBACK_CALL(&data);
313         }
314         else if (!g_strcmp0(sig, "VoiceCallStatusHeld") ) {
315                 TelCallStatusHeldNoti_t data;
316                 g_variant_get(param, "(i)", &data.id);
317                 dbg("[ check ] %s : call_id(%d)", "Status Held noti", data.id);
318                 CALLBACK_CALL(&data);
319         }
320         else if (!g_strcmp0(sig, "VoiceCallStatusIncoming") || !g_strcmp0(sig, "VideoCallStatusIncoming")) {
321                 TelCallStatusIncomingNoti_t data;
322                 g_variant_get(param, "(i)", &data.id);
323                 dbg("[ check ] %s : call_id(%d)", "Status Incoming noti", data.id);
324                 CALLBACK_CALL(&data);
325         }
326         else if (!g_strcmp0(sig, "Waiting")) {
327                 TelCallInfoWaitingNoti_t data;
328                 g_variant_get(param, "(i)", &data.id);
329                 dbg("[ check ] %s : data.id(%d)", "Call Info Waiting noti", data.id);
330                 CALLBACK_CALL(&data.id);
331         }
332         else if (!g_strcmp0(sig, "Forwarded")) {
333                 TelCallInfoForwardedNoti_t data;
334                 g_variant_get(param, "(i)", &data.id);
335                 dbg("[ check ] %s : data.id(%d)", "Call Info Forwarded noti", data.id);
336                 CALLBACK_CALL(&data.id);
337         }
338         else if (!g_strcmp0(sig, "BarredIncoming")) {
339                 TelCallInfoBarredIncomingNoti_t data;
340                 g_variant_get(param, "(i)", &data.id);
341                 dbg("[ check ] %s : data.id(%d)", "Call Info Barred Incoming noti", data.id);
342                 CALLBACK_CALL(&data.id);
343         }
344         else if (!g_strcmp0(sig, "BarredOutgoing")) {
345                 TelCallInfoBarredOutgoingNoti_t data;
346                 g_variant_get(param, "(i)", &data.id);
347                 dbg("[ check ] %s : data.id(%d)", "Call Info Barred Outgoing noti", data.id);
348                 CALLBACK_CALL(&data.id);
349         }
350         else if (!g_strcmp0(sig, "ForwardConditional")) {
351                 TelCallInfoForwardConditionalNoti_t data;
352                 g_variant_get(param, "(i)", &data.id);
353                 dbg("[ check ] %s : data.id(%d)", "Call Info Forward Conditional noti", data.id);
354                 CALLBACK_CALL(&data.id);
355         }
356         else if (!g_strcmp0(sig, "ForwardUnconditional")) {
357                 TelCallInfoForwardUnconditionalNoti_t data;
358                 g_variant_get(param, "(i)", &data.id);
359                 dbg("[ check ] %s : data.id(%d)", "Call Info Forward Unconditional noti", data.id);
360                 CALLBACK_CALL(&data.id);
361         }
362         else if (!g_strcmp0(sig, "CallActive")) {
363                 TelCallInfoActiveNoti_t data;
364                 g_variant_get(param, "(i)", &data.id);
365                 dbg("[ check ] %s : data.id(%d)", "Call Info Call Active noti", data.id);
366                 CALLBACK_CALL(&data.id);
367         }
368         else if (!g_strcmp0(sig, "CallHeld")) {
369                 TelCallInfoHeldNoti_t data;
370                 g_variant_get(param, "(i)", &data.id);
371                 dbg("[ check ] %s : data.id(%d)", "Call Info Call Held noti", data.id);
372                 CALLBACK_CALL(&data.id);
373         }
374         else if (!g_strcmp0(sig, "CallJoined")) {
375                 TelCallInfoJoinedNoti_t data;
376                 g_variant_get(param, "(i)", &data.id);
377                 dbg("[ check ] %s : data.id(%d)", "Call Info Call Joined noti", data.id);
378                 CALLBACK_CALL(&data.id);
379         }
380         else if (!g_strcmp0(sig, "CallSoundPath")) {
381                 TelCallSoundPathNoti_t data;
382                 g_variant_get(param, "(i)", &data.path);
383                 dbg("[ check ] %s : path(%d)", "Call Sound Path noti", data.path);
384                 CALLBACK_CALL(&data);
385         }
386         else if (!g_strcmp0(sig, "CallSoundRingbackTone")) {
387                 TelCallSoundRingbackToneNoti_t status;
388                 g_variant_get(param, "(i)", &status);
389                 dbg("[ check ] %s : status(%d)", "Call Sound Ringbacktone noti", status);
390                 CALLBACK_CALL(&status);
391         }
392         else if (!g_strcmp0(sig, "CallSoundWbamr")) {
393                 TelCallSoundWbamrNoti_t status;
394                 g_variant_get(param, "(i)", &status);
395                 dbg("[ check ] %s : status(%d)", "Call Sound Wbamr noti", status);
396                 CALLBACK_CALL(&status);
397         }
398         else if (!g_strcmp0(sig, "CallSoundEqualization")) {
399                 TelCallSoundEqualizationNoti_t data;
400                 g_variant_get(param, "(ii)", &data.mode, &data.direction);
401                 dbg("[ check ] %s : mode(%d), direction(%d)", "Call Sound Equalization noti", data.mode, data.direction);
402                 CALLBACK_CALL(&data);
403         }
404         else if (!g_strcmp0(sig, "CallSoundNoiseReduction")) {
405                 TelCallSoundNoiseReductionNoti_t data;
406                 g_variant_get(param, "(i)", &data.status);
407                 dbg("[ check ] %s : status(%d)", "Call Sound Noise Reduction noti", data.status);
408                 CALLBACK_CALL(&data);
409         }
410         else if (!g_strcmp0(sig, "CallSoundClockStatus")) {
411                 gboolean data;
412                 g_variant_get(param, "(b)", &data);
413                 dbg("[ check ] %s : status(%d)", "Call Sound Clock Status noti", data);
414                 CALLBACK_CALL(&data);
415         }
416         else {
417                 dbg("not handled Call noti[%s]", sig);
418         }
419 }
420
421 static void _process_sat_event(const gchar *sig, GVariant *param,
422         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
423 {
424         if (!evt_cb_data)
425                 return;
426
427         if (!g_strcmp0(sig, "SetupMenu")) {
428                 TelSatSetupMenuInfo_t setup_menu;
429
430                 gchar *title;
431                 gint command_id, item_cnt;
432                 gboolean b_present, b_helpinfo, b_updated;
433                 GVariant *items = NULL;
434
435                 memset(&setup_menu, 0, sizeof(TelSatSetupMenuInfo_t));
436
437                 g_variant_get(param, "(ibs@vibb)", &command_id, &b_present, &title, &items, &item_cnt,
438                                         &b_helpinfo, &b_updated);
439
440                 setup_menu.commandId = command_id;
441                 setup_menu.bIsMainMenuPresent = (b_present ? 1 : 0);
442                 memcpy(setup_menu.satMainTitle, title, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
443                 setup_menu.satMainMenuNum = item_cnt;
444                 if(items && item_cnt > 0){
445                         int index = 0;
446                         GVariant *unbox;
447                         GVariantIter *iter;
448
449                         gchar *item_str;
450                         gint item_id;
451                         unbox = g_variant_get_variant(items);
452                         dbg("items(%p) items type_format(%s)", items, g_variant_get_type_string(unbox));
453
454                         g_variant_get(unbox, "a(si)", &iter);
455                         while(g_variant_iter_loop(iter,"(si)",&item_str, &item_id)){
456                                 setup_menu.satMainMenuItem[index].itemId = item_id;
457                                 memcpy(setup_menu.satMainMenuItem[index].itemString, item_str, TAPI_SAT_DEF_ITEM_STR_LEN_MAX + 6);
458                                 dbg("item index(%d) id(%d) str(%s)",index, setup_menu.satMainMenuItem[index].itemId, setup_menu.satMainMenuItem[index].itemString);
459                                 //dbg("item index(%d) id(%d) str(%s)",index, item_id, item_str);
460                                 index++;
461                         }
462                         g_variant_iter_free(iter);
463                 }
464                 setup_menu.bIsSatMainMenuHelpInfo = (b_helpinfo ? 1 : 0);
465                 setup_menu.bIsUpdatedSatMainMenu = (b_updated ? 1 : 0);
466
467                 dbg("command id (%d)", setup_menu.commandId);
468                 dbg("menu present (%d)", setup_menu.bIsMainMenuPresent);
469                 dbg("menu title (%s)", setup_menu.satMainTitle);
470                 dbg("item cnt (%d)", setup_menu.satMainMenuNum);
471                 dbg("menu help info (%d)", setup_menu.bIsSatMainMenuHelpInfo);
472                 dbg("menu updated (%d)", setup_menu.bIsUpdatedSatMainMenu);
473
474                 CALLBACK_CALL(&setup_menu);
475         }
476         else if (!g_strcmp0(sig, "DisplayText")) {
477                 TelSatDisplayTextInd_t display_text;
478
479                 gchar* text;
480                 gint command_id, text_len, duration;
481                 gboolean high_priority, user_rsp_required, immediately_rsp;
482
483                 memset(&display_text, 0, sizeof(TelSatDisplayTextInd_t));
484
485                 g_variant_get(param, "(isiibbb)", &command_id, &text, &text_len, &duration,
486                         &high_priority, &user_rsp_required, &immediately_rsp);
487
488                 display_text.commandId = command_id;
489                 memcpy(display_text.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
490                 display_text.text.stringLen = text_len;
491                 display_text.duration = duration;
492                 display_text.bIsPriorityHigh = (high_priority ? 1 : 0);
493                 display_text.bIsUserRespRequired = (user_rsp_required ? 1 : 0);
494                 display_text.b_immediately_resp = (immediately_rsp ? 1 : 0);
495
496                 dbg("command id (%d)", display_text.commandId);
497                 dbg("display text (%s)", display_text.text.string);
498                 dbg("string len(%d)", display_text.text.stringLen);
499                 dbg("duration (%d)", display_text.duration);
500                 dbg("high priority (%d)", display_text.bIsPriorityHigh);
501                 dbg("user response required(%d)", display_text.bIsUserRespRequired);
502                 dbg("immediately response (%d)", display_text.b_immediately_resp);
503
504                 CALLBACK_CALL(&display_text);
505         }
506         else if (!g_strcmp0(sig, "SelectItem")) {
507                 TelSatSelectItemInd_t select_item;
508
509                 gboolean help_info ;
510                 gchar *selected_text;
511                 gint command_id, default_item_id, menu_cnt, text_len =0;
512                 GVariant *menu_items;
513
514                 memset(&select_item, 0, sizeof(TelSatSelectItemInd_t));
515
516                 g_variant_get(param, "(ibsiii@v)", &command_id, &help_info, &selected_text,
517                         &text_len, &default_item_id, &menu_cnt, &menu_items);
518
519                 select_item.commandId = command_id;
520                 select_item.bIsHelpInfoAvailable = (help_info ? 1 : 0);
521                 memcpy(select_item.text.string, selected_text, TAPI_SAT_DEF_TITLE_LEN_MAX+1);
522                 select_item.text.stringLen = text_len;
523                 select_item.defaultItemIndex = default_item_id;
524                 select_item.menuItemCount = menu_cnt;
525                 if(menu_items && menu_cnt > 0){
526                         int index = 0;
527                         GVariant *unbox;
528                         GVariantIter *iter;
529
530                         gchar *item_str;
531                         gint item_id, item_len;
532                         unbox = g_variant_get_variant(menu_items);
533                         dbg("items(%p) items type_format(%s)", menu_items, g_variant_get_type_string(unbox));
534
535                         g_variant_get(unbox, "a(iis)", &iter);
536                         while(g_variant_iter_loop(iter,"(iis)",&item_id, &item_len, &item_str)){
537                                 select_item.menuItem[index].itemId = item_id;
538                                 select_item.menuItem[index].textLen = item_len;
539                                 memcpy(select_item.menuItem[index].text, item_str, TAPI_SAT_ITEM_TEXT_LEN_MAX + 1);
540                                 dbg("item index(%d) id(%d) len(%d) str(%s)", index,
541                                                 select_item.menuItem[index].itemId, select_item.menuItem[index].textLen, select_item.menuItem[index].text);
542                                 index++;
543                         }
544                         g_variant_iter_free(iter);
545                 }
546
547                 dbg("command id (%d)", select_item.commandId);
548                 dbg("help info(%d)", select_item.bIsHelpInfoAvailable);
549                 dbg("selected item string(%s)", select_item.text.string);
550                 dbg("string len(%d)", select_item.text.stringLen);
551                 dbg("default item index(%d)", select_item.defaultItemIndex);
552                 dbg("item count(%d)", select_item.menuItemCount);
553
554                 CALLBACK_CALL(&select_item);
555         }
556         else if (!g_strcmp0(sig, "GetInkey")) {
557                 TelSatGetInkeyInd_t get_inkey;
558
559                 gint command_id, key_type, input_character_mode;
560                 gint text_len, duration;
561                 gboolean b_numeric, b_help_info;
562                 gchar *text;
563
564                 memset(&get_inkey, 0, sizeof(TelSatGetInkeyInd_t));
565
566                 g_variant_get(param, "(iiibbsii)", &command_id, &key_type, &input_character_mode,
567                         &b_numeric,&b_help_info, &text, &text_len, &duration);
568
569                 get_inkey.commandId = command_id;
570                 get_inkey.keyType = key_type;
571                 get_inkey.inputCharMode = input_character_mode;
572                 get_inkey.bIsNumeric = (b_numeric ? 1 : 0);
573                 get_inkey.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
574                 memcpy(get_inkey.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
575                 get_inkey.text.stringLen = text_len;
576                 get_inkey.duration = duration;
577
578                 dbg("command id(%d)", get_inkey.commandId);
579                 dbg("key type(%d)", get_inkey.keyType);
580                 dbg("input character mode(%d)", get_inkey.inputCharMode);
581                 dbg("numeric(%d)", get_inkey.bIsNumeric);
582                 dbg("help info available(%d)", get_inkey.bIsHelpInfoAvailable);
583                 dbg("text (%s)", get_inkey.text.string);
584                 dbg("text length", get_inkey.text.stringLen);
585                 dbg("duration", get_inkey.duration);
586
587                 CALLBACK_CALL(&get_inkey);
588         }
589         else if (!g_strcmp0(sig, "GetInput")) {
590                 TelSatGetInputInd_t get_input;
591
592                 gint command_id, input_character_mode;
593                 gint text_len, def_text_len, rsp_len_min, rsp_len_max;
594                 gboolean b_numeric, b_help_info, b_echo_input;
595                 gchar *text, *def_text;
596
597                 memset(&get_input, 0, sizeof(TelSatGetInputInd_t));
598
599                 g_variant_get(param, "(iibbbsiiisi)", &command_id, &input_character_mode, &b_numeric, &b_help_info, &b_echo_input,
600                         &text, &text_len, &rsp_len_max, &rsp_len_min, &def_text, &def_text_len);
601
602                 get_input.commandId = command_id;
603                 get_input.inputCharMode = input_character_mode;
604                 get_input.bIsNumeric = (b_numeric ? 1 : 0);
605                 get_input.bIsHelpInfoAvailable = (b_help_info ? 1 : 0);
606                 get_input.bIsEchoInput = (b_echo_input ? 1 : 0);
607                 memcpy(get_input.text.string, text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
608                 get_input.text.stringLen = text_len;
609                 get_input.respLen.max = rsp_len_max;
610                 get_input.respLen.min = rsp_len_min;
611                 memcpy(get_input.defaultText.string, def_text, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
612                 get_input.defaultText.stringLen = def_text_len;
613
614                 dbg("command id(%d)", get_input.commandId);
615                 dbg("input character mode(%d)", get_input.inputCharMode);
616                 dbg("numeric(%d)", get_input.bIsNumeric);
617                 dbg("help info avaiable(%d)", get_input.bIsHelpInfoAvailable);
618                 dbg("echo input(%d)", get_input.bIsEchoInput);
619                 dbg("text(%s)", get_input.text.string);
620                 dbg("text length(%d)", get_input.text.stringLen);
621                 dbg("response length max(%d)", get_input.respLen.max);
622                 dbg("response length min(%d)", get_input.respLen.min);
623                 dbg("default text(%s)", get_input.defaultText.string);
624                 dbg("default text length(%d)", get_input.defaultText.stringLen);
625
626                 CALLBACK_CALL(&get_input);
627         }
628         else if (!g_strcmp0(sig, "SendSMS")) {
629                 TelSatSendSmsIndSmsData_t send_sms;
630
631                 gint command_id, ton, npi, tpdu_type;
632                 gboolean b_packing_required;
633                 gint text_len, number_len, tpdu_data_len;
634                 gchar* text, *dialling_number;
635                 GVariant *tpdu_data;
636
637                 memset(&send_sms, 0, sizeof(TelSatSendSmsIndSmsData_t));
638
639                 g_variant_get(param, "(isibiisii@vi)", &command_id, &text, &text_len, &b_packing_required, &ton, &npi,
640                                         &dialling_number, &number_len, &tpdu_type, &tpdu_data, &tpdu_data_len);
641
642                 send_sms.commandId = command_id;
643                 send_sms.bIsPackingRequired = (b_packing_required ? 1 : 0);
644
645                 send_sms.address.ton = ton;
646                 send_sms.address.npi = npi;
647                 send_sms.address.diallingNumberLen = number_len;
648                 memcpy(send_sms.address.diallingNumber, dialling_number, TAPI_SAT_DIALLING_NUMBER_LEN_MAX);
649
650                 send_sms.smsTpdu.tpduType = tpdu_type;
651                 send_sms.smsTpdu.dataLen = tpdu_data_len;
652
653                 if(tpdu_data){
654                         int index = 0;
655                         guchar data;
656                         GVariantIter *iter = NULL;
657                         GVariant *inner_gv = NULL;
658
659                         inner_gv = g_variant_get_variant(tpdu_data);
660                         dbg("tpdu data exist type_format(%s)", g_variant_get_type_string(inner_gv));
661
662                         g_variant_get(inner_gv, "ay", &iter);
663                         while( g_variant_iter_loop (iter, "y", &data)){
664                                 dbg("index(%d) data(%c)", index, data);
665                                 send_sms.smsTpdu.data[index] = data;
666                                 index++;
667                         }
668                         g_variant_iter_free(iter);
669                         g_variant_unref(inner_gv);
670                 }
671
672                 dbg("command id(%d)", send_sms.commandId);
673                 dbg("packing required(%d)", send_sms.bIsPackingRequired);
674                 dbg("address ton(%d)", send_sms.address.ton);
675                 dbg("address npi(%d)", send_sms.address.npi);
676                 dbg("address dialing number (%s)", send_sms.address.diallingNumber);
677                 dbg("address number length (%d)", send_sms.address.diallingNumberLen);
678                 dbg("tpdu type (%d)", send_sms.smsTpdu.tpduType);
679                 dbg("tpdu length (%d)", send_sms.smsTpdu.dataLen);
680
681                 CALLBACK_CALL(&send_sms);
682         }
683         else if (!g_strcmp0(sig, "SetupEventList")) {
684                 int g_index = 0;
685                 gint event_cnt;
686                 GVariant *evt_list;
687                 TelSatEventListData_t event_list;
688
689                 memset(&event_list, 0, sizeof(TelSatEventListData_t));
690
691                 g_variant_get(param, "(i@v)", &event_cnt, &evt_list);
692
693                 if(evt_list){
694                         guchar data;
695                         GVariantIter *iter = NULL;
696                         GVariant *inner_gv = NULL;
697
698                         inner_gv = g_variant_get_variant(evt_list);
699                         dbg("event list exist type_format(%s)", g_variant_get_type_string(inner_gv));
700
701                         g_variant_get(inner_gv, "ai", &iter);
702                         while( g_variant_iter_loop (iter, "i", &data)){
703                                 dbg("g_index(%d) event(%d)", g_index, data);
704                                 g_event_list[g_index] = data;
705
706                                 if(data == TAPI_EVENT_SAT_DW_TYPE_IDLE_SCREEN_AVAILABLE){
707                                         event_list.bIsIdleScreenAvailable = 1;
708                                 }
709                                 else if(data == TAPI_EVENT_SAT_DW_TYPE_LANGUAGE_SELECTION){
710                                         event_list.bIsLanguageSelection = 1;
711                                 }
712                                 else if(data == TAPI_EVENT_SAT_DW_TYPE_BROWSER_TERMINATION){
713                                         event_list.bIsBrowserTermination = 1;
714                                 }
715                                 else if(data == TAPI_EVENT_SAT_DW_TYPE_DATA_AVAILABLE){
716                                         event_list.bIsDataAvailable = 1;
717                                 }
718                                 else if(data == TAPI_EVENT_SAT_DW_TYPE_CHANNEL_STATUS){
719                                         event_list.bIsChannelStatus = 1;
720                                 }
721
722                                 g_index++;
723                         }
724                         //while end
725                         g_variant_iter_free(iter);
726                         g_variant_unref(inner_gv);
727                 }
728
729                 dbg("event list cnt(%d)", event_cnt);
730
731                 CALLBACK_CALL(&event_list);
732         }
733         else if (!g_strcmp0(sig, "Refresh")) {
734                 TelSatRefreshInd_t refresh_info;
735
736                 gint command_id = 0;
737                 gint refresh_type =0;
738                 gint file_cnt = 0;
739                 GVariant *file_list = NULL;
740
741                 memset(&refresh_info, 0, sizeof(TelSatRefreshInd_t));
742
743                 g_variant_get(param, "(ii@v)", &command_id, &refresh_type, &file_list);
744
745                 refresh_info.commandId = command_id;
746                 refresh_info.refreshMode = refresh_type;
747
748                 if(file_list){
749                         int g_index = 0;
750                         guchar data;
751                         GVariantIter *iter = NULL;
752                         GVariant *inner_gv = NULL;
753
754                         inner_gv = g_variant_get_variant(file_list);
755                         dbg("file list exist type_format(%s)", g_variant_get_type_string(inner_gv));
756
757                         g_variant_get(inner_gv, "ai", &iter);
758                         while( g_variant_iter_loop (iter, "i", &data)){
759                                 dbg("g_index(%d) file id(%d)", g_index, data);
760                                 refresh_info.fileId[g_index] = data;
761                                 g_index++;
762                         }
763                         file_cnt = g_index;
764
765                         //while end
766                         g_variant_iter_free(iter);
767                         g_variant_unref(inner_gv);
768                 }
769                 refresh_info.fileCount = file_cnt;
770
771                 dbg("refresh event/file cnt(%d)", refresh_info.fileCount);
772
773                 CALLBACK_CALL(&refresh_info);
774         }
775         else if (!g_strcmp0(sig, "SendDtmf")) {
776                 TelSatSendDtmfIndDtmfData_t send_dtmf;
777
778                 gint command_id = 0;
779                 gint text_len = 0, dtmf_str_len = 0;
780                 gchar *text = NULL;
781                 gchar *dtmf_str = NULL;
782
783                 memset(&send_dtmf, 0, sizeof(TelSatSendDtmfIndDtmfData_t));
784
785                 g_variant_get(param, "(isisi)", &command_id, &text, &text_len, &dtmf_str, &dtmf_str_len);
786
787                 send_dtmf.commandId = command_id;
788                 if(text_len <= 0 || g_strcmp0(text,"") == 0 ){
789                         send_dtmf.bIsHiddenMode = 1;
790                 }
791
792                 send_dtmf.dtmfString.stringLen = dtmf_str_len;
793                 memcpy(send_dtmf.dtmfString.string, dtmf_str, TAPI_SAT_DEF_TEXT_STRING_LEN_MAX+1);
794
795                 dbg("dtmf event command id(%d)", send_dtmf.commandId);
796                 dbg("dtmf event dtmf(%s)", send_dtmf.dtmfString.string);
797
798                 CALLBACK_CALL(&send_dtmf);
799         }
800         else if (!g_strcmp0(sig, "EndProactiveSession")) {
801                 int command_type = 0;
802
803                 g_variant_get(param, "(i)", &command_type);
804                 dbg("end session evt : command type(%d)", command_type);
805                 CALLBACK_CALL(&command_type);
806         }
807         else {
808                 dbg("not handled Sat noti[%s]", sig);
809         }
810 }
811
812 static void _process_sim_event(const gchar *sig, GVariant *param,
813         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
814 {
815         if (!evt_cb_data)
816                 return;
817
818         if (!g_strcmp0(sig, "Status")) {
819                 int noti = 0;
820                 g_variant_get(param, "(i)", &noti);
821                 CALLBACK_CALL(&noti);
822         } else {
823                 dbg("not handled SIM noti[%s]",sig );
824         }
825 }
826
827 static void _process_pb_event(const gchar *sig, GVariant *param,
828         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
829 {
830         if (!evt_cb_data)
831                 return;
832
833         if (!g_strcmp0(sig, "Status")) {
834                 int noti = 0;
835                 g_variant_get(param, "(i)", &noti);
836                 CALLBACK_CALL(&noti);
837         } else {
838                 dbg("not handled Phonebook noti[%s]",sig );
839         }
840 }
841
842 static void _process_sap_event(const gchar *sig, GVariant *param,
843         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
844 {
845         if (!evt_cb_data)
846                 return;
847
848         if (!g_strcmp0(sig, "Status")) {
849                 int noti = 0;
850                 g_variant_get(param, "(i)", &noti);
851                 CALLBACK_CALL(&noti);
852         } else if (!g_strcmp0(sig, "Disconnect")) {
853                 int disconnect = 0;
854                 g_variant_get(param, "(i)", &disconnect);
855                 CALLBACK_CALL(&disconnect);
856         } else {
857                 dbg("not handled SAP noti[%s]",sig );
858         }
859 }
860
861 static void _process_modem_event(const gchar *sig, GVariant *param,
862         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
863 {
864         if (!evt_cb_data)
865                 return;
866
867         if (!g_strcmp0(sig, "Power")) {
868                 int noti = 0;
869
870                 g_variant_get(param, "(i)", &noti);
871
872                 CALLBACK_CALL(&noti);
873         }
874         else if (!g_strcmp0(sig, "DunPinCtrl")) {
875                 tapi_ps_btdun_pincontrol pin_ctrl;
876                 int signal = 0, status = 0;
877
878                 memset(&pin_ctrl, 0, sizeof(tapi_ps_btdun_pincontrol));
879                 g_variant_get(param, "(ib)", &signal, &status);
880                 pin_ctrl.signal = signal;
881                 pin_ctrl.status = status;
882
883                 CALLBACK_CALL(&pin_ctrl);
884         }
885         else if (!g_strcmp0(sig, "DunExternalCall")) {
886                 gboolean external_call;
887
888                 g_variant_get(param, "(b)", &external_call);
889
890                 CALLBACK_CALL(&external_call);
891         }
892         else {
893                 dbg("not handled Modem noti[%s]", sig);
894         }
895
896         return;
897 }
898
899 static void _process_ss_event(const gchar *sig, GVariant *param,
900         TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
901 {
902         if (!evt_cb_data)
903                 return;
904
905         if (!g_strcmp0(sig, "NotifyUSSD")) {
906                 TelSsUssdMsgInfo_t noti;
907                 char *str = NULL;
908                 memset(&noti, 0, sizeof(TelSsUssdMsgInfo_t));
909
910                 g_variant_get(param, "(iis)", &noti.Type, &noti.Length, &str);
911
912                 if (str) {
913                         g_strlcpy(noti.szString, str, TAPI_SS_USSD_DATA_SIZE_MAX);
914                         g_free(str);
915                 }
916
917                 CALLBACK_CALL(&noti);
918
919         } else if (!g_strcmp0(sig, "ReleaseComplete")) {
920                 TelSsRelCompMsgInfo_t noti;
921                 GVariant *msg = 0;
922                 int len = 0;
923
924                 memset ( &noti, 0, sizeof( TelSsRelCompMsgInfo_t ));
925
926                 g_variant_get(param, "(i@v)", &len, &msg);
927
928                 noti.RelCompMsgLen = (unsigned char)len;
929
930                 if(msg){
931                         int i = 0;
932                         guchar data;
933                         GVariantIter *iter = NULL;
934                         GVariant *inner_gv = NULL;
935
936                         inner_gv = g_variant_get_variant(msg);
937                         dbg("[ check ] data exist type_format(%s)", g_variant_get_type_string(inner_gv));
938
939                         g_variant_get(inner_gv, "ay", &iter);
940                         while( g_variant_iter_loop (iter, "y", &data)){
941                                 dbg("index(%d) data(%c)", index, data);
942                                 noti.szRelCompMsg[i] = data;
943                                 i++;
944                         }
945                         g_variant_iter_free(iter);
946                         g_variant_unref(inner_gv);
947                 }
948
949                 CALLBACK_CALL(&noti);
950
951         } else {
952                 dbg("not handled SS noti[%s]", sig);
953         }
954
955         return;
956 }
957
958 static void _process_gps_event(const gchar *sig, GVariant *param,
959                 TapiHandle *handle, char *noti_id, struct tapi_evt_cb *evt_cb_data)
960 {
961         gboolean b_decode_data = FALSE;
962         guchar *decoded_data = NULL;
963
964         if (!evt_cb_data)
965                 return;
966
967         if (!g_strcmp0(sig, "AssistData")) {
968                 b_decode_data = TRUE;
969         }
970         else if (!g_strcmp0(sig, "MeasurePosition")) {
971                 b_decode_data = TRUE;
972         }
973         else if (!g_strcmp0(sig, "ResetAssistData")) {
974                 /* noting to decode */
975         }
976         else if (!g_strcmp0(sig, "FrequencyAiding")) {
977                 b_decode_data = TRUE;
978         }
979         else {
980                 dbg("not handled Gps noti[%s]", sig);
981         }
982
983         /* decoding data */
984         if(b_decode_data) {
985                 gchar *data = NULL;
986                 gsize length;
987                 dbg("[%s] decoding start", sig);
988
989                 g_variant_get(param, "(s)", &data);
990                 decoded_data = g_base64_decode((const gchar *)data, &length);
991                 if (decoded_data) {
992                         CALLBACK_CALL(decoded_data);
993                 }
994
995                 dbg("length=%d", length);
996         }
997
998         if (decoded_data)
999                 g_free(decoded_data);
1000 }
1001
1002 static void on_signal_callback(GDBusConnection *conn, const gchar *name, const gchar *path, const gchar *interface,
1003                 const gchar *sig, GVariant *param, gpointer user_data)
1004 {
1005         TapiHandle *handle = user_data;
1006         struct tapi_evt_cb *evt_cb_data = NULL;
1007         char *noti_id;
1008
1009         if (!handle) {
1010                 dbg("handle is NULL");
1011                 return;
1012         }
1013
1014         noti_id = g_strdup_printf("%s:%s", interface, sig);
1015
1016         evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1017         if (!evt_cb_data) {
1018                 dbg("can't find noti_id(%s) callback info", noti_id);
1019                 g_free(noti_id);
1020                 return;
1021         }
1022
1023         if (!g_strcmp0(interface, DBUS_TELEPHONY_NETWORK_INTERFACE)) {
1024                 _process_network_event(sig, param, handle, noti_id, evt_cb_data);
1025         }
1026         else if (!g_strcmp0(interface, DBUS_TELEPHONY_SMS_INTERFACE)) {
1027                 _process_sms_event(sig, param, handle, noti_id, evt_cb_data);
1028         }
1029         else if (!g_strcmp0(interface, DBUS_TELEPHONY_CALL_INTERFACE)) {
1030                 _process_call_event(sig, param, handle, noti_id, evt_cb_data);
1031         }
1032         else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAT_INTERFACE)) {
1033                 _process_sat_event(sig, param, handle, noti_id, evt_cb_data);
1034         }
1035         else if (!g_strcmp0(interface, DBUS_TELEPHONY_SIM_INTERFACE)) {
1036                 _process_sim_event(sig, param, handle, noti_id, evt_cb_data);
1037         }
1038         else if (!g_strcmp0(interface, DBUS_TELEPHONY_PB_INTERFACE)) {
1039                 _process_pb_event(sig, param, handle, noti_id, evt_cb_data);
1040         }
1041         else if (!g_strcmp0(interface, DBUS_TELEPHONY_SAP_INTERFACE)) {
1042                 _process_sap_event(sig, param, handle, noti_id, evt_cb_data);
1043         }
1044         else if (!g_strcmp0(interface, DBUS_TELEPHONY_MODEM_INTERFACE)) {
1045                 _process_modem_event(sig, param, handle, noti_id, evt_cb_data);
1046         }
1047         else if (!g_strcmp0(interface, DBUS_TELEPHONY_SS_INTERFACE)) {
1048                 _process_ss_event(sig, param, handle, noti_id, evt_cb_data);
1049         }
1050         else if (!g_strcmp0(interface, DBUS_TELEPHONY_GPS_INTERFACE)) {
1051                 _process_gps_event(sig, param, handle, noti_id, evt_cb_data);
1052         }
1053         else {
1054                 dbg("can't find interface(%s)", interface);
1055         }
1056         g_free(noti_id);
1057 }
1058
1059 EXPORT_API char** tel_get_cp_name_list(void)
1060 {
1061         GError *error = NULL;
1062         GDBusProxy *proxy = NULL;
1063
1064         GVariantIter *iter = NULL;
1065         GVariant *rst = NULL;
1066
1067         gchar *modem_path = NULL;
1068         GSList *list = NULL;
1069         GSList *l = NULL;
1070
1071         int i = 0, element_cnt = 0;
1072         gchar **cp_list = NULL;
1073
1074         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1075                                 "org.tizen.telephony", "/org/tizen/telephony", "org.tizen.telephony.Manager",
1076                                 NULL, &error);
1077         if (!proxy) {
1078                 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1079                 g_error_free (error);
1080                 return NULL;
1081         }
1082
1083         rst = g_dbus_proxy_call_sync (proxy, "GetModems", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1084         if (!rst) {
1085                 dbg( "GetModems() failed. (%s)", error->message);
1086                 g_error_free (error);
1087                 goto OUT;
1088         }
1089
1090         g_variant_get (rst, "(as)", &iter);
1091         while (g_variant_iter_next(iter, "s", &modem_path))
1092                 list = g_slist_append(list, modem_path);
1093
1094         g_variant_iter_free(iter);
1095         g_variant_unref(rst);
1096
1097         if (!list) {
1098                 dbg( "No CP name");
1099                 goto OUT;
1100         }
1101
1102         element_cnt = g_slist_length(list);
1103         cp_list = g_new0(char*, element_cnt + 1);
1104         if (!cp_list) {
1105                 goto OUT;
1106         }
1107
1108         for (l = list; l; l = l->next, i++) {
1109                 cp_list[i] = g_strdup(l->data);
1110                 dbg("cp name[%d] = %s", i, cp_list[i]);
1111         }
1112         cp_list[element_cnt] = NULL;
1113
1114 OUT:
1115         g_slist_free_full(list, g_free);
1116         g_object_unref(proxy);
1117
1118         return cp_list;
1119 }
1120
1121 EXPORT_API int tel_get_property_int(TapiHandle *handle, const char *property, int *result)
1122 {
1123         char **dbus_info;
1124         GDBusProxy *proxy = NULL;
1125         GVariant *value = NULL;
1126         GError *error = NULL;
1127         int ret = TAPI_API_SUCCESS;
1128
1129         if (!handle || !property)
1130                 return TAPI_API_INVALID_INPUT;
1131
1132         dbus_info = g_strsplit(property, ":", 2);
1133         if (!dbus_info) {
1134                 dbg("invalid property");
1135                 return TAPI_API_INVALID_INPUT;
1136         }
1137
1138         if (!dbus_info[0] || !dbus_info[1]) {
1139                 dbg("invalid property");
1140                 ret = TAPI_API_INVALID_INPUT;
1141                 goto OUT;
1142         }
1143
1144         proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL,
1145                                 DBUS_TELEPHONY_SERVICE, handle->path, dbus_info[0],
1146                                 NULL, &error);
1147         if (!proxy) {
1148                 dbg("g_dbus_proxy_new_for_bus_sycn() failed. (%s)", error->message);
1149                 g_error_free (error);
1150                 ret = TAPI_API_OPERATION_FAILED;
1151                 goto OUT;
1152         }
1153
1154         value = g_dbus_proxy_get_cached_property(proxy, dbus_info[1]);
1155         if (!value) {
1156                 dbg("g_dbus_proxy_get_cached_property('power') failed.");
1157                 ret = TAPI_API_OPERATION_FAILED;
1158                 goto OUT;
1159         }
1160
1161         g_variant_get(value, "i", result);
1162         g_variant_unref(value);
1163
1164 OUT:
1165         if (proxy)
1166                 g_object_unref(proxy);
1167
1168         g_strfreev(dbus_info);
1169
1170         return ret;
1171 }
1172
1173 EXPORT_API TapiHandle* tel_init(const char *cp_name)
1174 {
1175         GError *error = NULL;
1176         struct tapi_handle *handle = NULL;
1177         gchar *addr;
1178 #if !GLIB_CHECK_VERSION (2, 35, 3)
1179         g_type_init();
1180 #endif
1181
1182         dbg("process info: env: [%s] invocation: [%s]",
1183                                                 getenv("_"), program_invocation_name);
1184
1185         /* Get System BUS */
1186         addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM,
1187                                                                                 NULL,
1188                                                                                 &error);
1189         if (addr == NULL) {
1190                 err("Error get dbus: [%s]", error->message);
1191                 goto ERROR;
1192         }
1193
1194         /* Allocate new Handle */
1195         handle = g_try_new0(struct tapi_handle, 1);
1196         if (handle == NULL) {
1197                 err("Failed to allocate handle");
1198                 goto ERROR;
1199         }
1200
1201         /* Create DBUS connection */
1202         handle->dbus_connection = g_dbus_connection_new_for_address_sync(addr,
1203                                                         (G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
1204                                                         G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
1205                                                         NULL,
1206                                                         NULL,
1207                                                         &error);
1208         if (handle->dbus_connection == NULL) {
1209                 err("Error creating DBUS connection: [%s]", error->message);
1210                 goto ERROR;
1211         }
1212
1213         handle->ca = g_cancellable_new();
1214         if (handle->ca == NULL) {
1215                 err("Error allocating cancellable object");
1216                 goto ERROR;
1217         }
1218
1219         /* Get CP name */
1220         if (cp_name != NULL)
1221                 handle->cp_name = g_strdup(cp_name);
1222         else {
1223                 char **list = NULL;
1224                 int i = 0;
1225
1226                 /* Get CP Name list */
1227                 list = tel_get_cp_name_list();
1228                 if ((list == NULL) || (list[0] == NULL)) {
1229                         err("Get CP name list failed");
1230
1231                         g_free(list);
1232                         goto ERROR;
1233                 }
1234
1235                 /*
1236                  * Presently, we would only be providing the 'default' CP name,
1237                  * it is the first CP name in the obtained list of CP names.
1238                  *
1239                  * We would evolve this logic in due course.
1240                  */
1241                 dbg("Use 'default' Plug-in: [%s]", list[0]);
1242                 handle->cp_name = g_strdup(list[0]);
1243
1244                 /* Free CP name list */
1245                 while (list[i] != NULL)
1246                         g_free(list[i++]);
1247
1248                 g_free(list);
1249         }
1250
1251         /* Create Event list Hash Table */
1252         handle->evt_list = g_hash_table_new_full(g_str_hash,
1253                                                                                 g_str_equal,
1254                                                                                 g_free,
1255                                                                                 g_free);
1256
1257         /* Set Path */
1258         handle->path = g_strdup_printf("%s/%s",
1259                                         DBUS_TELEPHONY_DEFAULT_PATH, handle->cp_name);
1260         dbg("handle: [0x%x] Path: [%s]", handle, handle->path);
1261
1262         g_free(addr);
1263         return handle;
1264
1265 ERROR:
1266         /* Free all resources */
1267         g_free(addr);
1268         g_error_free (error);
1269
1270         if (handle != NULL) {
1271                 g_cancellable_cancel(handle->ca);
1272                 g_object_unref(handle->ca);
1273
1274                 if (g_dbus_connection_close_sync(handle->dbus_connection,
1275                                                                         NULL,
1276                                                                         NULL) == FALSE) {
1277                         err("Failed to close connection");
1278                 }
1279                 g_object_unref(handle->dbus_connection);
1280                 g_free(handle);
1281         }
1282
1283         return NULL;
1284 }
1285
1286 static gboolean _unregister_noti(gpointer key, gpointer value, gpointer user_data)
1287 {
1288         struct tapi_evt_cb *evt_cb_data = value;
1289         TapiHandle *handle = user_data;
1290
1291         if (handle == NULL)
1292                 return TRUE;
1293
1294         g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1295
1296         return TRUE;
1297 }
1298
1299 EXPORT_API int tel_deinit(TapiHandle *handle)
1300 {
1301         if (handle == NULL)
1302                 return TAPI_API_INVALID_INPUT;
1303
1304         g_free(handle->cp_name);
1305         g_free(handle->path);
1306
1307         dbg("Remove all signals");
1308         g_hash_table_foreach_remove(handle->evt_list, _unregister_noti, handle);
1309         g_hash_table_destroy(handle->evt_list);
1310
1311         g_cancellable_cancel(handle->ca);
1312         g_object_unref(handle->ca);
1313
1314         dbg("Close DBUS connection");
1315         if (g_dbus_connection_close_sync(handle->dbus_connection,
1316                                                                         NULL, NULL) == FALSE) {
1317                 err("Failed to close DBUS connection");
1318         }
1319         g_object_unref(handle->dbus_connection);
1320         g_free(handle);
1321
1322         dbg("deinit complete");
1323         return TAPI_API_SUCCESS;
1324 }
1325
1326 EXPORT_API int tel_register_noti_event(TapiHandle *handle, const char *noti_id,
1327                                                                 tapi_notification_cb callback, void *user_data)
1328 {
1329         gchar **dbus_str = NULL;
1330         gpointer tmp = NULL;
1331         struct tapi_evt_cb *evt_cb_data = NULL;
1332
1333         if ((handle == NULL) || (handle->dbus_connection == NULL)
1334                         || (callback == NULL) || (noti_id == NULL)) {
1335                 err("Invalid input parameters");
1336                 return TAPI_API_INVALID_INPUT;
1337         }
1338
1339         tmp = g_hash_table_lookup(handle->evt_list, noti_id);
1340         if (tmp != NULL) {
1341                 dbg("noti_id(%s) is already registered", noti_id);
1342                 return TAPI_API_INVALID_INPUT;
1343         }
1344
1345         dbus_str = g_strsplit(noti_id, ":", 2);
1346         if (!dbus_str) {
1347                 dbg("invalid noti_id");
1348                 return TAPI_API_INVALID_INPUT;
1349         }
1350
1351         if (!dbus_str[0] || !dbus_str[1]) {
1352                 g_strfreev(dbus_str);
1353                 dbg("invalid noti_id");
1354                 return TAPI_API_INVALID_INPUT;
1355         }
1356
1357         evt_cb_data = g_try_new0(struct tapi_evt_cb, 1);
1358         if (evt_cb_data == NULL) {
1359                 err("Failed to allocate memory");
1360                 g_strfreev(dbus_str);
1361                 return TAPI_API_SYSTEM_OUT_OF_MEM;
1362         }
1363
1364         /* Assign callback and user_data */
1365         evt_cb_data->cb_fn = callback;
1366         evt_cb_data->user_data = user_data;
1367         evt_cb_data->handle = handle;
1368
1369         dbg("path(%s) interface (%s) signal (%s)", handle->path, dbus_str[0], dbus_str[1]);
1370
1371         evt_cb_data->evt_id = g_dbus_connection_signal_subscribe(handle->dbus_connection,
1372                         DBUS_TELEPHONY_SERVICE, /* Sender */
1373                         dbus_str[0], /* Interface */
1374                         dbus_str[1], /* Member */
1375                         handle->path, /* Object path */
1376                         NULL, /* arg0 */
1377                         G_DBUS_SIGNAL_FLAGS_NONE,
1378                         on_signal_callback, handle,
1379                         NULL);
1380
1381         g_hash_table_insert(handle->evt_list, g_strdup(noti_id), evt_cb_data);
1382
1383         g_strfreev(dbus_str);
1384
1385         return TAPI_API_SUCCESS;
1386 }
1387
1388 EXPORT_API int tel_deregister_noti_event(TapiHandle *handle, const char *noti_id)
1389 {
1390         struct tapi_evt_cb *evt_cb_data = NULL;
1391         gboolean rv = FALSE;
1392
1393         if (!handle || !handle->dbus_connection){
1394                 dbg("invalid parameter");
1395                 return TAPI_API_INVALID_INPUT;
1396         }
1397
1398         evt_cb_data = g_hash_table_lookup(handle->evt_list, noti_id);
1399
1400         if(!evt_cb_data){
1401                 dbg("event does not registered");
1402                 return TAPI_API_INVALID_INPUT;
1403         }
1404
1405         g_dbus_connection_signal_unsubscribe(handle->dbus_connection, evt_cb_data->evt_id);
1406
1407         rv = g_hash_table_remove(handle->evt_list, noti_id);
1408         if(!rv){
1409                 dbg("fail to deregister noti event(%s)", noti_id);
1410                 return TAPI_API_OPERATION_FAILED;
1411         }
1412
1413         return TAPI_API_SUCCESS;
1414 }
1415 /*      EOF     */