2 * Copyright (C) 2013 Intel Corporation.
4 * Author: Ludovic Ferrandis <ludovic.ferrandis@intel.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
22 #include <libgupnp/gupnp-control-point.h>
23 #include <libgupnp/gupnp-context-manager.h>
33 interrupt_signal_handler (G_GNUC_UNUSED int signum)
35 g_main_loop_quit (main_loop);
39 device_proxy_available_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
40 GUPnPDeviceProxy *proxy)
42 const char *type, *location;
44 type = gupnp_device_info_get_device_type (GUPNP_DEVICE_INFO (proxy));
45 location = gupnp_device_info_get_location (GUPNP_DEVICE_INFO (proxy));
47 g_print ("Device available:\n");
48 g_print ("\ttype: %s\n", type);
49 g_print ("\tlocation: %s\n", location);
53 device_proxy_unavailable_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
54 GUPnPDeviceProxy *proxy)
56 const char *type, *location;
58 type = gupnp_device_info_get_device_type (GUPNP_DEVICE_INFO (proxy));
59 location = gupnp_device_info_get_location (GUPNP_DEVICE_INFO (proxy));
61 g_print ("Device unavailable:\n");
62 g_print ("\ttype: %s\n", type);
63 g_print ("\tlocation: %s\n", location);
67 service_proxy_available_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
68 GUPnPServiceProxy *proxy)
70 const char *type, *location;
72 type = gupnp_service_info_get_service_type (GUPNP_SERVICE_INFO (proxy));
73 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
75 g_print ("Service available:\n");
76 g_print ("\ttype: %s\n", type);
77 g_print ("\tlocation: %s\n", location);
81 service_proxy_unavailable_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
82 GUPnPServiceProxy *proxy)
84 const char *type, *location;
86 type = gupnp_service_info_get_service_type (GUPNP_SERVICE_INFO (proxy));
87 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
89 g_print ("Service unavailable:\n");
90 g_print ("\ttype: %s\n", type);
91 g_print ("\tlocation: %s\n", location);
95 context_available_cb(GUPnPContextManager *context_manager,
96 GUPnPContext *context,
99 GUPnPControlPoint *cp;
100 GSSDPClient *client = GSSDP_CLIENT(context);
102 g_print ("Context Available:\n");
103 g_print ("\tServer ID: %s\n", gssdp_client_get_server_id (client));
104 g_print ("\tInterface: %s\n", gssdp_client_get_interface (client));
105 g_print ("\tHost IP : %s\n", gssdp_client_get_host_ip (client));
106 g_print ("\tNetwork : %s\n", gssdp_client_get_network (client));
107 g_print ("\tActive : %s\n", gssdp_client_get_active (client)? "TRUE" : "FALSE");
110 /* We're interested in everything */
111 cp = gupnp_control_point_new (context, "ssdp:all");
113 g_signal_connect (cp,
114 "device-proxy-available",
115 G_CALLBACK (device_proxy_available_cb),
117 g_signal_connect (cp,
118 "device-proxy-unavailable",
119 G_CALLBACK (device_proxy_unavailable_cb),
121 g_signal_connect (cp,
122 "service-proxy-available",
123 G_CALLBACK (service_proxy_available_cb),
125 g_signal_connect (cp,
126 "service-proxy-unavailable",
127 G_CALLBACK (service_proxy_unavailable_cb),
130 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
131 gupnp_context_manager_manage_control_point(context_manager, cp);
136 context_unavailable_cb(GUPnPContextManager *context_manager,
137 GUPnPContext *context,
140 GSSDPClient *client = GSSDP_CLIENT(context);
142 g_print ("Context Unavailable:\n");
143 g_print ("\tServer ID: %s\n", gssdp_client_get_server_id (client));
144 g_print ("\tInterface: %s\n", gssdp_client_get_interface (client));
145 g_print ("\tHost IP : %s\n", gssdp_client_get_host_ip (client));
146 g_print ("\tNetwork : %s\n", gssdp_client_get_network (client));
147 g_print ("\tActive : %s\n", gssdp_client_get_active (client)? "TRUE" : "FALSE");
151 print_wl_entry(gpointer data, gpointer user_data)
153 g_print ("\t\t\tEntry: %s\n", (char *)data);
157 print_white_list_entries(GUPnPWhiteList *wl)
161 g_print ("\t\tWhite List Entries:\n");
162 list = gupnp_white_list_get_entries(wl);
163 g_list_foreach (list, print_wl_entry, NULL);
168 change_white_list(gpointer user_data)
170 GUPnPContextManager *context_manager = user_data;
171 GUPnPWhiteList *white_list;
172 static int tomato = 0;
174 g_print ("\nChange White List:\n");
175 g_print ("\t Action number %d:\n", tomato);
177 white_list = gupnp_context_manager_get_white_list(context_manager);
181 g_print ("\t Add Entry eth0\n\n");
182 gupnp_white_list_add_entry(white_list, "eth0");
183 print_white_list_entries (white_list);
186 g_print ("\t Enable WL\n\n");
187 gupnp_white_list_set_enabled (white_list, TRUE);
190 g_print ("\t Add Entry 127.0.0.1\n\n");
191 gupnp_white_list_add_entry(white_list, "127.0.0.1");
192 print_white_list_entries (white_list);
195 g_print ("\t Add Entry eth5\n\n");
196 gupnp_white_list_add_entry(white_list, "eth5");
197 print_white_list_entries (white_list);
200 g_print ("\t Remove Entry eth5\n\n");
201 gupnp_white_list_remove_entry(white_list, "eth5");
202 print_white_list_entries (white_list);
205 g_print ("\t Clear all entries\n\n");
206 gupnp_white_list_clear(white_list);
207 print_white_list_entries (white_list);
210 g_print ("\t Add Entry wlan2\n\n");
211 gupnp_white_list_add_entry(white_list, "wlan2");
212 print_white_list_entries(white_list);
215 g_print ("\t Disable WL\n\n");
216 gupnp_white_list_set_enabled (white_list, FALSE);
219 g_print ("\t Enable WL\n\n");
220 gupnp_white_list_set_enabled (white_list, TRUE);
223 g_print ("\t Connect to wlan0\n\n");
224 g_timeout_add_seconds (35, change_white_list, context_manager);
227 g_print ("\t Add Entry wlan0\n\n");
228 gupnp_white_list_add_entry(white_list, "wlan0");
229 print_white_list_entries (white_list);
232 //~ g_print ("\t Enable WL\n");
233 //~ gupnp_white_list_enable(white_list, FALSE);
241 return (tomato < 11) && (tomato != 10);
245 main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
247 GUPnPContextManager *cm;
250 struct sigaction sig_action;
251 #endif /* G_OS_WIN32 */
253 #if !GLIB_CHECK_VERSION(2,35,0)
256 setlocale (LC_ALL, "");
258 cm = gupnp_context_manager_create(0);
262 G_CALLBACK(context_available_cb),
266 "context-unavailable",
267 G_CALLBACK(context_unavailable_cb),
270 main_loop = g_main_loop_new (NULL, FALSE);
272 id = g_timeout_add_seconds (5, change_white_list, cm);
275 /* Hook the handler for SIGTERM */
276 memset (&sig_action, 0, sizeof (sig_action));
277 sig_action.sa_handler = interrupt_signal_handler;
278 sigaction (SIGINT, &sig_action, NULL);
280 signal(SIGINT, interrupt_signal_handler);
281 #endif /* G_OS_WIN32 */
283 g_main_loop_run (main_loop);
284 g_main_loop_unref (main_loop);
286 g_source_remove (id);