4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngjoo Park <yjoo93.park@samsung.com>,
7 * Seungtaek Chung <seungtaek.chung@samsung.com>, Youngsub Ko <ys4610.ko@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
25 #include <status-monitor.h>
27 #define MAX_STRING_LEN 256
28 #define CLEAR_STDIN {gint ch; while((ch=getchar())!=EOF&&ch!='\n'); }
30 static GIOChannel *stdin_channel;
31 static GMainLoop *loop;
33 typedef void (*menu_cb)(void);
41 static void _monitor_message_cb(const char *message, void *data)
43 printf("new message received : %s\n", message);
46 static void _monitor_state_cb(status_background_type_e type,
47 status_background_state_e state, void *data)
50 case STATUS_BACKGROUND_TYPE_MUSIC:
51 printf("music state changed : state[%d]\n", state);
53 case STATUS_BACKGROUND_TYPE_RADIO:
54 printf("radio state changed : state[%d]\n", state);
56 case STATUS_BACKGROUND_TYPE_VOICE_RECORDING:
57 printf("voice recorder state changed : state[%d]\n", state);
60 printf("unknown type - [%d] \n", type);
66 static void do_quit(void)
68 g_main_loop_quit(loop);
71 static void do_message_monitor_set(void)
75 ret = status_monitor_message_cb_set(_monitor_message_cb, NULL);
76 if (ret != STATUS_ERROR_NONE) {
77 printf("fail to status_monitor_message_cb_set - %d \n", ret);
81 printf("success to status_monitor_message_cb_set\n");
84 static void do_message_monitor_unset(void)
88 ret = status_monitor_message_cb_unset();
89 if (ret != STATUS_ERROR_NONE) {
90 printf("fail to status_monitor_message_cb_unset - %d \n", ret);
94 printf("success to status_monitor_message_cb_unset\n");
97 static int _get_type(status_background_type_e *type)
103 g_print("Select type : \n");
104 g_print("0. Music\n");
105 g_print("1. Radio\n");
106 g_print("2. Voice recorder\n");
107 ret = scanf("%d", &input_type);
109 g_print("invaild input\n\n");
114 if (input_type >= 0 && input_type <= 2)
119 *type = (status_background_type_e)input_type;
124 static void do_state_monitor_set(void)
127 status_background_type_e type;
129 if (_get_type(&type)) {
130 g_print("fail to get type \n");
134 ret = status_monitor_state_cb_set(type, _monitor_state_cb, NULL);
135 if (ret != STATUS_ERROR_NONE) {
136 printf("fail to status_monitor_state_cb_set"\
137 "- type[%d], err[%d] \n", type, ret);
141 printf("success to status_monitor_state_cb_set - type[%d]\n", type);
144 static void do_state_monitor_unset(void)
147 status_background_type_e type;
149 if (_get_type(&type)) {
150 g_print("fail to get type \n");
154 ret = status_monitor_state_cb_unset(type);
155 if (ret != STATUS_ERROR_NONE) {
156 printf("fail to status_monitor_state_cb_unset"\
157 "- type[%d], err[%d] \n", type, ret);
161 printf("success to status_monitor_state_cb_unset - type[%d]\n", type);
164 static void do_state_get(void)
167 status_background_type_e type;
168 status_background_state_e state = STATUS_BACKGROUND_STATE_STOP;
170 if (_get_type(&type)) {
171 g_print("fail to get type \n");
175 ret = status_monitor_state_get(type, &state);
176 if (ret != STATUS_ERROR_NONE) {
177 printf("fail to status_monitor_state_get"\
178 "- type[%d], err[%d] \n", type, ret);
181 printf("success to status_monitor_state_get \n");
182 printf("type[%d], state[%d]\n", type, state);
186 static struct menu_item g_monitor_menu[] = {
187 {"q", "quit", do_quit},
188 {"w", "test message monitor set", do_message_monitor_set},
189 {"e", "test message monitor unset", do_message_monitor_unset},
190 {"s", "test background state monitor set", do_state_monitor_set},
191 {"a", "test background state monitor unset", do_state_monitor_unset},
192 {"g", "test background state get", do_state_get},
197 monitor_display_menu(void)
203 g_print("select commands \n");
204 while (g_monitor_menu[i].cmd) {
205 g_print("[%s] %s\n", g_monitor_menu[i].cmd,
206 g_monitor_menu[i].desc);
216 _monitor_parse_command(gchar *cmd)
220 while (g_monitor_menu[i].cmd) {
221 if (g_strcmp0(g_monitor_menu[i].cmd, cmd) == 0) {
222 if (g_monitor_menu[i].func)
223 g_monitor_menu[i].func();
228 monitor_display_menu();
234 _monitor_input_cb(GIOChannel *channel)
236 gchar buf[MAX_STRING_LEN+3];
239 g_io_channel_read(channel, buf, MAX_STRING_LEN, &len);
243 _monitor_parse_command(buf);
249 int main(int argc, char **argv)
251 loop = g_main_loop_new(NULL, FALSE);
253 stdin_channel = g_io_channel_unix_new (0);
254 g_io_add_watch(stdin_channel, G_IO_IN,
255 (GIOFunc)_monitor_input_cb, NULL);
257 monitor_display_menu();
259 g_main_loop_run(loop);
261 g_io_channel_unref(stdin_channel);
262 g_main_loop_unref(loop);