]> granicus.if.org Git - libnl/commitdiff
cache: Add co_include_event allowing caches to provide their own nl_cache_include...
authorThomas Graf <tgraf@redhat.com>
Sun, 22 Apr 2012 13:23:52 +0000 (15:23 +0200)
committerThomas Graf <tgraf@redhat.com>
Sun, 22 Apr 2012 13:23:52 +0000 (15:23 +0200)
include/netlink/cache-api.h
include/netlink/cache.h
lib/cache_mngr.c

index c1c3aaa6db3cfd5caf299d73061521c0e413f0ba..390cbea9e73eb18236e4155bea64549cb158b93e 100644 (file)
@@ -6,7 +6,7 @@
  *     License as published by the Free Software Foundation version 2.1
  *     of the License.
  *
- * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
+ * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
  */
 
 #ifndef NETLINK_CACHE_API_H_
@@ -18,6 +18,8 @@
 extern "C" {
 #endif
 
+typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
+
 /**
  * @ingroup cache
  * @defgroup cache_api Cache Implementation
@@ -225,6 +227,22 @@ struct nl_cache_ops
         */
        int   (*co_event_filter)(struct nl_cache *, struct nl_object *obj);
 
+       /**
+        * The function registered under this callback is called when an
+        * object formed from a notification event needs to be included in
+        * a cache.
+        *
+        * For each modified object, the change callback \c change_cb must
+        * be called with the \c data argument provided.
+        *
+        * If no function is registered, the function nl_cache_include()
+        * will be used for this purpose.
+        *
+        * @see nl_cache_include()
+        */
+       int   (*co_include_event)(struct nl_cache *cache, struct nl_object *obj,
+                                 change_func_t change_cb, void *data);
+
        /** Object operations */
        struct nl_object_ops *  co_obj_ops;
 
index 1e2bb9d28e675a31733c0692fe756da06822306b..fd137e1781a3c59dbf3410fc9852e44924fb9864 100644 (file)
@@ -24,8 +24,6 @@ extern "C" {
 
 struct nl_cache;
 
-typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
-
 /* Access Functions */
 extern int                     nl_cache_nitems(struct nl_cache *);
 extern int                     nl_cache_nitems_filter(struct nl_cache *,
index 39cf0ac026cceabda5875f0cc89c533720051f2d..dae8768489089ac1b2085d284d452f0296953088 100644 (file)
@@ -42,7 +42,11 @@ static int include_cb(struct nl_object *obj, struct nl_parser_param *p)
                if (ops->co_event_filter(ca->ca_cache, obj) != NL_OK)
                        return 0;
 
-       return nl_cache_include(ca->ca_cache, obj, ca->ca_change, ca->ca_change_data);
+       if (ops->co_include_event)
+               return ops->co_include_event(ca->ca_cache, obj, ca->ca_change,
+                                            ca->ca_change_data);
+       else
+               return nl_cache_include(ca->ca_cache, obj, ca->ca_change, ca->ca_change_data);
 }
 
 static int event_input(struct nl_msg *msg, void *arg)