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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <libgupnp/gupnp-control-point.h>
31 interrupt_signal_handler (int signum)
33 g_main_loop_quit (main_loop);
37 subscription_lost_cb (GUPnPServiceProxy *proxy,
41 g_print ("Lost subscription: %s\n", reason->message);
45 notify_cb (GUPnPServiceProxy *proxy,
50 g_print ("Received a notification for variable '%s':\n", variable);
51 g_print ("\tvalue: %d\n", g_value_get_uint (value));
52 g_print ("\tuser_data: %s\n", (const char *) user_data);
56 service_proxy_available_cb (GUPnPControlPoint *cp,
57 GUPnPServiceProxy *proxy)
64 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
66 g_print ("ContentDirectory available:\n");
67 g_print ("\tlocation: %s\n", location);
69 /* We want to be notified whenever SystemUpdateID (of type uint)
71 gupnp_service_proxy_add_notify (proxy,
78 g_signal_connect (proxy,
80 G_CALLBACK (subscription_lost_cb),
83 gupnp_service_proxy_set_subscribed (proxy, TRUE);
85 /* And test action IO */
86 gupnp_service_proxy_send_action (proxy,
95 "BrowseDirectChildren",
122 g_printerr ("Error: %s\n", error->message);
123 g_error_free (error);
128 g_print ("Browse returned:\n");
129 g_print ("\tResult: %s\n", result);
130 g_print ("\tNumberReturned: %u\n", count);
131 g_print ("\tTotalMatches: %u\n", total);
137 service_proxy_unavailable_cb (GUPnPControlPoint *cp,
138 GUPnPServiceProxy *proxy)
140 const char *location;
142 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
144 g_print ("ContentDirectory unavailable:\n");
145 g_print ("\tlocation: %s\n", location);
149 main (int argc, char **argv)
152 GUPnPContext *context;
153 GUPnPControlPoint *cp;
154 struct sigaction sig_action;
156 g_thread_init (NULL);
158 setlocale (LC_ALL, "");
161 context = gupnp_context_new (NULL, NULL, 0, &error);
163 g_printerr ("Error creating the GUPnP context: %s\n",
165 g_error_free (error);
170 /* We're interested in everything */
171 cp = gupnp_control_point_new
172 (context, "urn:schemas-upnp-org:service:ContentDirectory:1");
174 g_signal_connect (cp,
175 "service-proxy-available",
176 G_CALLBACK (service_proxy_available_cb),
178 g_signal_connect (cp,
179 "service-proxy-unavailable",
180 G_CALLBACK (service_proxy_unavailable_cb),
183 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
185 main_loop = g_main_loop_new (NULL, FALSE);
187 /* Hook the handler for SIGTERM */
188 memset (&sig_action, 0, sizeof (sig_action));
189 sig_action.sa_handler = interrupt_signal_handler;
190 sigaction (SIGINT, &sig_action, NULL);
192 g_main_loop_run (main_loop);
193 g_main_loop_unref (main_loop);
196 g_object_unref (context);