diff --git a/include/netlink/object.h b/include/netlink/object.h index 7dc62ac..bbda5f5 100644 --- a/include/netlink/object.h +++ b/include/netlink/object.h @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf + * Copyright (c) 2003-2012 Thomas Graf */ #ifndef NETLINK_OBJECT_H_ @@ -57,6 +57,11 @@ extern int nl_object_is_marked(struct nl_object *); /* Access Functions */ extern int nl_object_get_refcnt(struct nl_object *); extern struct nl_cache * nl_object_get_cache(struct nl_object *); +extern const char * nl_object_get_type(const struct nl_object *); +extern int nl_object_get_msgtype(const struct nl_object *); +struct nl_object_ops * nl_object_get_ops(const struct nl_object *); + + static inline void * nl_object_priv(struct nl_object *obj) { return obj; diff --git a/lib/object.c b/lib/object.c index 3bf02ea..554d09b 100644 --- a/lib/object.c +++ b/lib/object.c @@ -6,7 +6,7 @@ * License as published by the Free Software Foundation version 2.1 * of the License. * - * Copyright (c) 2003-2008 Thomas Graf + * Copyright (c) 2003-2012 Thomas Graf */ /** @@ -380,16 +380,69 @@ char *nl_object_attr_list(struct nl_object *obj, char *buf, size_t len) * @{ */ +/** + * Return number of references held + * @arg obj object + * + * @return The number of references held to this object + */ int nl_object_get_refcnt(struct nl_object *obj) { return obj->ce_refcnt; } +/** + * Return cache the object is associated with + * @arg obj object + * + * @note The returned pointer is not protected with a reference counter, + * it is your responsibility. + * + * @return Pointer to cache or NULL if not associated with a cache. + */ struct nl_cache *nl_object_get_cache(struct nl_object *obj) { return obj->ce_cache; } +/** + * Return the object's type + * @arg obj object + * + * FIXME: link to list of object types + * + * @return Name of the object type + */ +const char *nl_object_get_type(const struct nl_object *obj) +{ + if (!obj->ce_ops) + BUG(); + + return obj->ce_ops->oo_name; +} + +/** + * Return the netlink message type the object was derived from + * @arg obj object + * + * @return Netlink message type or 0. + */ +int nl_object_get_msgtype(const struct nl_object *obj) +{ + return obj->ce_msgtype; +} + +/** + * Return object operations structure + * @arg obj object + * + * @return Pointer to the object operations structure + */ +struct nl_object_ops *nl_object_get_ops(const struct nl_object *obj) +{ + return obj->ce_ops; +} + /** @} */ /** @} */