4 static void elapse(flxTimeEvent *e, void *userdata) {
5 flxSubscription *s = userdata;
11 flx_server_post_query(s->server, s->interface, s->protocol, s->key);
13 if (s->n_query++ <= 8)
16 g_message("%i. Continuous querying for %s", s->n_query, t = flx_key_to_string(s->key));
19 flx_elapse_time(&tv, s->sec_delay*1000, 0);
20 flx_time_event_queue_update(s->server->time_event_queue, s->time_event, &tv);
23 static void scan_cache_callback(flxInterfaceMonitor *m, flxInterface *i, gpointer userdata) {
24 flxSubscription *s = userdata;
31 for (e = flx_cache_lookup_key(i->cache, s->key); e; e = e->by_name_next)
32 s->callback(s, e->record, i->hardware->index, i->protocol, FLX_SUBSCRIPTION_NEW, s->userdata);
35 flxSubscription *flx_subscription_new(flxServer *server, flxKey *key, gint interface, guchar protocol, flxSubscriptionCallback callback, gpointer userdata) {
36 flxSubscription *s, *t;
43 s = g_new(flxSubscription, 1);
45 s->key = flx_key_ref(key);
46 s->interface = interface;
47 s->protocol = protocol;
48 s->callback = callback;
49 s->userdata = userdata;
53 flx_server_post_query(s->server, s->interface, s->protocol, s->key);
55 flx_elapse_time(&tv, s->sec_delay*1000, 0);
56 s->time_event = flx_time_event_queue_add(server->time_event_queue, &tv, elapse, s);
58 FLX_LLIST_PREPEND(flxSubscription, subscriptions, server->subscriptions, s);
60 /* Add the new entry to the subscription hash table */
61 t = g_hash_table_lookup(server->subscription_hashtable, key);
62 FLX_LLIST_PREPEND(flxSubscription, by_key, t, s);
63 g_hash_table_replace(server->subscription_hashtable, key, t);
66 flx_interface_monitor_walk(s->server->monitor, s->interface, s->protocol, scan_cache_callback, s);
71 void flx_subscription_free(flxSubscription *s) {
76 FLX_LLIST_REMOVE(flxSubscription, subscriptions, s->server->subscriptions, s);
78 t = g_hash_table_lookup(s->server->subscription_hashtable, s->key);
79 FLX_LLIST_REMOVE(flxSubscription, by_key, t, s);
81 g_hash_table_replace(s->server->subscription_hashtable, t->key, t);
83 g_hash_table_remove(s->server->subscription_hashtable, s->key);
85 flx_time_event_queue_remove(s->server->time_event_queue, s->time_event);
86 flx_key_unref(s->key);
92 void flx_subscription_notify(flxServer *server, flxInterface *i, flxRecord *record, flxSubscriptionEvent event) {
98 for (s = g_hash_table_lookup(server->subscription_hashtable, record->key); s; s = s->by_key_next)
99 if (flx_interface_match(i, s->interface, s->protocol))
100 s->callback(s, record, i->hardware->index, i->protocol, event, s->userdata);