abfbb8f72b89ef657442c3f1646fc15e36942b40
[framework/telephony/libslp-tapi.git] / wearable / test_src / sat.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
28 #include <tapi_common.h>
29 #include <ITapiSat.h>
30 #include <TapiUtility.h>
31
32 #include "menu.h"
33 #include "sat.h"
34
35 TelSatSetupMenuInfo_t main_menu;
36
37 static void on_noti_setup_menu(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
38 {
39         int index;
40         TelSatSetupMenuInfo_t *setup_menu = NULL;
41
42         msg("noti id (%s)", noti_id);
43
44         if(!data){
45                 msg("noti data is null");
46                 return;
47         }
48
49         setup_menu = (TelSatSetupMenuInfo_t *)data;
50         msg("command id (%d)", setup_menu->commandId);
51         msg("menu present (%d)", setup_menu->bIsMainMenuPresent);
52         msg("menu title (%s)", setup_menu->satMainTitle);
53         msg("item cnt (%d)", setup_menu->satMainMenuNum);
54         for(index=0;index < setup_menu->satMainMenuNum; index++){
55                 msg("item id(%d) (%s)", setup_menu->satMainMenuItem[index].itemId, setup_menu->satMainMenuItem[index].itemString);
56         }
57         msg("menu help info (%d)", setup_menu->bIsSatMainMenuHelpInfo);
58         msg("menu updated (%d)", setup_menu->bIsUpdatedSatMainMenu);
59 }
60
61 static void on_noti_display_text(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
62 {
63         TelSatDisplayTextInd_t *display_text = NULL;
64
65         msg("noti id (%s)", noti_id);
66
67         if(!data){
68                 msg("noti data is null");
69                 return;
70         }
71
72         display_text = (TelSatDisplayTextInd_t *)data;
73
74         msg("command id (%d)", display_text->commandId);
75         msg("display text (%s)", display_text->text.string);
76         msg("string len(%d)", display_text->text.stringLen);
77         msg("duration (%d)", display_text->duration);
78         msg("high priority (%d)", display_text->bIsPriorityHigh);
79         msg("user response required(%d)", display_text->bIsUserRespRequired);
80 }
81
82 static void on_noti_select_item(TapiHandle *handle, const char *noti_id, void *data, void *user_data)
83 {
84         int index;
85         TelSatSelectItemInd_t *select_item = NULL;
86
87         msg("noti id (%s)", noti_id);
88
89         if(!data){
90                 msg("noti data is null");
91                 return;
92         }
93
94         select_item = (TelSatSelectItemInd_t *)data;
95
96         msg("command id (%d)", select_item->commandId);
97         msg("help info(%d)", select_item->bIsHelpInfoAvailable);
98         msg("selected item string(%s)", select_item->text.string);
99         msg("string len(%d)", select_item->text.stringLen);
100         msg("default item index(%d)", select_item->defaultItemIndex);
101         msg("item count(%d)", select_item->menuItemCount);
102         for(index=0;index < select_item->menuItemCount; index++){
103                 msg("item index(%d) id(%d) len(%d) str(%s)", index,
104                         select_item->menuItem[index].itemId, select_item->menuItem[index].textLen, select_item->menuItem[index].text);
105         }
106 }
107
108 static void on_resp_select_menu(TapiHandle *handle, int result, void *data, void *user_data)
109 {
110         msg("");
111         msg("select menu item result(%d)", result);
112 }
113
114 static int run_sat_get_main_menu_info(MManager *mm, struct menu_data *menu)
115 {
116         TapiHandle *handle = menu_manager_ref_user_data(mm);
117         int result;
118
119         msg("call get main menu info()");
120
121         result = tel_get_sat_main_menu_info(handle, &main_menu);
122         if (result != TAPI_API_SUCCESS) {
123                 msg("failed. (result = %d)", result);
124         }
125
126         msg("success to get main menu");
127         return 0;
128 }
129
130 static int run_sat_select_menu(MManager *mm, struct menu_data *menu)
131 {
132         TapiHandle *handle = menu_manager_ref_user_data(mm);
133         TelSatMenuSelectionReqInfo_t selected_menu;
134         int result, index=0;
135         int item_id;
136
137         msg("call select menu()");
138
139         for(index=0;index < main_menu.satMainMenuNum; index++){
140                 msg("item id(%d) (%s)", main_menu.satMainMenuItem[index].itemId, main_menu.satMainMenuItem[index].itemString);
141         }
142         msg("select item >>> ");
143         if (scanf("%d", &item_id) < 0) {
144                 msg("scanf() failed.");
145                 return 0;
146         }
147
148         selected_menu.bIsHelpRequested = 0;
149         selected_menu.itemIdentifier = item_id;
150
151         msg("selected item id (%d)", selected_menu.itemIdentifier);
152         result = tel_select_sat_menu(handle, &selected_menu, on_resp_select_menu, NULL);
153         if (result != TAPI_API_SUCCESS) {
154                 msg("failed. (result = %d)", result);
155         }
156
157         return 0;
158 }
159
160 struct menu_data menu_sat[] = {
161         { "1", "GET Main Menu Info", NULL, run_sat_get_main_menu_info, NULL},
162         { "2", "SELECT Main Menu", NULL, run_sat_select_menu, NULL},
163 /*      { "2a", "SET PLMN Selection mode (Automatic)", menu_net_set_plmn_mode_automatic, NULL, NULL},
164         { "2s", "SET PLMN Selection mode (Manual)", menu_net_set_plmn_mode_manual, NULL, NULL},
165         { "2g", "GET PLMN Selection mode", menu_net_get_plmn_mode, NULL, NULL},
166         { "3s", "SET Service Domain", menu_net_set_service_domain, NULL, NULL},
167         { "3g", "GET Service Domain", menu_net_get_service_domain, NULL, NULL},
168         { "4s", "SET Band", menu_net_set_band, NULL, NULL},
169         { "4g", "GET Band", menu_net_get_band, NULL, NULL},
170         { "5s", "SET Preferred PLMN", menu_net_set_preferred_plmn, NULL, NULL},
171         { "5g", "GET Preferred PLMN", menu_net_get_preferred_plmn, NULL, NULL},
172         { "6", "SET Cancel manual search", menu_net_set_cancel_manual_search, NULL, NULL},
173         { "7", "GET Serving network", menu_net_get_serving_network, NULL, NULL},*/
174         { NULL, NULL, },
175 };
176
177 void register_sat_event(TapiHandle *handle)
178 {
179         int ret;
180
181         /* SAT */
182         ret = tel_register_noti_event(handle, TAPI_NOTI_SAT_SETUP_MENU, on_noti_setup_menu, NULL);
183         if (ret != TAPI_API_SUCCESS) {
184                 msg("event register failed(%d)", ret);
185         }
186
187         ret = tel_register_noti_event(handle, TAPI_NOTI_SAT_DISPLAY_TEXT, on_noti_display_text, NULL);
188         if (ret != TAPI_API_SUCCESS) {
189                 msg("event register failed(%d)", ret);
190         }
191
192         ret = tel_register_noti_event(handle, TAPI_NOTI_SAT_SELECT_ITEM, on_noti_select_item, NULL);
193         if (ret != TAPI_API_SUCCESS) {
194                 msg("event register failed(%d)", ret);
195         }
196
197         /*      ret = tel_register_noti_event(handle, TAPI_NOTI_SAT_GET_INKEY, on_noti_get_inkey, NULL);
198         ret = tel_register_noti_event(handle, TAPI_NOTI_SAT_GET_INPUT, on_noti_get_input, NULL);*/
199 }