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-root-device.h>
23 #include <libgupnp/gupnp-service.h>
32 interrupt_signal_handler (int signum)
34 g_main_loop_quit (main_loop);
38 notify_failed_cb (GUPnPService *service,
39 const GList *callback_urls,
43 g_print ("NOTIFY failed: %s\n", reason->message);
47 timeout (gpointer user_data)
49 gupnp_service_notify (GUPNP_SERVICE (user_data),
59 main (int argc, char **argv)
62 GUPnPContext *context;
64 GUPnPServiceInfo *content_dir;
65 struct sigaction sig_action;
68 g_printerr ("Usage: %s DESCRIPTION_FILE\n", argv[0]);
75 setlocale (LC_ALL, "");
78 context = gupnp_context_new (NULL, NULL, 0, &error);
80 g_printerr ("Error creating the GUPnP context: %s\n",
87 g_print ("Running on port %d\n", gupnp_context_get_port (context));
89 /* Create root device */
90 dev = gupnp_root_device_new (context, "description.xml", ".");
92 /* Implement Browse action on ContentDirectory if available */
93 content_dir = gupnp_device_info_get_service
94 (GUPNP_DEVICE_INFO (dev),
95 "urn:schemas-upnp-org:service:ContentDirectory:1");
98 gupnp_service_signals_autoconnect (GUPNP_SERVICE (content_dir),
102 g_warning ("Failed to autoconnect signals: %s",
105 g_error_free (error);
109 g_signal_connect (content_dir,
111 G_CALLBACK (notify_failed_cb),
114 g_timeout_add (5000, timeout, content_dir);
118 gupnp_root_device_set_available (dev, TRUE);
120 main_loop = g_main_loop_new (NULL, FALSE);
122 /* Hook the handler for SIGTERM */
123 memset (&sig_action, 0, sizeof (sig_action));
124 sig_action.sa_handler = interrupt_signal_handler;
125 sigaction (SIGINT, &sig_action, NULL);
127 g_main_loop_run (main_loop);
128 g_main_loop_unref (main_loop);
131 g_object_unref (content_dir);
133 g_object_unref (dev);
134 g_object_unref (context);