f6430a5324b56e625716be09e984c93ddc849697
[framework/multimedia/libmm-radio.git] / test / mm_radio_rt_api_test.c
1 /*
2  * libmm-radio
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, YoungHwan An <younghwan_.an@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
23 #include "mm_radio.h"
24 #include "mm_radio_rt_api_test.h"
25
26 #define MENU_ITEM_MAX   16
27
28 static int __menu(void);
29 static void __call_api( int choosen );
30 static int __msg_rt_callback(int message, void *param, void *user_param);
31
32 static MMHandleType g_my_radio = 0;
33
34 void __call_api( int choosen )
35 {
36         int ret = MM_ERROR_NONE;
37
38         switch( choosen )
39         {
40                 case 1:
41                 {
42                         RADIO_TEST__( mm_radio_create( &g_my_radio ); )
43                         RADIO_TEST__( mm_radio_set_message_callback( g_my_radio, __msg_rt_callback, &g_my_radio); )
44                 }
45                 break;
46
47                 case 2:
48                 {
49                         RADIO_TEST__( mm_radio_destroy( g_my_radio ); )
50                         g_my_radio = 0;
51                 }
52                 break;
53
54                 case 3:
55                 {
56                         RADIO_TEST__( mm_radio_realize(g_my_radio ); )
57                 }
58                 break;
59
60                 case 4:
61                 {
62                         RADIO_TEST__( mm_radio_unrealize(g_my_radio ); )
63                 }
64                 break;
65
66                 case 7:
67                 {
68                         MMRadioStateType state = 0;
69                         RADIO_TEST__( mm_radio_get_state(g_my_radio, &state); )
70
71                         printf("state : %d\n", state);
72                 }
73                 break;
74
75                 case 8:
76                 {
77                         RADIO_TEST__( mm_radio_start(g_my_radio); )
78                 }
79                 break;
80
81                 case 9:
82                 {
83                         RADIO_TEST__( mm_radio_stop(g_my_radio); )
84                 }
85                 break;
86
87                 case 10:
88                 {
89                         MMRadioSeekDirectionType direction = 0;
90                         printf("input seek direction(0:UP/1:DOWN) : ");
91                         scanf("%d", &direction);
92                         RADIO_TEST__( mm_radio_seek(g_my_radio, direction); )
93                 }
94                 break;
95
96                 case 11:
97                 {
98                         int freq = 0;
99                         printf("input freq : ");
100                         scanf("%d", &freq);
101                         RADIO_TEST__( mm_radio_set_frequency(g_my_radio, freq); )
102                 }
103                 break;
104
105                 case 12:
106                 {
107                         int freq = 0;
108                         RADIO_TEST__( mm_radio_get_frequency(g_my_radio, &freq ); )
109
110                         printf("freq : %d\n", freq);
111                 }
112                 break;
113
114                 case 13:
115                 {
116                         RADIO_TEST__( mm_radio_scan_start(g_my_radio); )
117                 }
118                 break;
119
120                 case 14:
121                 {
122                         RADIO_TEST__( mm_radio_scan_stop(g_my_radio); )
123                 }
124                 break;
125
126                 case 15:
127                 {
128                         MMRadioOutputType path = 0;
129                         printf("input path(0:NONE/1:AUTO/2:SPK/3:EAR) : ");
130                         scanf("%d", &path);
131                         RADIO_TEST__( mm_radio_set_sound_path(g_my_radio, path); )
132                 }
133                 break;
134
135                 case 16:
136                 {
137                         bool muted = 0;
138                         printf("select one(0:UNMUTE/1:MUTE) : ");
139                         scanf("%d", &muted);
140                         RADIO_TEST__( mm_radio_set_mute(g_my_radio, muted); )
141                 }
142                 break;
143
144                 default:
145                         break;
146         }
147 }
148
149 int mm_radio_rt_api_test(void)
150 {
151         while(1)
152         {
153                 char key = 0;
154                 int choosen = 0;
155
156                 choosen = __menu();
157
158                 if ( choosen == -1)
159                         continue;
160
161                 if ( choosen == 0 )
162                         break;
163
164                 __call_api( choosen );
165         }
166
167         printf("radio test client finished\n");
168
169         return 0;
170 }
171
172 int __menu(void)
173 {
174         int menu_item = 0;
175
176         printf("---------------------------------------------------------\n");
177         printf("mm-radio rt api test. try now!\n");
178         printf("---------------------------------------------------------\n");
179         printf("[1] mm_radio_create\n");
180         printf("[2] mm_radio_destroy\n");
181         printf("[3] mm_radio_realize\n");
182         printf("[4] mm_radio_unrealize\n");
183         printf("[7] mm_radio_get_state\n");
184         printf("[8] mm_radio_start\n");
185         printf("[9] mm_radio_stop\n");
186         printf("[10] mm_radio_seek\n");
187         printf("[11] mm_radio_set_frequency(ex.1077)\n");
188         printf("[12] mm_radio_get_frequency\n");
189         printf("[13] mm_radio_scan_start\n");
190         printf("[14] mm_radio_scan_stop\n");
191         printf("[15] mm_radio_set_sound_path\n");
192         printf("[16] mm_radio_set_mute\n");
193         printf("[0] quit\n");
194         printf("---------------------------------------------------------\n");
195         printf("choose one : ");
196         scanf("%d", &menu_item);
197
198         if ( menu_item > MENU_ITEM_MAX )
199                 menu_item = -1;
200
201         return menu_item;
202 }
203
204
205 int __msg_rt_callback(int message, void *pParam, void *user_param)
206 {
207         MMMessageParamType* param = (MMMessageParamType*)pParam;
208         MMHandleType radio = (MMHandleType) user_param;
209         int ret = 0;
210
211         printf("incomming message : %d\n", message);
212
213         switch(message)
214         {
215         case MM_MESSAGE_STATE_CHANGED:
216
217                 printf("MM_MESSAGE_STATE_CHANGED: current : %d    old : %d\n"
218                                 , param->state.current, param->state.previous);
219                 break;
220         case MM_MESSAGE_RADIO_SCAN_START:
221                 printf("MM_MESSAGE_RADIO_SCAN_START\n");
222                 break;
223         case MM_MESSAGE_RADIO_SCAN_INFO:
224                 assert(param);
225                 printf("MM_MESSAGE_RADIO_SCAN_INFO : freq : %d\n", param->radio_scan.frequency);
226                 break;
227         case MM_MESSAGE_RADIO_SCAN_STOP:
228                 printf("MM_MESSAGE_RADIO_SCAN_STOP\n");
229                 break;
230         case MM_MESSAGE_RADIO_SCAN_FINISH:
231                 printf("MM_MESSAGE_RADIO_SCAN_FINISHED\n");
232                 RADIO_TEST__( mm_radio_scan_stop(radio); )
233                 break;
234         case MM_MESSAGE_RADIO_SEEK_START:
235                         printf("MM_MESSAGE_RADIO_SEEK_START\n");
236                         break;
237         case MM_MESSAGE_RADIO_SEEK_FINISH:
238                 printf("MM_MESSAGE_RADIO_SEEK_FINISHED : freq : %d\n", param->radio_scan.frequency);
239                 break;
240         default:
241                 printf("ERROR : unknown message received!\n");
242                 break;
243         }
244
245         return true;
246 }