Many places in the code call virGetLastError() just to check the
raised error code, or domain. However virGetLastError() can return
NULL, so the code has to check for that first. This patch therefore
introduces virGetLasError{Code,Domain} functions which always return a
valid error code or domain respectively, thus dropping the need to
perform any checks on the error object.
Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
void virResetError (virErrorPtr err);
void virFreeError (virErrorPtr err);
+int virGetLastErrorCode (void);
+int virGetLastErrorDomain (void);
const char * virGetLastErrorMessage (void);
virErrorPtr virConnGetLastError (virConnectPtr conn);
virConnectBaselineHypervisorCPU;
} LIBVIRT_4.1.0;
+LIBVIRT_4.5.0 {
+ global:
+ virGetLastErrorCode;
+ virGetLastErrorDomain;
+} LIBVIRT_4.4.0;
+
# .... define new API here using predicted next version number ....
}
+/**
+ * virGetLastErrorCode:
+ *
+ * Get the most recent error code (enum virErrorNumber).
+ *
+ * Returns the most recent error code, or VIR_ERR_OK if none is set.
+ */
+int
+virGetLastErrorCode(void)
+{
+ virErrorPtr err = virLastErrorObject();
+ if (!err)
+ return VIR_ERR_OK;
+ return err->code;
+}
+
+
+/**
+ * virGetLastErrorDomain:
+ *
+ * Get the most recent error domain (enum virErrorDomain).
+ *
+ * Returns a numerical value of the most recent error's origin, or VIR_FROM_NONE
+ * if none is set.
+ */
+int
+virGetLastErrorDomain(void)
+{
+ virErrorPtr err = virLastErrorObject();
+ if (!err)
+ return VIR_FROM_NONE;
+ return err->domain;
+}
+
+
/**
* virGetLastErrorMessage:
*