Add a pair of accessor API's for the object elements which will return
the requested key value from the object to the caller.

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

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 src/libvirt_private.syms |  2 ++
 src/util/virobject.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virobject.h     |  6 ++++++
 3 files changed, 56 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 44d712d..bfc68eb 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2285,6 +2285,8 @@ virObjectListFree;
 virObjectListFreeCount;
 virObjectLock;
 virObjectLockableNew;
+virObjectLookupKeysGetName;
+virObjectLookupKeysGetUUID;
 virObjectLookupKeysNew;
 virObjectNew;
 virObjectRef;
diff --git a/src/util/virobject.c b/src/util/virobject.c
index 6908e8d..862d46b 100644
--- a/src/util/virobject.c
+++ b/src/util/virobject.c
@@ -419,6 +419,18 @@ virObjectGetLockableObj(void *anyobj)
 }
 
 
+static virObjectLookupKeysPtr
+virObjectGetLookupKeysObj(void *anyobj)
+{
+    if (virObjectIsClass(anyobj, virObjectLookupKeysClass))
+        return anyobj;
+
+    VIR_OBJECT_USAGE_PRINT_WARNING(anyobj, virObjectLookupKeysClass);
+
+    return NULL;
+}
+
+
 /**
  * virObjectLock:
  * @anyobj: any instance of virObjectLockablePtr
@@ -570,3 +582,39 @@ virObjectListFreeCount(void *list,
 
     VIR_FREE(list);
 }
+
+
+/**
+ * virObjectLookupKeysGetUUID
+ * @anyobj: Pointer to a LookupKeys object
+ *
+ * Returns: Pointer to the object's uuid key value or possibly NULL
+ */
+const char *
+virObjectLookupKeysGetUUID(void *anyobj)
+{
+    virObjectLookupKeysPtr obj = virObjectGetLookupKeysObj(anyobj);
+
+    if (!obj)
+        return NULL;
+
+    return obj->uuid;
+}
+
+
+/**
+ * virObjectLookupKeysGetName
+ * @anyobj: Pointer to a LookupKeys object
+ *
+ * Returns: Pointer to the object's name key value or possibly NULL
+ */
+const char *
+virObjectLookupKeysGetName(void *anyobj)
+{
+    virObjectLookupKeysPtr obj = virObjectGetLookupKeysObj(anyobj);
+
+    if (!obj)
+        return NULL;
+
+    return obj->name;
+}
diff --git a/src/util/virobject.h b/src/util/virobject.h
index 1cade9d..e77634b 100644
--- a/src/util/virobject.h
+++ b/src/util/virobject.h
@@ -140,4 +140,10 @@ void
 virObjectListFreeCount(void *list,
                        size_t count);
 
+const char *
+virObjectLookupKeysGetUUID(void *anyobj);
+
+const char *
+virObjectLookupKeysGetName(void *anyobj);
+
 #endif /* __VIR_OBJECT_H */
-- 
2.9.4

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

Reply via email to