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 <security-server.h>
28 #include "tapi_common_sipc.h"
29 #include "tapi_sipc.h"
31 #define SERVER_PATH "/tmp/telephony"
34 static void _free_event(gpointer data)
36 struct _tapi_event *e = 0;
38 e = (struct _tapi_event *) data;
44 static struct _tapi_event* _find_event(GSList *list, unsigned int event)
46 struct _tapi_event *e = 0;
50 e = (struct _tapi_event *) list->data;
54 if (e->event == event) {
58 list = g_slist_next( list );
64 static void _dump_cookie(char *data, int size)
66 char buf[255] = { 0, };
70 for (i = 0; i < size; i++) {
71 snprintf(tmp, 3, "%02X", data[i]);
78 static gboolean _get_cookie(char *out)
83 ret = security_server_request_cookie(out, 20);
88 _dump_cookie(out, 20);
93 static void _register_name(char* dest, char* src)
95 /*int len = strlen( src );
96 *dest = g_new0( char, len + 1 );*/
98 memcpy(dest, src, 16);
101 static int _tapi_cb(unsigned int id, void *data, unsigned int data_len, void **_unused_, void *cb_data)
103 struct _tapi_handle* hdl = (struct _tapi_handle*) cb_data;
104 struct _tapi_header hdr = { 0, };
105 struct _tapi_service_object* o_data = NULL;
107 int hdr_len = sizeof(struct _tapi_header);
109 struct _tapi_event* e = NULL;
112 memcpy(&hdr, (char*) data, hdr_len);
114 d = g_new0( char, hdr.data_len );
115 memcpy(d, (char*) (data + hdr_len), hdr.data_len);
117 if ((hdr.cmd & 0xF0000000) == TCORE_NOTIFICATION) {
119 dbg("notification cmd = 0x%x", hdr.cmd);
122 if ((hdr.cmd & 0xF0000000) == TCORE_REQUEST) {
124 dbg("response cmd = 0x%x", hdr.cmd);
127 e = _find_event(l, hdr.cmd);
130 o_data = _tapi_service_object_extract_async_data(d);
131 o_data->cmd = hdr.cmd;
137 e->cb(o_data, e->cb_data);
140 dbg("e->cb is NULL");
152 struct _tapi_handle* tapi_init(char *app_name, char *cp_name)
154 struct _tapi_handle *h = 0;
155 sipc_callback_t *cb = NULL;
160 h = g_new0( struct _tapi_handle, 1 );
162 // create channel key
163 h->key = sipc_channel_key_create();
169 // create tx channel & init
170 h->tx_ch = sipc_channel_open(h->key);
171 sipc_channel_set_type(h->tx_ch, SIPC_CHANNEL_TYPE_TX);
172 if (!sipc_channel_connect(h->tx_ch, SERVER_PATH))
175 // create rx channel & init
176 h->rx_ch = sipc_channel_open(h->key);
177 sipc_channel_set_type(h->rx_ch, SIPC_CHANNEL_TYPE_RX);
178 if (!sipc_channel_connect(h->rx_ch, SERVER_PATH))
181 cb = g_new0( sipc_callback_t, 1 );
182 cb->func = (sipc_cb) _tapi_cb;
183 cb->data = (void*) h;
184 sipc_channel_register_rx_callback(h->rx_ch, cb);
186 if (!_get_cookie(h->cookie))
189 // register app_name, cp_name
190 _register_name(h->app_name, app_name);
191 _register_name(h->cp_name, cp_name);
196 gboolean tapi_deinit(struct _tapi_handle *h)
198 // g_free( h->app_name );
199 // g_free( h->cp_name );
201 sipc_channel_close(h->tx_ch, h->key);
202 sipc_channel_close(h->rx_ch, h->key);
206 sipc_channel_key_destroy(h->key);
209 g_slist_free(h->cfrms);
210 g_slist_free(h->notis);
217 struct _tapi_service_object* tapi_create_service_object(tapi_service_command_e cmd)
219 struct _tapi_service_object *obj = 0;
221 obj = g_new0( struct _tapi_service_object, 1 );
222 obj = _tapi_service_object_create(cmd);
227 gboolean tapi_service_object_add_data(struct _tapi_service_object* obj, const gchar* key, void *in_data,
228 tapi_object_data_type_e type)
232 rv = _tapi_service_object_add_data(obj, key, in_data, type);
239 tapi_service_command_e tapi_service_object_get_command(const struct _tapi_service_object* obj)
242 return TAPI_SERVICE_UNKNOWN;
247 gboolean tapi_service_object_get_data(const struct _tapi_service_object* obj, const gchar* key, void **out_data,
248 tapi_object_data_type_e type)
252 rv = _tapi_service_object_get_data(obj, key, out_data, type);
259 gchar tapi_service_object_get_char(const tapi_service_object_t* obj, const gchar* key)
261 return _tapi_service_object_get_char(obj, key);
264 gboolean tapi_service_object_get_boolean(const tapi_service_object_t* obj, const gchar* key)
266 return _tapi_service_object_get_boolean(obj, key);
269 gint tapi_service_object_get_int(const tapi_service_object_t* obj, const gchar* key)
271 return _tapi_service_object_get_int(obj, key);
274 gdouble tapi_service_object_get_double(const tapi_service_object_t* obj, const gchar* key)
276 return _tapi_service_object_get_double(obj, key);
279 gchar* tapi_service_object_get_string(const tapi_service_object_t* obj, const gchar* key)
281 return _tapi_service_object_get_string(obj, key);
284 struct _tapi_service_object* tapi_service_object_get_object(const tapi_service_object_t* obj, const gchar* key)
286 return _tapi_service_object_get_object(obj, key);
289 gboolean tapi_service_object_remove_data(struct _tapi_service_object* obj, const gchar* key)
293 rv = _tapi_service_object_remove_data(obj, key);
300 gboolean tapi_service_object_remove_alldata(struct _tapi_service_object* obj)
304 rv = _tapi_service_object_remove_alldata(obj);
311 gboolean tapi_service_object_destory(struct _tapi_service_object* obj)
315 rv = _tapi_service_object_destory(obj);
322 gboolean tel_processing_command_sync(struct _tapi_handle *h, struct _tapi_service_object *in_obj,
323 struct _tapi_service_object *out_obj)
327 rv = _tapi_send_service_request_sync(h, in_obj, out_obj);
334 gboolean tel_processing_command_async(struct _tapi_handle *h, struct _tapi_service_object *in_obj, tapi_cb cb,
338 struct _tapi_event *e = 0;
340 e = g_new0( struct _tapi_event, 1 );
341 e->event = in_obj->cmd;
343 e->cb_data = user_data;
345 if( e->event & TCORE_REQUEST){
346 h->cfrms = g_slist_append(h->cfrms, e);
352 rv = _tapi_send_service_request_sync(h, in_obj, NULL);
359 gboolean tapi_register_notification(struct _tapi_handle *h, tapi_service_notification_e noti, tapi_cb cb, void *cb_data)
361 struct _tapi_event *e = 0;
363 e = g_new0( struct _tapi_event, 1 );
366 e->cb_data = cb_data;
368 if ((e->event & 0xF0000000) == TCORE_NOTIFICATION) {
369 h->notis = g_slist_append(h->notis, e);