---
src/vbox/vbox_tmpl.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 390fc3b..5c9c271 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -36,6 +36,9 @@
#include <sys/utsname.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "internal.h"
#include "datatypes.h"
@@ -51,6 +54,7 @@
#include "nodeinfo.h"
#include "logging.h"
#include "vbox_driver.h"
+#include "files.h"
/* This one changes from version to version. */
#if VBOX_API_VERSION == 2002
@@ -8522,6 +8526,94 @@ static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
return ret;
}
+#if VBOX_API_VERSION == 4000
+static int
+vboxDomainScreenshot(virDomainPtr dom, const char *path,
+ int flags ATTRIBUTE_UNUSED)
+{
+ VBOX_OBJECT_CHECK(dom->conn, int, -1);
+ IConsole *console = NULL;
+ vboxIID iid = VBOX_IID_INITIALIZER;
+ IMachine *machine = NULL;
+ nsresult rc;
+ int fd = -1;
+
+ vboxIIDFromUUID(&iid, dom->uuid);
+ rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
+ if (NS_FAILED(rc)) {
+ vboxError(VIR_ERR_NO_DOMAIN, "%s",
+ _("no domain with matching uuid"));
+ return -1;
+ }
+
+ rc = VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
+ if (NS_SUCCEEDED(rc)) {
+ rc = data->vboxSession->vtbl->GetConsole(data->vboxSession,
&console);
+ if (NS_SUCCEEDED(rc) && console) {
+ IDisplay *display = NULL;
+
+ console->vtbl->GetDisplay(console, &display);
+
+ if (display) {
+ PRUint32 width, height, bitsPerPixel;
+ PRUint32 screenDataSize;
+ PRUint8 *screenData;
+
+ rc = display->vtbl->GetScreenResolution(display, 0,
+ &width, &height,
+ &bitsPerPixel);
+
+ if (NS_FAILED(rc) || !width || !height) {
+ vboxError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("unable to get screen resolution"));
+ goto endjob;
+ }
+
+ rc = display->vtbl->TakeScreenShotPNGToArray(display, 0,
+ width, height,
+ &screenDataSize,
+ &screenData);
+ if (NS_FAILED(rc)) {
+ vboxError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("failed to take screenshot"));
+ goto endjob;
+ }
+
+ if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY,
+ S_IRUSR|S_IWUSR)) < 0) {
+ vboxError(VIR_ERR_OPERATION_FAILED, _("failed to "
+ "create '%s'"), path);
+ goto endjob;
+ }
+
+ if (safewrite(fd, (char *) screenData, screenDataSize) < 0) {
+ virReportSystemError(errno, _("unable to write data "
+ "to '%s'"), path);
+ goto endjob;
+ }
+
+ if (VIR_CLOSE(fd) < 0) {
+ virReportSystemError(errno, _("error closing
'%s'"),
+ path);
+ goto endjob;
+ }
+
+ ret = 0;
+
+endjob:
+ VBOX_RELEASE(display);
+ }
+ VBOX_RELEASE(console);
+ }
+ VBOX_SESSION_CLOSE();
+ }
+
+ VBOX_RELEASE(machine);
+ vboxIIDUnalloc(&iid);
+ return ret;
+}
+#endif /* VBOX_API_VERSION == 4000 */
+
/**
* Function Tables
*/
@@ -8564,7 +8656,11 @@ virDriver NAME(Driver) = {
vboxDomainSave, /* domainSave */
NULL, /* domainRestore */
NULL, /* domainCoreDump */
+#if VBOX_API_VERSION == 4000
+ vboxDomainScreenshot, /* domainScreenshot */
+#else
NULL, /* domainScreenshot */
+#endif
vboxDomainSetVcpus, /* domainSetVcpus */
vboxDomainSetVcpusFlags, /* domainSetVcpusFlags */
vboxDomainGetVcpusFlags, /* domainGetVcpusFlags */
--
1.7.4