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>
39 #include "tapi_common.h"
40 #include "module_req.h"
42 static void _request_fail(UserRequest *ur, int cmd, int resp_len, void *resp)
44 tcore_user_request_send_response(ur, cmd, resp_len, resp);
45 tcore_user_request_free(ur);
48 gboolean scomm_service_request_ps(unsigned int ch_id, Communicator *c, TcorePlugin *plugin,
49 tapi_service_command_e cmd, gchar *data, void **outparam)
52 struct _sipc_marshal_object *out_obj;
53 struct _sipc_marshal_object *in_obj;
54 gboolean result = TRUE;
55 UserRequest *ur = NULL;
56 struct tcore_user_info ui = { 0, 0, 0, NULL, 0, 0, NULL };
58 in_obj = sipc_util_marshal_object_deserializer(data);
60 dbg("in_obj is NULL");
65 ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
72 ui.channel_id = ch_id;
74 tcore_user_request_set_user_info(ur, &ui);
77 case TAPI_SERVICE_PS_SET_DUN_PIN_CONTROL: {
78 struct treq_ps_set_dun_pin_control data_pincontrol;
79 struct tresp_ps_set_dun_pin_control resp;
80 gchar *str_signal = NULL;
82 enum telephony_ps_dun_pincontrol_signal in_signal = DUN_PINCONTROL_SIGNAL_DCD;
84 str_signal = sipc_util_marshal_object_get_string(in_obj, "signal");
85 status = sipc_util_marshal_object_get_boolean(in_obj, "status");
89 resp.result = TCORE_RETURN_EINVAL;
90 _request_fail(ur, TRESP_PS_SET_DUN_PIN_CONTROL, sizeof(struct tresp_ps_set_dun_pin_control), &resp);
95 dbg("signal = [%s]", str_signal);
98 if (!g_strcmp0(str_signal, "dcd")) {
99 in_signal = DUN_PINCONTROL_SIGNAL_DCD;
101 else if (!g_strcmp0(str_signal, "dtr")) {
102 in_signal = DUN_PINCONTROL_SIGNAL_DTR;
104 else if (!g_strcmp0(str_signal, "dsr")) {
105 in_signal = DUN_PINCONTROL_SIGNAL_DSR;
107 else if (!g_strcmp0(str_signal, "rts")) {
108 in_signal = DUN_PINCONTROL_SIGNAL_RTS;
110 else if (!g_strcmp0(str_signal, "cts")) {
111 in_signal = DUN_PINCONTROL_SIGNAL_CTS;
113 else if (!g_strcmp0(str_signal, "ri")) {
114 in_signal = DUN_PINCONTROL_SIGNAL_RI;
119 resp.result = TCORE_RETURN_EINVAL;
120 _request_fail(ur, TRESP_PS_SET_DUN_PIN_CONTROL, sizeof(struct tresp_ps_set_dun_pin_control), &resp);
127 dbg("signal = %d, status = %d", in_signal, status);
129 data_pincontrol.signal = in_signal;
130 data_pincontrol.status = status;
132 tcore_user_request_set_data(ur, sizeof(struct treq_ps_set_dun_pin_control), &data_pincontrol);
133 tcore_user_request_set_command(ur, TREQ_PS_SET_DUN_PIN_CONTROL);
139 sipc_util_marshal_object_destory(in_obj);
140 out_obj = sipc_util_marshal_object_create();
141 sipc_util_marshal_object_add_data(out_obj, "result", &result, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
143 dbg("result = %d", result);
145 *outparam = sipc_util_marshal_object_serializer(out_obj);
146 sipc_util_marshal_object_destory(out_obj);
148 if (result == FALSE) {
152 ret = tcore_communicator_dispatch_request(c, ur);
153 if (ret != TCORE_RETURN_SUCCESS) {
160 gboolean scomm_service_response_ps(Communicator *comm, UserRequest *ur, enum tcore_response_command command,
161 unsigned int data_len, const void *data)
163 const struct tresp_ps_set_dun_pin_control *resp_dun_pin_control = data;
165 gchar *out_d = NULL, *serial_d = NULL;
166 struct custom_data *ctx = NULL;
167 const struct tcore_user_info *ui;
168 struct _tapi_header hdr;
169 struct _sipc_marshal_object* out_obj = NULL;
170 struct _sipc_marshal_object* in_obj = NULL;
172 ctx = tcore_communicator_ref_user_data(comm);
174 dbg("user_data is NULL");
178 ui = tcore_user_request_ref_user_info(ur);
180 dbg("response command = [0x%x], data_len = %d", command, data_len);
181 dbg("channel_id = %d, client_cmd = %d", ui->channel_id, ui->client_cmd);
183 memset(&hdr, 0, sizeof(struct _tapi_header));
184 hdr.cmd = (tapi_service_command_e) ui->client_cmd;
186 out_obj = sipc_util_marshal_object_create();
189 case TRESP_PS_SET_DUN_PIN_CONTROL:
190 dbg("TRESP_PS_SET_DUN_PIN_CONTROL");
191 sipc_util_marshal_object_add_data(out_obj, "result", (void*) &resp_dun_pin_control->result,
192 SIPC_MARSHAL_DATA_INT_TYPE);
197 serial_d = sipc_util_marshal_object_serializer(out_obj);
198 hdr.data_len = strlen(serial_d);
199 sipc_util_marshal_object_destory(out_obj);
202 out_d = g_new0(char, sizeof(struct _tapi_header) + hdr.data_len);
203 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
206 memcpy(out_d + sizeof(struct _tapi_header), serial_d, hdr.data_len);
207 dbg("serial_d = [%s]", serial_d);
211 ret = sipc_server_send(ctx->sk_server, ui->channel_id, out_d, sizeof(struct _tapi_header) + hdr.data_len,
212 SIPC_SEND_DATA_ASYNC);
216 dbg("ret = %d", ret);
223 gboolean scomm_service_notification_ps(Communicator *comm, CoreObject *source, enum tcore_notification_command command,
224 unsigned int data_len, const void *data)
226 const struct tnoti_ps_dun_pin_control *noti_pin_info = data;
229 struct custom_data *ctx = NULL;
230 struct _tapi_header hdr;
231 struct _sipc_marshal_object* out_obj = NULL;
232 gchar *out_d = NULL, *serial_d = NULL;
234 ctx = tcore_communicator_ref_user_data(comm);
236 dbg("user_data is NULL");
240 dbg("notification !!! (command = 0x%x, data_len = %d)", command, data_len);
243 case TNOTI_PS_DUN_PIN_CONTROL: {
244 gchar *str_signal = NULL;
247 switch (noti_pin_info->signal) {
248 case DUN_PINCONTROL_SIGNAL_DCD:
249 str_signal = strdup("dcd");
252 case DUN_PINCONTROL_SIGNAL_DTR:
253 str_signal = strdup("dtr");
256 case DUN_PINCONTROL_SIGNAL_DSR:
257 str_signal = strdup("dsr");
260 case DUN_PINCONTROL_SIGNAL_RTS:
261 str_signal = strdup("rts");
264 case DUN_PINCONTROL_SIGNAL_CTS:
265 str_signal = strdup("cts");
268 case DUN_PINCONTROL_SIGNAL_RI:
269 str_signal = strdup("ri");
272 status = noti_pin_info->status;
274 hdr.cmd = TAPI_NOTI_PS_DUN_PIN_CONTROL;
276 dbg("signal = [%s], status = %d", str_signal, status);
278 out_obj = sipc_util_marshal_object_create();
279 sipc_util_marshal_object_add_data(out_obj, "signal", str_signal, SIPC_MARSHAL_DATA_STRING_TYPE);
280 sipc_util_marshal_object_add_data(out_obj, "status", &status, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
284 case TNOTI_PS_EXTERNAL_CALL:
285 hdr.cmd = TAPI_NOTI_PS_EXTERNAL_CALL;
291 serial_d = sipc_util_marshal_object_serializer(out_obj);
292 hdr.data_len = strlen(serial_d);
293 sipc_util_marshal_object_destory(out_obj);
296 out_d = g_new0(char, sizeof(struct _tapi_header)+hdr.data_len);
297 memcpy(out_d, &hdr, sizeof(struct _tapi_header));
299 memcpy(out_d + sizeof(struct _tapi_header), serial_d, hdr.data_len);
303 dbg("len = %d, out_d = [%s]", sizeof(struct _tapi_header) + hdr.data_len, out_d);
305 ret = sipc_server_broadcast(ctx->sk_server, out_d, sizeof(struct _tapi_header) + hdr.data_len);
306 dbg("ret = %d", ret);