summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@redhat.com>2012-04-24 14:55:23 +0200
committerThomas Graf <tgraf@redhat.com>2012-04-24 14:55:23 +0200
commitff3e9e314cd0dac21806b95d513abadeae0cc96f (patch)
tree9f6477d06dfbafc7ae782dd1dcf0ec4f1d9eaf8b
parentbd1e4d03840a4d8289ba87935096c6dcb0c18ea7 (diff)
downloadlibnl-ff3e9e314cd0dac21806b95d513abadeae0cc96f.tar.gz
object: Add functions to access the object type, cache and object ops
-rw-r--r--include/netlink/object.h7
-rw-r--r--lib/object.c55
2 files changed, 60 insertions, 2 deletions
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 <tgraf@suug.ch>
+ * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
*/
#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 <tgraf@suug.ch>
+ * Copyright (c) 2003-2012 Thomas Graf <tgraf@suug.ch>
*/
/**
@@ -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;
+}
+
/** @} */
/** @} */