On Fri, Apr 13, 2018 at 01:15:17PM +0200, Katerina Koukiou wrote: > Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> > --- > data/org.libvirt.Domain.xml | 5 +++++ > src/domain.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+) > > diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml > index 5c310ad..c672053 100644 > --- a/data/org.libvirt.Domain.xml > +++ b/data/org.libvirt.Domain.xml > @@ -62,6 +62,11 @@ > <arg name="xml" type="s" direction="in"/> > <arg name="flags" type="u" direction="in"/> > </method> > + <method name="GetJobInfo"> > + <annotation name="org.gtk.GDBus.DocString" > + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/> > + <arg name="jobInfo" type="(sttttttttttt)" direction="out"/> > + </method> > <method name="GetStats"> > <annotation name="org.gtk.GDBus.DocString" > value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStats"/> > diff --git a/src/domain.c b/src/domain.c > index 2c3174b..47bd585 100644 > --- a/src/domain.c > +++ b/src/domain.c > @@ -3,6 +3,16 @@ > > #include <libvirt/libvirt.h> > > +VIRT_DBUS_ENUM_DECL(virtDBusDomainJob) > +VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob, > + VIR_DOMAIN_JOB_LAST, > + "none", > + "bounded", > + "unbounded", > + "completed", > + "failed", > + "canceled") > + > VIRT_DBUS_ENUM_DECL(virtDBusDomainMemoryStat) > VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat, > VIR_DOMAIN_MEMORY_STAT_LAST, > @@ -390,6 +400,44 @@ virtDBusDomainDetachDevice(GVariant *inArgs, > virtDBusUtilSetLastVirtError(error); > } > > +static void > +virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED, > + GUnixFDList *inFDs G_GNUC_UNUSED, > + const gchar *objectPath, > + gpointer userData, > + GVariant **outArgs, > + GUnixFDList **outFDs G_GNUC_UNUSED, > + GError **error) > +{ > + virtDBusConnect *connect = userData; > + g_autoptr(virDomain) domain = NULL; > + g_autofree virDomainJobInfoPtr jobInfo = NULL; > + const gchar *jobTypeStr; > + > + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); > + if (!domain) > + return; > + > + jobInfo = g_new0(virDomainJobInfo, 1); > + if (virDomainGetJobInfo(domain, jobInfo) < 0) > + return virtDBusUtilSetLastVirtError(error); > + > + jobTypeStr = virtDBusDomainJobTypeToString(jobInfo->type); > + if (!jobTypeStr) { > + g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT, > + "Can't translate virDomainJobType to string."); In this case setting the error makes sense since the other two options are not to translate the type to string or returning job type 'none' with all values as 0. How about this error message: "Can't format virDomainJobType '%d' to string.", jobInfo->type ? > + virtDBusUtilSetLastVirtError(error); This would overwrite the previous error so it should not be used here. The purpose of this function is to get an libvirt error if some libvirt API fails. Pavel
Attachment:
signature.asc
Description: PGP signature
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list