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>
31 interrupt_signal_handler (int signum)
33 g_main_loop_quit (main_loop);
37 device_proxy_available_cb (GUPnPControlPoint *cp,
38 GUPnPDeviceProxy *proxy)
40 const char *type, *location;
42 type = gupnp_device_info_get_device_type (GUPNP_DEVICE_INFO (proxy));
43 location = gupnp_device_info_get_location (GUPNP_DEVICE_INFO (proxy));
45 g_print ("Device available:\n");
46 g_print ("\ttype: %s\n", type);
47 g_print ("\tlocation: %s\n", location);
51 device_proxy_unavailable_cb (GUPnPControlPoint *cp,
52 GUPnPDeviceProxy *proxy)
54 const char *type, *location;
56 type = gupnp_device_info_get_device_type (GUPNP_DEVICE_INFO (proxy));
57 location = gupnp_device_info_get_location (GUPNP_DEVICE_INFO (proxy));
59 g_print ("Device unavailable:\n");
60 g_print ("\ttype: %s\n", type);
61 g_print ("\tlocation: %s\n", location);
65 service_proxy_available_cb (GUPnPControlPoint *cp,
66 GUPnPServiceProxy *proxy)
68 const char *type, *location;
70 type = gupnp_service_info_get_service_type (GUPNP_SERVICE_INFO (proxy));
71 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
73 g_print ("Service available:\n");
74 g_print ("\ttype: %s\n", type);
75 g_print ("\tlocation: %s\n", location);
79 service_proxy_unavailable_cb (GUPnPControlPoint *cp,
80 GUPnPServiceProxy *proxy)
82 const char *type, *location;
84 type = gupnp_service_info_get_service_type (GUPNP_SERVICE_INFO (proxy));
85 location = gupnp_service_info_get_location (GUPNP_SERVICE_INFO (proxy));
87 g_print ("Service unavailable:\n");
88 g_print ("\ttype: %s\n", type);
89 g_print ("\tlocation: %s\n", location);
93 main (int argc, char **argv)
96 GUPnPContext *context;
97 GUPnPControlPoint *cp;
98 struct sigaction sig_action;
101 setlocale (LC_ALL, "");
104 context = g_initable_new (GUPNP_TYPE_CONTEXT, NULL, &error, NULL);
106 g_printerr ("Error creating the GUPnP context: %s\n",
108 g_error_free (error);
113 /* We're interested in everything */
114 cp = gupnp_control_point_new (context, "ssdp:all");
116 g_signal_connect (cp,
117 "device-proxy-available",
118 G_CALLBACK (device_proxy_available_cb),
120 g_signal_connect (cp,
121 "device-proxy-unavailable",
122 G_CALLBACK (device_proxy_unavailable_cb),
124 g_signal_connect (cp,
125 "service-proxy-available",
126 G_CALLBACK (service_proxy_available_cb),
128 g_signal_connect (cp,
129 "service-proxy-unavailable",
130 G_CALLBACK (service_proxy_unavailable_cb),
133 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
135 main_loop = g_main_loop_new (NULL, FALSE);
137 /* Hook the handler for SIGTERM */
138 memset (&sig_action, 0, sizeof (sig_action));
139 sig_action.sa_handler = interrupt_signal_handler;
140 sigaction (SIGINT, &sig_action, NULL);
142 g_main_loop_run (main_loop);
143 g_main_loop_unref (main_loop);
146 g_object_unref (context);