[PATCH v2 6/8] 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 a400d8f..dd3ea68 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2270,6 +2270,8 @@ virObjectListFreeCount;
 virObjectLock;
 virObjectLockableNew;
 virObjectNew;
+virObjectPoolableHashElementGetPrimaryKey;
+virObjectPoolableHashElementGetSecondaryKey;
 virObjectPoolableHashElementNew;
 virObjectRef;
 virObjectUnlock;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 302b7ac..18cef0f 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -409,6 +409,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
@@ -560,3 +572,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 e29dae7..1ed856e 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -140,4 +140,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