summaryrefslogtreecommitdiffstats
path: root/avahi-core
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-core
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-core')
-rw-r--r--avahi-core/avahi-test.c2
-rw-r--r--avahi-core/conformance-test.c2
-rw-r--r--avahi-core/timeeventq.c45
3 files changed, 30 insertions, 19 deletions
diff --git a/avahi-core/avahi-test.c b/avahi-core/avahi-test.c
index 2713185..375fb7d 100644
--- a/avahi-core/avahi-test.c
+++ b/avahi-core/avahi-test.c
@@ -226,7 +226,7 @@ int main(int argc, char *argv[]) {
int error;
avahi_set_allocator(avahi_glib_allocator());
- glib_poll = avahi_glib_poll_new(NULL);
+ glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT);
avahi_server_config_init(&config);
/* config.host_name = g_strdup("test"); */
diff --git a/avahi-core/conformance-test.c b/avahi-core/conformance-test.c
index b786e85..fab9b56 100644
--- a/avahi-core/conformance-test.c
+++ b/avahi-core/conformance-test.c
@@ -109,7 +109,7 @@ int main(int argc, char *argv[]) {
avahi_set_allocator(avahi_glib_allocator());
- glib_poll = avahi_glib_poll_new(NULL);
+ glib_poll = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT);
avahi = avahi_server_new(avahi_glib_poll_get(glib_poll), NULL, server_callback, NULL, &error);
diff --git a/avahi-core/timeeventq.c b/avahi-core/timeeventq.c
index bb9a5cd..5e24ba3 100644
--- a/avahi-core/timeeventq.c
+++ b/avahi-core/timeeventq.c
@@ -44,6 +44,7 @@ struct AvahiTimeEvent {
struct AvahiTimeEventQueue {
const AvahiPoll *poll_api;
AvahiPrioQueue *prioq;
+ AvahiTimeout *timeout;
};
static int compare(const void* _a, const void* _b) {
@@ -58,19 +59,17 @@ static int compare(const void* _a, const void* _b) {
return avahi_timeval_compare(&a->last_run, &b->last_run);
}
-static void expiration_event(AvahiPoll *poll_api, void *userdata);
-
-static void update_wakeup(AvahiTimeEventQueue *q) {
+static void update_timeout(AvahiTimeEventQueue *q) {
+ AvahiTimeEvent *e;
assert(q);
- if (q->prioq->root) {
- AvahiTimeEvent *e = q->prioq->root->data;
- q->poll_api->set_wakeup(q->poll_api, &e->expiry, expiration_event, q);
- } else
- q->poll_api->set_wakeup(q->poll_api, NULL, NULL, NULL);
+ if ((e = avahi_time_event_queue_root(q)))
+ q->poll_api->timeout_update(q->timeout, &e->expiry);
+ else
+ q->poll_api->timeout_update(q->timeout, NULL);
}
-void expiration_event(AvahiPoll *poll_api, void *userdata) {
+static void expiration_event(AvahiTimeout *timeout, void *userdata) {
struct timeval now;
AvahiTimeEventQueue *q = userdata;
AvahiTimeEvent *e;
@@ -92,7 +91,7 @@ void expiration_event(AvahiPoll *poll_api, void *userdata) {
}
}
- update_wakeup(q);
+ update_timeout(q);
}
static void fix_expiry_time(AvahiTimeEvent *e) {
@@ -113,27 +112,39 @@ AvahiTimeEventQueue* avahi_time_event_queue_new(const AvahiPoll *poll_api) {
goto oom;
}
+ q->poll_api = poll_api;
+
if (!(q->prioq = avahi_prio_queue_new(compare)))
goto oom;
- q->poll_api = poll_api;
+ if (!(q->timeout = poll_api->timeout_new(poll_api, NULL, expiration_event, q)))
+ goto oom;
+
return q;
oom:
- if (q)
+ if (q) {
avahi_free(q);
+
+ if (q->prioq)
+ avahi_prio_queue_free(q->prioq);
+ }
return NULL;
}
void avahi_time_event_queue_free(AvahiTimeEventQueue *q) {
+ AvahiTimeEvent *e;
+
assert(q);
- while (q->prioq->root)
- avahi_time_event_free(q->prioq->root->data);
+ while ((e = avahi_time_event_queue_root(q)))
+ avahi_time_event_free(e);
avahi_prio_queue_free(q->prioq);
+ q->poll_api->timeout_free(q->timeout);
+
avahi_free(q);
}
@@ -175,7 +186,7 @@ AvahiTimeEvent* avahi_time_event_new(
return NULL;
}
- update_wakeup(q);
+ update_timeout(q);
return e;
}
@@ -188,7 +199,7 @@ void avahi_time_event_free(AvahiTimeEvent *e) {
avahi_prio_queue_remove(q->prioq, e->node);
avahi_free(e);
- update_wakeup(q);
+ update_timeout(q);
}
void avahi_time_event_update(AvahiTimeEvent *e, const struct timeval *timeval) {
@@ -199,7 +210,7 @@ void avahi_time_event_update(AvahiTimeEvent *e, const struct timeval *timeval) {
fix_expiry_time(e);
avahi_prio_queue_shuffle(e->queue->prioq, e->node);
- update_wakeup(e->queue);
+ update_timeout(e->queue);
}
AvahiTimeEvent* avahi_time_event_queue_root(AvahiTimeEventQueue *q) {