libnl 1.1.4
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
22extern "C" {
23#endif
24
25struct nl_cache;
26
27typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int);
28
29/* Access Functions */
30extern int nl_cache_nitems(struct nl_cache *);
31extern int nl_cache_nitems_filter(struct nl_cache *,
32 struct nl_object *);
33extern struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *);
34extern struct nl_object * nl_cache_get_first(struct nl_cache *);
35extern struct nl_object * nl_cache_get_last(struct nl_cache *);
36extern struct nl_object * nl_cache_get_next(struct nl_object *);
37extern 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)
41extern struct nl_cache * nl_cache_alloc(struct nl_cache_ops *);
42extern struct nl_cache * nl_cache_alloc_name(const char *);
43extern struct nl_cache * nl_cache_subset(struct nl_cache *,
44 struct nl_object *);
45extern void nl_cache_clear(struct nl_cache *);
46extern void nl_cache_get(struct nl_cache *);
47extern void nl_cache_free(struct nl_cache *);
48
49/* Cache modification */
50extern int nl_cache_add(struct nl_cache *,
51 struct nl_object *);
52extern int nl_cache_parse_and_add(struct nl_cache *,
53 struct nl_msg *);
54#define nl_cache_delete(a, b) nl_cache_remove(b)
55extern void nl_cache_remove(struct nl_object *);
56#define nl_cache_update(a, b) nl_cache_refill(a, b)
57extern int nl_cache_refill(struct nl_handle *,
58 struct nl_cache *);
59extern int nl_cache_pickup(struct nl_handle *,
60 struct nl_cache *);
61extern int nl_cache_resync(struct nl_handle *,
62 struct nl_cache *,
63 change_func_t);
64extern int nl_cache_include(struct nl_cache *,
65 struct nl_object *,
66 change_func_t);
67
68/* General */
69extern int nl_cache_is_empty(struct nl_cache *);
70extern void nl_cache_mark_all(struct nl_cache *);
71
72/* Dumping */
73extern void nl_cache_dump(struct nl_cache *,
74 struct nl_dump_params *);
75extern void nl_cache_dump_filter(struct nl_cache *,
76 struct nl_dump_params *,
77 struct nl_object *);
78
79/* Iterators */
80extern void nl_cache_foreach(struct nl_cache *,
81 void (*cb)(struct nl_object *,
82 void *),
83 void *arg);
84extern void nl_cache_foreach_filter(struct nl_cache *,
85 struct nl_object *,
86 void (*cb)(struct
87 nl_object *,
88 void *),
89 void *arg);
90
91/* --- cache management --- */
92
93/* Cache type management */
94extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
95extern struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *);
96extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
97extern struct nl_cache_ops * nl_cache_ops_associate_safe(int, int);
98extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
99extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
100extern int nl_cache_mngt_register(struct nl_cache_ops *);
101extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
102
103/* Global cache provisioning/requiring */
104extern void nl_cache_mngt_provide(struct nl_cache *);
105extern void nl_cache_mngt_unprovide(struct nl_cache *);
106extern struct nl_cache * nl_cache_mngt_require(const char *);
107
108struct nl_cache_mngr;
109
110#define NL_AUTO_PROVIDE 1
111
112extern struct nl_cache_mngr * nl_cache_mngr_alloc(struct nl_handle *,
113 int, int);
114extern struct nl_cache * nl_cache_mngr_add(struct nl_cache_mngr *,
115 const char *,
116 change_func_t);
117extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
118extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
119 int);
120extern int nl_cache_mngr_data_ready(struct nl_cache_mngr *);
121extern void nl_cache_mngr_free(struct nl_cache_mngr *);
122
123#ifdef __cplusplus
124}
125#endif
126
127#endif
void nl_cache_mngr_free(struct nl_cache_mngr *)
Free cache manager.
Definition: cache_mngr.c:373
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_mngr_poll(struct nl_cache_mngr *, int)
Check for event notifications.
Definition: cache_mngr.c:325
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
int nl_cache_mngr_get_fd(struct nl_cache_mngr *)
Get file descriptor.
Definition: cache_mngr.c:305
int nl_cache_mngr_data_ready(struct nl_cache_mngr *)
Receive available event notifications.
Definition: cache_mngr.c:356
int nl_cache_mngt_unregister(struct nl_cache_ops *)
Unregister a set of cache operations.
Definition: cache_mngt.c:261
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:207
int nl_cache_mngt_register(struct nl_cache_ops *)
Register a set of cache operations.
Definition: cache_mngt.c:226
void nl_cache_mngt_unprovide(struct nl_cache *)
Unprovide a cache for global use.
Definition: cache_mngt.c:329
struct nl_cache_ops * nl_cache_ops_associate(int, int)
Associate protocol and message type to cache operations.
Definition: cache_mngt.c:129
struct nl_cache * nl_cache_mngt_require(const char *)
Demand the use of a global cache.
Definition: cache_mngt.c:356
struct nl_cache_ops * nl_cache_ops_lookup(const char *)
Lookup cache operations by name.
Definition: cache_mngt.c:68
void nl_cache_mngt_provide(struct nl_cache *)
Provide a cache for global use.
Definition: cache_mngt.c:304
struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int)
Lookup message type cache association.
Definition: cache_mngt.c:178
struct nl_cache_ops * nl_cache_ops_lookup_safe(const char *)
Lookup cache operations by name.
Definition: cache_mngt.c:88
struct nl_cache_ops * nl_cache_ops_associate_safe(int, int)
Associate protocol and message type to cache operations.
Definition: cache_mngt.c:153
struct nl_cache * nl_cache_alloc_name(const char *)
Allocate an empty cache based on type name.
Definition: cache.c:194
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:791
int nl_cache_nitems(struct nl_cache *)
Return the number of items in the cache.
Definition: cache.c:58
void nl_cache_free(struct nl_cache *)
Free a cache.
Definition: cache.c:277
void nl_cache_get(struct nl_cache *)
Increase reference counter of cache.
Definition: cache.c:264
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
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:745
int nl_cache_add(struct nl_cache *, struct nl_object *)
Add object to a cache.
Definition: cache.c:320
void nl_cache_foreach_filter(struct nl_cache *, struct nl_object *, void(*cb)(struct nl_object *, void *), void *arg)
Call a callback on each element of the cache (filtered).
Definition: cache.c:808
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:660
struct nl_object * nl_cache_get_last(struct nl_cache *)
Return the last element in the cache.
Definition: cache.c:122
struct nl_cache * nl_cache_alloc(struct nl_cache_ops *)
Allocate an empty cache.
Definition: cache.c:170
struct nl_object * nl_cache_get_next(struct nl_object *)
Return the next element in the cache.
Definition: cache.c:135
void nl_cache_remove(struct nl_object *)
Removes an object from a cache.
Definition: cache.c:374
void nl_cache_dump(struct nl_cache *, struct nl_dump_params *)
Dump all elements of a cache.
Definition: cache.c:731
int nl_cache_is_empty(struct nl_cache *)
Returns true if the cache is empty.
Definition: cache.c:91
struct nl_object * nl_cache_get_first(struct nl_cache *)
Return the first element in the cache.
Definition: cache.c:109
struct nl_object * nl_cache_get_prev(struct nl_object *)
Return the previous element in the cache.
Definition: cache.c:148
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:213
void nl_cache_clear(struct nl_cache *)
Clear a cache.
Definition: cache.c:242
int nl_cache_pickup(struct nl_handle *, struct nl_cache *)
Pickup a netlink dump response and put it into a cache.
Definition: cache.c:505
struct nl_cache_ops * nl_cache_get_ops(struct nl_cache *)
Return the operations set of the cache.
Definition: cache.c:100
int nl_cache_refill(struct nl_handle *, struct nl_cache *)
(Re)fill a cache with the contents in the kernel.
Definition: cache.c:680
void nl_cache_mark_all(struct nl_cache *)
Mark all objects in a cache.
Definition: cache.c:706
Cache Operations.
Definition: cache-api.h:164
Dumping parameters.
Definition: types.h:37
Message type to cache action association.
Definition: cache-api.h:129