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 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;
100 g_thread_init (NULL);
102 setlocale (LC_ALL, "");
105 context = gupnp_context_new (NULL, NULL, 0, &error);
107 g_printerr ("Error creating the GUPnP context: %s\n",
109 g_error_free (error);
114 /* We're interested in everything */
115 cp = gupnp_control_point_new (context, "ssdp:all");
117 g_signal_connect (cp,
118 "device-proxy-available",
119 G_CALLBACK (device_proxy_available_cb),
121 g_signal_connect (cp,
122 "device-proxy-unavailable",
123 G_CALLBACK (device_proxy_unavailable_cb),
125 g_signal_connect (cp,
126 "service-proxy-available",
127 G_CALLBACK (service_proxy_available_cb),
129 g_signal_connect (cp,
130 "service-proxy-unavailable",
131 G_CALLBACK (service_proxy_unavailable_cb),
134 gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (cp), TRUE);
136 main_loop = g_main_loop_new (NULL, FALSE);
138 /* Hook the handler for SIGTERM */
139 memset (&sig_action, 0, sizeof (sig_action));
140 sig_action.sa_handler = interrupt_signal_handler;
141 sigaction (SIGINT, &sig_action, NULL);
143 g_main_loop_run (main_loop);
144 g_main_loop_unref (main_loop);
147 g_object_unref (context);