summaryrefslogtreecommitdiffstats
path: root/avahi-client
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-14 22:11:35 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-14 22:11:35 +0000
commit769c00f228ba0d37217aaf1424dedde390e7a01c (patch)
treee641d94f918a133f59e0eeb8e07109247d4d7aab /avahi-client
parenta4acfaf4f942f702606e660990c873c9ff5b0395 (diff)
* add new priority parameter to avahi_glib_poll_new()
* beef up AvahiPoll a little to contain real timeout events * cleanups in avahi-client * drop glib dependency * port to AvahiPoll system * put some "const"s and "static"s in to make gcc shut up * change all uses of malloc/free to avahi_malloc/avahi_new/avahi_free git-svn-id: file:///home/lennart/svn/public/avahi/trunk@324 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-client')
-rw-r--r--avahi-client/Makefile.am9
-rw-r--r--avahi-client/browser.c34
-rw-r--r--avahi-client/client-test.c32
-rw-r--r--avahi-client/client.c27
-rw-r--r--avahi-client/client.h25
-rw-r--r--avahi-client/dbus-watch-glue.c234
-rw-r--r--avahi-client/dbus-watch-glue.h31
-rw-r--r--avahi-client/entrygroup.c23
-rw-r--r--avahi-client/internal.h1
9 files changed, 349 insertions, 67 deletions
diff --git a/avahi-client/Makefile.am b/avahi-client/Makefile.am
index 2c80e84..4b755fc 100644
--- a/avahi-client/Makefile.am
+++ b/avahi-client/Makefile.am
@@ -35,6 +35,7 @@ avahi_clientinclude_HEADERS = \
noinst_HEADERS = \
internal.h
+ dbus-watch-glue.h
noinst_PROGRAMS = \
client-test
@@ -45,11 +46,15 @@ lib_LTLIBRARIES = \
libavahi_client_la_SOURCES = \
client.c client.h \
entrygroup.c \
- browser.c
+ browser.c \
+ dbus-watch-glue.c
+
+libavahi_client_la_CFLAGS = $(AM_CFLAGS)
+libavahi_client_la_LIBADD = $(AM_LDADD)
client_test_SOURCES = \
client-test.c
client_test_CFLAGS = $(AM_CFLAGS)
-client_test_LDADD = $(AM_LDADD) libavahi-client.la ../avahi-common/libavahi-common.la
+client_test_LDADD = $(AM_LDADD) libavahi-client.la ../avahi-common/libavahi-common.la ../avahi-glib/libavahi-glib.la
endif
diff --git a/avahi-client/browser.c b/avahi-client/browser.c
index a20b5d2..e994d2a 100644
--- a/avahi-client/browser.c
+++ b/avahi-client/browser.c
@@ -23,10 +23,6 @@
#include <config.h>
#endif
-#include <avahi-client/client.h>
-#include <avahi-common/dbus.h>
-#include <avahi-common/llist.h>
-#include <avahi-common/error.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -34,14 +30,18 @@
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <stdlib.h>
+#include <avahi-client/client.h>
+#include <avahi-common/dbus.h>
+#include <avahi-common/llist.h>
+#include <avahi-common/error.h>
+#include <avahi-common/malloc.h>
#include "client.h"
#include "internal.h"
/* AvahiDomainBrowser */
-AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiDomainBrowserType btype, AvahiDomainBrowserCallback callback, void *user_data)
+AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiDomainBrowserType btype, AvahiDomainBrowserCallback callback, void *user_data)
{
AvahiDomainBrowser *tmp = NULL;
DBusMessage *message = NULL, *reply;
@@ -70,7 +70,7 @@ AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client, AvahiIfIndex
if (dbus_error_is_set (&error) || path == NULL)
goto dbus_error;
- tmp = malloc (sizeof (AvahiDomainBrowser));
+ tmp = avahi_new (AvahiDomainBrowser, 1);
tmp->client = client;
tmp->callback = callback;
tmp->user_data = user_data;
@@ -107,12 +107,12 @@ avahi_domain_browser_free (AvahiDomainBrowser *b)
AVAHI_LLIST_REMOVE(AvahiDomainBrowser, domain_browsers, client->domain_browsers, b);
- free (b);
+ avahi_free (b);
return avahi_client_set_errno (client, AVAHI_OK);
}
-char*
+const char*
avahi_domain_browser_path (AvahiDomainBrowser *b)
{
return b->path;
@@ -161,7 +161,7 @@ out:
}
/* AvahiServiceTypeBrowser */
-AvahiServiceTypeBrowser* avahi_service_type_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *domain, AvahiServiceTypeBrowserCallback callback, void *user_data)
+AvahiServiceTypeBrowser* avahi_service_type_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiServiceTypeBrowserCallback callback, void *user_data)
{
AvahiServiceTypeBrowser *tmp = NULL;
DBusMessage *message = NULL, *reply;
@@ -192,7 +192,7 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new (AvahiClient *client, Av
if (dbus_error_is_set (&error) || path == NULL)
goto dbus_error;
- tmp = malloc (sizeof (AvahiServiceTypeBrowser));
+ tmp = avahi_new(AvahiServiceTypeBrowser, 1);
tmp->client = client;
tmp->callback = callback;
tmp->user_data = user_data;
@@ -229,12 +229,12 @@ avahi_service_type_browser_free (AvahiServiceTypeBrowser *b)
AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, service_type_browsers, b->client->service_type_browsers, b);
- free (b);
+ avahi_free (b);
return avahi_client_set_errno (client, AVAHI_OK);
}
-char*
+const char*
avahi_service_type_browser_path (AvahiServiceTypeBrowser *b)
{
return b->path;
@@ -288,7 +288,7 @@ out:
/* AvahiServiceBrowser */
-AvahiServiceBrowser* avahi_service_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, char *type, char *domain, AvahiServiceBrowserCallback callback, void *user_data)
+AvahiServiceBrowser* avahi_service_browser_new (AvahiClient *client, AvahiIfIndex interface, AvahiProtocol protocol, const char *type, const char *domain, AvahiServiceBrowserCallback callback, void *user_data)
{
AvahiServiceBrowser *tmp = NULL;
DBusMessage *message = NULL, *reply;
@@ -322,7 +322,7 @@ AvahiServiceBrowser* avahi_service_browser_new (AvahiClient *client, AvahiIfInde
if (dbus_error_is_set (&error) || path == NULL)
goto dbus_error;
- tmp = malloc (sizeof (AvahiServiceBrowser));
+ tmp = avahi_new(AvahiServiceBrowser, 1);
tmp->client = client;
tmp->callback = callback;
tmp->user_data = user_data;
@@ -359,12 +359,12 @@ avahi_service_browser_free (AvahiServiceBrowser *b)
AVAHI_LLIST_REMOVE(AvahiServiceBrowser, service_browsers, b->client->service_browsers, b);
- free (b);
+ avahi_free (b);
return avahi_client_set_errno (client, AVAHI_OK);
}
-char*
+const char*
avahi_service_browser_path (AvahiServiceBrowser *b)
{
return b->path;
diff --git a/avahi-client/client-test.c b/avahi-client/client-test.c
index 352ee58..2189467 100644
--- a/avahi-client/client-test.c
+++ b/avahi-client/client-test.c
@@ -25,53 +25,55 @@
#include <avahi-client/client.h>
#include <avahi-common/error.h>
+#include <avahi-glib/glib-watch.h>
+#include <avahi-glib/glib-malloc.h>
#include <stdio.h>
#include <glib.h>
-void
+static void
avahi_client_callback (AvahiClient *c, AvahiClientState state, void *user_data)
{
printf ("XXX: Callback on client, state -> %d, data -> %s\n", state, (char*)user_data);
}
-void
+static void
avahi_entry_group_callback (AvahiEntryGroup *g, AvahiEntryGroupState state, void *user_data)
{
printf ("XXX: Callback on %s, state -> %d, data -> %s\n", avahi_entry_group_path (g), state, (char*)user_data);
}
-void
-avahi_domain_browser_callback (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *domain, void *user_data)
+static void
+avahi_domain_browser_callback (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, void *user_data)
{
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), domain (%s), data (%s)\n", avahi_domain_browser_path (b), interface, protocol, event, domain, (char*)user_data);
}
-void
-avahi_service_browser_callback (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *name, char *type, char *domain, void *user_data)
+static void
+avahi_service_browser_callback (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, void *user_data)
{
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), name (%s), type (%s), domain (%s), data (%s)\n", avahi_service_browser_path (b), interface, protocol, event, name, type, domain, (char*)user_data);
}
-void
-avahi_service_type_browser_callback (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *type, char *domain, void *user_data)
+static void
+avahi_service_type_browser_callback (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, void *user_data)
{
printf ("XXX: Callback on %s, interface (%d), protocol (%d), event (%d), type (%s), domain (%s), data (%s)\n", avahi_service_type_browser_path (b), interface, protocol, event, type, domain, (char*)user_data);
}
-gboolean
+static gboolean
test_free_domain_browser (gpointer data)
{
- printf ("XXX: freeing domain browser\n");
AvahiServiceBrowser *b = data;
+ printf ("XXX: freeing domain browser\n");
avahi_service_browser_free (b);
return FALSE;
}
-gboolean
+static gboolean
test_free_entry_group (gpointer data)
{
- printf ("XXX: freeing entry group\n");
AvahiEntryGroup *g = data;
+ printf ("XXX: freeing entry group\n");
avahi_entry_group_free (g);
return FALSE;
}
@@ -85,11 +87,15 @@ main (int argc, char *argv[])
AvahiDomainBrowser *domain;
AvahiServiceBrowser *sb;
AvahiServiceTypeBrowser *st;
+ AvahiGLibPoll *glib_poll;
char *ret;
+ avahi_set_allocator(avahi_glib_allocator());
+
+ glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT);
loop = g_main_loop_new (NULL, FALSE);
- avahi = avahi_client_new (avahi_client_callback, "omghai2u");
+ avahi = avahi_client_new (avahi_glib_poll_get(glib_poll), avahi_client_callback, "omghai2u");
g_assert (avahi != NULL);
diff --git a/avahi-client/client.c b/avahi-client/client.c
index ad64946..7edc469 100644
--- a/avahi-client/client.c
+++ b/avahi-client/client.c
@@ -27,15 +27,16 @@
#include <avahi-common/dbus.h>
#include <avahi-common/llist.h>
#include <avahi-common/error.h>
+#include <avahi-common/malloc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <stdlib.h>
+#include "dbus-watch-glue.h"
#include "client.h"
#include "internal.h"
@@ -58,7 +59,7 @@ void avahi_client_state_change (AvahiClient *client, int state)
client->callback (client, state, client->user_data);
}
-void
+static void
avahi_client_state_request_callback (DBusPendingCall *call, void *data)
{
AvahiClient *client = data;
@@ -87,7 +88,7 @@ avahi_client_state_request_callback (DBusPendingCall *call, void *data)
dbus_pending_call_unref (call);
}
-void
+static void
avahi_client_schedule_state_request (AvahiClient *client)
{
DBusMessage *message;
@@ -116,7 +117,7 @@ filter_func (DBusConnection *bus, DBusMessage *message, void *data)
dbus_error_init (&error);
if (dbus_message_is_signal(message, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
- gchar *name, *old, *new;
+ char *name, *old, *new;
dbus_message_get_args(message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new, DBUS_TYPE_INVALID);
if (dbus_error_is_set (&error)) {
@@ -181,14 +182,14 @@ out:
}
AvahiClient *
-avahi_client_new (AvahiClientCallback callback, void *user_data)
+avahi_client_new (const AvahiPoll *poll_api, AvahiClientCallback callback, void *user_data)
{
AvahiClient *tmp = NULL;
DBusError error;
dbus_error_init (&error);
- if (!(tmp = malloc(sizeof(AvahiClient))))
+ if (!(tmp = avahi_new(AvahiClient, 1)))
goto fail;
AVAHI_LLIST_HEAD_INIT(AvahiEntryGroup, tmp->groups);
@@ -196,14 +197,18 @@ avahi_client_new (AvahiClientCallback callback, void *user_data)
AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, tmp->service_browsers);
AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, tmp->service_type_browsers);
+ tmp->poll_api = poll_api;
tmp->bus = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
if (dbus_error_is_set (&error)) {
goto fail;
}
- dbus_connection_setup_with_g_main (tmp->bus, NULL);
- dbus_connection_set_exit_on_disconnect (tmp->bus, FALSE);
+/* dbus_connection_setup_with_g_main (tmp->bus, NULL); */
+/* dbus_connection_set_exit_on_disconnect (tmp->bus, FALSE); */
+
+ if (avahi_dbus_connection_glue(tmp->bus, poll_api) < 0)
+ goto fail;
if (!dbus_connection_add_filter (tmp->bus, filter_func, tmp, NULL))
{
@@ -243,7 +248,7 @@ avahi_client_new (AvahiClientCallback callback, void *user_data)
return tmp;
fail:
- free (tmp);
+ avahi_free (tmp);
if (dbus_error_is_set(&error))
dbus_error_free(&error);
@@ -252,7 +257,7 @@ fail:
}
static char*
-avahi_client_get_string_reply_and_block (AvahiClient *client, char *method, char *param)
+avahi_client_get_string_reply_and_block (AvahiClient *client, const char *method, const char *param)
{
DBusMessage *message;
DBusMessage *reply;
@@ -303,7 +308,7 @@ avahi_client_get_string_reply_and_block (AvahiClient *client, char *method, char
return NULL;
}
- new = strdup (ret);
+ new = avahi_strdup (ret);
avahi_client_set_errno (client, AVAHI_OK);
return new;
diff --git a/avahi-client/client.h b/avahi-client/client.h
index 16e9998..de6f207 100644
--- a/avahi-client/client.h
+++ b/avahi-client/client.h
@@ -28,6 +28,7 @@
#include <avahi-common/address.h>
#include <avahi-common/strlst.h>
#include <avahi-common/defs.h>
+#include <avahi-common/watch.h>
/** \file client.h Definitions and functions for the client API over D-Bus */
@@ -58,16 +59,16 @@ typedef void (*AvahiClientCallback) (AvahiClient *s, AvahiClientState state, voi
typedef void (*AvahiEntryGroupCallback) (AvahiEntryGroup *g, AvahiEntryGroupState state, void* userdata);
/** The function prototype for the callback of an AvahiDomainBrowser */
-typedef void (*AvahiDomainBrowserCallback) (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *domain, void *user_data);
+typedef void (*AvahiDomainBrowserCallback) (AvahiDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, void *user_data);
/** The function prototype for the callback of an AvahiServiceBrowser */
-typedef void (*AvahiServiceBrowserCallback) (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *name, char *type, char *domain, void *user_data);
+typedef void (*AvahiServiceBrowserCallback) (AvahiServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, void *user_data);
/** The function prototype for the callback of an AvahiServiceTypeBrowser */
-typedef void (*AvahiServiceTypeBrowserCallback) (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, char *type, char *domain, void *user_data);
+typedef void (*AvahiServiceTypeBrowserCallback) (AvahiServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, void *user_data);
/** Creates a new client instance */
-AvahiClient* avahi_client_new (AvahiClientCallback callback, void *user_data);
+AvahiClient* avahi_client_new (const AvahiPoll *poll_api, AvahiClientCallback callback, void *user_data);
/** Get the version of the server */
char* avahi_client_get_version_string (AvahiClient*);
@@ -118,19 +119,19 @@ avahi_entry_group_add_service (AvahiEntryGroup *group,
AvahiStringList *txt);
/** Get the D-Bus path of an AvahiEntryGroup object, for debugging purposes only. */
-char* avahi_entry_group_path (AvahiEntryGroup *);
+const char* avahi_entry_group_path (AvahiEntryGroup *);
/** Browse for domains on the local network */
AvahiDomainBrowser* avahi_domain_browser_new (AvahiClient *client,
AvahiIfIndex interface,
AvahiProtocol protocol,
- char *domain,
+ const char *domain,
AvahiDomainBrowserType btype,
AvahiDomainBrowserCallback callback,
void *user_data);
/** Get the D-Bus path of an AvahiDomainBrowser object, for debugging purposes only. */
-char* avahi_domain_browser_path (AvahiDomainBrowser *);
+const char* avahi_domain_browser_path (AvahiDomainBrowser *);
/** Cleans up and frees an AvahiDomainBrowser object */
int avahi_domain_browser_free (AvahiDomainBrowser *);
@@ -140,12 +141,12 @@ AvahiServiceTypeBrowser* avahi_service_type_browser_new (
AvahiClient *client,
AvahiIfIndex interface,
AvahiProtocol protocol,
- char *domain,
+ const char *domain,
AvahiServiceTypeBrowserCallback callback,
void *user_data);
/** Get the D-Bus path of an AvahiServiceTypeBrowser object, for debugging purposes only. */
-char* avahi_service_type_browser_path (AvahiServiceTypeBrowser *);
+const char* avahi_service_type_browser_path (AvahiServiceTypeBrowser *);
/** Cleans up and frees an AvahiServiceTypeBrowser object */
int avahi_service_type_browser_free (AvahiServiceTypeBrowser *);
@@ -155,13 +156,13 @@ AvahiServiceBrowser* avahi_service_browser_new (
AvahiClient *client,
AvahiIfIndex interface,
AvahiProtocol protocol,
- char *type,
- char *domain,
+ const char *type,
+ const char *domain,
AvahiServiceBrowserCallback callback,
void *user_data);
/** Get the D-Bus path of an AvahiServiceBrowser object, for debugging purposes only. */
-char* avahi_service_browser_path (AvahiServiceBrowser *);
+const char* avahi_service_browser_path (AvahiServiceBrowser *);
/* Cleans up and frees an AvahiServiceBrowser object */
int avahi_service_browser_free (AvahiServiceBrowser *);
diff --git a/avahi-client/dbus-watch-glue.c b/avahi-client/dbus-watch-glue.c
new file mode 100644
index 0000000..025aeac
--- /dev/null
+++ b/avahi-client/dbus-watch-glue.c
@@ -0,0 +1,234 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <assert.h>
+
+#include <avahi-common/malloc.h>
+
+#include "dbus-watch-glue.h"
+
+static AvahiWatchEvent translate_dbus_to_avahi(unsigned int f) {
+ AvahiWatchEvent e = 0;
+
+ if (f & DBUS_WATCH_READABLE)
+ e |= AVAHI_WATCH_IN;
+ if (f & DBUS_WATCH_WRITABLE)
+ e |= AVAHI_WATCH_OUT;
+ if (f & DBUS_WATCH_ERROR)
+ e |= AVAHI_WATCH_ERR;
+ if (f & DBUS_WATCH_HANGUP)
+ e |= AVAHI_WATCH_HUP;
+
+ return e;
+}
+
+static unsigned int translate_avahi_to_dbus(AvahiWatchEvent e) {
+ unsigned int f = 0;
+
+ if (e & AVAHI_WATCH_IN)
+ f |= DBUS_WATCH_READABLE;
+ if (e & AVAHI_WATCH_OUT)
+ f |= DBUS_WATCH_WRITABLE;
+ if (e & AVAHI_WATCH_ERR)
+ f |= DBUS_WATCH_ERROR;
+ if (e & AVAHI_WATCH_HUP)
+ f |= DBUS_WATCH_HANGUP;
+
+ return f;
+}
+
+static void watch_callback(AvahiWatch *avahi_watch, int fd, AvahiWatchEvent events, void *userdata) {
+ DBusWatch *dbus_watch = userdata;
+ assert(avahi_watch);
+ assert(dbus_watch);
+
+ dbus_watch_handle(dbus_watch, translate_avahi_to_dbus(events));
+ /* Ignore the return value */
+}
+
+static dbus_bool_t update_watch(const AvahiPoll *poll_api, DBusWatch *dbus_watch) {
+ AvahiWatch *avahi_watch;
+ dbus_bool_t b;
+
+ assert(dbus_watch);
+
+ avahi_watch = dbus_watch_get_data(dbus_watch);
+
+ b = dbus_watch_get_enabled(dbus_watch);
+
+ if (b && !avahi_watch) {
+
+ if (!(avahi_watch = poll_api->watch_new(
+ poll_api,
+ dbus_watch_get_fd(dbus_watch),
+ translate_dbus_to_avahi(dbus_watch_get_flags(dbus_watch)),
+ watch_callback,
+ dbus_watch)))
+ return FALSE;
+
+ dbus_watch_set_data(dbus_watch, avahi_watch, (DBusFreeFunction) poll_api->watch_free);
+
+ } else if (!b && avahi_watch) {
+
+ poll_api->watch_free(avahi_watch);
+ dbus_watch_set_data(dbus_watch, NULL, NULL);
+
+ } else if (avahi_watch) {
+
+ /* Update flags */
+ poll_api->watch_update(avahi_watch, dbus_watch_get_flags(dbus_watch));
+ }
+
+ return TRUE;
+}
+
+static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ return update_watch(poll_api, dbus_watch);
+}
+
+static void remove_watch(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+ AvahiWatch *avahi_watch;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ avahi_watch = dbus_watch_get_data(dbus_watch);
+ poll_api->watch_free(avahi_watch);
+ dbus_watch_set_data(dbus_watch, NULL, NULL);
+}
+
+static void watch_toggled(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ update_watch(poll_api, dbus_watch);
+}
+
+typedef struct TimeoutData {
+ const AvahiPoll *poll_api;
+ AvahiTimeout *avahi_timeout;
+ DBusTimeout *dbus_timeout;
+} TimeoutData;
+
+static void update_timeout(TimeoutData *timeout) {
+ assert(timeout);
+
+ if (dbus_timeout_get_enabled(timeout->dbus_timeout)) {
+ struct timeval tv;
+ avahi_elapse_time(&tv, dbus_timeout_get_interval(timeout->dbus_timeout), 0);
+ timeout->poll_api->timeout_update(timeout->
+ avahi_timeout, &tv);
+ } else
+ timeout->poll_api->timeout_update(timeout->avahi_timeout, NULL);
+
+}
+
+static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) {
+ TimeoutData *timeout = userdata;
+
+ assert(avahi_timeout);
+ assert(timeout);
+
+ dbus_timeout_handle(timeout->dbus_timeout);
+ /* Ignore the return value */
+
+ update_timeout(timeout);
+}
+
+static dbus_bool_t add_timeout(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+ struct timeval tv;
+ dbus_bool_t b;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ if (!(timeout = avahi_new(TimeoutData, 1)))
+ return FALSE;
+
+ timeout->dbus_timeout = dbus_timeout;
+ timeout->poll_api = poll_api;
+
+ if ((b = dbus_timeout_get_enabled(dbus_timeout)))
+ avahi_elapse_time(&tv, dbus_timeout_get_interval(dbus_timeout), 0);
+
+ if (!(timeout->avahi_timeout = poll_api->timeout_new(
+ poll_api,
+ b ? &tv : NULL,
+ timeout_callback,
+ dbus_timeout))) {
+ avahi_free(timeout);
+ return FALSE;
+ }
+
+ dbus_timeout_set_data(dbus_timeout, timeout, NULL);
+ return TRUE;
+}
+
+static void remove_timeout(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ timeout = dbus_timeout_get_data(dbus_timeout);
+ assert(timeout);
+
+ poll_api->timeout_free(timeout->avahi_timeout);
+ avahi_free(timeout);
+ dbus_timeout_set_data(dbus_timeout, NULL, NULL);
+}
+
+static void timeout_toggled(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ timeout = dbus_timeout_get_data(dbus_timeout);
+ assert(timeout);
+
+ update_timeout(timeout);
+}
+
+int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) {
+ assert(c);
+ assert(poll_api);
+
+ if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, (void*) poll_api, NULL)))
+ return -1;
+
+ if (!(dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, timeout_toggled, (void*) poll_api, NULL)))
+ return -1;
+
+ return 0;
+}
diff --git a/avahi-client/dbus-watch-glue.h b/avahi-client/dbus-watch-glue.h
new file mode 100644
index 0000000..e815b45
--- /dev/null
+++ b/avahi-client/dbus-watch-glue.h
@@ -0,0 +1,31 @@
+#ifndef foodbuswatchgluehfoo
+#define foodbuswatchgluehfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <dbus/dbus.h>
+
+#include <avahi-common/watch.h>
+
+int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api);
+
+#endif
diff --git a/avahi-client/entrygroup.c b/avahi-client/entrygroup.c
index 93c3fd6..6335755 100644
--- a/avahi-client/entrygroup.c
+++ b/avahi-client/entrygroup.c
@@ -23,18 +23,17 @@
#include <config.h>
#endif
-#include <avahi-client/client.h>
-#include <avahi-common/dbus.h>
-#include <avahi-common/llist.h>
-#include <avahi-common/error.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <stdlib.h>
+#include <avahi-client/client.h>
+#include <avahi-common/dbus.h>
+#include <avahi-common/llist.h>
+#include <avahi-common/error.h>
+#include <avahi-common/malloc.h>
#include "client.h"
#include "internal.h"
@@ -88,11 +87,11 @@ avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCallback callback, vo
goto fail;
}
- tmp = malloc (sizeof (AvahiEntryGroup));
+ tmp = avahi_new(AvahiEntryGroup, 1);
tmp->client = client;
- tmp->path = strdup (path);
+ tmp->path = avahi_strdup (path);
tmp->callback = callback;
tmp->user_data = user_data;
@@ -104,7 +103,7 @@ avahi_entry_group_new (AvahiClient *client, AvahiEntryGroupCallback callback, vo
return tmp;
fail:
- if (tmp) free (tmp);
+ if (tmp) avahi_free (tmp);
if (message) dbus_message_unref (message);
return NULL;
}
@@ -128,7 +127,7 @@ avahi_entry_group_free (AvahiEntryGroup *group)
AVAHI_LLIST_REMOVE(AvahiEntryGroup, groups, client->groups, group);
- free (group);
+ avahi_free (group);
return avahi_client_set_errno (client, AVAHI_OK);
}
@@ -252,7 +251,7 @@ avahi_entry_group_add_service (AvahiEntryGroup *group,
/* Assemble the AvahiStringList into an Array of Array of Bytes to send over dbus */
for (p = txt; p != NULL; p = p->next) {
DBusMessageIter sub2;
- const guint8 *data = p->text;
+ const uint8_t *data = p->text;
dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2);
dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
@@ -267,7 +266,7 @@ avahi_entry_group_add_service (AvahiEntryGroup *group,
}
/* XXX: debug function */
-char* avahi_entry_group_path (AvahiEntryGroup *group)
+const char* avahi_entry_group_path (AvahiEntryGroup *group)
{
if (group != NULL) return group->path;
else return NULL;
diff --git a/avahi-client/internal.h b/avahi-client/internal.h
index d37958e..6058e20 100644
--- a/avahi-client/internal.h
+++ b/avahi-client/internal.h
@@ -27,6 +27,7 @@
struct _AvahiClient
{
+ const AvahiPoll *poll_api;
DBusConnection *bus;
int error;
AvahiClientCallback callback;