---
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 cc25633..62ab43b 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -2354,3 +2354,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 96df49c..f8d4b8f 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -916,58 +916,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);
@@ -10026,6 +9974,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);
@@ -10461,6 +10415,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,
@@ -10537,6 +10496,7 @@ static vboxUniformedISession _UISession = {
static vboxUniformedIConsole _UIConsole = {
.SaveState = _consoleSaveState,
+ .Pause = _consolePause,
};
static vboxUniformedIProgress _UIProgress = {
@@ -10626,6 +10586,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 8397d1b..f7d674e 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -249,6 +249,7 @@ typedef struct {
/* Functions for IConsole */
typedef struct {
nsresult (*SaveState)(IConsole *console, IProgress **progress);
+ nsresult (*Pause)(IConsole *console);
} vboxUniformedIConsole;
/* Functions for IProgress */
@@ -356,6 +357,7 @@ typedef struct {
typedef struct {
bool (*Online)(PRUint32 state);
bool (*NotStart)(PRUint32 state);
+ bool (*Running)(PRUint32 state);
} uniformedMachineStateChecker;
typedef struct {
@@ -431,6 +433,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