X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-common%2Fdbus-watch-glue.c;h=b18f555c191c5fbb31f1c62598f17644eb615199;hb=e9f7d4faa2566d22ad1589438cdce51244a2ce4f;hp=b2b4bb2e8662f6dd0c272cd0e19738dcde58a01b;hpb=854f901f491ccda79aee11edc3d59109cb229d28;p=catta diff --git a/avahi-common/dbus-watch-glue.c b/avahi-common/dbus-watch-glue.c index b2b4bb2..b18f555 100644 --- a/avahi-common/dbus-watch-glue.c +++ b/avahi-common/dbus-watch-glue.c @@ -1,24 +1,26 @@ -/* $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. ***/ +#ifdef HAVE_CONFIG_H +#include +#endif + #include #include @@ -81,13 +83,15 @@ static void connection_data_unref(ConnectionData *d) { } } -static void request_dispatch(ConnectionData *d) { +static void request_dispatch(ConnectionData *d, int enable) { static const struct timeval tv = { 0, 0 }; assert(d); - assert(dbus_connection_get_dispatch_status(d->connection) == DBUS_DISPATCH_DATA_REMAINS); - - d->poll_api->timeout_update(d->dispatch_timeout, &tv); + if (enable) { + assert(dbus_connection_get_dispatch_status(d->connection) == DBUS_DISPATCH_DATA_REMAINS); + d->poll_api->timeout_update(d->dispatch_timeout, &tv); + } else + d->poll_api->timeout_update(d->dispatch_timeout, NULL); } static void dispatch_timeout_callback(AvahiTimeout *t, void *userdata) { @@ -100,7 +104,9 @@ static void dispatch_timeout_callback(AvahiTimeout *t, void *userdata) { if (dbus_connection_dispatch(d->connection) == DBUS_DISPATCH_DATA_REMAINS) /* If there's still data, request that this handler is called again */ - request_dispatch(d); + request_dispatch(d, 1); + else + request_dispatch(d, 0); dbus_connection_unref(d->connection); connection_data_unref(d); @@ -108,7 +114,7 @@ static void dispatch_timeout_callback(AvahiTimeout *t, void *userdata) { static void watch_callback(AvahiWatch *avahi_watch, AVAHI_GCC_UNUSED int fd, AvahiWatchEvent events, void *userdata) { DBusWatch *dbus_watch = userdata; - + assert(avahi_watch); assert(dbus_watch); @@ -119,32 +125,36 @@ static void watch_callback(AvahiWatch *avahi_watch, AVAHI_GCC_UNUSED int fd, Ava 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, +#if (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR == 1 && DBUS_VERSION_MICRO >= 1) || (DBUS_VERSION_MAJOR == 1 && DBUS_VERSION_MINOR > 1) || (DBUS_VERSION_MAJOR > 1) + dbus_watch_get_unix_fd(dbus_watch), +#else dbus_watch_get_fd(dbus_watch), +#endif translate_dbus_to_avahi(dbus_watch_get_flags(dbus_watch)), watch_callback, dbus_watch))) return FALSE; dbus_watch_set_data(dbus_watch, avahi_watch, NULL); - + } 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)); } @@ -154,7 +164,7 @@ static dbus_bool_t update_watch(const AvahiPoll *poll_api, DBusWatch *dbus_watch static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) { ConnectionData *d = userdata; - + assert(dbus_watch); assert(d); @@ -164,7 +174,7 @@ static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) { static void remove_watch(DBusWatch *dbus_watch, void *userdata) { ConnectionData *d = userdata; AvahiWatch *avahi_watch; - + assert(dbus_watch); assert(d); @@ -176,7 +186,7 @@ static void remove_watch(DBusWatch *dbus_watch, void *userdata) { static void watch_toggled(DBusWatch *dbus_watch, void *userdata) { ConnectionData *d = userdata; - + assert(dbus_watch); assert(d); @@ -205,7 +215,7 @@ static void timeout_data_unref(TimeoutData *t) { if (--t->ref <= 0) { if (t->avahi_timeout) t->poll_api->timeout_free(t->avahi_timeout); - + avahi_free(t); } } @@ -213,7 +223,7 @@ static void timeout_data_unref(TimeoutData *t) { static void update_timeout(TimeoutData *timeout) { assert(timeout); assert(timeout->ref >= 1); - + if (dbus_timeout_get_enabled(timeout->dbus_timeout)) { struct timeval tv; avahi_elapse_time(&tv, dbus_timeout_get_interval(timeout->dbus_timeout), 0); @@ -226,7 +236,7 @@ static void update_timeout(TimeoutData *timeout) { static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) { TimeoutData *timeout = userdata; - + assert(avahi_timeout); assert(timeout); @@ -237,7 +247,7 @@ static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) { if (timeout->avahi_timeout) update_timeout(timeout); - + timeout_data_unref(timeout); } @@ -259,7 +269,7 @@ static dbus_bool_t add_timeout(DBusTimeout *dbus_timeout, void *userdata) { if ((b = dbus_timeout_get_enabled(dbus_timeout))) avahi_elapse_time(&tv, dbus_timeout_get_interval(dbus_timeout), 0); - + if (!(timeout->avahi_timeout = d->poll_api->timeout_new( d->poll_api, b ? &tv : NULL, @@ -299,14 +309,14 @@ static void timeout_toggled(DBusTimeout *dbus_timeout, AVAHI_GCC_UNUSED void *us static void dispatch_status(AVAHI_GCC_UNUSED DBusConnection *connection, DBusDispatchStatus new_status, void *userdata) { ConnectionData *d = userdata; - + if (new_status == DBUS_DISPATCH_DATA_REMAINS) - request_dispatch(d); + request_dispatch(d, 1); } int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) { ConnectionData *d = NULL; - + assert(c); assert(poll_api); @@ -316,10 +326,10 @@ int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) { d->poll_api = poll_api; d->connection = c; d->ref = 1; - + if (!(d->dispatch_timeout = poll_api->timeout_new(poll_api, NULL, dispatch_timeout_callback, d))) goto fail; - + if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, connection_data_ref(d), (DBusFreeFunction)connection_data_unref))) goto fail; @@ -329,10 +339,10 @@ int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) { dbus_connection_set_dispatch_status_function(c, dispatch_status, connection_data_ref(d), (DBusFreeFunction)connection_data_unref); if (dbus_connection_get_dispatch_status(c) == DBUS_DISPATCH_DATA_REMAINS) - request_dispatch(d); + request_dispatch(d, 1); connection_data_unref(d); - + return 0; fail: