]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
object: Add functions to access the object type, cache and object ops
authorThomas Graf <tgraf@redhat.com>
Tue, 24 Apr 2012 12:55:23 +0000 (14:55 +0200)
committerThomas Graf <tgraf@redhat.com>
Tue, 24 Apr 2012 12:55:23 +0000 (14:55 +0200)
include/netlink/object.h
lib/object.c

index 7dc62ac5465b7bb0aa97394ebd46c99e14ff6d83..bbda5f520a0f1ae2b776da928630eadecbe2a3d4 100644 (file)
@@ -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;
index 3bf02ea3a16c019b12cfb4e533ffcd564b0fcc40..554d09b0860b6c781effe1a54607c5dcddce359e 100644 (file)
@@ -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;
+}
+
 /** @} */
 
 /** @} */