[PATCH] Implement a virBool type

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

 



Signed-off-by: Claudio Bley <cbley@xxxxxxxxxx>
---
 include/libvirt/libvirt.h.in |   25 +++++++++++++++++++++----
 python/generator.py          |   16 ++++++++++++++++
 src/libvirt.c                |    8 ++++----
 3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index c1233f6..b51f415 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -80,6 +80,23 @@ typedef void (*virFreeCallback)(void *opaque);
 
 
 /**
+ * virBool:
+ *
+ * A tri-state boolean type being able to signal an error in addition
+ * to having a value of true or false.
+ *
+ * 1 - true
+ * 0 - false
+ * -1 on error
+ */
+typedef enum {
+    VIR_BOOL_TRUE = 1,
+    VIR_BOOL_FALSE = 0,
+    VIR_BOOL_ERROR = -1
+} virBool;
+
+
+/**
  * virConnect:
  *
  * a virConnect is a private structure representing a connection to
@@ -3728,11 +3745,11 @@ int virNetworkIsPersistent(virNetworkPtr net);
 int virStoragePoolIsActive(virStoragePoolPtr pool);
 int virStoragePoolIsPersistent(virStoragePoolPtr pool);
 
-int virInterfaceIsActive(virInterfacePtr iface);
+virBool virInterfaceIsActive(virInterfacePtr iface);
 
-int virConnectIsEncrypted(virConnectPtr conn);
-int virConnectIsSecure(virConnectPtr conn);
-int virConnectIsAlive(virConnectPtr conn);
+virBool virConnectIsEncrypted(virConnectPtr conn);
+virBool virConnectIsSecure(virConnectPtr conn);
+virBool virConnectIsAlive(virConnectPtr conn);
 
 /*
  * CPU specification API
diff --git a/python/generator.py b/python/generator.py
index bae4edc..43df257 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -266,6 +266,8 @@ py_types = {
     'const char *':  ('z', None, "constcharPtr", "const char *"),
     'size_t': ('n', None, "size_t", "size_t"),
 
+    'virBool': ('i', None, "int", "int"),
+
     'virDomainPtr':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
     'const virDomainPtr':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
     'virDomain *':  ('O', "virDomain", "virDomainPtr", "virDomainPtr"),
@@ -1291,6 +1293,13 @@ def buildWrappers(module):
                     classes.write(classes_type[ret[0]][1] % ("ret"));
                     classes.write("\n");
 
+                # special case for virBool
+                elif ret[0] == 'virBool':
+                    classes.write(("    if " + functions_int_default_test +
+                                   ": raise libvirtError ('%s() failed')\n" +
+                                   "    return (ret == 1)\n") %
+                                  ("ret", name))
+
                 # For functions returning an integral type there are
                 # several things that we can do, depending on the
                 # contents of functions_int_*:
@@ -1529,6 +1538,13 @@ def buildWrappers(module):
                         classes.write(converter_type[ret[0]] % ("ret"));
                         classes.write("\n");
 
+                    # special case for virBool
+                    elif ret[0] == 'virBool':
+                        classes.write(("        if " + functions_int_default_test +
+                                       ": raise libvirtError ('%s() failed')\n" +
+                                       "        return (ret == 1)\n") %
+                                      ("ret", name))
+
                     # For functions returning an integral type there
                     # are several things that we can do, depending on
                     # the contents of functions_int_*:
diff --git a/src/libvirt.c b/src/libvirt.c
index a783fa6..2e298d7 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -17112,7 +17112,7 @@ virNWFilterRef(virNWFilterPtr nwfilter)
  *
  * Returns 1 if running, 0 if inactive, -1 on error
  */
-int virInterfaceIsActive(virInterfacePtr iface)
+virBool virInterfaceIsActive(virInterfacePtr iface)
 {
     VIR_DEBUG("iface=%p", iface);
 
@@ -17146,7 +17146,7 @@ error:
  *
  * Returns 1 if encrypted, 0 if not encrypted, -1 on error
  */
-int virConnectIsEncrypted(virConnectPtr conn)
+virBool virConnectIsEncrypted(virConnectPtr conn)
 {
     VIR_DEBUG("conn=%p", conn);
 
@@ -17183,7 +17183,7 @@ error:
  *
  * Returns 1 if secure, 0 if secure, -1 on error
  */
-int virConnectIsSecure(virConnectPtr conn)
+virBool virConnectIsSecure(virConnectPtr conn)
 {
     VIR_DEBUG("conn=%p", conn);
 
@@ -19858,7 +19858,7 @@ error:
  *
  * Returns 1 if alive, 0 if dead, -1 on error
  */
-int virConnectIsAlive(virConnectPtr conn)
+virBool virConnectIsAlive(virConnectPtr conn)
 {
     VIR_DEBUG("conn=%p", conn);
 
-- 
1.7.9.5

--
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]