本文整理汇总了C++中CSession::GetMachine方法的典型用法代码示例。如果您正苦于以下问题:C++ CSession::GetMachine方法的具体用法?C++ CSession::GetMachine怎么用?C++ CSession::GetMachine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSession
的用法示例。
在下文中一共展示了CSession::GetMachine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: startMachine
/* static */
bool UIMachine::startMachine(const QString &strID)
{
/* Some restrictions: */
AssertMsgReturn(vboxGlobal().isValid(), ("VBoxGlobal is invalid.."), false);
AssertMsgReturn(!vboxGlobal().virtualMachine(), ("Machine already started.."), false);
/* Restore current snapshot if requested: */
if (vboxGlobal().shouldRestoreCurrentSnapshot())
{
/* Create temporary session: */
CSession session = vboxGlobal().openSession(strID, KLockType_VM);
if (session.isNull())
return false;
/* Which VM we operate on? */
CMachine machine = session.GetMachine();
/* Which snapshot we are restoring? */
CSnapshot snapshot = machine.GetCurrentSnapshot();
/* Prepare restore-snapshot progress: */
CProgress progress = machine.RestoreSnapshot(snapshot);
if (!machine.isOk())
return msgCenter().cannotRestoreSnapshot(machine, snapshot.GetName(), machine.GetName());
/* Show the snapshot-discarding progress: */
msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
if (progress.GetResultCode() != 0)
return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
/* Unlock session finally: */
session.UnlockMachine();
/* Clear snapshot-restoring request: */
vboxGlobal().setShouldRestoreCurrentSnapshot(false);
}
/* For separate process we should launch VM before UI: */
if (vboxGlobal().isSeparateProcess())
{
/* Get corresponding machine: */
CMachine machine = vboxGlobal().virtualBox().FindMachine(vboxGlobal().managedVMUuid());
AssertMsgReturn(!machine.isNull(), ("VBoxGlobal::managedVMUuid() should have filter that case before!\n"), false);
/* Try to launch corresponding machine: */
if (!vboxGlobal().launchMachine(machine, VBoxGlobal::LaunchMode_Separate))
return false;
}
/* Try to create machine UI: */
return create();
}
示例2: isItemRunningHeadless
/* static */
bool UIVMItem::isItemRunningHeadless(UIVMItem *pItem)
{
if (isItemRunning(pItem))
{
/* Open session to determine which frontend VM is started with: */
CSession session = vboxGlobal().openExistingSession(pItem->id());
if (!session.isNull())
{
/* Acquire the session name: */
const QString strSessionName = session.GetMachine().GetSessionName();
/* Close the session early: */
session.UnlockMachine();
/* Check whether we are in 'headless' session: */
return strSessionName == "headless";
}
}
return false;
}
示例3: createVM
//.........这里部分代码省略.........
{
m_machine.SetKeyboardHIDType(KKeyboardHIDType_USBKeyboard);
m_machine.SetPointingHIDType(KPointingHIDType_USBMouse);
if (!fOhciEnabled && !usbDeviceFilters.isNull())
m_machine.AddUSBController("OHCI", KUSBControllerType_OHCI);
}
if (type.GetRecommendedUSBTablet())
{
m_machine.SetPointingHIDType(KPointingHIDType_USBTablet);
if (!fOhciEnabled && !usbDeviceFilters.isNull())
m_machine.AddUSBController("OHCI", KUSBControllerType_OHCI);
}
/* Set HPET flag: */
m_machine.SetHPETEnabled(type.GetRecommendedHPET());
/* Set UTC flags: */
m_machine.SetRTCUseUTC(type.GetRecommendedRTCUseUTC());
/* Set graphic bits: */
if (type.GetRecommended2DVideoAcceleration())
m_machine.SetAccelerate2DVideoEnabled(type.GetRecommended2DVideoAcceleration());
if (type.GetRecommended3DAcceleration())
m_machine.SetAccelerate3DEnabled(type.GetRecommended3DAcceleration());
/* Register the VM prior to attaching hard disks: */
vbox.RegisterMachine(m_machine);
if (!vbox.isOk())
{
msgCenter().cannotRegisterMachine(vbox, m_machine.GetName(), this);
return false;
}
/* Attach default devices: */
{
bool success = false;
QString strMachineId = m_machine.GetId();
CSession session = vboxGlobal().openSession(strMachineId);
if (!session.isNull())
{
CMachine machine = session.GetMachine();
QString strId = field("virtualDiskId").toString();
/* Boot virtual hard drive: */
if (!strId.isNull())
{
UIMedium vmedium = vboxGlobal().medium(strId);
CMedium medium = vmedium.medium(); // @todo r=dj can this be cached somewhere?
machine.AttachDevice(strHDName, 0, 0, KDeviceType_HardDisk, medium);
if (!machine.isOk())
msgCenter().cannotAttachDevice(machine, UIMediumType_HardDisk, field("virtualDiskLocation").toString(),
StorageSlot(ctrHDBus, 0, 0), this);
}
/* Attach empty optical drive: */
machine.AttachDevice(strDVDName, 1, 0, KDeviceType_DVD, CMedium());
if (!machine.isOk())
msgCenter().cannotAttachDevice(machine, UIMediumType_DVD, QString(), StorageSlot(strDVDBus, 1, 0), this);
/* Attach an empty floppy drive if recommended */
if (type.GetRecommendedFloppy()) {
machine.AttachDevice(strFloppyName, 0, 0, KDeviceType_Floppy, CMedium());
if (!machine.isOk())
msgCenter().cannotAttachDevice(machine, UIMediumType_Floppy, QString(),
StorageSlot(KStorageBus_Floppy, 0, 0), this);
}
if (machine.isOk())
{
machine.SaveSettings();
if (machine.isOk())
success = true;
else
msgCenter().cannotSaveMachineSettings(machine, this);
}
session.UnlockMachine();
}
if (!success)
{
/* Unregister on failure */
QVector<CMedium> aMedia = m_machine.Unregister(KCleanupMode_UnregisterOnly); // @todo replace with DetachAllReturnHardDisksOnly once a progress dialog is in place below
if (vbox.isOk())
{
CProgress progress = m_machine.DeleteConfig(aMedia);
progress.WaitForCompletion(-1); // @todo do this nicely with a progress dialog, this can delete lots of files
}
return false;
}
}
/* Ensure we don't try to delete a newly created virtual hard drive on success: */
if (!field("virtualDisk").value<CMedium>().isNull())
field("virtualDisk").value<CMedium>().detach();
return true;
}
示例4: vboxGlobal
//.........这里部分代码省略.........
else
{
/* The HD controller is the same as DVD */
hdCtr = dvdCtr;
ctrHdName = ctrDvdName;
}
/* Turn on PAE, if recommended */
m_Machine.SetCPUProperty(KCPUPropertyType_PAE, type.GetRecommendedPae());
/* Set recommended firmware type */
KFirmwareType fwType = type.GetRecommendedFirmware();
m_Machine.SetFirmwareType(fwType);
/* Set recommended human interface device types */
if (type.GetRecommendedUsbHid())
{
m_Machine.SetKeyboardHidType(KKeyboardHidType_USBKeyboard);
m_Machine.SetPointingHidType(KPointingHidType_USBMouse);
if (!usbController.isNull())
usbController.SetEnabled(true);
}
if (type.GetRecommendedUsbTablet())
{
m_Machine.SetPointingHidType(KPointingHidType_USBTablet);
if (!usbController.isNull())
usbController.SetEnabled(true);
}
/* Set HPET flag */
m_Machine.SetHpetEnabled(type.GetRecommendedHpet());
/* Set UTC flags */
m_Machine.SetRTCUseUTC(type.GetRecommendedRtcUseUtc());
/* Register the VM prior to attaching hard disks */
vbox.RegisterMachine(m_Machine);
if (!vbox.isOk())
{
msgCenter().cannotCreateMachine(vbox, m_Machine, this);
return false;
}
/* Attach default devices */
{
bool success = false;
QString machineId = m_Machine.GetId();
CSession session = vboxGlobal().openSession(machineId);
if (!session.isNull())
{
CMachine m = session.GetMachine();
QString strId = field("hardDiskId").toString();
/* Boot hard disk */
if (!strId.isNull())
{
VBoxMedium vmedium = vboxGlobal().findMedium(strId);
CMedium medium = vmedium.medium(); // @todo r=dj can this be cached somewhere?
m.AttachDevice(ctrHdName, 0, 0, KDeviceType_HardDisk, medium);
if (!m.isOk())
msgCenter().cannotAttachDevice(m, VBoxDefs::MediumType_HardDisk, field("hardDiskLocation").toString(),
StorageSlot(ctrHdBus, 0, 0), this);
}
/* Attach empty CD/DVD ROM Device */
m.AttachDevice(ctrDvdName, 1, 0, KDeviceType_DVD, CMedium());
if (!m.isOk())
msgCenter().cannotAttachDevice(m, VBoxDefs::MediumType_DVD, QString(), StorageSlot(ctrDvdBus, 1, 0), this);
if (m.isOk())
{
m.SaveSettings();
if (m.isOk())
success = true;
else
msgCenter().cannotSaveMachineSettings(m, this);
}
session.UnlockMachine();
}
if (!success)
{
/* Unregister on failure */
QVector<CMedium> aMedia = m_Machine.Unregister(KCleanupMode_UnregisterOnly); // @todo replace with DetachAllReturnHardDisksOnly once a progress dialog is in place below
if (vbox.isOk())
{
CProgress progress = m_Machine.Delete(aMedia);
progress.WaitForCompletion(-1); // @todo do this nicely with a progress dialog, this can delete lots of files
}
return false;
}
}
/* Ensure we don't try to delete a newly created hard disk on success */
if (!field("hardDisk").value<CMedium>().isNull())
field("hardDisk").value<CMedium>().detach();
return true;
}
示例5: cloneVM
bool UIWizardCloneVM::cloneVM()
{
/* Get clone name: */
QString strName = field("cloneName").toString();
/* Should we reinit mac status? */
bool fReinitMACs = field("reinitMACs").toBool();
/* Should we create linked clone? */
bool fLinked = field("linkedClone").toBool();
/* Get clone mode: */
KCloneMode cloneMode = (mode() == WizardMode_Basic && page(Page3)) ||
(mode() == WizardMode_Expert && page(PageExpert)) ?
field("cloneMode").value<KCloneMode>() : KCloneMode_MachineState;
/* Get VBox object: */
CVirtualBox vbox = vboxGlobal().virtualBox();
/* Prepare machine for cloning: */
CMachine srcMachine = m_machine;
/* If the user like to create a linked clone from the current machine, we
* have to take a little bit more action. First we create an snapshot, so
* that new differencing images on the source VM are created. Based on that
* we could use the new snapshot machine for cloning. */
if (fLinked && m_snapshot.isNull())
{
/* Open session: */
CSession session = vboxGlobal().openSession(m_machine.GetId());
if (session.isNull())
return false;
/* Prepare machine: */
CMachine machine = session.GetMachine();
/* Take the snapshot: */
QString strSnapshotName = tr("Linked Base for %1 and %2").arg(m_machine.GetName()).arg(strName);
QString strSnapshotId;
CProgress progress = machine.TakeSnapshot(strSnapshotName, "", true, strSnapshotId);
if (machine.isOk())
{
/* Show the "Taking Snapshot" progress dialog: */
msgCenter().showModalProgressDialog(progress, m_machine.GetName(), ":/progress_snapshot_create_90px.png", this);
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotTakeSnapshot(progress, m_machine.GetName(), this);
return false;
}
}
else
{
msgCenter().cannotTakeSnapshot(machine, m_machine.GetName(), this);
return false;
}
/* Unlock machine finally: */
session.UnlockMachine();
/* Get the new snapshot and the snapshot machine. */
const CSnapshot &newSnapshot = m_machine.FindSnapshot(strSnapshotId);
if (newSnapshot.isNull())
{
msgCenter().cannotFindSnapshotByName(m_machine, strSnapshotName, this);
return false;
}
srcMachine = newSnapshot.GetMachine();
}
/* Create a new machine object. */
const QString &strSettingsFile = vbox.ComposeMachineFilename(strName, QString::null /**< @todo group support */, QString::null, QString::null);
CMachine cloneMachine = vbox.CreateMachine(strSettingsFile, strName, QVector<QString>(), QString::null, QString::null);
if (!vbox.isOk())
{
msgCenter().cannotCreateMachine(vbox, this);
return false;
}
/* Add the keep all MACs option to the import settings when requested. */
QVector<KCloneOptions> options;
if (!fReinitMACs)
options.append(KCloneOptions_KeepAllMACs);
/* Linked clones requested? */
if (fLinked)
options.append(KCloneOptions_Link);
/* Start cloning. */
CProgress progress = srcMachine.CloneTo(cloneMachine, cloneMode, options);
if (!srcMachine.isOk())
{
msgCenter().cannotCreateClone(srcMachine, this);
return false;
}
/* Wait until done. */
msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_clone_90px.png", this);
if (progress.GetCanceled())
return false;
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotCreateClone(progress, srcMachine.GetName(), this);
//.........这里部分代码省略.........