2 * tel-plugin-socket-communicator
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
25 #include <glib-object.h>
31 #include <communicator.h>
32 #include <core_object.h>
34 #include <user_request.h>
36 #include <co_phonebook.h>
40 #include "tapi_common.h"
41 #include "module_req.h"
43 gboolean scomm_service_reqeust_pb(unsigned int ch_id, Communicator *c, TcorePlugin *plugin, tapi_service_command_e cmd, gchar *data, void **outparam)
45 GSList *co_list = NULL;
46 CoreObject *co_pb = NULL;
47 UserRequest *ur = NULL;
48 struct tcore_user_info ui = { 0, 0, 0, NULL,0,0, NULL };
53 struct _tapi_service_object out_o = {0,};
54 struct _sipc_marshal_object *in_o;
56 co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_PHONEBOOK);
58 dbg("err-no phonebook core object list in current plugin");
62 co_pb = (CoreObject *)co_list->data;
64 dbg("err-no phonebook core object in current plugin");
68 g_slist_free(co_list);
70 if (cmd == TAPI_SERVICE_PB_GET_INITINFO ) {
71 /*synchronous data return case*/
73 out_o.mo = sipc_util_marshal_object_create();
75 /*asynchronous data return case*/
76 ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
78 dbg("err - ur creation failed");
82 ui.channel_id = ch_id;
84 tcore_user_request_set_user_info(ur, &ui);
86 in_o = sipc_util_marshal_object_deserializer(data);
88 dbg("err - data deserializer failed");
94 case TAPI_SERVICE_PB_GET_INITINFO : {
96 struct tel_phonebook_support_list *g_pb_list;
97 g_init = tcore_phonebook_get_status(co_pb);
98 g_pb_list = (struct tel_phonebook_support_list*)tcore_phonebook_get_support_list(co_pb);
99 sipc_util_marshal_object_add_data(out_o.mo, "status", (void*)&g_init, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
100 sipc_util_marshal_object_add_data(out_o.mo, "support_fdn", (void*)&g_pb_list->b_fdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
101 sipc_util_marshal_object_add_data(out_o.mo, "support_adn", (void*)&g_pb_list->b_adn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
102 sipc_util_marshal_object_add_data(out_o.mo, "support_sdn", (void*)&g_pb_list->b_sdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
103 sipc_util_marshal_object_add_data(out_o.mo, "support_usim", (void*)&g_pb_list->b_usim, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
104 sipc_util_marshal_object_add_data(out_o.mo, "support_grp", (void*)&g_pb_list->b_gas, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
106 tmp = sipc_util_marshal_object_serializer(out_o.mo);
107 tmp_len = strlen(tmp);
108 *outparam = g_new0(char, tmp_len+1);
109 memcpy(*outparam, tmp, tmp_len);
114 case TAPI_SERVICE_PB_GET_COUNT : {
115 struct treq_phonebook_get_count pb_count;
116 enum tel_phonebook_type g_pb_type;
117 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
118 pb_count.phonebook_type = g_pb_type;
120 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_count), &pb_count);
121 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETCOUNT);
125 case TAPI_SERVICE_PB_GET_META : {
126 struct treq_phonebook_get_info pb_info;
127 struct treq_phonebook_get_usim_info pb_usim;
128 enum tel_phonebook_type g_pb_type;
129 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
130 pb_info.phonebook_type = g_pb_type;
132 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_info), &pb_info);
133 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETMETAINFO);
137 case TAPI_SERVICE_PB_READ_RECORD : {
138 struct treq_phonebook_read_record pb_read;
139 enum tel_phonebook_type g_pb_type;
141 g_index = sipc_util_marshal_object_get_int(in_o, "index");
142 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
143 pb_read.index = (unsigned short)g_index;
144 pb_read.phonebook_type = g_pb_type;
146 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_read_record), &pb_read);
147 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_READRECORD);
151 case TAPI_SERVICE_PB_UPDATE_RECORD : {
152 struct treq_phonebook_update_record pb_update;
153 enum tel_phonebook_type g_pb_type;
155 gchar *g_name = NULL;
157 gchar *g_number = NULL;
159 gchar *g_number2 = NULL;
160 gint g_number2_ton = 0;
161 gchar *g_number3 = NULL;
162 gint g_number3_ton = 0;
163 gchar *g_number4 = NULL;
164 gint g_number4_ton = 0;
165 gchar *g_email1 = NULL;
166 gchar *g_email2 = NULL;
167 gchar *g_email3 = NULL;
168 gchar *g_email4 = NULL;
169 gint g_group_index =0;
170 g_index = sipc_util_marshal_object_get_int(in_o, "index");
171 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
172 g_name = sipc_util_marshal_object_get_string(in_o, "name");
173 g_dcs = sipc_util_marshal_object_get_int(in_o, "dcs");
174 g_number = sipc_util_marshal_object_get_string(in_o, "number");
175 g_ton = sipc_util_marshal_object_get_int(in_o, "ton");
176 g_number2 = sipc_util_marshal_object_get_string(in_o, "number2");
177 g_number2_ton = sipc_util_marshal_object_get_int(in_o, "number2_ton");
178 g_number3 = sipc_util_marshal_object_get_string(in_o, "number3");
179 g_number3_ton = sipc_util_marshal_object_get_int(in_o, "number3_ton");
180 g_number4 = sipc_util_marshal_object_get_string(in_o, "number4");
181 g_number4_ton = sipc_util_marshal_object_get_int(in_o, "number4_ton");
182 g_email1 = sipc_util_marshal_object_get_string(in_o, "email1");
183 g_email2 = sipc_util_marshal_object_get_string(in_o, "email2");
184 g_email3 = sipc_util_marshal_object_get_string(in_o, "email3");
185 g_email4 = sipc_util_marshal_object_get_string(in_o, "email4");
186 g_group_index = sipc_util_marshal_object_get_int(in_o, "group_index");
188 pb_update.index = (unsigned short)g_index;
189 pb_update.phonebook_type = g_pb_type;
191 snprintf(pb_update.name, strlen(g_name)+1, g_name);
192 pb_update.dcs = g_dcs;
194 if(strlen(g_number)){
195 snprintf(pb_update.number, strlen(g_number)+1, g_number);
196 pb_update.ton = g_ton;
198 if(strlen(g_number2)){
199 snprintf(pb_update.anr1, strlen(g_number2)+1, g_number2);
200 pb_update.anr1_ton = g_number2_ton;
202 if(strlen(g_number3)){
203 snprintf(pb_update.anr2, strlen(g_number3)+1, g_number3);
204 pb_update.anr2_ton = g_number3_ton;
206 if(strlen(g_number4)){
207 snprintf(pb_update.anr3, strlen(g_number4)+1, g_number4);
208 pb_update.anr3_ton = g_number4_ton;
210 pb_update.group_index = (unsigned short)g_group_index;
212 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_update_record), &pb_update);
213 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_UPDATERECORD);
217 case TAPI_SERVICE_PB_DELETE_RECORD : {
218 struct treq_phonebook_delete_record pb_delete;
219 enum tel_phonebook_type g_pb_type;
221 g_index = sipc_util_marshal_object_get_int(in_o, "index");
222 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
223 pb_delete.index = (unsigned short)g_index;
224 pb_delete.phonebook_type = g_pb_type;
226 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_delete_record), &pb_delete);
227 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_DELETERECORD);
232 dbg("not handled command [%d] here",cmd);
236 if (cmd == TAPI_SERVICE_PB_GET_INITINFO ) {
237 /*synchronous data return case*/
239 /*asynchronous data return case*/
240 ret = tcore_communicator_dispatch_request(c, ur);
241 if (ret != TCORE_RETURN_SUCCESS) {
249 gboolean scomm_service_response_pb(Communicator *comm, UserRequest *ur, enum tcore_response_command command,
250 unsigned int data_len, const void *data)
252 const struct tresp_phonebook_get_count *resp_pbcnt = data;
253 const struct tresp_phonebook_get_info *resp_entry = data;
254 const struct tresp_phonebook_get_usim_info *resp_capa = data;
255 const struct tresp_phonebook_read_record *resp_pbread = data;
256 const struct tresp_phonebook_update_record *resp_pbupdate = data;
257 const struct tresp_phonebook_delete_record *resp_pbdelete = data;
260 gchar *out_d= NULL, *serial_d = NULL;
261 gchar *entry_key = NULL;
262 struct custom_data *ctx = NULL;
263 const struct tcore_user_info *ui;
264 sipc_server_t *s = NULL;
265 struct _tapi_header hdr;
266 struct _sipc_marshal_object* out_o = NULL;
267 struct _sipc_marshal_object* entry_o = NULL;
269 memset(&hdr, 0, sizeof(struct _tapi_header));
271 ctx = tcore_communicator_ref_user_data(comm);
273 dbg("user_data is NULL");
277 ui = tcore_user_request_ref_user_info(ur);
280 dbg("application channel id(%d), Command = [0x%x], data_len = %d", ui->channel_id, command, data_len);
281 hdr.cmd = (tapi_service_command_e)ui->client_cmd;
283 out_o = sipc_util_marshal_object_create();
286 case TRESP_PHONEBOOK_GETCOUNT:
287 dbg("dbus comm - TRESP_PHONEBOOK_GETCOUNT");
288 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbcnt->result, SIPC_MARSHAL_DATA_INT_TYPE);
289 sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_pbcnt->type, SIPC_MARSHAL_DATA_INT_TYPE);
290 sipc_util_marshal_object_add_data(out_o, "used", (void*)&resp_pbcnt->used_count, SIPC_MARSHAL_DATA_INT_TYPE);
291 sipc_util_marshal_object_add_data(out_o, "total", (void*)&resp_pbcnt->total_count, SIPC_MARSHAL_DATA_INT_TYPE);
294 case TRESP_PHONEBOOK_GETMETAINFO:
295 case TRESP_PHONEBOOK_GETUSIMINFO:
296 dbg("dbus comm - TRESP_PHONEBOOK_GETMETAINFO");
297 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_entry->result, SIPC_MARSHAL_DATA_INT_TYPE);
298 sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_entry->type, SIPC_MARSHAL_DATA_INT_TYPE);
299 sipc_util_marshal_object_add_data(out_o, "index_min", (void*)&resp_entry->index_min, SIPC_MARSHAL_DATA_INT_TYPE);
300 sipc_util_marshal_object_add_data(out_o, "index_max", (void*)&resp_entry->index_max, SIPC_MARSHAL_DATA_INT_TYPE);
301 sipc_util_marshal_object_add_data(out_o, "number_length_max", (void*)&resp_entry->number_length_max, SIPC_MARSHAL_DATA_INT_TYPE);
302 sipc_util_marshal_object_add_data(out_o, "text_length_max", (void*)&resp_entry->text_length_max, SIPC_MARSHAL_DATA_INT_TYPE);
305 case TRESP_PHONEBOOK_READRECORD:
306 dbg("dbus comm - TRESP_PHONEBOOK_READRECORD");
307 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbread->result, SIPC_MARSHAL_DATA_INT_TYPE);
308 sipc_util_marshal_object_add_data(out_o, "index", (void*)&resp_pbread->index, SIPC_MARSHAL_DATA_INT_TYPE);
309 sipc_util_marshal_object_add_data(out_o, "next_index", (void*)&resp_pbread->next_index, SIPC_MARSHAL_DATA_INT_TYPE);
310 sipc_util_marshal_object_add_data(out_o, "name", (void*)&resp_pbread->name, SIPC_MARSHAL_DATA_STRING_TYPE);
311 sipc_util_marshal_object_add_data(out_o, "dcs", (void*)&resp_pbread->dcs, SIPC_MARSHAL_DATA_INT_TYPE);
312 sipc_util_marshal_object_add_data(out_o, "number", (void*)&resp_pbread->number, SIPC_MARSHAL_DATA_STRING_TYPE);
313 sipc_util_marshal_object_add_data(out_o, "ton", (void*)&resp_pbread->ton, SIPC_MARSHAL_DATA_INT_TYPE);
314 sipc_util_marshal_object_add_data(out_o, "number2", (void*)&resp_pbread->anr1, SIPC_MARSHAL_DATA_STRING_TYPE);
315 sipc_util_marshal_object_add_data(out_o, "number2_ton", (void*)&resp_pbread->anr1_ton, SIPC_MARSHAL_DATA_INT_TYPE);
316 sipc_util_marshal_object_add_data(out_o, "number3", (void*)&resp_pbread->anr2, SIPC_MARSHAL_DATA_STRING_TYPE);
317 sipc_util_marshal_object_add_data(out_o, "number3_ton", (void*)&resp_pbread->anr2_ton, SIPC_MARSHAL_DATA_INT_TYPE);
318 sipc_util_marshal_object_add_data(out_o, "number4", (void*)&resp_pbread->anr3, SIPC_MARSHAL_DATA_STRING_TYPE);
319 sipc_util_marshal_object_add_data(out_o, "number4_ton", (void*)&resp_pbread->anr3_ton, SIPC_MARSHAL_DATA_INT_TYPE);
320 sipc_util_marshal_object_add_data(out_o, "email1", (void*)&resp_pbread->email1, SIPC_MARSHAL_DATA_STRING_TYPE);
321 sipc_util_marshal_object_add_data(out_o, "email2", (void*)&resp_pbread->email2, SIPC_MARSHAL_DATA_STRING_TYPE);
322 sipc_util_marshal_object_add_data(out_o, "email3", (void*)&resp_pbread->email3, SIPC_MARSHAL_DATA_STRING_TYPE);
323 sipc_util_marshal_object_add_data(out_o, "email4", (void*)&resp_pbread->email4, SIPC_MARSHAL_DATA_STRING_TYPE);
324 sipc_util_marshal_object_add_data(out_o, "group_index", (void*)&resp_pbread->group_index, SIPC_MARSHAL_DATA_INT_TYPE);
327 case TRESP_PHONEBOOK_UPDATERECORD:
328 dbg("dbus comm - TRESP_PHONEBOOK_UPDATERECORD");
329 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbupdate->result, SIPC_MARSHAL_DATA_INT_TYPE);
332 case TRESP_PHONEBOOK_DELETERECORD:
333 dbg("dbus comm - TRESP_PHONEBOOK_DELETERECORD");
334 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbdelete->result, SIPC_MARSHAL_DATA_INT_TYPE);
339 serial_d = sipc_util_marshal_object_serializer(out_o);
340 hdr.data_len = strlen(serial_d);
341 sipc_util_marshal_object_destory(out_o);
344 out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
345 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
347 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
351 ret = sipc_server_send(s, ui->channel_id, out_d, sizeof(struct _tapi_header)+hdr.data_len, SIPC_SEND_DATA_ASYNC);
362 gboolean scomm_service_notification_pb(Communicator *comm, CoreObject *source, enum tcore_notification_command command,
363 unsigned int data_len, const void *data)
365 const struct tnoti_phonebook_status *n_pb_status = data;
367 gchar *out_d = NULL, *serial_d = NULL;
369 struct custom_data *ctx = NULL;
370 sipc_server_t *s = NULL;
372 struct _tapi_header hdr;
373 struct _sipc_marshal_object* out_o = NULL;
375 memset(&hdr, 0, sizeof(struct _tapi_header));
377 ctx = tcore_communicator_ref_user_data(comm);
379 dbg("user_data is NULL");
384 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
386 out_o = sipc_util_marshal_object_create();
389 case TNOTI_PHONEBOOK_STATUS :
390 dbg("notified sim_status[%d]", n_pb_status->b_init);
391 sipc_util_marshal_object_add_data(out_o, "status", (void*)&n_pb_status->b_init, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
392 sipc_util_marshal_object_add_data(out_o, "support_fdn", (void*)&n_pb_status->support_list.b_fdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
393 sipc_util_marshal_object_add_data(out_o, "support_adn", (void*)&n_pb_status->support_list.b_adn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
394 sipc_util_marshal_object_add_data(out_o, "support_sdn", (void*)&n_pb_status->support_list.b_sdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
395 sipc_util_marshal_object_add_data(out_o, "support_usim", (void*)&n_pb_status->support_list.b_usim, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
396 sipc_util_marshal_object_add_data(out_o, "support_grp", (void*)&n_pb_status->support_list.b_gas, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
400 dbg("not handled command [%d] here",command);
405 serial_d = sipc_util_marshal_object_serializer(out_o);
406 hdr.data_len = strlen(serial_d);
407 sipc_util_marshal_object_destory(out_o);
410 out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
411 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
413 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
417 ret = sipc_server_broadcast(s, out_d, sizeof(struct _tapi_header)+hdr.data_len);