]> git.meshlink.io Git - catta/blobdiff - avahi-qt/qt-watch.cpp
fix avahi_netlink_new to allow multiple netlinks per process
[catta] / avahi-qt / qt-watch.cpp
index 627d3d98daabf168ffafd7f7ec044bb93282ceec..dac9dcc7ea116d0328f219ca3be1b1bd619224b1 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of avahi.
  
@@ -29,6 +27,7 @@
 #include <qobject.h>
 #include <qtimer.h>
 #endif
+#include <avahi-common/timeval.h>
 #include "qt-watch.h"
 
 class AvahiWatch : public QObject 
@@ -124,17 +123,14 @@ AvahiTimeout::AvahiTimeout(const struct timeval* tv, AvahiTimeoutCallback callba
 void AvahiTimeout::update(const struct timeval *tv)
 {
     m_timer.stop();
-    if (tv) 
-       if (tv->tv_sec==0 && tv->tv_usec==0) timeout(); // absolute timeval they say ...
-       else {
-            struct timeval now;
-           gettimeofday(&now, 0);
+    if (tv) {
+    AvahiUsec u = avahi_age(tv)/1000;
 #ifdef QT4
-            m_timer.start((tv->tv_sec-now.tv_sec)*1000+(tv->tv_usec-now.tv_usec)/1000);
+    m_timer.start( (u>0) ? 0 : -u);
 #else
-            m_timer.start((tv->tv_sec-now.tv_sec)*1000+(tv->tv_usec-now.tv_usec)/1000,true);
+    m_timer.start( (u>0) ? 0 : -u,true);
 #endif
-        }
+    }
 }
 
 void AvahiTimeout::timeout()
@@ -179,19 +175,19 @@ static void q_timeout_free(AvahiTimeout *t)
     delete t;
 }
 
-static AvahiPoll qt_poll;
-
 const AvahiPoll* avahi_qt_poll_get(void) 
 {
-    qt_poll.userdata=0;
-    qt_poll.watch_new = q_watch_new;
-    qt_poll.watch_free = q_watch_free;
-    qt_poll.watch_update = q_watch_update;
-    qt_poll.watch_get_events = q_watch_get_events;
-    
-    qt_poll.timeout_new = q_timeout_new;
-    qt_poll.timeout_free = q_timeout_free;
-    qt_poll.timeout_update = q_timeout_update;
+    static const AvahiPoll qt_poll = {
+        NULL,
+        q_watch_new,
+        q_watch_update,
+        q_watch_get_events,
+        q_watch_free,
+        q_timeout_new,
+        q_timeout_update,
+        q_timeout_free
+    };
+
     return &qt_poll;
 }