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."); + virtDBusUtilSetLastVirtError(error); + return; + } + *outArgs = g_variant_new("((sttttttttttt))", jobTypeStr, + jobInfo->timeElapsed, jobInfo->timeRemaining, + jobInfo->dataTotal, jobInfo->dataProcessed, + jobInfo->dataRemaining, jobInfo->memTotal, + jobInfo->memProcessed, jobInfo->memRemaining, + jobInfo->fileTotal, jobInfo->fileProcessed, + jobInfo->fileRemaining); +} + G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree); static void @@ -669,6 +717,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "Create", virtDBusDomainCreate }, { "Destroy", virtDBusDomainDestroy }, { "DetachDevice", virtDBusDomainDetachDevice }, + { "GetJobInfo", virtDBusDomainGetJobInfo }, { "GetStats", virtDBusDomainGetStats }, { "GetVcpus", virtDBusDomainGetVcpus }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list