summaryrefslogtreecommitdiffstats
path: root/libavahi-core/cache.h
blob: de0ec9fc5bb01bc1db1d39fd47e91537dd9299b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef foocachehfoo
#define foocachehfoo

#include <glib.h>

struct _AvahiCache;
typedef struct _AvahiCache AvahiCache;

#include "prioq.h"
#include "server.h"
#include "llist.h"
#include "timeeventq.h"

typedef enum {
    AVAHI_CACHE_VALID,
    AVAHI_CACHE_EXPIRY1,
    AVAHI_CACHE_EXPIRY2,
    AVAHI_CACHE_EXPIRY3,
    AVAHI_CACHE_FINAL
} AvahiCacheEntryState;

typedef struct AvahiCacheEntry AvahiCacheEntry;

struct AvahiCacheEntry {
    AvahiCache *cache;
    AvahiRecord *record;
    GTimeVal timestamp;
    GTimeVal expiry;
    
    AvahiAddress origin;

    AvahiCacheEntryState state;
    AvahiTimeEvent *time_event;

    AVAHI_LLIST_FIELDS(AvahiCacheEntry, by_key);
    AVAHI_LLIST_FIELDS(AvahiCacheEntry, entry);
};

struct _AvahiCache {
    AvahiServer *server;
    
    AvahiInterface *interface;
    
    GHashTable *hash_table;

    AVAHI_LLIST_HEAD(AvahiCacheEntry, entries);
};

AvahiCache *avahi_cache_new(AvahiServer *server, AvahiInterface *interface);
void avahi_cache_free(AvahiCache *c);

AvahiCacheEntry *avahi_cache_lookup_key(AvahiCache *c, AvahiKey *k);
AvahiCacheEntry *avahi_cache_lookup_record(AvahiCache *c, AvahiRecord *r);

void avahi_cache_update(AvahiCache *c, AvahiRecord *r, gboolean unique, const AvahiAddress *a);

void avahi_cache_drop_record(AvahiCache *c,  AvahiRecord *r);

void avahi_cache_dump(AvahiCache *c, FILE *f);

typedef gpointer AvahiCacheWalkCallback(AvahiCache *c, AvahiKey *pattern, AvahiCacheEntry *e, gpointer userdata);
gpointer avahi_cache_walk(AvahiCache *c, AvahiKey *pattern, AvahiCacheWalkCallback cb, gpointer userdata);

gboolean avahi_cache_entry_half_ttl(AvahiCache *c, AvahiCacheEntry *e);

#endif