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);
71 if (cmd == TAPI_SERVICE_PB_GET_INITINFO ) {
72 /*synchronous data return case*/
74 out_o.mo = sipc_util_marshal_object_create();
77 /*asynchronous data return case*/
78 ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
80 dbg("err - ur creation failed");
84 ui.channel_id = ch_id;
86 tcore_user_request_set_user_info(ur, &ui);
88 in_o = sipc_util_marshal_object_deserializer(data);
90 dbg("err - data deserializer failed");
99 case TAPI_SERVICE_PB_GET_INITINFO : {
101 struct tel_phonebook_support_list *g_pb_list;
102 g_init = tcore_phonebook_get_status(co_pb);
103 g_pb_list = (struct tel_phonebook_support_list*)tcore_phonebook_get_support_list(co_pb);
104 sipc_util_marshal_object_add_data(out_o.mo, "status", (void*)&g_init, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
105 sipc_util_marshal_object_add_data(out_o.mo, "support_fdn", (void*)&g_pb_list->b_fdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
106 sipc_util_marshal_object_add_data(out_o.mo, "support_adn", (void*)&g_pb_list->b_adn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
107 sipc_util_marshal_object_add_data(out_o.mo, "support_sdn", (void*)&g_pb_list->b_sdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
108 sipc_util_marshal_object_add_data(out_o.mo, "support_usim", (void*)&g_pb_list->b_usim, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
109 sipc_util_marshal_object_add_data(out_o.mo, "support_grp", (void*)&g_pb_list->b_gas, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
111 tmp = sipc_util_marshal_object_serializer(out_o.mo);
112 tmp_len = strlen(tmp);
113 *outparam = g_new0(char, tmp_len+1);
114 memcpy(*outparam, tmp, tmp_len);
119 case TAPI_SERVICE_PB_GET_COUNT : {
120 struct treq_phonebook_get_count pb_count;
121 enum tel_phonebook_type g_pb_type;
122 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
123 pb_count.phonebook_type = g_pb_type;
125 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_count), &pb_count);
126 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETCOUNT);
130 case TAPI_SERVICE_PB_GET_METAINFO : {
131 struct treq_phonebook_get_info pb_info;
132 struct treq_phonebook_get_usim_info pb_usim;
133 enum tel_phonebook_type g_pb_type;
134 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
135 pb_info.phonebook_type = g_pb_type;
137 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_get_info), &pb_info);
138 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_GETMETAINFO);
142 case TAPI_SERVICE_PB_READ_RECORD : {
143 struct treq_phonebook_read_record pb_read;
144 enum tel_phonebook_type g_pb_type;
146 g_index = sipc_util_marshal_object_get_int(in_o, "index");
147 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
148 pb_read.index = (unsigned short)g_index;
149 pb_read.phonebook_type = g_pb_type;
151 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_read_record), &pb_read);
152 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_READRECORD);
156 case TAPI_SERVICE_PB_UPDATE_RECORD : {
157 struct treq_phonebook_update_record pb_update;
158 enum tel_phonebook_type g_pb_type;
160 gchar *g_name = NULL;
162 gchar *g_number = NULL;
164 gchar *g_number2 = NULL;
165 gint g_number2_ton = 0;
166 gchar *g_number3 = NULL;
167 gint g_number3_ton = 0;
168 gchar *g_number4 = NULL;
169 gint g_number4_ton = 0;
170 gchar *g_email1 = NULL;
171 gchar *g_email2 = NULL;
172 gchar *g_email3 = NULL;
173 gchar *g_email4 = NULL;
174 gint g_group_index =0;
175 g_index = sipc_util_marshal_object_get_int(in_o, "index");
176 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
177 g_name = sipc_util_marshal_object_get_string(in_o, "name");
178 g_dcs = sipc_util_marshal_object_get_int(in_o, "dcs");
179 g_number = sipc_util_marshal_object_get_string(in_o, "number");
180 g_ton = sipc_util_marshal_object_get_int(in_o, "ton");
181 g_number2 = sipc_util_marshal_object_get_string(in_o, "number2");
182 g_number2_ton = sipc_util_marshal_object_get_int(in_o, "number2_ton");
183 g_number3 = sipc_util_marshal_object_get_string(in_o, "number3");
184 g_number3_ton = sipc_util_marshal_object_get_int(in_o, "number3_ton");
185 g_number4 = sipc_util_marshal_object_get_string(in_o, "number4");
186 g_number4_ton = sipc_util_marshal_object_get_int(in_o, "number4_ton");
187 g_email1 = sipc_util_marshal_object_get_string(in_o, "email1");
188 g_email2 = sipc_util_marshal_object_get_string(in_o, "email2");
189 g_email3 = sipc_util_marshal_object_get_string(in_o, "email3");
190 g_email4 = sipc_util_marshal_object_get_string(in_o, "email4");
191 g_group_index = sipc_util_marshal_object_get_int(in_o, "group_index");
193 pb_update.index = (unsigned short)g_index;
194 pb_update.phonebook_type = g_pb_type;
196 snprintf(pb_update.name, strlen(g_name)+1, g_name);
197 pb_update.dcs = g_dcs;
199 if(strlen(g_number)){
200 snprintf(pb_update.number, strlen(g_number)+1, g_number);
201 pb_update.ton = g_ton;
203 if(strlen(g_number2)){
204 snprintf(pb_update.anr1, strlen(g_number2)+1, g_number2);
205 pb_update.anr1_ton = g_number2_ton;
207 if(strlen(g_number3)){
208 snprintf(pb_update.anr2, strlen(g_number3)+1, g_number3);
209 pb_update.anr2_ton = g_number3_ton;
211 if(strlen(g_number4)){
212 snprintf(pb_update.anr3, strlen(g_number4)+1, g_number4);
213 pb_update.anr3_ton = g_number4_ton;
215 pb_update.group_index = (unsigned short)g_group_index;
217 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_update_record), &pb_update);
218 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_UPDATERECORD);
222 case TAPI_SERVICE_PB_DELETE_RECORD : {
223 struct treq_phonebook_delete_record pb_delete;
224 enum tel_phonebook_type g_pb_type;
226 g_index = sipc_util_marshal_object_get_int(in_o, "index");
227 g_pb_type = sipc_util_marshal_object_get_int(in_o, "type");
228 pb_delete.index = (unsigned short)g_index;
229 pb_delete.phonebook_type = g_pb_type;
231 tcore_user_request_set_data(ur, sizeof(struct treq_phonebook_delete_record), &pb_delete);
232 tcore_user_request_set_command(ur, TREQ_PHONEBOOK_DELETERECORD);
237 dbg("not handled command [%d] here",cmd);
242 if (cmd == TAPI_SERVICE_PB_GET_INITINFO ) {
243 /*synchronous data return case*/
246 /*asynchronous data return case*/
247 ret = tcore_communicator_dispatch_request(c, ur);
248 if (ret != TCORE_RETURN_SUCCESS) {
258 gboolean scomm_service_response_pb(Communicator *comm, UserRequest *ur, enum tcore_response_command command,
259 unsigned int data_len, const void *data)
261 const struct tresp_phonebook_get_count *resp_pbcnt = data;
262 const struct tresp_phonebook_get_info *resp_entry = data;
263 const struct tresp_phonebook_get_usim_info *resp_capa = data;
264 const struct tresp_phonebook_read_record *resp_pbread = data;
265 const struct tresp_phonebook_update_record *resp_pbupdate = data;
266 const struct tresp_phonebook_delete_record *resp_pbdelete = data;
269 gchar *out_d= NULL, *serial_d = NULL;
270 gchar *entry_key = NULL;
271 struct custom_data *ctx = NULL;
272 const struct tcore_user_info *ui;
273 sipc_server_t *s = NULL;
274 struct _tapi_header hdr;
275 struct _sipc_marshal_object* out_o = NULL;
276 struct _sipc_marshal_object* entry_o = NULL;
278 memset(&hdr, 0, sizeof(struct _tapi_header));
280 ctx = tcore_communicator_ref_user_data(comm);
282 dbg("user_data is NULL");
286 ui = tcore_user_request_ref_user_info(ur);
289 dbg("application channel id(%d), Command = [0x%x], data_len = %d", ui->channel_id, command, data_len);
290 hdr.cmd = (tapi_service_command_e)ui->client_cmd;
292 out_o = sipc_util_marshal_object_create();
295 case TRESP_PHONEBOOK_GETCOUNT:
296 dbg("dbus comm - TRESP_PHONEBOOK_GETCOUNT");
297 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbcnt->result, SIPC_MARSHAL_DATA_INT_TYPE);
298 sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_pbcnt->type, SIPC_MARSHAL_DATA_INT_TYPE);
299 sipc_util_marshal_object_add_data(out_o, "used", (void*)&resp_pbcnt->used_count, SIPC_MARSHAL_DATA_INT_TYPE);
300 sipc_util_marshal_object_add_data(out_o, "total", (void*)&resp_pbcnt->total_count, SIPC_MARSHAL_DATA_INT_TYPE);
303 case TRESP_PHONEBOOK_GETMETAINFO:
304 case TRESP_PHONEBOOK_GETUSIMINFO:
305 dbg("dbus comm - TRESP_PHONEBOOK_GETMETAINFO");
306 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_entry->result, SIPC_MARSHAL_DATA_INT_TYPE);
307 sipc_util_marshal_object_add_data(out_o, "type", (void*)&resp_entry->type, SIPC_MARSHAL_DATA_INT_TYPE);
308 sipc_util_marshal_object_add_data(out_o, "index_min", (void*)&resp_entry->index_min, SIPC_MARSHAL_DATA_INT_TYPE);
309 sipc_util_marshal_object_add_data(out_o, "index_max", (void*)&resp_entry->index_max, SIPC_MARSHAL_DATA_INT_TYPE);
310 sipc_util_marshal_object_add_data(out_o, "number_length_max", (void*)&resp_entry->number_length_max, SIPC_MARSHAL_DATA_INT_TYPE);
311 sipc_util_marshal_object_add_data(out_o, "text_length_max", (void*)&resp_entry->text_length_max, SIPC_MARSHAL_DATA_INT_TYPE);
314 case TRESP_PHONEBOOK_READRECORD:
315 dbg("dbus comm - TRESP_PHONEBOOK_READRECORD");
316 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbread->result, SIPC_MARSHAL_DATA_INT_TYPE);
317 sipc_util_marshal_object_add_data(out_o, "index", (void*)&resp_pbread->index, SIPC_MARSHAL_DATA_INT_TYPE);
318 sipc_util_marshal_object_add_data(out_o, "next_index", (void*)&resp_pbread->next_index, SIPC_MARSHAL_DATA_INT_TYPE);
319 sipc_util_marshal_object_add_data(out_o, "name", (void*)&resp_pbread->name, SIPC_MARSHAL_DATA_STRING_TYPE);
320 sipc_util_marshal_object_add_data(out_o, "dcs", (void*)&resp_pbread->dcs, SIPC_MARSHAL_DATA_INT_TYPE);
321 sipc_util_marshal_object_add_data(out_o, "number", (void*)&resp_pbread->number, SIPC_MARSHAL_DATA_STRING_TYPE);
322 sipc_util_marshal_object_add_data(out_o, "ton", (void*)&resp_pbread->ton, SIPC_MARSHAL_DATA_INT_TYPE);
323 sipc_util_marshal_object_add_data(out_o, "number2", (void*)&resp_pbread->anr1, SIPC_MARSHAL_DATA_STRING_TYPE);
324 sipc_util_marshal_object_add_data(out_o, "number2_ton", (void*)&resp_pbread->anr1_ton, SIPC_MARSHAL_DATA_INT_TYPE);
325 sipc_util_marshal_object_add_data(out_o, "number3", (void*)&resp_pbread->anr2, SIPC_MARSHAL_DATA_STRING_TYPE);
326 sipc_util_marshal_object_add_data(out_o, "number3_ton", (void*)&resp_pbread->anr2_ton, SIPC_MARSHAL_DATA_INT_TYPE);
327 sipc_util_marshal_object_add_data(out_o, "number4", (void*)&resp_pbread->anr3, SIPC_MARSHAL_DATA_STRING_TYPE);
328 sipc_util_marshal_object_add_data(out_o, "number4_ton", (void*)&resp_pbread->anr3_ton, SIPC_MARSHAL_DATA_INT_TYPE);
329 sipc_util_marshal_object_add_data(out_o, "email1", (void*)&resp_pbread->email1, SIPC_MARSHAL_DATA_STRING_TYPE);
330 sipc_util_marshal_object_add_data(out_o, "email2", (void*)&resp_pbread->email2, SIPC_MARSHAL_DATA_STRING_TYPE);
331 sipc_util_marshal_object_add_data(out_o, "email3", (void*)&resp_pbread->email3, SIPC_MARSHAL_DATA_STRING_TYPE);
332 sipc_util_marshal_object_add_data(out_o, "email4", (void*)&resp_pbread->email4, SIPC_MARSHAL_DATA_STRING_TYPE);
333 sipc_util_marshal_object_add_data(out_o, "group_index", (void*)&resp_pbread->group_index, SIPC_MARSHAL_DATA_INT_TYPE);
336 case TRESP_PHONEBOOK_UPDATERECORD:
337 dbg("dbus comm - TRESP_PHONEBOOK_UPDATERECORD");
338 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbupdate->result, SIPC_MARSHAL_DATA_INT_TYPE);
341 case TRESP_PHONEBOOK_DELETERECORD:
342 dbg("dbus comm - TRESP_PHONEBOOK_DELETERECORD");
343 sipc_util_marshal_object_add_data(out_o, "result", (void*)&resp_pbdelete->result, SIPC_MARSHAL_DATA_INT_TYPE);
348 serial_d = sipc_util_marshal_object_serializer(out_o);
349 hdr.data_len = strlen(serial_d);
350 sipc_util_marshal_object_destory(out_o);
353 out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
354 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
356 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
360 ret = sipc_server_send(s, ui->channel_id, out_d, sizeof(struct _tapi_header)+hdr.data_len, SIPC_SEND_DATA_ASYNC);
371 gboolean scomm_service_notification_pb(Communicator *comm, CoreObject *source, enum tcore_notification_command command,
372 unsigned int data_len, const void *data)
374 const struct tnoti_phonebook_status *n_pb_status = data;
376 gchar *out_d = NULL, *serial_d = NULL;
378 struct custom_data *ctx = NULL;
379 sipc_server_t *s = NULL;
381 struct _tapi_header hdr;
382 struct _sipc_marshal_object* out_o = NULL;
384 memset(&hdr, 0, sizeof(struct _tapi_header));
386 ctx = tcore_communicator_ref_user_data(comm);
388 dbg("user_data is NULL");
393 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
395 out_o = sipc_util_marshal_object_create();
398 case TNOTI_PHONEBOOK_STATUS :
399 dbg("notified sim_status[%d]", n_pb_status->b_init);
400 sipc_util_marshal_object_add_data(out_o, "status", (void*)&n_pb_status->b_init, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
401 sipc_util_marshal_object_add_data(out_o, "support_fdn", (void*)&n_pb_status->support_list.b_fdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
402 sipc_util_marshal_object_add_data(out_o, "support_adn", (void*)&n_pb_status->support_list.b_adn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
403 sipc_util_marshal_object_add_data(out_o, "support_sdn", (void*)&n_pb_status->support_list.b_sdn, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
404 sipc_util_marshal_object_add_data(out_o, "support_usim", (void*)&n_pb_status->support_list.b_usim, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
405 sipc_util_marshal_object_add_data(out_o, "support_grp", (void*)&n_pb_status->support_list.b_gas, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
409 dbg("not handled command [%d] here",command);
414 serial_d = sipc_util_marshal_object_serializer(out_o);
415 hdr.data_len = strlen(serial_d);
416 sipc_util_marshal_object_destory(out_o);
419 out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
420 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
422 memcpy(out_d+sizeof(struct _tapi_header), serial_d, hdr.data_len);
426 ret = sipc_server_broadcast(s, out_d, sizeof(struct _tapi_header)+hdr.data_len);