]> git.meshlink.io Git - catta/blobdiff - avahi-core/announce.c
implement new main loop abstraction layer
[catta] / avahi-core / announce.c
index 8149b387a3464356a0e50cc32394df831bb4fe7c..9a6d505c43f7fb4860b6b93dd4cb6818be14eee9 100644 (file)
@@ -23,8 +23,8 @@
 #include <config.h>
 #endif
 
+#include <avahi-common/timeval.h>
 #include "announce.h"
-#include "util.h"
 
 #define AVAHI_ANNOUNCEMENT_JITTER_MSEC 250
 #define AVAHI_PROBE_JITTER_MSEC 250
@@ -45,7 +45,7 @@ static void remove_announcement(AvahiServer *s, AvahiAnnouncement *a) {
 
 static void elapse_announce(AvahiTimeEvent *e, void *userdata);
 
-static void set_timeout(AvahiAnnouncement *a, const GTimeVal *tv) {
+static void set_timeout(AvahiAnnouncement *a, const struct timeval *tv) {
     g_assert(a);
 
     if (!tv) {
@@ -95,7 +95,7 @@ void avahi_entry_group_check_probed(AvahiEntryGroup *g, gboolean immediately) {
                 a->n_iteration = 1;
                 next_state(a);
             } else {
-                GTimeVal tv;
+                struct timeval tv;
                 a->n_iteration = 0;
                 avahi_elapse_time(&tv, 0, AVAHI_ANNOUNCEMENT_JITTER_MSEC);
                 set_timeout(a, &tv);
@@ -107,7 +107,7 @@ void avahi_entry_group_check_probed(AvahiEntryGroup *g, gboolean immediately) {
 static void next_state(AvahiAnnouncement *a) {
     g_assert(a);
 
-/*     g_message("%i -- %u", a->state, a->n_iteration);   */
+/*     avahi_log_debug("%i -- %u", a->state, a->n_iteration);   */
     
     if (a->state == AVAHI_WAITING) {
 
@@ -120,10 +120,10 @@ static void next_state(AvahiAnnouncement *a) {
         if (a->n_iteration >= 4) {
             /* Probing done */
             
-            gchar *t;
+/*             gchar *t; */
 
-            g_message("Enough probes for record [%s]", t = avahi_record_to_string(a->entry->record));
-            g_free(t);
+/*             avahi_log_debug("Enough probes for record [%s]", t = avahi_record_to_string(a->entry->record)); */
+/*             g_free(t); */
 
             if (a->entry->group) {
                 g_assert(a->entry->group->n_probing);
@@ -140,7 +140,7 @@ static void next_state(AvahiAnnouncement *a) {
             set_timeout(a, NULL);
             next_state(a);
         } else {
-            GTimeVal tv;
+            struct timeval tv;
 
             avahi_interface_post_probe(a->interface, a->entry->record, FALSE);
             
@@ -156,22 +156,22 @@ static void next_state(AvahiAnnouncement *a) {
             /* Send the whole rrset at once */
             avahi_server_prepare_matching_responses(a->server, a->interface, a->entry->record->key, FALSE);
         else
-            avahi_server_prepare_response(a->server, a->interface, a->entry, FALSE);
+            avahi_server_prepare_response(a->server, a->interface, a->entry, FALSE, FALSE);
 
-        avahi_server_generate_response(a->server, a->interface, NULL, NULL, 0, FALSE);
+        avahi_server_generate_response(a->server, a->interface, NULL, NULL, 0, FALSE, FALSE);
 
         if (++a->n_iteration >= 4) {
-            gchar *t;
+/*             gchar *t; */
             /* Announcing done */
 
-            g_message("Enough announcements for record [%s]", t = avahi_record_to_string(a->entry->record));
-            g_free(t);
+/*             avahi_log_debug("Enough announcements for record [%s]", t = avahi_record_to_string(a->entry->record)); */
+/*             g_free(t); */
 
             a->state = AVAHI_ESTABLISHED;
 
             set_timeout(a, NULL);
         } else {
-            GTimeVal tv;
+            struct timeval tv;
             avahi_elapse_time(&tv, a->sec_delay*1000, AVAHI_ANNOUNCEMENT_JITTER_MSEC);
         
             if (a->n_iteration < 10)
@@ -204,11 +204,11 @@ AvahiAnnouncement *avahi_get_announcement(AvahiServer *s, AvahiEntry *e, AvahiIn
 
 static void go_to_initial_state(AvahiAnnouncement *a, gboolean immediately) {
     AvahiEntry *e;
-    GTimeVal tv;
+    struct timeval tv;
         
     g_assert(a);
     e = a->entry;
-    
+
     if ((e->flags & AVAHI_ENTRY_UNIQUE) && !(e->flags & AVAHI_ENTRY_NOPROBE))
         a->state = AVAHI_PROBING;
     else if (!(e->flags & AVAHI_ENTRY_NOANNOUNCE)) {
@@ -239,14 +239,14 @@ static void go_to_initial_state(AvahiAnnouncement *a, gboolean immediately) {
 
 static void new_announcement(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) {
     AvahiAnnouncement *a;
-    gchar *t; 
+/*     gchar *t;  */
 
     g_assert(s);
     g_assert(i);
     g_assert(e);
     g_assert(!e->dead);
 
-/*     g_message("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record)); */
+/*     avahi_log_debug("NEW ANNOUNCEMENT: %s.%i [%s]", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record)); */
 /*     g_free(t); */
     
     if (!avahi_interface_match(i, e->interface, e->protocol) || !i->announcing || !avahi_entry_commited(e))
@@ -254,7 +254,7 @@ static void new_announcement(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) {
 
     /* We don't want duplicate announcements */
     if (avahi_get_announcement(s, e, i))
-        return;
+        return;    
 
     a = g_new(AvahiAnnouncement, 1);
     a->server = s;
@@ -267,8 +267,8 @@ static void new_announcement(AvahiServer *s, AvahiInterface *i, AvahiEntry *e) {
 
     go_to_initial_state(a, FALSE);
     
-    g_message("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record), a->state);
-    g_free(t);
+/*     avahi_log_debug("New announcement on interface %s.%i for entry [%s] state=%i", i->hardware->name, i->protocol, t = avahi_record_to_string(e->record), a->state); */
+/*     g_free(t); */
 }
 
 void avahi_announce_interface(AvahiServer *s, AvahiInterface *i) {
@@ -342,6 +342,8 @@ gboolean avahi_entry_probing(AvahiServer *s, AvahiEntry *e, AvahiInterface *i) {
 
     if (!(a = avahi_get_announcement(s, e, i)))
         return FALSE;
+
+/*     avahi_log_debug("state: %i", a->state); */
     
     return
         a->state == AVAHI_PROBING ||
@@ -370,7 +372,7 @@ static AvahiRecord *make_goodbye_record(AvahiRecord *r) {
     
     g_assert(r);
 
-/*     g_message("Preparing goodbye for record [%s]", t = avahi_record_to_string(r)); */
+/*     avahi_log_debug("Preparing goodbye for record [%s]", t = avahi_record_to_string(r)); */
 /*     g_free(t); */
 
     g = avahi_record_copy(r);
@@ -399,7 +401,7 @@ static void send_goodbye_callback(AvahiInterfaceMonitor *m, AvahiInterface *i, g
         return;
     
     g = make_goodbye_record(e->record);
-    avahi_interface_post_response(i, g, e->flags & AVAHI_ENTRY_UNIQUE, TRUE, NULL);
+    avahi_interface_post_response(i, g, e->flags & AVAHI_ENTRY_UNIQUE, NULL, TRUE);
     avahi_record_unref(g);
 }
     
@@ -407,7 +409,7 @@ void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean goodbye
     g_assert(s);
     g_assert(i);
 
-/*     g_message("goodbye interface: %s.%u", i->hardware->name, i->protocol); */
+/*     avahi_log_debug("goodbye interface: %s.%u", i->hardware->name, i->protocol); */
 
     if (goodbye && avahi_interface_relevant(i)) {
         AvahiEntry *e;
@@ -420,7 +422,7 @@ void avahi_goodbye_interface(AvahiServer *s, AvahiInterface *i, gboolean goodbye
     while (i->announcements)
         remove_announcement(s, i->announcements);
 
-/*     g_message("goodbye interface done: %s.%u", i->hardware->name, i->protocol); */
+/*     avahi_log_debug("goodbye interface done: %s.%u", i->hardware->name, i->protocol); */
 
 }
 
@@ -428,7 +430,7 @@ void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean goodbye) {
     g_assert(s);
     g_assert(e);
     
-/*     g_message("goodbye entry: %p", e); */
+/*     avahi_log_debug("goodbye entry: %p", e); */
     
     if (goodbye && !e->dead)
         avahi_interface_monitor_walk(s->monitor, 0, AF_UNSPEC, send_goodbye_callback, e);
@@ -436,7 +438,7 @@ void avahi_goodbye_entry(AvahiServer *s, AvahiEntry *e, gboolean goodbye) {
     while (e->announcements)
         remove_announcement(s, e->announcements);
 
-/*     g_message("goodbye entry done: %p", e); */
+/*     avahi_log_debug("goodbye entry done: %p", e); */
 
 }
 
@@ -445,13 +447,13 @@ void avahi_goodbye_all(AvahiServer *s, gboolean goodbye) {
     
     g_assert(s);
 
-/*     g_message("goodbye all"); */
+/*     avahi_log_debug("goodbye all"); */
 
     for (e = s->entries; e; e = e->entries_next)
         if (!e->dead)
             avahi_goodbye_entry(s, e, goodbye);
 
-/*     g_message("goodbye all done"); */
+/*     avahi_log_debug("goodbye all done"); */
 
 }