4 * Copyright (c) 2011 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: JongHyuk Choi <jhchoi.choi@samsung.com>, ByungWook Jang <bw.jang@samsung.com>,
7 * Manoj Kumar K <manojkumar.k@samsung.com>, Hyunil Park <hyunil46.park@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 <mm_message.h>
26 #include <mm_wfd_proxy.h>
32 #include <X11/Xutil.h>
35 #define PACKAGE "mm_wfd_proxy_test"
37 #if defined(_USE_GMAINLOOP)
41 #define MAX_STRING_LEN 2048
45 CURRENT_STATUS_MAINMENU,
46 CURRENT_STATUS_SERVER_IP,
47 CURRENT_STATUS_SERVER_PORT,
48 CURRENT_STATUS_CONNECT,
51 static MMHandleType g_wfd = 0;
52 gboolean quit_pushing;
53 static int g_current_state = WFDSRC_STATE_NULL;
55 static void wfd_start();
56 static void wfd_stop();
57 static void wfd_destroy ();
58 static void set_display_mode(char *mode);
60 gboolean timeout_quit_program(void* data);
63 static void wfd_proxy_callback(MMHandleType pHandle,
64 WfdSrcProxyRet error_code,
65 WfdSrcProxyState state,
68 if(error_code == WFDSRC_ERROR_NONE)
70 if(g_current_state != state)
72 g_print("miracast server STATE changed from %d --> %d \n",g_current_state, state);
73 g_current_state = state;
77 g_print("Miracast server notified error %d", error_code);
79 case WFDSRC_STATE_NULL:
80 case WFDSRC_STATE_READY:
81 case WFDSRC_STATE_CONNECTION_WAIT:
82 case WFDSRC_STATE_CONNECTED:
87 case WFDSRC_STATE_PLAYING:
88 case WFDSRC_STATE_PAUSED:
94 case WFDSRC_STATE_NONE:
104 static void wfd_input_server_ip_and_port(char* serverIP, char* port)
106 if (WfdSrcProxySetIPAddrAndPort(g_wfd, serverIP, port) != MM_ERROR_NONE)
108 g_print ("wfd_input_server_ip_and_port Failed to set attributes");
114 static void wfd_connect()
116 if (WfdSrcProxyConnect(g_wfd) != MM_ERROR_NONE)
118 g_print ("wfd_start Failed to start WFD");
125 static void wfd_start()
127 if (WfdSrcProxyStart(g_wfd) != MM_ERROR_NONE)
129 g_print ("wfd_start Failed to start WFD");
136 static void wfd_stop()
138 int ret = MM_ERROR_NONE;
140 ret = WfdSrcProxyStop(g_wfd);
141 if (ret != MM_ERROR_NONE)
143 g_print ("wfd_stop Error to do stop...\n");
150 static void wfd_pause()
152 int ret = MM_ERROR_NONE;
154 ret = WfdSrcProxyPause(g_wfd);
155 if (ret != MM_ERROR_NONE)
157 g_print ("wfd_pause Error to do pause...\n");
163 static void wfd_resume()
165 int ret = MM_ERROR_NONE;
167 ret = WfdSrcProxyResume(g_wfd);
168 if (ret != MM_ERROR_NONE)
170 g_print ("wfd_resume Error to do resume...\n");
178 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_STDOUT);
181 WfdSrcProxyDeInit(g_wfd);
183 g_main_loop_quit(g_loop);
188 WfdSrcProxyDestroyServer(g_wfd);
189 g_print("wfd_destroy wfd server is destroyed.\n");
192 static void set_display_mode(char *mode)
194 int len = strlen(mode);
196 int ret = MM_ERROR_NONE;
197 static Atom g_sc_status_atom = 0;
198 static Display *dpy = NULL;
199 int dispmode = UTILX_SCRNCONF_DISPMODE_NULL;
201 if ( len < 0 || len > MAX_STRING_LEN )
203 dpy = XOpenDisplay(NULL);
206 g_printf ("Error : fail to open display\n");
209 g_sc_status_atom = XInternAtom (dpy, STR_ATOM_SCRNCONF_STATUS, False);
210 XSelectInput (dpy, RootWindow(dpy, 0), StructureNotifyMask);
212 g_printf("%s", mode);
213 if (strncmp(mode, "a", 1) == 0) {
214 dispmode = UTILX_SCRNCONF_DISPMODE_CLONE;
216 else if (strncmp(mode, "b", 1) == 0) {
217 dispmode = UTILX_SCRNCONF_DISPMODE_EXTENDED;
219 if (!utilx_scrnconf_set_dispmode (dpy, dispmode)) {
220 g_printf ("fail to set dispmode\n");
222 g_printf("set dispmode : %d", dispmode);
225 static void displaymenu()
228 g_print("=========================================================================================\n");
229 g_print(" MM-WFD Testsuite (press q to quit) \n");
230 g_print("-----------------------------------------------------------------------------------------\n");
231 g_print("-----------------------------------------------------------------------------------------\n");
232 g_print("a : a ip port\t");
233 g_print("c : Connect\t");
234 g_print("d : displaymode (a:clone b:desktop) \t");
235 g_print("s : Start \t");
236 g_print("p : pause \t");
237 g_print("r : resume \t");
238 g_print("e : stop\t");
239 g_print("u : destroy server\t");
240 g_print("q : quit\t");
242 g_print("=========================================================================================\n");
245 gboolean timeout_menu_display(void* data)
251 gboolean timeout_quit_program(void* data)
257 static void interpret (char *cmd)
259 //if ( strlen(cmd) == 1 )
261 if (strncmp(cmd, "a", 1) == 0)
264 g_print ("Input server IP and port number..\n\n");
265 IP_port = g_strsplit(cmd," ",0);
266 wfd_input_server_ip_and_port(IP_port[1], IP_port[2]);
268 else if (strncmp(cmd, "c", 1) == 0)
270 g_print ("Connecting... WFD..\n\n");
273 else if (strncmp(cmd, "d", 1) == 0)
275 gchar **Display_mode;
276 Display_mode = g_strsplit(cmd," ",0);
277 g_print ("set display mode\n\n");
278 set_display_mode(Display_mode[1]);
280 else if (strncmp(cmd, "s", 1) == 0)
282 g_print ("Starting... WFD..\n\n");
285 else if (strncmp(cmd, "p", 1) == 0)
287 g_print ("PAUSING..\n\n");
290 else if (strncmp(cmd, "r", 1) == 0)
292 g_print ("RESUMING..\n\n");
295 else if (strncmp(cmd, "e", 1) == 0)
299 else if (strncmp(cmd, "u", 1) == 0)
303 else if (strncmp(cmd, "q", 1) == 0)
310 g_print("unknown menu \n");
313 g_timeout_add(100, timeout_menu_display, 0);
316 gboolean input (GIOChannel *channel)
318 char buf[MAX_STRING_LEN + 3];
321 g_io_channel_read(channel, buf, MAX_STRING_LEN, &read);
328 int main(int argc, char *argv[])
331 GIOChannel *stdin_channel;
333 WfdSrcProxyInit( &g_wfd, wfd_proxy_callback, NULL);
334 stdin_channel = g_io_channel_unix_new(0);
335 g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
339 #if defined(_USE_GMAINLOOP)
340 g_print (" <<<< GTK Loop >>>>");
341 g_loop = g_main_loop_new(NULL, FALSE);
342 g_main_loop_run(g_loop);