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.
23 /*===========================================================================================
27 ========================================================================================== */
32 #include <mm_message.h>
35 #include <mm_message.h>
39 #include <iniparser.h>
42 #include <sys/types.h>
43 #include <sys/socket.h>
44 #include <netinet/in.h>
49 #include <dbus/dbus.h>
50 #include <dbus/dbus-glib-lowlevel.h>
54 #define PACKAGE "mm_wfd_testsuite"
56 /*===========================================================================================
58 | LOCAL DEFINITIONS AND DECLARATIONS FOR MODULE |
60 ========================================================================================== */
62 #if defined(_USE_GMAINLOOP)
66 gboolean wfd_server_test_method(void *pObject, int pid, char *test_name,
69 debug_log("Received test %s\n", test_name);
73 #include "wfd-structure.h"
75 #define WFD_PROXY_COMM_PORT 8888
77 typedef struct WfdServerObject WfdServerObject;
78 typedef struct WfdServerObjectClass WfdServerObjectClass;
80 GType Daemon_Object_get_type(void);
81 struct WfdServerObject {
85 struct WfdServerObjectClass {
89 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
91 #define WFD_SERVER_TYPE_OBJECT (Daemon_Object_get_type())
93 #define WFD_SERVER_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST \
94 ((object), WFD_SERVER_TYPE_OBJECT, WfdServerObject))
96 G_DEFINE_TYPE(WfdServerObject, Daemon_Object, G_TYPE_OBJECT)
97 static void Daemon_Object_init(WfdServerObject * obj)
99 debug_log("Daemon_Object_init\n");
102 static void Daemon_Object_class_init(WfdServerObjectClass * klass)
104 debug_log("Daemon_Object_class_init\n");
107 /*---------------------------------------------------------------------------
109 ---------------------------------------------------------------------------*/
110 #define MAX_STRING_LEN 2048
112 /*---------------------------------------------------------------------------
113 | LOCAL CONSTANT DEFINITIONS: |
114 ---------------------------------------------------------------------------*/
117 CURRENT_STATUS_MAINMENU,
118 CURRENT_STATUS_SERVER_IP,
119 CURRENT_STATUS_SERVER_PORT,
120 CURRENT_STATUS_CONNECT,
126 struct sockaddr_in cli_addr;
138 struct sockaddr_in serv_addr;
143 /*---------------------------------------------------------------------------
144 | LOCAL VARIABLE DEFINITIONS: |
145 ---------------------------------------------------------------------------*/
148 static MMHandleType g_wfd = 0;
149 char *g_err_name = NULL;
150 gboolean quit_pushing;
152 /*---------------------------------------------------------------------------
153 | LOCAL FUNCTION PROTOTYPES: |
154 ---------------------------------------------------------------------------*/
155 static void wfd_connect();
156 static void wfd_start();
157 static void wfd_stop();
161 static void wfd_set_signal();
163 /*---------------------------------------------------------------------------
164 | LOCAL FUNCTION DEFINITIONS: |
165 ---------------------------------------------------------------------------*/
166 static bool msg_callback(int message, MMMessageParamType *param, void *user_param)
168 /* TODO any error notification or state change should be forwarded to the active list of proxy apps */
170 case MM_MESSAGE_ERROR:
172 WFDClient *client = (WFDClient *)user_param;
173 if(!client) return FALSE;
174 WFDServer *lserver = (WFDServer*) client->parent;
175 if(!lserver) return FALSE;
176 debug_log("msg_callback error : code = %x\n", param->code);
177 debug_log ("DESTROY..\n\n");
179 shutdown (lserver->sockfd, SHUT_RDWR);
180 debug_log("msg_callback error call quit_program()");
184 case MM_MESSAGE_WARNING:
185 // debug_log("warning : code = %d\n", param->code);
187 case MM_MESSAGE_END_OF_STREAM:
188 debug_log("msg_callback end of stream\n");
191 case MM_MESSAGE_STATE_CHANGED:
192 g_current_state = param->state.current;
193 switch(g_current_state)
195 case MM_WFD_STATE_NULL:
196 debug_log("\n ==> [WFDApp] Player is [NULL]\n");
198 case MM_WFD_STATE_READY:
199 debug_log("\n ==> [WFDApp] Player is [READY]\n");
201 case MM_WFD_STATE_PLAYING:
202 debug_log("\n ==> [WFDApp] Player is [PLAYING]\n");
204 case MM_WFD_STATE_PAUSED:
205 debug_log("\n ==> [WFDApp] Player is [PAUSED]\n");
215 static gboolean proxy_write (WFDClient *client, char *wbuf)
217 write(client->connfd, wbuf, strlen(wbuf));
221 static void input_server_ip_and_port(char *server_ip, char* port, WFDClient *client)
223 int len = strlen(server_ip);
224 int ret = MM_ERROR_NONE;
225 if ( len < 0 || len > MAX_STRING_LEN )
230 if ( mm_wfd_create(&g_wfd) != MM_ERROR_NONE )
232 debug_log("input_server_ip wfd create is failed\n");
235 ret = mm_wfd_set_message_callback(g_wfd, msg_callback, (void*)client);
236 if (ret != MM_ERROR_NONE)
238 debug_log ("input_server_ip Error in setting server_port...\n");
242 ret = mm_wfd_set_attribute(g_wfd,
244 "server_ip", server_ip, strlen(server_ip),
246 if (ret != MM_ERROR_NONE)
248 debug_log ("input_server_ip Error in setting server_port...\n");
251 ret = mm_wfd_set_attribute(g_wfd,
253 "server_port", port, strlen(port),
255 if (ret != MM_ERROR_NONE)
257 debug_log ("input_server_port Error in setting server_port...\n");
260 /*set wfd source status*/
261 gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_ON;
262 if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) {
263 debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_ON");
266 static void wfd_connect()
268 int ret = MM_ERROR_NONE;
272 debug_log ("wfd_start Creating server with default values : ");
273 if ( mm_wfd_create(&g_wfd) != MM_ERROR_NONE )
275 debug_log("wfd_start wfd create is failed\n");
279 ret = mm_wfd_set_message_callback(g_wfd, msg_callback, (void*)g_wfd);
280 if (ret != MM_ERROR_NONE)
282 debug_log ("wfd_start Error in setting server_port...\n");
286 if ( mm_wfd_realize(g_wfd) != MM_ERROR_NONE )
288 debug_log("wfd_start wfd realize is failed\n");
292 if ( mm_wfd_connect(g_wfd) != MM_ERROR_NONE )
294 debug_log("wfd_start wfd connect is failed\n");
300 static void wfd_start()
302 int ret = MM_ERROR_NONE;
306 debug_log ("wfd_start Creating server with default values : ");
307 if ( mm_wfd_create(&g_wfd) != MM_ERROR_NONE )
309 debug_log("wfd_start wfd create is failed\n");
313 ret = mm_wfd_set_message_callback(g_wfd, msg_callback, (void*)g_wfd);
314 if (ret != MM_ERROR_NONE)
316 debug_log ("wfd_start Error in setting server_port...\n");
320 if ( mm_wfd_realize(g_wfd) != MM_ERROR_NONE )
322 debug_log("wfd_start wfd realize is failed\n");
326 if ( mm_wfd_connect(g_wfd) != MM_ERROR_NONE )
328 debug_log("wfd_start wfd connect is failed\n");
333 if (mm_wfd_start(g_wfd) != MM_ERROR_NONE)
335 debug_log ("wfd_start Failed to start WFD");
340 static void wfd_stop()
342 int ret = MM_ERROR_NONE;
344 ret = mm_wfd_stop(g_wfd);
345 if (ret != MM_ERROR_NONE)
347 debug_log ("wfd_stop Error to do stop...\n");
352 static void wfd_pause()
354 int ret = MM_ERROR_NONE;
356 ret = mm_wfd_pause(g_wfd);
357 if (ret != MM_ERROR_NONE)
359 debug_log ("wfd_pause Error to do pausep...\n");
364 static void wfd_resume()
366 int ret = MM_ERROR_NONE;
368 ret = mm_wfd_resume(g_wfd);
369 if (ret != MM_ERROR_NONE)
371 debug_log ("wfd_resume Error to do resume...\n");
376 static void wfd_standby()
378 int ret = MM_ERROR_NONE;
379 ret = mm_wfd_standby(g_wfd);
380 if (ret != MM_ERROR_NONE)
382 debug_log ("wfd_standby Error to do standby...\n");
389 MMTA_ACUM_ITEM_SHOW_RESULT_TO(MMTA_SHOW_STDOUT);
391 debug_log ("quit_program...\n");
393 /*set wfd source status*/
394 gboolean status = VCONFKEY_MIRACAST_WFD_SOURCE_OFF;
395 if (!vconf_set_bool(VCONFKEY_MIRACAST_WFD_SOURCE_STATUS, status)) {
396 debug_log ("set VCONFKEY_MIRACAST_WFD_SOURCE_OFF");
400 mm_wfd_unrealize(g_wfd);
401 mm_wfd_destroy(g_wfd);
404 g_main_loop_quit(g_loop);
407 gchar * convert_state_to_string(MMWfdStateType aState)
410 cmd_replay = g_string_new ("");
413 case MM_WFD_STATE_NULL:
414 g_string_append_printf (cmd_replay, "MM_WFD_STATE_NULL");
416 case MM_WFD_STATE_READY:
417 g_string_append_printf (cmd_replay, "MM_WFD_STATE_READY");
419 case MM_WFD_STATE_CONNECTION_WAIT:
420 g_string_append_printf (cmd_replay, "MM_WFD_STATE_CONNECTION_WAIT");
422 case MM_WFD_STATE_CONNECTED:
423 g_string_append_printf (cmd_replay, "MM_WFD_STATE_CONNECTED");
425 case MM_WFD_STATE_PLAYING:
426 g_string_append_printf (cmd_replay, "MM_WFD_STATE_PLAYING");
428 case MM_WFD_STATE_PAUSED:
429 g_string_append_printf (cmd_replay, "MM_WFD_STATE_PAUSED");
431 case MM_WFD_STATE_NONE:
432 g_string_append_printf (cmd_replay, "MM_WFD_STATE_NONE");
434 case MM_WFD_STATE_NUM:
435 g_string_append_printf (cmd_replay, "MM_WFD_STATE_NUM");
438 return g_string_free (cmd_replay, FALSE);
441 static void interpret (WFDClient *client, char *cmd)
444 if (strstr(cmd, "WFD_PROXY_SET_IP_PORT"))
449 debug_log ("setting attributes... WFD..\n\n");
450 IP_port = g_strsplit(cmd,"\r\n",0);
451 IP = g_strsplit(IP_port[1]," ",0);
452 port = g_strsplit(IP_port[2]," ",0);
453 debug_log ("received IP %s port %s\n", IP[1], port[1]);
454 input_server_ip_and_port(IP[1], port[1], client);
455 cmd_replay = g_string_new ("");
456 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_SET_IP_PORT");
457 g_string_append_printf (cmd_replay, "\r\n");
458 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
459 proxy_write(client, g_string_free (cmd_replay, FALSE));
460 debug_log ("STATE QUERY..demon return\n\n");
462 else if (strstr(cmd, "WFD_PROXY_CONNECT"))
464 debug_log ("Starting... WFD..\n\n");
465 cmd_replay = g_string_new ("");
466 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_CONNECT");
467 g_string_append_printf (cmd_replay, "\r\n");
468 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
469 proxy_write(client, g_string_free (cmd_replay, FALSE));
470 debug_log ("STATE QUERY..demon return\n\n");
473 else if (strstr(cmd, "WFD_PROXY_START"))
475 debug_log ("Starting... WFD..\n\n");
476 cmd_replay = g_string_new ("");
477 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_START");
478 g_string_append_printf (cmd_replay, "\r\n");
479 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
480 proxy_write(client, g_string_free (cmd_replay, FALSE));
481 debug_log ("STATE QUERY..demon return\n\n");
484 else if (strstr(cmd, "WFD_PROXY_PAUSE"))
486 debug_log ("PAUSING..\n\n");
488 cmd_replay = g_string_new ("");
489 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_PAUSE");
490 g_string_append_printf (cmd_replay, "\r\n");
491 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
492 proxy_write(client, g_string_free (cmd_replay, FALSE));
493 debug_log ("STATE QUERY..demon return\n\n");
495 else if (strstr(cmd, "WFD_PROXY_RESUME"))
497 debug_log ("RESUMING..\n\n");
499 cmd_replay = g_string_new ("");
500 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_RESUME");
501 g_string_append_printf (cmd_replay, "\r\n");
502 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
503 proxy_write(client, g_string_free (cmd_replay, FALSE));
504 debug_log ("STATE QUERY..demon return\n\n");
506 else if (strstr(cmd, "WFD_PROXY_STOP"))
508 debug_log ("STOPPING..\n\n");
510 cmd_replay = g_string_new ("");
511 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_STOP");
512 g_string_append_printf (cmd_replay, "\r\n");
513 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
514 proxy_write(client, g_string_free (cmd_replay, FALSE));
515 debug_log ("STATE QUERY..demon return\n\n");
517 else if (strstr(cmd, "WFD_PROXY_DESTROY"))
519 WFDServer *lserver = (WFDServer*) client->parent;
520 debug_log ("DESTROY..\n\n");
521 cmd_replay = g_string_new ("");
522 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_DESTROY");
523 g_string_append_printf (cmd_replay, "\r\n");
524 g_string_append_printf (cmd_replay, "MM_ERROR_NONE");
525 proxy_write(client, g_string_free (cmd_replay, FALSE));
526 debug_log ("STATE QUERY..demon return\n\n");
528 shutdown (lserver->sockfd, SHUT_RDWR);
529 debug_log("interpret calll quit_program()");
532 else if (strstr(cmd, "WFD_PROXY_STATE_QUERY"))
534 debug_log ("STATE QUERY..\n\n");
535 cmd_replay = g_string_new ("");
536 g_string_append_printf (cmd_replay, "REPLAY WFD_PROXY_STATE_QUERY");
537 g_string_append_printf (cmd_replay, "\r\n");
538 g_string_append_printf (cmd_replay, convert_state_to_string(g_current_state));
539 proxy_write(client, g_string_free (cmd_replay, FALSE));
540 debug_log ("STATE QUERY..demon return\n\n");
544 debug_log("unknown menu \n");
548 gboolean input (GIOChannel *channel, GIOCondition condition, gpointer data)
550 WFDClient *client = (WFDClient*)data;
552 GError *error = NULL;
553 if(condition & G_IO_IN) {
554 memset(&(client->inbuff),0,sizeof(client->inbuff));
555 g_io_channel_read(client->channel, client->inbuff, sizeof(client->inbuff), &read);
558 client->inbuff[read] = '\0';
559 g_strstrip(client->inbuff);
560 debug_log("got command %s\n", client->inbuff);
561 if(!g_str_has_prefix(client->inbuff,"WFD")) goto client_cleanup;
562 interpret (client, client->inbuff);
563 debug_log("command return \n");
565 else goto client_cleanup;
567 if (condition & G_IO_HUP) goto client_cleanup;
571 WFDServer *lserver = (WFDServer *)client->parent;
572 client->inactive = TRUE;
573 debug_log("client connection closed \n");
574 shutdown (client->connfd, SHUT_RDWR);
575 g_io_channel_shutdown(client->channel, TRUE, &error);
576 debug_log("IO channel closed \n");
577 if(g_list_length(lserver->clients))
579 lserver->clients = g_list_remove(lserver->clients, client);
582 debug_log("client removed from list \n");
587 static void* wfd_server_thread_function(void * asrc)
592 WFDServer *pserver = (WFDServer *)asrc;
593 pserver->sockfd = socket(AF_INET, SOCK_STREAM, 0);
594 debug_log("wfd_proxy_initialize socke is %d", pserver->sockfd);
595 if (pserver->sockfd < 0)
597 debug_log("ERROR opening socket");
600 debug_log("wfd_proxy_initialize get socket created\n");
601 bzero((char *) &pserver->serv_addr, sizeof(pserver->serv_addr));
602 pserver->portno = WFD_PROXY_COMM_PORT;
603 pserver->serv_addr.sin_family = AF_INET;
604 pserver->serv_addr.sin_addr.s_addr = INADDR_ANY;
605 pserver->serv_addr.sin_port = htons(pserver->portno);
606 debug_log("serv_addr = %p sizeof %d ", (struct sockaddr *) &pserver->serv_addr, sizeof(pserver->serv_addr));
607 setsockopt(pserver->sockfd, SOL_SOCKET, SO_REUSEADDR, &nSockOpt, sizeof(nSockOpt));
608 if (bind(pserver->sockfd, (struct sockaddr *) &pserver->serv_addr, sizeof(pserver->serv_addr)) < 0)
610 debug_log("ERROR on binding");
613 debug_log("wfd_proxy_initialize get socket bind\n");
614 if (listen(pserver->sockfd,5) <0)
616 debug_log("ERROR on socket listen");
624 socklen_t clilen = {0};
625 struct sockaddr_in cli_addr = {0};
626 WFDClient *client = NULL;
627 clilen = sizeof(cli_addr);
628 debug_log("wfd_proxy_initialize waiting for accept \n");
629 newsockfd = accept(pserver->sockfd, (struct sockaddr *) &cli_addr, &clilen);
631 debug_log("ERROR on accept");
634 debug_log("wfd_proxy_initialize get socket accept \n");
635 client = g_malloc(sizeof(WFDClient));
638 debug_log("client malloc failed. out of memory");
641 client->connfd = newsockfd;
642 socket_id = newsockfd;
643 client->lock = g_mutex_new ();
644 client->inactive = 0;
645 client->parent = pserver;
646 client->channel = g_io_channel_unix_new(client->connfd);
647 g_io_add_watch(client->channel, G_IO_IN|G_IO_HUP|G_IO_ERR, (GIOFunc)input, client);
648 pserver->clients = g_list_prepend(pserver->clients, client);
651 debug_log("wfd_server_thread_function cleanup \n");
652 for(i=0;i<g_list_length(pserver->clients); i++)
654 GError *error = NULL;
655 WFDClient *tempclient = (WFDClient *)g_list_nth_data(pserver->clients,i);
657 tempclient->inactive = TRUE;
658 shutdown (tempclient->connfd, SHUT_RDWR);
659 g_io_channel_shutdown(tempclient->channel, TRUE, &error);
660 pserver->clients = g_list_remove(pserver->clients, tempclient);
664 g_list_free(pserver->clients);
665 shutdown (pserver->sockfd, SHUT_RDWR);
666 debug_log("wfd_server_thread_function calll quit_program()");
669 debug_log("wfd_server_thread_function THREAD EXIT \n");
674 static gboolean __func1(void *data)
676 GError *error = NULL;
677 WFDServer *server = (WFDServer *)data;
678 debug_log("__func1 enter \n");
679 server->thread = g_thread_create ((GThreadFunc) wfd_server_thread_function, server, TRUE, &error);
680 server->clients = g_list_alloc ();
681 debug_log("__func1 exit \n");
685 static bool __wfd_server_setup(void* pserver)
687 WFDServer *server = (WFDServer *)pserver;
688 DBusGConnection *conn = NULL;
689 GObject *object = NULL;
690 DBusGObjectInfo dbus_glib_wfd_server_object_info;
694 debug_log("__wfd_server_setup start\n");
695 dbus_g_object_type_install_info(WFD_SERVER_TYPE_OBJECT,
696 &dbus_glib_wfd_server_object_info);
698 conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
700 debug_log("Unable to get dbus!");
703 dbus_error_init(&derr);
705 ret = dbus_bus_request_name(dbus_g_connection_get_connection(conn),
706 "com.samsung.wfd.server",
707 DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, &derr);
709 if (dbus_error_is_set(&derr)) {
710 debug_log("dbus_bus_request_name failed with error:%s", derr.message);
711 dbus_error_free(&derr);
714 object = g_object_new(WFD_SERVER_TYPE_OBJECT, NULL);
715 if (NULL == object) {
716 debug_log("Unable to create new object");
719 dbus_g_connection_register_g_object(conn, "/com/samsung/wfd/server", G_OBJECT(object));
720 g_idle_add(__func1, server);
721 debug_log("__wfd_server_setup end\n");
724 void wfd_signal_handler(int signo) {
726 debug_log("wfd_signal_handler calll quit_program()");
727 shutdown (socket_id, SHUT_RDWR);
732 static void wfd_set_signal()
735 /*refer to signal.h*/
736 /*SIGABRT A Process abort signal.
737 SIGALRM T Alarm clock.
738 SIGBUS A Access to an undefined portion of a memory object.
739 SIGCHLD I Child process terminated, stopped,
740 SIGCONT C Continue executing, if stopped.
741 SIGFPE A Erroneous arithmetic operation.
743 SIGILL A Illegal instruction.
744 SIGINT T Terminal interrupt signal.
745 SIGKILL T Kill (cannot be caught or ignored).
746 SIGPIPE T Write on a pipe with no one to read it.
747 SIGQUIT A Terminal quit signal.
748 SIGSEGV A Invalid memory reference.
749 SIGSTOP S Stop executing (cannot be caught or ignored).
750 SIGTERM T Termination signal.
751 SIGTSTP S Terminal stop signal.
752 SIGTTIN S Background process attempting read.
753 SIGTTOU S Background process attempting write.
754 SIGUSR1 T User-defined signal 1.
755 SIGUSR2 T User-defined signal 2.
756 SIGPOLL T Pollable event.
757 SIGPROF T Profiling timer expired.
758 SIGSYS A Bad system call.
759 SIGTRAP A Trace/breakpoint trap.
760 SIGURG I High bandwidth data is available at a socket.
761 SIGVTALRM T Virtual timer expired.
762 SIGXCPU A CPU time limit exceeded.
763 SIGXFSZ A File size limit exceeded.
765 The default actions are as follows:
766 T : Abnormal termination of the process. The process is terminated with all the consequences of _exit()
767 A : Abnormal termination of the process.
768 I : Ignore the signal.
771 struct sigaction act_new;
772 memset (&act_new, 0, sizeof (struct sigaction));
774 act_new.sa_handler = wfd_signal_handler;
776 sigaction(SIGABRT, &act_new, NULL);
777 sigaction(SIGBUS, &act_new, NULL);
778 sigaction(SIGINT, &act_new, NULL); //
779 sigaction(SIGKILL, &act_new, NULL);
780 sigaction(SIGPIPE, &act_new, NULL);
781 sigaction(SIGQUIT, &act_new, NULL); //
782 sigaction(SIGSEGV, &act_new, NULL);
783 sigaction(SIGTERM, &act_new, NULL); //
784 sigaction(SIGSYS, &act_new, NULL);
790 static void wifi_direct_state_change_cb(keynode_t *key, void *data)
792 WFDServer *server = (WFDServer *)data;
794 debug_log("wifi direct state changed");
796 state = vconf_keynode_get_int(key);
797 if (state < VCONFKEY_WIFI_DIRECT_GROUP_OWNER) {
798 debug_log("wifi disconnected");
800 shutdown (server->sockfd, SHUT_RDWR);
801 debug_log("wifi_direct_state_change_cb calll quit_program()");
806 static void lcd_state_change_cb(keynode_t *key, void *data)
808 WFDServer *server = (WFDServer *)data;
812 state = vconf_keynode_get_int(key);
813 if (state == VCONFKEY_PM_STATE_NORMAL) {
814 debug_log("source has woke up time to wake-up-sink");
817 else if(state == VCONFKEY_PM_STATE_LCDOFF || VCONFKEY_PM_STATE_SLEEP) {
818 debug_log("source is sleeping time to go to sleep");
823 int main(int argc, char *argv[])
826 server.thread = NULL;
827 server.clients = NULL;
829 g_loop = g_main_loop_new(NULL, FALSE);
831 debug_log("Unable to create gmain loop! Aborting wfd server\n");
835 debug_log("wfd_proxy_initialize\n");
836 if (!__wfd_server_setup(&server)) {
837 debug_log("Unable to initialize test server\n");
840 debug_log("set vconf_notify_key_changed about wifi direct");
841 if (0 != vconf_notify_key_changed(VCONFKEY_WIFI_DIRECT_STATE, wifi_direct_state_change_cb, &server)) {
842 debug_log("vconf_notify_key_changed() failed");
844 debug_log("set vconf_notify_key_changed about LCD state");
845 if (0 != vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_change_cb, &server)) {
846 debug_log("vconf_notify_key_changed() failed");
848 debug_log("wfd_proxy_initialize run loop \n");
849 g_main_loop_run(g_loop);
850 g_thread_join(server.thread);
851 shutdown (server.sockfd, SHUT_RDWR);
852 debug_log("WFD SERVER EXIT \n");