2cff5a91519bfd5b44b0824c43d764ed9375b93e
[framework/telephony/libslp-tapi.git] / wearable / test_src / main.c
1 /*
2  * Telephony test application
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 <stdlib.h>
23 #include <string.h>
24 #include <sys/time.h>
25 #include <unistd.h>
26 #include <glib.h>
27 #include <gio/gio.h>
28
29 #include <tapi_common.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "network.h"
34 #include "sat.h"
35 #include "sms.h"
36 #include "sim.h"
37 #include "phonebook.h"
38 #include "modem.h"
39 #include "call.h"
40 #include "ss.h"
41 #include "gps.h"
42
43
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[];
52 extern struct menu_data menu_gps[];
53
54 TapiHandle *handle = NULL;
55
56 static char data_modem_name[MENU_DATA_SIZE + 1] = "";
57 static char data_property_int[MENU_DATA_SIZE + 1] = "org.tizen.telephony.Modem:power";
58 static char data_property_string[MENU_DATA_SIZE + 1] = "org.tizen.telephony.Network:network_name";
59
60 static int get_modem_info(MManager *mm, struct menu_data *menu)
61 {
62         char **cp_list = NULL;
63         int i = 0;
64
65         cp_list = tel_get_cp_name_list();
66         if (!cp_list) {
67                 msg("failed.");
68                 return 0;
69         }
70
71         while (cp_list[i]) {
72                 msg("[%02d] strlen(%d), '%s'", i, strlen(cp_list[i]), cp_list[i]);
73                 i++;
74         }
75
76         free(cp_list);
77
78         return 0;
79 }
80
81 static int init(MManager *mm, struct menu_data *menu)
82 {
83         if (handle) {
84                 msg("already handle exist");
85                 return 0;
86         }
87
88         if (strlen(data_modem_name) < 1) {
89                 msg("call tel_init(NULL)");
90                 handle = tel_init(NULL);
91         }
92         else {
93                 msg("call tel_init(\"%s\")", data_modem_name);
94                 handle = tel_init(data_modem_name);
95         }
96
97         if (!handle)
98                 msg("handle is null");
99
100         menu_manager_set_user_data(mm, handle);
101
102         return 0;
103 }
104
105 static int deinit(MManager *mm, struct menu_data *menu)
106 {
107         if (!handle) {
108                 msg("handle is null");
109                 return 0;
110         }
111
112         msg("call tel_deinit()");
113         tel_deinit(handle);
114         handle = NULL;
115
116         menu_manager_set_user_data(mm, handle);
117
118         return 0;
119 }
120
121 static int get_property_int(MManager *mm, struct menu_data *menu)
122 {
123         TapiHandle *handle = menu_manager_ref_user_data(mm);
124         int result_int = -1;
125         int ret;
126
127         msg("call tel_get_property_int()");
128
129         ret = tel_get_property_int(handle, data_property_int, &result_int);
130         if (ret != TAPI_API_SUCCESS) {
131                 msg("failed. (return = %d)", ret);
132         }
133
134         msg(" - result = %d", result_int);
135
136         return 0;
137 }
138
139 static int get_property_string(MManager *mm, struct menu_data *menu)
140 {
141         TapiHandle *handle = menu_manager_ref_user_data(mm);
142         char *result_str = NULL;
143         int ret;
144
145         msg("call tel_get_property_string()");
146
147         ret = tel_get_property_string (handle, data_property_string, &result_str);
148         if (ret != TAPI_API_SUCCESS) {
149                 msg("failed. (return = %d)", ret);
150         }
151
152         msg(" - result = %s", result_str);
153
154         if (result_str)
155                 free (result_str);
156
157         return 0;
158 }
159
160 static struct menu_data menu_common[] = {
161         { "1", "tel_get_modem_info", NULL, get_modem_info, NULL},
162         { "2", "tel_init", NULL, init, NULL},
163         { "2s", " - modem_name", NULL, NULL, data_modem_name},
164         { "3", "tel_deinit", NULL,      deinit, NULL},
165         { "4", "tel_get_property_int",  NULL, get_property_int, NULL},
166         { "4s", " - property", NULL, NULL, data_property_int},
167         { "5", "tel_get_property_string", NULL, get_property_string, NULL},
168         { "5s", " - property", NULL, NULL, data_property_string},
169         { NULL, NULL, },
170 };
171
172 static struct menu_data menu_main[] = {
173         { "1", "Common",        menu_common,NULL,               NULL},
174         { "2", "Modem",         menu_modem,     NULL,           NULL},
175         { "3", "Network",       menu_net,       NULL,           NULL},
176         { "4", "SIM",           menu_sim,       NULL,           NULL},
177         { "5", "Phonebook",     menu_phonebook, NULL,   NULL},
178         { "6", "SMS",           menu_sms,       NULL,           NULL},
179         { "7", "SS",            menu_ss,        NULL,           NULL},
180         { "8", "SAT",           menu_sat,       NULL,           NULL},
181         { "9", "Call",          menu_call,      NULL,           NULL},
182         { "a", "Gps",           menu_gps,       NULL,           NULL},
183         { NULL, NULL, },
184 };
185
186 int main(int arg, char **argv)
187 {
188         GMainLoop *mainloop;
189         GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
190         MManager *manager;
191
192         g_type_init();
193         mainloop = g_main_loop_new(NULL, FALSE);
194
195         msg("");
196         msg("* Telephony Test application ");
197         msg("* Build On: %s  %s", __DATE__, __TIME__);
198
199         manager = menu_manager_new(menu_main, mainloop);
200 #if 1
201         if (strlen(data_modem_name) < 1)
202                 handle = tel_init(NULL);
203         else
204                 handle = tel_init(data_modem_name);
205 #endif
206         msg("");
207
208         if (!handle) {
209                 msg("tel_init(%s) failed.", data_modem_name);
210         }
211         else {
212                 msg("tel_init(%s) success.", data_modem_name);
213         }
214
215         menu_manager_set_user_data(manager, handle);
216
217         register_network_event(handle);
218         register_modem_event(handle);
219         register_sat_event(handle);
220         register_sim_event(handle);
221         register_phonebook_event(handle);
222         register_sms_event(handle);
223         register_call_event(handle);
224         register_ss_event(handle);
225         register_gps_event(handle);
226
227         menu_manager_run(manager);
228
229         g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
230                         on_menu_manager_keyboard, manager);
231
232         g_main_loop_run(mainloop);
233
234         msg("******* Bye bye *******");
235
236         return 0;
237 }
238