提交 50e96bb2 编写于 作者: R ramyelkest 提交者: Erik Skultety

util: virerror: Introduce virGetLastError{Code,Domain} public APIs

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: NRamy Elkest <ramyelkest@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 52d88d11
......@@ -344,6 +344,8 @@ void virResetLastError (void);
void virResetError (virErrorPtr err);
void virFreeError (virErrorPtr err);
int virGetLastErrorCode (void);
int virGetLastErrorDomain (void);
const char * virGetLastErrorMessage (void);
virErrorPtr virConnGetLastError (virConnectPtr conn);
......
......@@ -792,4 +792,10 @@ LIBVIRT_4.4.0 {
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 ....
......@@ -271,6 +271,41 @@ virGetLastError(void)
}
/**
* 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:
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册