2 * lib/cache_mngt.c Cache Management
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
9 * Copyright (c) 2003-2008 Thomas Graf <tgraf@suug.ch>
14 * @defgroup cache_mngt Caching
18 #include <netlink-local.h>
19 #include <netlink/netlink.h>
20 #include <netlink/cache.h>
21 #include <netlink/utils.h>
23 static struct nl_cache_ops
*cache_ops
;
26 * @name Cache Operations Sets
31 * Lookup the set cache operations of a certain cache type
32 * @arg name name of the cache type
34 * @return The cache operations or NULL if no operations
35 * have been registered under the specified name.
37 struct nl_cache_ops
*nl_cache_ops_lookup(const char *name
)
39 struct nl_cache_ops
*ops
;
41 for (ops
= cache_ops
; ops
; ops
= ops
->co_next
)
42 if (!strcmp(ops
->co_name
, name
))
49 * Associate a message type to a set of cache operations
50 * @arg protocol netlink protocol
51 * @arg msgtype netlink message type
53 * Associates the specified netlink message type with
54 * a registered set of cache operations.
56 * @return The cache operations or NULL if no association
59 struct nl_cache_ops
*nl_cache_ops_associate(int protocol
, int msgtype
)
62 struct nl_cache_ops
*ops
;
64 for (ops
= cache_ops
; ops
; ops
= ops
->co_next
) {
65 if (ops
->co_protocol
!= protocol
)
68 for (i
= 0; ops
->co_msgtypes
[i
].mt_id
>= 0; i
++)
69 if (ops
->co_msgtypes
[i
].mt_id
== msgtype
)
77 * Register a set of cache operations
78 * @arg ops cache operations
80 * Called by users of caches to announce the avaibility of
81 * a certain cache type.
83 * @return 0 on success or a negative error code.
85 int nl_cache_mngt_register(struct nl_cache_ops
*ops
)
87 if (!ops
->co_name
|| !ops
->co_obj_ops
)
90 if (nl_cache_ops_lookup(ops
->co_name
))
93 ops
->co_next
= cache_ops
;
96 NL_DBG(1, "Registered cache operations %s\n", ops
->co_name
);
102 * Unregister a set of cache operations
103 * @arg ops cache operations
105 * Called by users of caches to announce a set of
106 * cache operations is no longer available. The
107 * specified cache operations must have been registered
108 * previously using nl_cache_mngt_register()
110 * @return 0 on success or a negative error code
112 int nl_cache_mngt_unregister(struct nl_cache_ops
*ops
)
114 struct nl_cache_ops
*t
, **tp
;
116 for (tp
= &cache_ops
; (t
=*tp
) != NULL
; tp
= &t
->co_next
)
123 NL_DBG(1, "Unregistered cache operations %s\n", ops
->co_name
);