diff options
author | Arend van Spriel <arend@broadcom.com> | 2013-09-05 14:11:29 +0200 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2013-09-05 17:46:00 +0200 |
commit | 934626903cf6fc7cc4b0b4d7c347d2562229563f (patch) | |
tree | 5119c8dfb50a89076b6a487aea52b81b39d5e192 /lib/handlers.c | |
parent | 9828326c7ff9018e21610eb4a8d5e29eb27ff5b4 (diff) | |
download | libnl-934626903cf6fc7cc4b0b4d7c347d2562229563f.tar.gz |
nl_cb: store nl_cb_type in struct nl_cb
The application could use the same handler for multiple
nl_cb_type events. This patch stores the nl_cb_type in
the nl_cb struct during the callback. This allows the
application to obtain that information using the new
nl_cb_active_type() function. This way the callback
signature remains as is so existing applications are
not affected.
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
Diffstat (limited to 'lib/handlers.c')
-rw-r--r-- | lib/handlers.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/handlers.c b/lib/handlers.c index e52c850f..a6a97bb8 100644 --- a/lib/handlers.c +++ b/lib/handlers.c @@ -35,7 +35,7 @@ static void print_header_content(FILE *ofd, struct nlmsghdr *n) { char flags[128]; char type[32]; - + fprintf(ofd, "type=%s length=%u flags=<%s> sequence-nr=%u pid=%u", nl_nlmsgtype2str(n->nlmsg_type, type, sizeof(type)), n->nlmsg_len, nl_nlmsg_flags2str(n->nlmsg_flags, flags, @@ -71,7 +71,7 @@ static int nl_overrun_handler_verbose(struct nl_msg *msg, void *arg) fprintf(ofd, "-- Error: Netlink Overrun: "); print_header_content(ofd, nlmsg_hdr(msg)); fprintf(ofd, "\n"); - + return NL_STOP; } @@ -107,7 +107,7 @@ static int nl_finish_handler_debug(struct nl_msg *msg, void *arg) fprintf(ofd, "-- Debug: End of multipart message block: "); print_header_content(ofd, nlmsg_hdr(msg)); fprintf(ofd, "\n"); - + return NL_STOP; } @@ -117,7 +117,7 @@ static int nl_msg_in_handler_debug(struct nl_msg *msg, void *arg) fprintf(ofd, "-- Debug: Received Message:\n"); nl_msg_dump(msg, ofd); - + return NL_OK; } @@ -211,6 +211,7 @@ struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind) return NULL; cb->cb_refcnt = 1; + cb->cb_active = NL_CB_TYPE_MAX + 1; for (i = 0; i <= NL_CB_TYPE_MAX; i++) nl_cb_set(cb, i, kind, NULL, NULL); @@ -229,7 +230,7 @@ struct nl_cb *nl_cb_alloc(enum nl_cb_kind kind) struct nl_cb *nl_cb_clone(struct nl_cb *orig) { struct nl_cb *cb; - + cb = nl_cb_alloc(NL_CB_DEFAULT); if (!cb) return NULL; @@ -261,6 +262,17 @@ void nl_cb_put(struct nl_cb *cb) free(cb); } +/** + * Obtain type of current active callback + * @arg cb callback to query + * + * @return type or __NL_CB_TYPE_MAX if none active + */ +enum nl_cb_type nl_cb_active_type(struct nl_cb *cb) +{ + return cb->cb_active; +} + /** @} */ /** @@ -269,7 +281,7 @@ void nl_cb_put(struct nl_cb *cb) */ /** - * Set up a callback + * Set up a callback * @arg cb callback set * @arg type callback to modify * @arg kind kind of implementation |