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_sap(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
66 case TCORE_TYPE_PHONEBOOK:
67 dbg("phonebook request");
68 scomm_service_reqeust_pb(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
71 case TCORE_TYPE_NETWORK:
72 dbg("network request");
73 scomm_service_request_network(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
77 dbg("packet service request");
78 scomm_service_request_ps(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
83 scomm_service_request_sms(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
86 case TCORE_TYPE_CUSTOM:
87 dbg("custom request");
88 scomm_service_request_custom(ch_id, d->comm, plugin, hdr->cmd, data, outparam);
92 dbg("unknown request (0x%x)", hdr->cmd);
99 static gboolean sipc_send_response(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
101 switch (command & (TCORE_RESPONSE | 0x0FF00000)) {
104 scomm_service_response_call(comm, ur, command, data_len, data);
109 scomm_service_response_ps(comm, ur, command, data_len, data);
114 scomm_service_response_sim(comm, ur, command, data_len, data);
119 scomm_service_response_sap(comm, ur, command, data_len, data);
122 case TRESP_PHONEBOOK:
123 dbg("TRESP_PHONEBOOK");
124 scomm_service_response_pb(comm, ur, command, data_len, data);
128 dbg("TRESP_NETWORK");
129 scomm_service_response_network(comm, ur, command, data_len, data);
138 scomm_service_response_sms(comm, ur, command, data_len, data);
143 scomm_service_response_custom(comm, ur, command, data_len, data);
147 warn("unknown command (0x%x)", command);
154 static gboolean sipc_send_notification(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
156 switch (command & (TCORE_NOTIFICATION | 0x0FF00000)) {
159 scomm_service_notification_call(comm, source, command, data_len, data);
164 scomm_service_notification_ps(comm, source, command, data_len, data);
169 scomm_service_notification_sim(comm, source, command, data_len, data);
174 scomm_service_notification_sap(comm, source, command, data_len, data);
177 case TNOTI_PHONEBOOK:
178 dbg("TNOTI_PHONEBOOK");
179 scomm_service_notification_pb(comm, source, command, data_len, data);
183 dbg("TNOTI_NETWORK");
184 scomm_service_notification_network(comm, source, command, data_len, data);
197 scomm_service_notification_sms(comm, source, command, data_len, data);
202 scomm_service_notification_custom(comm, source, command, data_len, data);
206 warn("unknown command (0x%x)", command);
213 struct tcore_communitor_operations ops = {
214 .send_response = sipc_send_response,
215 .send_notification = sipc_send_notification,
218 static int on_recv( unsigned int ch_id, void* inparam, unsigned int inparam_len, void **outparam, void *cb_data )
223 gchar *o_data = NULL;
224 struct _tapi_header hdr;
226 memcpy(&hdr, inparam, sizeof(struct _tapi_header));
227 data = g_new0(char , hdr.data_len+1);
228 memcpy(data, (inparam+sizeof(struct _tapi_header)), hdr.data_len );
230 if( !(hdr.cmd & TCORE_REQUEST) ){
231 dbg("does not request command");
235 //check cookie, if cookie is wrong return -1 ( send fail? , or return another?)
236 /* if( cookie does not matched)
238 dbg("cookie is not matched");
243 rv = _dispatch_service_request(ch_id, &hdr, data, (void **)&o_data, cb_data);
246 o_data_len = strlen(o_data);
247 *outparam = g_new0(char, o_data_len);
248 memcpy(*outparam, o_data, o_data_len);
251 *outparam = g_new0(char, hdr.data_len+1);
252 memcpy(*outparam, data, hdr.data_len);
258 static gboolean on_load(void)
260 dbg("socket communicator plug-in load!");
264 static gboolean on_init(TcorePlugin *p)
269 struct custom_data *data = NULL;
270 sipc_server_t *sk_server = NULL;
271 sipc_callback_t *cbck = NULL;
278 dbg("func entrance");
280 sk_server = sipc_server_open(SERVER_PATH);
282 warn("error : fail to open server");
286 comm = tcore_communicator_new(p, "socket_communicator", &ops);
288 data = g_new0( struct custom_data, 1 );
289 data->server = tcore_plugin_ref_server(p);
292 data->sk_server = (void*) sk_server;
293 tcore_communicator_link_user_data(comm, data);
295 cbck = g_new0( sipc_callback_t, 1 );
296 cbck->func = on_recv;
298 sipc_server_register_rx_callback(sk_server, cbck);
300 rv = sipc_server_run(sk_server);
304 dbg("server is running");
308 static void on_unload(TcorePlugin *p)
314 struct tcore_plugin_define_desc plugin_define_desc =
316 .name = "SOCKET_COMMUNICATOR",
317 .priority = TCORE_PLUGIN_PRIORITY_HIGH,