[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v4 4/8] screenshot: Implementing the remote protocol



* src/remote/remote_protocol.x: Wire protocol definition
* daemon/remote.c: Daemon part
* src/remote/remote_driver.c: Client part
* src/remote_protocol-structs: Add structures
---
 daemon/remote.c              |   57 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   42 ++++++++++++++++++++++++++++++-
 src/remote/remote_protocol.x |   13 +++++++++-
 src/remote_protocol-structs  |    8 ++++++
 4 files changed, 118 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 1b424fe..6e13958 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -1692,6 +1692,63 @@ no_memory:
     goto cleanup;
 }
 
+static int
+remoteDispatchDomainScreenshot (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                struct qemud_client *client,
+                                virConnectPtr conn,
+                                remote_message_header *hdr,
+                                remote_error *rerr,
+                                remote_domain_screenshot_args *args,
+                                remote_domain_screenshot_ret *ret)
+{
+    int rv = -1;
+    struct qemud_client_stream *stream = NULL;
+    virDomainPtr dom;
+    char *mime, **mime_p;
+
+    ret->mime = NULL;
+
+    dom = get_nonnull_domain (conn, args->dom);
+    if (dom == NULL)
+        goto err;
+
+    stream = remoteCreateClientStream(conn, hdr);
+    if (!stream)
+        goto err;
+
+    mime = virDomainScreenshot(dom, stream->st, args->screen, args->flags);
+    if (!mime)
+        goto err;
+
+    if (remoteAddClientStream(client, stream, 1) < 0) {
+        virStreamAbort(stream->st);
+        goto err;
+    }
+
+    if (VIR_ALLOC(mime_p) < 0) {
+        remoteDispatchOOMError(rerr);
+        goto cleanup;
+    }
+
+    *mime_p = strdup(mime);
+    if (*mime_p == NULL) {
+        remoteDispatchOOMError(rerr);
+        goto cleanup;
+    }
+
+    ret->mime = mime_p;
+    rv = 0;
+
+err:
+    if (rv < 0)
+        remoteDispatchError(rerr);
+cleanup:
+    virDomainFree(dom);
+    if (stream && rv != 0)
+        remoteFreeClientStream(client, stream);
+    return rv;
+}
+
 /*-------------------------------------------------------------*/
 
 static int
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 328ef62..7ba2770 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -4803,6 +4803,46 @@ done:
     return rv;
 }
 
+static char *
+remoteDomainScreenshot (virDomainPtr domain,
+                        virStreamPtr st,
+                        unsigned int screen,
+                        unsigned int flags)
+{
+    struct private_data *priv = domain->conn->privateData;
+    struct private_stream_data *privst = NULL;
+    remote_domain_screenshot_args args;
+    remote_domain_screenshot_ret ret;
+    char *rv = NULL;
+
+    remoteDriverLock(priv);
+
+    if (!(privst = remoteStreamOpen(st,
+                                    REMOTE_PROC_DOMAIN_SCREENSHOT,
+                                    priv->counter)))
+        goto done;
+
+    st->driver = &remoteStreamDrv;
+    st->privateData = privst;
+
+    make_nonnull_domain(&args.dom, domain);
+    args.flags = flags;
+    args.screen = screen;
+
+    memset(&ret, 0, sizeof(ret));
+    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SCREENSHOT,
+              (xdrproc_t) xdr_remote_domain_screenshot_args, (char *) &args,
+              (xdrproc_t) xdr_remote_domain_screenshot_ret, (char *) &ret) == -1)
+        goto done;
+
+    rv = ret.mime ? *ret.mime : NULL;
+    VIR_FREE(ret.mime);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 static int
 remoteStorageVolUpload(virStorageVolPtr vol,
                        virStreamPtr st,
@@ -6425,7 +6465,7 @@ static virDriver remote_driver = {
     remoteDomainSave, /* domainSave */
     remoteDomainRestore, /* domainRestore */
     remoteDomainCoreDump, /* domainCoreDump */
-    NULL, /* domainScreenshot */
+    remoteDomainScreenshot, /* domainScreenshot */
     remoteDomainSetVcpus, /* domainSetVcpus */
     remoteDomainSetVcpusFlags, /* domainSetVcpusFlags */
     remoteDomainGetVcpusFlags, /* domainGetVcpusFlags */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 99e5c95..e115f39 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -714,6 +714,16 @@ struct remote_domain_core_dump_args {
     int flags;
 };
 
+struct remote_domain_screenshot_args {
+    remote_nonnull_domain dom;
+    unsigned int screen;
+    unsigned int flags;
+};
+
+struct remote_domain_screenshot_ret {
+    remote_string mime;
+};
+
 struct remote_domain_get_xml_desc_args {
     remote_nonnull_domain dom;
     int flags;
@@ -2185,8 +2195,9 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207, /* autogen autogen */
     REMOTE_PROC_STORAGE_VOL_UPLOAD = 208, /* skipgen skipgen */
     REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209, /* skipgen skipgen */
-    REMOTE_PROC_DOMAIN_INJECT_NMI = 210 /* autogen autogen */
+    REMOTE_PROC_DOMAIN_INJECT_NMI = 210, /* autogen autogen */
 
+    REMOTE_PROC_DOMAIN_SCREENSHOT = 211 /* skipgen skipgen */
     /*
      * Notice how the entries are grouped in sets of 10 ?
      * Nice isn't it. Please keep it this way when adding more.
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 0507a91..bb4c8d5 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -403,6 +403,14 @@ struct remote_domain_core_dump_args {
         remote_nonnull_string      to;
         int                        flags;
 };
+struct remote_domain_screenshot_args {
+        remote_nonnull_domain      dom;
+        unsigned int               screen;
+        unsigned int               flags;
+};
+struct remote_domain_screenshot_ret {
+        remote_string              mime;
+};
 struct remote_domain_get_xml_desc_args {
         remote_nonnull_domain      dom;
         int                        flags;
-- 
1.7.5.rc3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]