libnl  1.1
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 #include <netlink/cache-api.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 struct nl_cache;
26 
27 typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int);
28 
29 /* Access Functions */
30 extern int nl_cache_nitems(struct nl_cache *);
31 extern int nl_cache_nitems_filter(struct nl_cache *,
32  struct nl_object *);
33 extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
34 extern struct nl_object * nl_cache_get_first(struct nl_cache *);
35 extern struct nl_object * nl_cache_get_last(struct nl_cache *);
36 extern struct nl_object * nl_cache_get_next(struct nl_object *);
37 extern struct nl_object * nl_cache_get_prev(struct nl_object *);
38 
39 /* Cache creation/deletion */
40 #define nl_cache_alloc_from_ops(ptr) nl_cache_alloc(ptr)
41 extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
42 extern struct nl_cache * nl_cache_alloc_name(const char *);
43 extern struct nl_cache * nl_cache_subset(struct nl_cache *,
44  struct nl_object *);
45 extern void nl_cache_clear(struct nl_cache *);
46 extern void nl_cache_free(struct nl_cache *);
47 
48 /* Cache modification */
49 extern int nl_cache_add(struct nl_cache *,
50  struct nl_object *);
51 extern int nl_cache_parse_and_add(struct nl_cache *,
52  struct nl_msg *);
53 #define nl_cache_delete(a, b) nl_cache_remove(b)
54 extern void nl_cache_remove(struct nl_object *);
55 #define nl_cache_update(a, b) nl_cache_refill(a, b)
56 extern int nl_cache_refill(struct nl_handle *,
57  struct nl_cache *);
58 extern int nl_cache_pickup(struct nl_handle *,
59  struct nl_cache *);
60 extern int nl_cache_resync(struct nl_handle *,
61  struct nl_cache *,
62  change_func_t);
63 extern int nl_cache_include(struct nl_cache *,
64  struct nl_object *,
65  change_func_t);
66 
67 /* General */
68 extern int nl_cache_is_empty(struct nl_cache *);
69 extern void nl_cache_mark_all(struct nl_cache *);
70 
71 /* Dumping */
72 extern void nl_cache_dump(struct nl_cache *,
73  struct nl_dump_params *);
74 extern void nl_cache_dump_filter(struct nl_cache *,
75  struct nl_dump_params *,
76  struct nl_object *);
77 
78 /* Iterators */
79 extern void nl_cache_foreach(struct nl_cache *,
80  void (*cb)(struct nl_object *,
81  void *),
82  void *arg);
83 extern void nl_cache_foreach_filter(struct nl_cache *,
84  struct nl_object *,
85  void (*cb)(struct
86  nl_object *,
87  void *),
88  void *arg);
89 
90 /* --- cache management --- */
91 
92 /* Cache type management */
93 extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
94 extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
95 extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
96 extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
97 extern int nl_cache_mngt_register(struct nl_cache_ops *);
98 extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
99 
100 /* Global cache provisioning/requiring */
101 extern void nl_cache_mngt_provide(struct nl_cache *);
102 extern void nl_cache_mngt_unprovide(struct nl_cache *);
103 extern struct nl_cache * nl_cache_mngt_require(const char *);
104 
105 struct nl_cache_mngr;
106 
107 #define NL_AUTO_PROVIDE 1
108 
109 extern struct nl_cache_mngr * nl_cache_mngr_alloc(struct nl_handle *,
110  int, int);
111 extern struct nl_cache * nl_cache_mngr_add(struct nl_cache_mngr *,
112  const char *,
113  change_func_t);
114 extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
115 extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
116  int);
117 extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
118 extern void nl_cache_mngr_free(struct nl_cache_mngr *);
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif
Message type to cache action association.
Definition: cache-api.h:128
void nl_cache_mngt_provide(struct nl_cache *)
Provide a cache for global use.
Definition: cache_mngt.c:189
struct nl_object * nl_cache_get_prev(struct nl_object *)
Return the previous element in the cache.
Definition: cache.c:151
struct nl_cache * nl_cache_mngr_add(struct nl_cache_mngr *, const char *, change_func_t)
Add cache responsibility to cache manager.
Definition: cache_mngr.c:209
struct nl_cache * nl_cache_subset(struct nl_cache *, struct nl_object *)
Allocate a new cache containing a subset of a cache.
Definition: cache.c:215
int nl_cache_mngr_get_fd(struct nl_cache_mngr *)
Get file descriptor.
Definition: cache_mngr.c:305
int nl_cache_mngt_unregister(struct nl_cache_ops *)
Unregister a set of cache operations.
Definition: cache_mngt.c:157
int nl_cache_pickup(struct nl_handle *, struct nl_cache *)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:487
void nl_cache_dump_filter(struct nl_cache *, struct nl_dump_params *, struct nl_object *)
Dump all elements of a cache (filtered).
Definition: cache.c:727
void nl_cache_foreach_filter(struct nl_cache *cache, struct nl_object *filter, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
Definition: cache.c:790
struct nl_object * nl_cache_get_last(struct nl_cache *)
Return the last element in the cache.
Definition: cache.c:125
int nl_cache_mngr_poll(struct nl_cache_mngr *, int)
Check for event notifications.
Definition: cache_mngr.c:325
struct nl_cache_ops * nl_cache_ops_lookup(const char *)
Lookup the set cache operations of a certain cache type.
Definition: cache_mngt.c:36
void nl_cache_free(struct nl_cache *)
Free a cache.
Definition: cache.c:265
int nl_cache_mngt_register(struct nl_cache_ops *)
Register a set of cache operations.
Definition: cache_mngt.c:127
int nl_cache_refill(struct nl_handle *, struct nl_cache *)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:662
struct nl_cache * nl_cache_alloc_name(const char *)
Allocate an empty cache based on type name.
Definition: cache.c:196
void nl_cache_foreach(struct nl_cache *, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache.
Definition: cache.c:773
Cache Operations.
Definition: cache-api.h:163
void nl_cache_remove(struct nl_object *)
Removes an object from a cache.
Definition: cache.c:356
struct nl_cache * nl_cache_mngt_require(const char *)
Demand the use of a global cache.
Definition: cache_mngt.c:229
int nl_cache_is_empty(struct nl_cache *)
Returns true if the cache is empty.
Definition: cache.c:94
void nl_cache_clear(struct nl_cache *)
Clear a cache.
Definition: cache.c:247
void nl_cache_dump(struct nl_cache *, struct nl_dump_params *)
Dump all elements of a cache.
Definition: cache.c:713
void nl_cache_mngt_unprovide(struct nl_cache *)
Unprovide a cache for global use.
Definition: cache_mngt.c:208
int nl_cache_parse_and_add(struct nl_cache *, struct nl_msg *)
Parse a netlink message and add it to the cache.
Definition: cache.c:642
int nl_cache_nitems(struct nl_cache *)
Return the number of items in the cache.
Definition: cache.c:58
struct nl_object * nl_cache_get_next(struct nl_object *)
Return the next element in the cache.
Definition: cache.c:138
void nl_cache_ops_foreach(void(*cb)(struct nl_cache_ops *, void *), void *)
Call a function for each registered cache operation.
Definition: cache_mngt.c:110
void nl_cache_mark_all(struct nl_cache *)
Mark all objects in a cache.
Definition: cache.c:688
int nl_cache_mngr_data_ready(struct nl_cache_mngr *)
Receive available event notifications.
Definition: cache_mngr.c:356
struct nl_cache_mngr * nl_cache_mngr_alloc(struct nl_handle *, int, int)
Allocate new cache manager.
Definition: cache_mngr.c:149
int nl_cache_nitems_filter(struct nl_cache *, struct nl_object *)
Return the number of items matching a filter in the cache.
Definition: cache.c:68
struct nl_cache_ops * nl_cache_ops_associate(int, int)
Associate a message type to a set of cache operations.
Definition: cache_mngt.c:58
Dumping parameters.
Definition: types.h:36
void nl_cache_mngr_free(struct nl_cache_mngr *)
Free cache manager.
Definition: cache_mngr.c:373
struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *)
Return the operations set of the cache.
Definition: cache.c:103
int nl_cache_add(struct nl_cache *, struct nl_object *)
Add object to a cache.
Definition: cache.c:302
struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int)
Lookup message type cache association.
Definition: cache_mngt.c:82
struct nl_object * nl_cache_get_first(struct nl_cache *)
Return the first element in the cache.
Definition: cache.c:112
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *)
Allocate an empty cache.
Definition: cache.c:173