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>
33 #include <user_request.h>
37 #include "tapi_common.h"
38 #include "module_req.h"
40 #define SERVER_PATH "/tmp/telephony"
43 static int _dispatch_service_request(unsigned int ch_id, struct _tapi_header *hdr, gchar *data, void **outparam, void *cb_data)
45 TcorePlugin *plugin = NULL;
46 struct custom_data *d = (struct custom_data*)cb_data;
48 plugin = tcore_server_find_plugin(d->server, hdr->cp_name);
50 switch (hdr->cmd & 0x0FF00000) {
53 scomm_service_reqeust_call(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
58 scomm_service_reqeust_sim(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
63 scomm_service_reqeust_sat(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
68 scomm_service_reqeust_sap(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
71 case TCORE_TYPE_PHONEBOOK:
72 dbg("phonebook request");
73 scomm_service_reqeust_pb(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
76 case TCORE_TYPE_NETWORK:
77 dbg("network request");
78 scomm_service_request_network(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
82 dbg("packet service request");
83 scomm_service_request_ps(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
88 scomm_service_request_sms(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
91 case TCORE_TYPE_CUSTOM:
92 dbg("custom request");
93 scomm_service_request_custom(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
97 dbg("unknown request (0x%x)", hdr->cmd);
104 static gboolean sipc_send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
106 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
109 scomm_service_response_call(comm, ur, command, data_len, data);
114 scomm_service_response_ps(comm, ur, command, data_len, data);
119 scomm_service_response_sim(comm, ur, command, data_len, data);
124 scomm_service_response_sap(comm, ur, command, data_len, data);
127 case TRESP_PHONEBOOK:
128 dbg("TRESP_PHONEBOOK");
129 scomm_service_response_pb(comm, ur, command, data_len, data);
133 dbg("TRESP_NETWORK");
134 scomm_service_response_network(comm, ur, command, data_len, data);
143 scomm_service_response_sms(comm, ur, command, data_len, data);
148 scomm_service_response_custom(comm, ur, command, data_len, data);
152 warn("unknown command (0x%x)", command);
159 static gboolean sipc_send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
161 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
164 scomm_service_notification_call(comm, source, command, data_len, data);
169 scomm_service_notification_ps(comm, source, command, data_len, data);
174 scomm_service_notification_sim(comm, source, command, data_len, data);
179 scomm_service_notification_sap(comm, source, command, data_len, data);
182 case TNOTI_PHONEBOOK:
183 dbg("TNOTI_PHONEBOOK");
184 scomm_service_notification_pb(comm, source, command, data_len, data);
188 dbg("TNOTI_NETWORK");
189 scomm_service_notification_network(comm, source, command, data_len, data);
202 scomm_service_notification_sms(comm, source, command, data_len, data);
207 scomm_service_notification_custom(comm, source, command, data_len, data);
211 warn("unknown command (0x%x)", command);
218 struct tcore_communitor_operations ops = {
219 .send_response = sipc_send_response,
220 .send_notification = sipc_send_notification,
223 static int on_recv( unsigned int ch_id, void* inparam, unsigned int inparam_len, void **outparam, void *cb_data )
228 gchar *o_data = NULL;
229 struct _tapi_header hdr;
231 memcpy(&hdr, inparam, sizeof(struct _tapi_header));
232 data = g_new0(char , hdr.data_len+1);
233 memcpy(data, (inparam+sizeof(struct _tapi_header)), hdr.data_len );
235 if( !(hdr.cmd & TCORE_REQUEST) ){
236 dbg("does not request command");
240 //check cookie, if cookie is wrong return -1 ( send fail? , or return another?)
241 /* if( cookie does not matched)
243 dbg("cookie is not matched");
248 rv = _dispatch_service_request(ch_id, &hdr, data, (void **)&o_data, cb_data);
251 o_data_len = strlen(o_data);
252 *outparam = g_new0(char, o_data_len);
253 memcpy(*outparam, o_data, o_data_len);
256 *outparam = g_new0(char, hdr.data_len+1);
257 memcpy(*outparam, data, hdr.data_len);
263 static gboolean on_load(void)
265 dbg("socket communicator plug-in load!");
269 static gboolean on_init(TcorePlugin *p)
274 struct custom_data *data = NULL;
275 sipc_server_t *sk_server = NULL;
276 sipc_callback_t *cbck = NULL;
283 dbg("func entrance");
285 sk_server = sipc_server_open(SERVER_PATH);
287 warn("error : fail to open server");
291 comm = tcore_communicator_new(p, "socket_communicator", &ops);
293 data = g_new0( struct custom_data, 1 );
294 data->server = tcore_plugin_ref_server(p);
297 data->sk_server = (void*) sk_server;
298 tcore_communicator_link_user_data(comm, data);
300 cbck = g_new0( sipc_callback_t, 1 );
301 cbck->func = on_recv;
303 sipc_server_register_rx_callback(sk_server, cbck);
305 rv = sipc_server_run(sk_server);
309 dbg("server is running");
313 static void on_unload(TcorePlugin *p)
319 struct tcore_plugin_define_desc plugin_define_desc =
321 .name = "SOCKET_COMMUNICATOR",
322 .priority = TCORE_PLUGIN_PRIORITY_HIGH,