diff options
author | Andreas Fett <a.fett@gmx.de> | 2010-09-22 18:10:26 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-10-13 11:41:57 (GMT) |
commit | 4ab22ccd47319e7d9a972bcf018e1a03870f64f0 (patch) | |
tree | ceeb38a56218b4d17e297b21fd43fe7d76dcd720 /lib | |
parent | 86b6f6f6291eaaec542a2f4028087fa823122082 (diff) | |
download | libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.zip libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.tar.gz libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.tar.bz2 |
add user data to change_func_t for caches
the patch below adds the possibility to
pass user data to callbacks of type
change_func_t when using the nl_cache_mngr_*
family of functions.
If there is any better way to do this,
without duplicating the code in
cache_mngr.c please let me know.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache.c | 19 | ||||
-rw-r--r-- | lib/cache_mngr.c | 5 |
2 files changed, 13 insertions, 11 deletions
diff --git a/lib/cache.c b/lib/cache.c index 5fab32a..2b24946 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -517,7 +517,7 @@ int nl_cache_pickup(struct nl_sock *sk, struct nl_cache *cache) } static int cache_include(struct nl_cache *cache, struct nl_object *obj, - struct nl_msgtype *type, change_func_t cb) + struct nl_msgtype *type, change_func_t cb, void *data) { struct nl_object *old; @@ -529,7 +529,7 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj, nl_cache_remove(old); if (type->mt_act == NL_ACT_DEL) { if (cb) - cb(cache, old, NL_ACT_DEL); + cb(cache, old, NL_ACT_DEL, data); nl_object_put(old); } } @@ -537,10 +537,10 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj, if (type->mt_act == NL_ACT_NEW) { nl_cache_move(cache, obj); if (old == NULL && cb) - cb(cache, obj, NL_ACT_NEW); + cb(cache, obj, NL_ACT_NEW, data); else if (old) { if (nl_object_diff(old, obj) && cb) - cb(cache, obj, NL_ACT_CHANGE); + cb(cache, obj, NL_ACT_CHANGE, data); nl_object_put(old); } @@ -555,7 +555,7 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj, } int nl_cache_include(struct nl_cache *cache, struct nl_object *obj, - change_func_t change_cb) + change_func_t change_cb, void *data) { struct nl_cache_ops *ops = cache->c_ops; int i; @@ -566,7 +566,7 @@ int nl_cache_include(struct nl_cache *cache, struct nl_object *obj, for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) if (ops->co_msgtypes[i].mt_id == obj->ce_msgtype) return cache_include(cache, obj, &ops->co_msgtypes[i], - change_cb); + change_cb, data); return -NLE_MSGTYPE_NOSUPPORT; } @@ -575,16 +575,17 @@ static int resync_cb(struct nl_object *c, struct nl_parser_param *p) { struct nl_cache_assoc *ca = p->pp_arg; - return nl_cache_include(ca->ca_cache, c, ca->ca_change); + return nl_cache_include(ca->ca_cache, c, ca->ca_change, ca->ca_change_data); } int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache, - change_func_t change_cb) + change_func_t change_cb, void *data) { struct nl_object *obj, *next; struct nl_cache_assoc ca = { .ca_cache = cache, .ca_change = change_cb, + .ca_change_data = data, }; struct nl_parser_param p = { .pp_cb = resync_cb, @@ -610,7 +611,7 @@ int nl_cache_resync(struct nl_sock *sk, struct nl_cache *cache, nl_object_get(obj); nl_cache_remove(obj); if (change_cb) - change_cb(cache, obj, NL_ACT_DEL); + change_cb(cache, obj, NL_ACT_DEL, data); nl_object_put(obj); } } diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c index 0675316..81052aa 100644 --- a/lib/cache_mngr.c +++ b/lib/cache_mngr.c @@ -95,7 +95,7 @@ static int include_cb(struct nl_object *obj, struct nl_parser_param *p) if (nl_debug >= 4) nl_object_dump(obj, &nl_debug_dp); #endif - return nl_cache_include(ca->ca_cache, obj, ca->ca_change); + 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) @@ -207,7 +207,7 @@ errout: * @return 0 on success or a negative error code. */ int nl_cache_mngr_add(struct nl_cache_mngr *mngr, const char *name, - change_func_t cb, struct nl_cache **result) + change_func_t cb, void *data, struct nl_cache **result) { struct nl_cache_ops *ops; struct nl_cache *cache; @@ -264,6 +264,7 @@ retry: mngr->cm_assocs[i].ca_cache = cache; mngr->cm_assocs[i].ca_change = cb; + mngr->cm_assocs[i].ca_change_data = data; if (mngr->cm_flags & NL_AUTO_PROVIDE) nl_cache_mngt_provide(cache); |