release tizen_2.0 beta
[framework/telephony/tel-plugin-socket_communicator.git] / plugin / src / socket_sat.c
1 /*
2  * tel-plugin-socket-communicator
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Ja-young Gu <jygu@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <errno.h>
25 #include <glib-object.h>
26
27 #include <tcore.h>
28 #include <server.h>
29 #include <plugin.h>
30 #include <hal.h>
31 #include <communicator.h>
32 #include <core_object.h>
33 #include <queue.h>
34 #include <user_request.h>
35 #include <util.h>
36 #include <co_sat.h>
37
38 #include "sipc.h"
39 #include "tapi_common.h"
40 #include "module_req.h"
41
42 gboolean scomm_service_reqeust_sat(unsigned int ch_id, Communicator *c, TcorePlugin *plugin, tapi_service_command_e cmd, gchar *data, void **outparam)
43 {
44         int ret = 0;
45         int err_cause = 0;
46         gboolean result = TRUE;
47         int s_data_len = 0;
48         gchar *serial_d = NULL;
49
50         GSList *co_list = NULL;
51         CoreObject *co_sat = NULL;
52         UserRequest *ur = NULL;
53         struct tcore_user_info ui = { 0, 0, 0, NULL,0,0, NULL };
54
55         struct _sipc_marshal_object *out_obj = NULL;
56         struct _sipc_marshal_object *in_obj = NULL;
57
58         co_list = tcore_plugin_get_core_objects_bytype(plugin, CORE_OBJECT_TYPE_SAT);
59         if (!co_list) {
60                 dbg("coreobjects does not exist");
61                 result = FALSE;
62                 goto RETURN;
63         }
64
65         co_sat = (CoreObject *)co_list->data;
66         if (!co_sat) {
67                 dbg("sat objects does not exist");
68                 result = FALSE;
69                 goto RETURN;
70         }
71         g_slist_free(co_list);
72
73         in_obj = sipc_util_marshal_object_deserializer(data);
74         if(in_obj){
75                 dbg("in_obj is NULL");
76                 result = FALSE;
77                 goto RETURN;
78         }
79
80         ui.channel_id = ch_id;
81         ui.client_cmd = (unsigned int)cmd;
82         ur = tcore_user_request_new(c, tcore_plugin_get_description(plugin)->name);
83         if (!ur) {
84                 dbg("ur is NULL");
85                 result = FALSE;
86                 goto RETURN;
87         }
88         tcore_user_request_set_user_info(ur, &ui);
89
90         switch (cmd) {
91                 case TAPI_SERVICE_SAT_MENU_SELECTION_ENVELOP: {
92                         gchar item_identifier = '\0';
93                         gboolean help_request = FALSE;
94                         struct treq_sat_envelop_cmd_data envelop_data;
95
96                         dbg("TAPI_CS_SIMATK_SEND_MENU_SELECTION_ENVELOPE");
97
98                         item_identifier = sipc_util_marshal_object_get_char(in_obj,"item_identifier");
99                         help_request = sipc_util_marshal_object_get_boolean(in_obj, "help_request");
100                         dbg("[SAT] menu selection envelop item_identifier(0x%x) help_request(%d)");
101
102                         memset(&envelop_data, 0, sizeof(struct treq_sat_envelop_cmd_data));
103
104                         envelop_data.sub_cmd = ENVELOP_MENU_SELECTION;
105                         envelop_data.envelop_data.menu_select.device_identitie.src = DEVICE_ID_KEYPAD;
106                         envelop_data.envelop_data.menu_select.device_identitie.dest = DEVICE_ID_SIM;
107                         envelop_data.envelop_data.menu_select.item_identifier.item_identifier = item_identifier;
108                         envelop_data.envelop_data.menu_select.help_request = help_request;
109
110                         tcore_user_request_set_data(ur, sizeof(struct treq_sat_envelop_cmd_data), (void *) &envelop_data);
111                         tcore_user_request_set_command(ur, TREQ_SAT_REQ_ENVELOPE);
112
113                         ret = tcore_communicator_dispatch_request(c, ur);
114                         if (ret != TCORE_RETURN_SUCCESS){
115                                 dbg("dispatch request fail");
116                                 result = FALSE;
117                                 goto RETURN;
118                         }
119                 }break;
120                 /*case TAPI_SERVICE_SAT_SEND_EVENT_DOWNLOAD: {
121                         tcore_user_request_set_data(ur, 0, NULL);
122                         tcore_user_request_set_command(ur, TREQ_SAT_REQ_ENVELOPE);
123                         ret = tcore_communicator_dispatch_request(ctx->comm, ur);
124                         if (ret != TCORE_RETURN_SUCCESS)
125                                 api_err = TAPI_API_OPERATION_FAILED;
126
127                         g_array_append_vals(*out_param2, &request_id, sizeof(int));
128                         dbg("ret = 0x%x", ret);
129                 }break;
130                 case TAPI_SERVICE_SAT_UI_USER_CONFIRM: {
131                         TelSatUiUserConfirmInfo_t cnf;
132                         TelSatTextInfo_t* additional_data = NULL;
133
134                         memset(&cnf, 0x00, sizeof(TelSatUiUserConfirmInfo_t));
135                         cnf.commandId = g_array_index(in_param1,int, 0);
136                         cnf.commandType = g_array_index(in_param1,int, 1);
137                         cnf.keyType = g_array_index(in_param1, int, 2);
138                         cnf.dataLen = g_array_index(in_param1, int, 3);
139
140                         dbg("command_id = 0x%x", cnf.commandId);
141                         dbg("command_type = 0x%x", cnf.commandType);
142                         dbg("key_type = 0x%x", cnf.keyType);
143                         dbg("data_length = %d", cnf.dataLen);
144
145                         if (cnf.dataLen > 0) {
146                                 additional_data = &g_array_index(in_param2, TelSatTextInfo_t, 0);
147                                 dbg("tel_send_sat_ui_user_confirm :[%d]", additional_data->string[0]);
148                                 api_err = sat_mgr_handle_user_confirm(ctx, plugin, conn_name.name, &cnf,        additional_data->string, additional_data->stringLen);
149                                 if (api_err != TAPI_API_SUCCESS)
150                                         dbg("return_value = %d", api_err);
151                         }
152                         else if (cnf.dataLen == 0) {
153                                 api_err = sat_mgr_handle_user_confirm(ctx, plugin, conn_name.name, &cnf, NULL, 0);
154                                 if (api_err != TAPI_API_SUCCESS)
155                                         dbg("return_value = %d", api_err);
156                         }
157                         else if (cnf.dataLen < 0) {
158                                 api_err = TAPI_API_SERVER_FAILURE;
159                         }
160                         if (api_err != TCORE_RETURN_SUCCESS) {
161                                 api_err = TAPI_API_OPERATION_FAILED;
162                         }
163                         dbg("api_err = 0x%x", api_err);
164                 }break;
165                 case TAPI_SERVICE_SEND_APP_EXEC_RESULT: {
166                         TelSatAppsRetInfo_t* app_req_info = NULL;
167                         dbg("TAPI_CS_SIMATK_SEND_APP_EXEC_RESULT");
168                         app_req_info = &g_array_index(in_param1, TelSatAppsRetInfo_t, 0);
169                         ret = sat_mgr_handle_app_exec_result(ctx, plugin, conn_name.name, app_req_info);
170                         if (ret != TCORE_RETURN_SUCCESS)
171                                 api_err = TAPI_API_OPERATION_FAILED;
172
173                         dbg("ret = 0x%x", ret);
174                 }break;
175                 case TAPI_SERVICE_GET_MAIN_MENU_INFO: {
176                         dbg("TAPI_CS_SIMATK_GET_MAIN_MENU_INFO");
177                         if (ctx->pSatMainMenu != NULL && ctx->pSatMainMenu->satMainMenuNum > 0) {
178                                 dbg("[SAT] pSatMainMenu->satMainMenuNum: [%d]", ctx->pSatMainMenu->satMainMenuNum);
179                                 dbg("[SAT] pSatMainMenu->satiMainTitle [%s]", ctx->pSatMainMenu->satMainTitle);
180                                 ctx->pSatMainMenu->bIsMainMenuPresent = TRUE;
181                                 g_array_append_vals(*out_param2, ctx->pSatMainMenu, sizeof(TelSatSetupMenuInfo_t));
182                         }
183                         else {
184                                 memset(&satMainMenu, 0x00, sizeof(TelSatSetupMenuInfo_t));
185                                 satMainMenu.bIsMainMenuPresent = FALSE;
186                                 g_array_append_vals(*out_param2, &satMainMenu, sizeof(TelSatSetupMenuInfo_t));
187                         }
188                 }break;*/
189                 case TAPI_SERVICE_SAT_UI_DISPLAY_STATUS:
190                 default :
191                         break;
192         }
193
194 RETURN:
195         sipc_util_marshal_object_destory(in_obj);
196         out_obj = sipc_util_marshal_object_create();
197         sipc_util_marshal_object_add_data(out_obj, "result", &result, SIPC_MARSHAL_DATA_BOOLEAN_TYPE);
198
199         dbg("result = %d", result);
200
201         *outparam = sipc_util_marshal_object_serializer(out_obj);
202         sipc_util_marshal_object_destory(out_obj);
203
204         if (result == FALSE) {
205                 tcore_user_request_unref(ur);
206                 return FALSE;
207         }
208
209         ret = tcore_communicator_dispatch_request(c, ur);
210         if (ret != TCORE_RETURN_SUCCESS) {
211                 return FALSE;
212         }
213
214         return TRUE;
215 }
216
217 gboolean scomm_service_response_sat(Communicator *comm, UserRequest *ur, enum tcore_response_command command, unsigned int data_len, const void *data)
218 {
219         return FALSE;
220 }
221
222 gboolean scomm_service_notification_sat(Communicator *comm, CoreObject *source, enum tcore_notification_command command, unsigned int data_len, const void *data)
223 {
224         return FALSE;
225 }