add libnl
[libnl.git] / include / netlink / cache.h
1 /*
2  * netlink/cache.h              Caching Module
3  *
4  *      This library is free software; you can redistribute it and/or
5  *      modify it under the terms of the GNU Lesser General Public
6  *      License as published by the Free Software Foundation version 2.1
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #ifndef NETLINK_CACHE_H_
13 #define NETLINK_CACHE_H_
14
15 #include <netlink/netlink.h>
16 #include <netlink/msg.h>
17 #include <netlink/utils.h>
18 #include <netlink/object.h>
19
20 struct nl_cache;
21 struct nl_cache_ops;
22
23 /* Access Functions */
24 extern int                      nl_cache_nitems(struct nl_cache *);
25 extern int                      nl_cache_nitems_filter(struct nl_cache *,
26                                                        struct nl_object *);
27 extern struct nl_cache_ops *    nl_cache_get_ops(struct nl_cache *);
28 extern struct nl_object *       nl_cache_get_first(struct nl_cache *);
29 extern struct nl_object *       nl_cache_get_last(struct nl_cache *);
30 extern struct nl_object *       nl_cache_get_next(struct nl_object *);
31 extern struct nl_object *       nl_cache_get_prev(struct nl_object *);
32
33 /* Cache creation/deletion */
34 extern struct nl_cache *        nl_cache_alloc(void);
35 extern struct nl_cache *        nl_cache_alloc_from_ops(struct nl_cache_ops *);
36 extern struct nl_cache *        nl_cache_alloc_name(const char *);
37 extern void                     nl_cache_clear(struct nl_cache *);
38 extern void                     nl_cache_free(struct nl_cache *);
39
40 /* Cache modification */
41 extern int                      nl_cache_add(struct nl_cache *,
42                                              struct nl_object *);
43 extern int                      nl_cache_parse_and_add(struct nl_cache *,
44                                                        struct nl_msg *);
45 extern void                     nl_cache_delete(struct nl_cache *,
46                                                 struct nl_object *);
47 extern int                      nl_cache_update(struct nl_handle *,
48                                                 struct nl_cache *);
49 extern int                      nl_cache_pickup(struct nl_handle *,
50                                                 struct nl_cache *);
51
52 /* General */
53 extern int                      nl_cache_is_empty(struct nl_cache *);
54
55 /* Dumping */
56 extern void                     nl_cache_dump(struct nl_cache *,
57                                               struct nl_dump_params *);
58 extern void                     nl_cache_dump_filter(struct nl_cache *,
59                                                      struct nl_dump_params *,
60                                                      struct nl_object *);
61
62 /* Iterators */
63 extern void                     nl_cache_foreach(struct nl_cache *,
64                                                  void (*cb)(struct nl_object *,
65                                                             void *),
66                                                  void *arg);
67 extern void                     nl_cache_foreach_filter(struct nl_cache *,
68                                                         struct nl_object *,
69                                                         void (*cb)(struct
70                                                                    nl_object *,
71                                                                    void *),
72                                                         void *arg);
73
74 /* --- cache management --- */
75
76 /* Access Functions */
77 extern char *                   nl_cache_ops_get_name(struct nl_cache_ops *);
78
79 /* Message type association */
80 extern struct nl_cache_ops *    nl_cache_mngt_associate(int, int);
81 extern char *                   nl_cache_mngt_type2name(struct nl_cache_ops *,
82                                                         int, char *, size_t);
83
84 /* Cache type management */
85 extern struct nl_cache_ops *    nl_cache_mngt_lookup(const char *);
86 extern int                      nl_cache_mngt_register(struct nl_cache_ops *);
87 extern int                      nl_cache_mngt_unregister(struct nl_cache_ops *);
88
89 /* Global cache provisioning/requiring */
90 extern void                     nl_cache_mngt_provide(struct nl_cache *);
91 extern void                     nl_cache_mngt_unprovide(struct nl_cache *);
92 extern struct nl_cache *        nl_cache_mngt_require(const char *);
93
94 #endif