[PATCH 7/9] util: Add virObjectPoolableHashElementGet*Key

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a pair of accessor API's:

   virObjectPoolableHashElementGetPrimaryKey
   virObjectPoolableHashElementGetSecondaryKey

which will return the requested key from the object to the caller.

It is up to the caller to check the returned key and error if the
return value is NULL.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/libvirt_private.syms |  2 ++
 src/util/virobject.c     | 50 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virobject.h     |  6 ++++++
 3 files changed, 58 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index eca1980..fea0be7 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2271,6 +2271,8 @@ virObjectLock;
 virObjectLockableNew;
 virObjectLockableRecursiveNew;
 virObjectNew;
+virObjectPoolableHashElementGetPrimaryKey;
+virObjectPoolableHashElementGetSecondaryKey;
 virObjectPoolableHashElementNew;
 virObjectRef;
 virObjectUnlock;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 25dbb8f..74299f8 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -441,6 +441,18 @@ virObjectGetLockableObj(void *anyobj)
 }
 
 
+static virObjectPoolableHashElementPtr
+virObjectGetPoolableHashElementObj(void *anyobj)
+{
+    if (virObjectIsClass(anyobj, virObjectPoolableHashElementClass))
+        return anyobj;
+
+    VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectPoolableHashElementClass);
+
+    return NULL;
+}
+
+
 /**
  * virObjectLock:
  * @anyobj: any instance of virObjectLockablePtr
@@ -592,3 +604,41 @@ virObjectListFreeCount(void *list,
 
     VIR_FREE(list);
 }
+
+
+/**
+ * virObjectPoolableHashElementGetPrimaryKey
+ * @anyobj: Pointer to a PoolableHashElement object
+ *
+ * Returns: Pointer to the primaryKey or NULL on failure
+ */
+const char *
+virObjectPoolableHashElementGetPrimaryKey(void *anyobj)
+{
+    virObjectPoolableHashElementPtr obj =
+        virObjectGetPoolableHashElementObj(anyobj);
+
+    if (!obj)
+        return NULL;
+
+    return obj->primaryKey;
+}
+
+
+/**
+ * virObjectPoolableHashElementGetSecondaryKey
+ * @anyobj: Pointer to a PoolableHashElement object
+ *
+ * Returns: Pointer to the secondaryKey which may be NULL
+ */
+const char *
+virObjectPoolableHashElementGetSecondaryKey(void *anyobj)
+{
+    virObjectPoolableHashElementPtr obj =
+        virObjectGetPoolableHashElementObj(anyobj);
+
+    if (!obj)
+        return NULL;
+
+    return obj->secondaryKey;
+}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 0377cd5..4706502 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -146,4 +146,10 @@ void
 virObjectListFreeCount(void *list,
                        size_t count);
 
+const char *
+virObjectPoolableHashElementGetPrimaryKey(void *anyobj);
+
+const char *
+virObjectPoolableHashElementGetSecondaryKey(void *anyobj);
+
 #endif /* __VIR_OBJECT_H */
-- 
2.9.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux