]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/avahi-wrap.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / avahi-wrap.c
index 9da765589c0fec69918e9ed9ed26a19794a63d81..997d81ff5f31faa8999a2b5f84ca833d2ed609b8 100644 (file)
@@ -1,29 +1,32 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
+
+  Copyright 2006 Lennart Poettering
+
   PulseAudio 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 of the
+  published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.
+
   PulseAudio 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
   General Public License for more details.
+
   You should have received a copy of the GNU Lesser General Public
   License along with PulseAudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 
-#include <assert.h>
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include <pulse/timeval.h>
 #include <pulse/xmalloc.h>
 
-#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
 
 #include "avahi-wrap.h"
 
@@ -58,10 +61,10 @@ static pa_io_event_flags_t translate_io_flags(AvahiWatchEvent e) {
 
 static void watch_callback(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) {
     AvahiWatch *w = userdata;
-    
-    assert(a);
-    assert(e);
-    assert(w);
+
+    pa_assert(a);
+    pa_assert(e);
+    pa_assert(w);
 
     w->current_event = translate_io_flags_back(events);
     w->callback(w, fd, w->current_event, w->userdata);
@@ -72,12 +75,10 @@ static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event
     pa_avahi_poll *p;
     AvahiWatch *w;
 
-    assert(api);
-    assert(fd >= 0);
-    assert(callback);
-    
-    p = api->userdata;
-    assert(p);
+    pa_assert(api);
+    pa_assert(fd >= 0);
+    pa_assert(callback);
+    pa_assert_se(p = api->userdata);
 
     w = pa_xnew(AvahiWatch, 1);
     w->avahi_poll = p;
@@ -88,21 +89,21 @@ static AvahiWatch* watch_new(const AvahiPoll *api, int fd, AvahiWatchEvent event
 
     return w;
 }
+
 static void watch_update(AvahiWatch *w, AvahiWatchEvent event) {
-    assert(w);
+    pa_assert(w);
 
     w->avahi_poll->mainloop->io_enable(w->io_event, translate_io_flags(event));
 }
+
 static AvahiWatchEvent watch_get_events(AvahiWatch *w) {
-    assert(w);
+    pa_assert(w);
 
     return w->current_event;
 }
+
 static void watch_free(AvahiWatch *w) {
-    assert(w);
+    pa_assert(w);
 
     w->avahi_poll->mainloop->io_free(w->io_event);
     pa_xfree(w);
@@ -115,55 +116,62 @@ struct AvahiTimeout {
     void *userdata;
 };
 
-static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *tv, void *userdata) {
-    AvahiTimeout *t = userdata;
-    
-    assert(a);
-    assert(e);
-    assert(t);
+static void timeout_callback(pa_mainloop_api*a, pa_time_event* e, const struct timeval *t, void *userdata) {
+    AvahiTimeout *to = userdata;
 
-    t->callback(t, t->userdata);
+    pa_assert(a);
+    pa_assert(e);
+
+    to->callback(to, to->userdata);
 }
 
 static AvahiTimeout* timeout_new(const AvahiPoll *api, const struct timeval *tv, AvahiTimeoutCallback callback, void *userdata) {
     pa_avahi_poll *p;
     AvahiTimeout *t;
 
-    assert(api);
-    assert(callback);
-    
-    p = api->userdata;
-    assert(p);
+    pa_assert(api);
+    pa_assert(callback);
+    pa_assert_se(p = api->userdata);
 
     t = pa_xnew(AvahiTimeout, 1);
     t->avahi_poll = p;
     t->callback = callback;
     t->userdata = userdata;
-    t->time_event = p->mainloop->time_new(p->mainloop, tv, timeout_callback, t);
+
+    t->time_event = tv ? p->mainloop->time_new(p->mainloop, tv, timeout_callback, t) : NULL;
 
     return t;
 }
+
 static void timeout_update(AvahiTimeout *t, const struct timeval *tv) {
-    assert(t);
 
-    t->avahi_poll->mainloop->time_restart(t->time_event, tv);
+    pa_assert(t);
+
+    if (t->time_event && tv)
+        t->avahi_poll->mainloop->time_restart(t->time_event, tv);
+    else if (!t->time_event && tv)
+        t->time_event = t->avahi_poll->mainloop->time_new(t->avahi_poll->mainloop, tv, timeout_callback, t);
+    else if (t->time_event && !tv) {
+        t->avahi_poll->mainloop->time_free(t->time_event);
+        t->time_event = NULL;
+    }
 }
-     
+
 static void timeout_free(AvahiTimeout *t) {
-    assert(t);
+    pa_assert(t);
 
-    t->avahi_poll->mainloop->time_free(t->time_event);
+    if (t->time_event)
+        t->avahi_poll->mainloop->time_free(t->time_event);
     pa_xfree(t);
 }
 
 AvahiPoll* pa_avahi_poll_new(pa_mainloop_api *m) {
     pa_avahi_poll *p;
 
-    assert(m);
-    
+    pa_assert(m);
+
     p = pa_xnew(pa_avahi_poll, 1);
-    
+
     p->api.userdata = p;
     p->api.watch_new = watch_new;
     p->api.watch_update = watch_update;
@@ -173,16 +181,15 @@ AvahiPoll* pa_avahi_poll_new(pa_mainloop_api *m) {
     p->api.timeout_update = timeout_update;
     p->api.timeout_free = timeout_free;
     p->mainloop = m;
-    
+
     return &p->api;
 }
 
 void pa_avahi_poll_free(AvahiPoll *api) {
     pa_avahi_poll *p;
-    assert(api);
-    p = api->userdata;
-    assert(p);
-    
+    pa_assert(api);
+    pa_assert_se(p = api->userdata);
+
     pa_xfree(p);
 }