4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <avahi-client/client.h>
27 #include <avahi-common/dbus.h>
28 #include <avahi-common/llist.h>
29 #include <avahi-common/error.h>
34 #define DBUS_API_SUBJECT_TO_CHANGE
35 #include <dbus/dbus.h>
36 #include <dbus/dbus-glib-lowlevel.h>
43 AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiDomainBrowserType btype, AvahiDomainBrowserCallback callback, void *user_data)
45 AvahiDomainBrowser *tmp = NULL;
46 DBusMessage *message = NULL, *reply;
53 dbus_error_init (&error);
55 message = dbus_message_new_method_call (AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER,
56 AVAHI_DBUS_INTERFACE_SERVER, "DomainBrowserNew");
58 if (!dbus_message_append_args (message, DBUS_TYPE_INT32, &interface, DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INT32, &btype, DBUS_TYPE_INVALID))
61 reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
63 if (dbus_error_is_set (&error) || reply == NULL)
66 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
69 if (dbus_error_is_set (&error) || path == NULL)
72 tmp = malloc (sizeof (AvahiDomainBrowser));
74 tmp->callback = callback;
75 tmp->user_data = user_data;
76 tmp->path = strdup (path);
78 AVAHI_LLIST_PREPEND(AvahiDomainBrowser, domain_browsers, client->domain_browsers, tmp);
83 dbus_error_free (&error);
84 avahi_client_set_errno (client, AVAHI_ERR_DBUS_ERROR);
90 avahi_domain_browser_path (AvahiDomainBrowser *b)
96 avahi_entry_group_event (AvahiClient *client, AvahiBrowserEvent event, DBusMessage *message)
98 AvahiDomainBrowser *n, *db = NULL;
102 int interface, protocol;
104 dbus_error_init (&error);
106 path = dbus_message_get_path (message);
108 printf ("bailing out 1\n");
112 for (n = client->domain_browsers; n != NULL; n = n->domain_browsers_next)
114 printf ("cmp: %s, %s\n", n->path, path);
115 if (strcmp (n->path, path) == 0) {
121 printf ("bailing out 2\n");
125 dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &interface,
126 DBUS_TYPE_INT32, &protocol, DBUS_TYPE_STRING, &domain, DBUS_TYPE_INVALID);
128 printf ("bailing out 3\n");
129 if (dbus_error_is_set (&error))
132 db->callback (db, interface, protocol, event, domain, db->user_data);
134 return DBUS_HANDLER_RESULT_HANDLED;
137 dbus_error_free (&error);
138 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;