---
src/vbox/vbox_common.c | 47 +++++++++++++++++++++++++++++
src/vbox/vbox_tmpl.c | 65 +++++++++--------------------------------
src/vbox/vbox_uniformed_api.h | 3 ++
3 files changed, 63 insertions(+), 52 deletions(-)
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 01d0104..d796be7 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2362,3 +2362,50 @@ int vboxDomainIsUpdated(virDomainPtr dom)
vboxIIDUnalloc(&iid);
return ret;
}
+
+int vboxDomainSuspend(virDomainPtr dom)
+{
+ VBOX_OBJECT_CHECK(dom->conn, int, -1);
+ IMachine *machine = NULL;
+ vboxIIDUnion iid;
+ IConsole *console = NULL;
+ PRBool isAccessible = PR_FALSE;
+ PRUint32 state;
+
+ if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0)
+ goto cleanup;
+
+ if (!machine)
+ goto cleanup;
+
+ gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
+ if (!isAccessible)
+ goto cleanup;
+
+ gVBoxAPI.UIMachine.GetState(machine, &state);
+
+ if (gVBoxAPI.machineStateChecker.Running(state)) {
+ /* set state pause */
+ gVBoxAPI.UISession.OpenExisting(data, &iid, machine);
+ gVBoxAPI.UISession.GetConsole(data->vboxSession, &console);
+ if (console) {
+ gVBoxAPI.UIConsole.Pause(console);
+ VBOX_RELEASE(console);
+ ret = 0;
+ } else {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("error while suspending the domain"));
+ goto cleanup;
+ }
+ gVBoxAPI.UISession.Close(data->vboxSession);
+ } else {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("machine not in running state to suspend it"));
+ goto cleanup;
+ }
+
+ cleanup:
+ VBOX_RELEASE(machine);
+ vboxIIDUnalloc(&iid);
+ return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 669a89d..df7c290 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -932,58 +932,6 @@ vboxSocketParseAddrUtf16(vboxGlobalData *data, const PRUnichar
*utf16,
return result;
}
-static int vboxDomainSuspend(virDomainPtr dom)
-{
- VBOX_OBJECT_CHECK(dom->conn, int, -1);
- IMachine *machine = NULL;
- vboxIID iid = VBOX_IID_INITIALIZER;
- IConsole *console = NULL;
- PRBool isAccessible = PR_FALSE;
- PRUint32 state;
- nsresult rc;
-
- vboxIIDFromUUID(&iid, dom->uuid);
- rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
- if (NS_FAILED(rc)) {
- virReportError(VIR_ERR_NO_DOMAIN,
- _("no domain with matching id %d"), dom->id);
- goto cleanup;
- }
-
- if (!machine)
- goto cleanup;
-
- machine->vtbl->GetAccessible(machine, &isAccessible);
- if (isAccessible) {
- machine->vtbl->GetState(machine, &state);
-
- if (state == MachineState_Running) {
- /* set state pause */
- VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
- data->vboxSession->vtbl->GetConsole(data->vboxSession,
&console);
- if (console) {
- console->vtbl->Pause(console);
- VBOX_RELEASE(console);
- ret = 0;
- } else {
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("error while suspending the domain"));
- goto cleanup;
- }
- VBOX_SESSION_CLOSE();
- } else {
- virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("machine not in running state to suspend it"));
- goto cleanup;
- }
- }
-
- cleanup:
- VBOX_RELEASE(machine);
- vboxIIDUnalloc(&iid);
- return ret;
-}
-
static int vboxDomainResume(virDomainPtr dom)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
@@ -10045,6 +9993,12 @@ _consoleSaveState(IConsole *console, IProgress **progress)
}
static nsresult
+_consolePause(IConsole *console)
+{
+ return console->vtbl->Pause(console);
+}
+
+static nsresult
_progressWaitForCompletion(IProgress *progress, PRInt32 timeout)
{
return progress->vtbl->WaitForCompletion(progress, timeout);
@@ -10472,6 +10426,11 @@ static bool _machineStateNotStart(PRUint32 state)
(state == MachineState_Aborted));
}
+static bool _machineStateRunning(PRUint32 state)
+{
+ return state == MachineState_Running;
+}
+
static vboxUniformedPFN _UPFN = {
.Initialize = _pfnInitialize,
.Uninitialize = _pfnUninitialize,
@@ -10552,6 +10511,7 @@ static vboxUniformedISession _UISession = {
static vboxUniformedIConsole _UIConsole = {
.SaveState = _consoleSaveState,
+ .Pause = _consolePause,
};
static vboxUniformedIProgress _UIProgress = {
@@ -10637,6 +10597,7 @@ static vboxUniformedIMedium _UIMedium = {
static uniformedMachineStateChecker _machineStateChecker = {
.Online = _machineStateOnline,
.NotStart = _machineStateNotStart,
+ .Running = _machineStateRunning,
};
void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 1568948..8334437 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -237,6 +237,7 @@ typedef struct {
/* Functions for IConsole */
typedef struct {
nsresult (*SaveState)(IConsole *console, IProgress **progress);
+ nsresult (*Pause)(IConsole *console);
} vboxUniformedIConsole;
/* Functions for IProgress */
@@ -339,6 +340,7 @@ typedef struct {
typedef struct {
bool (*Online)(PRUint32 state);
bool (*NotStart)(PRUint32 state);
+ bool (*Running)(PRUint32 state);
} uniformedMachineStateChecker;
typedef struct {
@@ -414,6 +416,7 @@ virDomainPtr vboxDomainCreateXML(virConnectPtr conn, const char *xml,
int vboxDomainIsActive(virDomainPtr dom);
int vboxDomainIsPersistent(virDomainPtr dom);
int vboxDomainIsUpdated(virDomainPtr dom);
+int vboxDomainSuspend(virDomainPtr dom);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
--
1.7.9.5