[libvirt] [PATCH v3 3/8] screenshot: Implementing the public API

Michal Privoznik mprivozn at redhat.com
Tue May 10 13:45:14 UTC 2011


* src/libvirt.c: new function
---
 src/libvirt.c |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index abacf85..2320ddb 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2412,6 +2412,62 @@ error:
 }
 
 /**
+ * virDomainScreenshot:
+ * @domain: a domain object
+ * @stream: stream to use as output
+ * @flags: extra flags, currently unused
+ *
+ * Take a screenshot of current domain console as a stream. The image format
+ * is hypervisor specific.
+ *
+ * This call sets up a stream; subsequent use of stream API is necessary
+ * to transfer actual data, determine how much data is successfully
+ * transfered, and detect any errors.
+ *
+ * Returns a string representing the mime-type of the image format, or
+ * NULL upon error. The caller must free() the returned value.
+ */
+char *
+virDomainScreenshot(virDomainPtr domain,
+                    virStreamPtr stream,
+                    unsigned int flags)
+{
+    VIR_DOMAIN_DEBUG(domain, "stream=%p flags=%u", stream, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return NULL;
+    }
+    if (!VIR_IS_STREAM(stream)) {
+        virLibConnError(VIR_ERR_INVALID_STREAM, __FUNCTION__);
+        return NULL;
+    }
+    if (domain->conn->flags & VIR_CONNECT_RO ||
+        stream->conn->flags & VIR_CONNECT_RO) {
+        virLibConnError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    if (domain->conn->driver->domainScreenshot) {
+        char * ret;
+        ret = domain->conn->driver->domainScreenshot(domain, stream, flags);
+
+        if (ret == NULL)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return NULL;
+}
+
+/**
  * virDomainShutdown:
  * @domain: a domain object
  *
-- 
1.7.5.rc3




More information about the libvir-list mailing list