2 * Copyright (C) 2007 OpenedHand Ltd.
4 * Author: Jorn Baayen <jorn@openedhand.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library 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>
32 interrupt_signal_handler (G_GNUC_UNUSED int signum)
34 g_main_loop_quit (main_loop);
38 subscription_lost_cb (G_GNUC_UNUSED GUPnPServiceProxy *proxy,
40 G_GNUC_UNUSED gpointer user_data)
42 g_print ("Lost subscription: %s\n", reason->message);
46 notify_cb (G_GNUC_UNUSED GUPnPServiceProxy *proxy,
51 g_print ("Received a notification for variable '%s':\n", variable);
52 g_print ("\tvalue: %d\n", g_value_get_uint (value));
53 g_print ("\tuser_data: %s\n", (const char *) user_data);
57 service_proxy_available_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
58 GUPnPServiceProxy *proxy)
65 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
67 g_print ("ContentDirectory available:\n");
68 g_print ("\tlocation: %s\n", location);
70 /* We want to be notified whenever SystemUpdateID (of type uint)
72 gupnp_service_proxy_add_notify (proxy,
79 g_signal_connect (proxy,
81 G_CALLBACK (subscription_lost_cb),
84 gupnp_service_proxy_set_subscribed (proxy, TRUE);
86 /* And test action IO */
87 gupnp_service_proxy_send_action (proxy,
96 "BrowseDirectChildren",
123 g_printerr ("Error: %s\n", error->message);
124 g_error_free (error);
129 g_print ("Browse returned:\n");
130 g_print ("\tResult: %s\n", result);
131 g_print ("\tNumberReturned: %u\n", count);
132 g_print ("\tTotalMatches: %u\n", total);
138 service_proxy_unavailable_cb (G_GNUC_UNUSED GUPnPControlPoint *cp,
139 GUPnPServiceProxy *proxy)
141 const char *location;
143 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
145 g_print ("ContentDirectory unavailable:\n");
146 g_print ("\tlocation: %s\n", location);
150 main (G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv)
153 GUPnPContext *context;
154 GUPnPControlPoint *cp;
156 struct sigaction sig_action;
157 #endif /* G_OS_WIN32 */
159 #if !GLIB_CHECK_VERSION(2,35,0)
162 setlocale (LC_ALL, "");
165 context = g_initable_new (GUPNP_TYPE_CONTEXT, NULL, &error, NULL);
167 g_printerr ("Error creating the GUPnP context: %s\n",
169 g_error_free (error);
174 /* We're interested in everything */
175 cp = gupnp_control_point_new
176 (context, "urn:schemas-upnp-org:service:ContentDirectory:1");
178 g_signal_connect (cp,
179 "service-proxy-available",
180 G_CALLBACK (service_proxy_available_cb),
182 g_signal_connect (cp,
183 "service-proxy-unavailable",
184 G_CALLBACK (service_proxy_unavailable_cb),
187 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
189 main_loop = g_main_loop_new (NULL, FALSE);
191 /* Hook the handler for SIGTERM */
193 memset (&sig_action, 0, sizeof (sig_action));
194 sig_action.sa_handler = interrupt_signal_handler;
195 sigaction (SIGINT, &sig_action, NULL);
197 signal(SIGINT,interrupt_signal_handler);
198 #endif /* G_OS_WIN32 */
200 g_main_loop_run (main_loop);
201 g_main_loop_unref (main_loop);
204 g_object_unref (context);