4 * Copyright (c) 2014 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.
29 #include <tapi_common.h>
30 #include <TapiUtility.h>
37 #include "phonebook.h"
42 #define SIM_SEL_MENU_KEY_COUNT 2
44 extern struct menu_data menu_modem[];
45 extern struct menu_data menu_sat[];
46 extern struct menu_data menu_net[];
47 extern struct menu_data menu_sms[];
48 extern struct menu_data menu_sim[];
49 extern struct menu_data menu_phonebook[];
50 extern struct menu_data menu_ss[];
51 extern struct menu_data menu_call[];
53 TapiHandle *handle = NULL;
54 char **cp_list = NULL;
57 static char data_subscription_type[MENU_DATA_SIZE + 1] = "";
58 static char data_property_int[MENU_DATA_SIZE + 1] = "org.tizen.telephony.Modem:power";
59 static char data_property_string[MENU_DATA_SIZE + 1] = "org.tizen.telephony.Network:network_name";
60 static char data_convert_string[MENU_DATA_SIZE + 1] = "";
61 static char data_convert_dcs[MENU_DATA_SIZE + 1] = "1";
63 static int get_modem_info(MManager *mm, struct menu_data *menu)
68 msg("[%02d] strlen(%d), '%s'", i, strlen(cp_list[i]), cp_list[i]);
75 static int init(MManager *mm, struct menu_data *menu)
77 int subs_type = atoi(data_subscription_type);
80 msg("already handle exist");
83 if (cp_list[subs_type-1]) {
84 msg("call tel_init(%s)", cp_list[subs_type-1]);
85 handle = tel_init(cp_list[subs_type-1]);
88 msg("handle is null");
90 menu_manager_set_user_data(mm, handle);
95 static int deinit(MManager *mm, struct menu_data *menu)
98 msg("handle is null");
102 msg("call tel_deinit()");
106 menu_manager_set_user_data(mm, handle);
111 static int get_property_int(MManager *mm, struct menu_data *menu)
113 TapiHandle *local_handle = menu_manager_ref_user_data(mm);
117 msg("call tel_get_property_int()");
119 ret = tel_get_property_int(local_handle, data_property_int, &result_int);
120 if (ret != TAPI_API_SUCCESS) {
121 msg("failed. (return = %d)", ret);
124 msg(" - result = %d", result_int);
129 static int get_property_string(MManager *mm, struct menu_data *menu)
131 TapiHandle *local_handle = menu_manager_ref_user_data(mm);
132 char *result_str = NULL;
135 msg("call tel_get_property_string()");
137 ret = tel_get_property_string (local_handle, data_property_string, &result_str);
138 if (ret != TAPI_API_SUCCESS) {
139 msg("failed. (return = %d)", ret);
142 msg(" - result = %s", result_str);
150 static int convert_string(MManager *mm, struct menu_data *menu)
152 TapiHandle *local_handle = menu_manager_ref_user_data(mm);
153 char *result_str = NULL;
156 msg("call tel_get_property_string()");
158 ret = tel_get_property_string (local_handle, data_property_string, &result_str);
159 if (ret != TAPI_API_SUCCESS) {
160 msg("failed. (return = %d)", ret);
163 msg(" - result = %s", result_str);
171 static struct menu_data menu_common[] = {
172 { "1", "tel_get_modem_info", NULL, get_modem_info, NULL},
173 { "2", "tel_init", NULL, init, NULL},
174 { "3", "tel_deinit", NULL, deinit, NULL},
175 { "4", "tel_get_property_int", NULL, get_property_int, NULL},
176 { "4s", " - property", NULL, NULL, data_property_int},
177 { "5", "tel_get_property_string", NULL, get_property_string, NULL},
178 { "5s", " - property", NULL, NULL, data_property_string},
179 { "6", "tcore_util_convert_string_to_utf8", NULL, convert_string, NULL},
180 { "6d", " - dcs", NULL, NULL, data_convert_dcs},
181 { "6s", " - string", NULL, NULL, data_convert_string},
185 static struct menu_data menu_main[] = {
186 { "1", "Common", menu_common,NULL, NULL},
187 { "2", "Modem", menu_modem, NULL, NULL},
188 { "3", "Network", menu_net, NULL, NULL},
189 { "4", "SIM", menu_sim, NULL, NULL},
190 { "5", "Phonebook", menu_phonebook, NULL, NULL},
191 { "6", "SMS", menu_sms, NULL, NULL},
192 { "7", "SS", menu_ss, NULL, NULL},
193 { "8", "SAT", menu_sat, NULL, NULL},
194 { "9", "Call", menu_call, NULL, NULL},
198 static int __select_handle_register_event (MManager *mm, struct menu_data *menu)
200 int subs_type = atoi(data_subscription_type);
202 if (subs_type < 1 || subs_type > cp_count) {
203 msg("Please select an existing CP Name");
212 handle = tel_init(cp_list[subs_type-1]);
217 msg("[SIM%d] tel_init(%s) - FAILED!!!.", subs_type, cp_list[subs_type-1]);
220 msg("[SIM%d] tel_init(%s) - SUCCESS!!!.", subs_type, cp_list[subs_type-1]);
223 menu_manager_set_user_data(mm, handle);
225 register_network_event(handle);
226 register_modem_event(handle);
227 register_sat_event(handle);
228 register_sim_event(handle);
229 register_phonebook_event(handle);
230 register_sms_event(handle);
231 register_call_event(handle);
232 register_ss_event(handle);
237 static gboolean __create_sim_selection_menu(struct menu_data sim_selection_menu[SIM_SEL_MENU_KEY_COUNT+1])
239 unsigned int total_cp_len = 0;
240 unsigned int title_len = 0;
241 unsigned int index_count = 0;
244 cp_list = tel_get_cp_name_list();
246 msg("cp_list is null");
251 total_cp_len += strlen(cp_list[i]);
257 * Available CPs are displayed as below (in UI) -
258 * Modems(1=Modem0,2=Modem1,3=Modem2)
260 * Title length is calculated as,
261 * title_len = total_cp_len + (2*cp_count) + (cp_count-1) + 8 + 1;
263 * total_cp_len = strlen(Modem0)+strlen(Modem1)+ strlen(Modem2)
264 * (2*cp_count) = To print "1=" "2=" "3="
265 * cp_count-1 = Number of commas
267 * 1 = NULL termination
269 title_len = total_cp_len + (2*cp_count) + (cp_count-1) + 8 + 1;
270 sim_selection_menu[0].title = (char *)g_try_malloc0(title_len);
271 index_count += sprintf((char *)&sim_selection_menu[0].title[index_count], "Modems(");
276 // sim_selection_menu[0].title[index_count++] = ',';
277 strncat((char *)&sim_selection_menu[0].title[index_count++], ",", sizeof(char));
280 index_count += sprintf((char *)&sim_selection_menu[0].title[index_count], "%d=", (i+1));
281 index_count += sprintf((char *)&sim_selection_menu[0].title[index_count], "%s", cp_list[i]);
285 if (index_count <= title_len - 2) {
286 strncat((char *)&sim_selection_menu[0].title[index_count++], ")", sizeof(char));
288 msg("Invalid count");
292 sim_selection_menu[0].key = "1";
293 sim_selection_menu[0].sub_menu = NULL;
294 sim_selection_menu[0].callback = NULL;
295 sim_selection_menu[0].data = data_subscription_type;
297 sim_selection_menu[1].key = "2";
298 sim_selection_menu[1].title = "run";
299 sim_selection_menu[1].sub_menu = menu_main;
300 sim_selection_menu[1].callback = __select_handle_register_event;
301 sim_selection_menu[1].data = NULL;
306 int main(int arg, char **argv)
309 GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
311 struct menu_data sim_selection_menu[SIM_SEL_MENU_KEY_COUNT+1] = { {NULL, NULL, }, };
314 mainloop = g_main_loop_new(NULL, FALSE);
317 msg("* Telephony Test application ");
318 msg("* Build On: %s %s", __DATE__, __TIME__);
320 if (__create_sim_selection_menu(sim_selection_menu) == FALSE)
323 manager = menu_manager_new(sim_selection_menu, mainloop);
324 menu_manager_run(manager);
326 g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
327 on_menu_manager_keyboard, manager);
328 g_main_loop_run(mainloop);
332 g_free((gpointer *)sim_selection_menu[0].title);
333 g_main_loop_unref(mainloop);
334 msg("******* Bye bye *******");