summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Fett <a.fett@gmx.de>2010-09-22 20:10:26 +0200
committerThomas Graf <tgraf@suug.ch>2010-10-13 13:41:57 +0200
commit4ab22ccd47319e7d9a972bcf018e1a03870f64f0 (patch)
treeceeb38a56218b4d17e297b21fd43fe7d76dcd720
parent86b6f6f6291eaaec542a2f4028087fa823122082 (diff)
downloadandroid_external_libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.tar.gz
android_external_libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.tar.bz2
android_external_libnl-4ab22ccd47319e7d9a972bcf018e1a03870f64f0.zip
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.
-rw-r--r--include/netlink-types.h1
-rw-r--r--include/netlink/cache.h9
-rw-r--r--lib/cache.c19
-rw-r--r--lib/cache_mngr.c5
4 files changed, 20 insertions, 14 deletions
diff --git a/include/netlink-types.h b/include/netlink-types.h
index ace5dde..ff699bb 100644
--- a/include/netlink-types.h
+++ b/include/netlink-types.h
@@ -83,6 +83,7 @@ struct nl_cache_assoc
{
struct nl_cache * ca_cache;
change_func_t ca_change;
+ void * ca_change_data;
};
struct nl_cache_mngr
diff --git a/include/netlink/cache.h b/include/netlink/cache.h
index f4db3b9..c752920 100644
--- a/include/netlink/cache.h
+++ b/include/netlink/cache.h
@@ -24,7 +24,7 @@ extern "C" {
struct nl_cache;
-typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int);
+typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int, void *);
/* Access Functions */
extern int nl_cache_nitems(struct nl_cache *);
@@ -59,10 +59,12 @@ extern int nl_cache_pickup(struct nl_sock *,
struct nl_cache *);
extern int nl_cache_resync(struct nl_sock *,
struct nl_cache *,
- change_func_t);
+ change_func_t,
+ void *);
extern int nl_cache_include(struct nl_cache *,
struct nl_object *,
- change_func_t);
+ change_func_t,
+ void *);
/* General */
extern int nl_cache_is_empty(struct nl_cache *);
@@ -112,6 +114,7 @@ extern int nl_cache_mngr_alloc(struct nl_sock *,
extern int nl_cache_mngr_add(struct nl_cache_mngr *,
const char *,
change_func_t,
+ void *,
struct nl_cache **);
extern int nl_cache_mngr_get_fd(struct nl_cache_mngr *);
extern int nl_cache_mngr_poll(struct nl_cache_mngr *,
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);