Imported Upstream version 0.14.4
[platform/upstream/gssdp.git] / tests / test-browser.c
1 /* 
2  * Copyright (C) 2006 OpenedHand Ltd.
3  *
4  * Author: Jorn Baayen <jorn@openedhand.com>
5  *
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.
10  *
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.
15  *
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.
20  */
21
22 #include <libgssdp/gssdp.h>
23 #include <gio/gio.h>
24 #include <stdlib.h>
25
26 static void
27 resource_available_cb (G_GNUC_UNUSED GSSDPResourceBrowser *resource_browser,
28                        const char                         *usn,
29                        GList                              *locations)
30 {
31         GList *l;
32
33         g_print ("resource available\n"
34                  "  USN:      %s\n",
35                  usn);
36         
37         for (l = locations; l; l = l->next)
38                 g_print ("  Location: %s\n", (char *) l->data);
39 }
40
41 static void
42 resource_unavailable_cb (G_GNUC_UNUSED GSSDPResourceBrowser *resource_browser,
43                          const char                         *usn)
44 {
45         g_print ("resource unavailable\n"
46                  "  USN:      %s\n",
47                  usn);
48 }
49
50 int
51 main (G_GNUC_UNUSED int    argc,
52       G_GNUC_UNUSED char **argv)
53 {
54         GSSDPClient *client;
55         GSSDPResourceBrowser *resource_browser;
56         GError *error;
57         GMainLoop *main_loop;
58
59 #if !GLIB_CHECK_VERSION (2, 35, 0)
60         g_type_init ();
61 #endif
62
63         error = NULL;
64         client = g_initable_new (GSSDP_TYPE_CLIENT,
65                                  NULL,
66                                  &error,
67                                  NULL);
68         if (error) {
69                 g_printerr ("Error creating the GSSDP client: %s\n",
70                             error->message);
71
72                 g_error_free (error);
73
74                 return EXIT_FAILURE;
75         }
76
77         resource_browser = gssdp_resource_browser_new (client,
78                                                        GSSDP_ALL_RESOURCES);
79
80         g_signal_connect (resource_browser,
81                           "resource-available",
82                           G_CALLBACK (resource_available_cb),
83                           NULL);
84         g_signal_connect (resource_browser,
85                           "resource-unavailable",
86                           G_CALLBACK (resource_unavailable_cb),
87                           NULL);
88
89         gssdp_resource_browser_set_active (resource_browser, TRUE);
90
91         main_loop = g_main_loop_new (NULL, FALSE);
92         g_main_loop_run (main_loop);
93         g_main_loop_unref (main_loop);
94
95         g_object_unref (resource_browser);
96         g_object_unref (client);
97
98         return EXIT_SUCCESS;
99 }