本文整理汇总了C++中CSession::isNull方法的典型用法代码示例。如果您正苦于以下问题:C++ CSession::isNull方法的具体用法?C++ CSession::isNull怎么用?C++ CSession::isNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CSession
的用法示例。
在下文中一共展示了CSession::isNull方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: sltRestoreSnapshot
void VBoxSnapshotsWgt::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false*/)
{
/* Get currently chosen item: */
SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;
AssertReturn(pItem, (void)0);
/* Detemine snapshot id: */
QString strSnapshotId = pItem->snapshotId();
AssertReturn(!strSnapshotId.isNull(), (void)0);
/* Get currently desired snapshot: */
CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId);
/* Ask the user if he really wants to restore the snapshot: */
int iResultCode = AlertButton_Ok;
if (!fSuppressNonCriticalWarnings || mMachine.GetCurrentStateModified())
{
iResultCode = msgCenter().confirmSnapshotRestoring(snapshot.GetName(), mMachine.GetCurrentStateModified());
if (iResultCode & AlertButton_Cancel)
return;
}
/* If user also confirmed new snapshot creation: */
if (iResultCode & AlertOption_CheckBox)
{
/* Take snapshot of changed current state: */
mTreeWidget->setCurrentItem(curStateItem());
if (!takeSnapshot())
return;
}
/* Open a direct session (this call will handle all errors): */
CSession session = vboxGlobal().openSession(mMachineId);
if (session.isNull())
return;
/* Restore chosen snapshot: */
CConsole console = session.GetConsole();
CProgress progress = console.RestoreSnapshot(snapshot);
if (console.isOk())
{
msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png");
if (progress.GetResultCode() != 0)
msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), mMachine.GetName());
}
else
msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), mMachine.GetName());
/* Unlock machine finally: */
session.UnlockMachine();
}
示例3: putBackToSnapshot
void VBoxSnapshotDetailsDlg::putBackToSnapshot()
{
AssertReturn (!mSnapshot.isNull(), (void) 0);
/* We need a session when we manipulate the snapshot data of a machine. */
CSession session = vboxGlobal().openExistingSession(mSnapshot.GetMachine().GetId());
if (session.isNull())
return;
mSnapshot.SetName(mLeName->text());
mSnapshot.SetDescription(mTeDescription->toPlainText());
/* Close the session again. */
session.UnlockMachine();
}
示例4: sltDeleteSnapshot
void VBoxSnapshotsWgt::sltDeleteSnapshot()
{
SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :
static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());
AssertReturn (item, (void) 0);
QString snapId = item->snapshotId();
AssertReturn (!snapId.isNull(), (void) 0);
CSnapshot snapshot = mMachine.FindSnapshot(snapId);
if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName()))
return;
/** @todo check available space on the target filesystem etc etc. */
#if 0
if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(snapshot.GetName(),
"/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi",
"59 GiB",
"15 GiB"))
return;
#endif
/* Open a direct session (this call will handle all errors) */
bool busy = mSessionState != KSessionState_Unlocked;
CSession session;
if (busy)
session = vboxGlobal().openExistingSession(mMachineId);
else
session = vboxGlobal().openSession(mMachineId);
if (session.isNull())
return;
CConsole console = session.GetConsole();
CProgress progress = console.DeleteSnapshot (snapId);
if (console.isOk())
{
/* Show the progress dialog */
msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png");
if (progress.GetResultCode() != 0)
msgCenter().cannotRemoveSnapshot(progress, snapshot.GetName(), mMachine.GetName());
}
else
msgCenter().cannotRemoveSnapshot(console, snapshot.GetName(), mMachine.GetName());
session.UnlockMachine();
}
示例5: 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;
}
示例6: createVM
bool UIWizardNewVM::createVM()
{
/* Get VBox object: */
CVirtualBox vbox = vboxGlobal().virtualBox();
/* OS type: */
CGuestOSType type = field("type").value<CGuestOSType>();
QString strTypeId = type.GetId();
/* Create virtual machine: */
if (m_machine.isNull())
{
QVector<QString> groups;
if (!m_strGroup.isEmpty())
groups << m_strGroup;
m_machine = vbox.CreateMachine(field("machineFilePath").toString(),
field("machineBaseName").toString(),
groups, strTypeId, QString());
if (!vbox.isOk())
{
msgCenter().cannotCreateMachine(vbox, this);
return false;
}
/* The First RUN Wizard is to be shown:
* 1. if we don't attach any virtual hard-drive
* 2. or attach a new (empty) one.
* Usually we are assigning extra-data values through UIExtraDataManager,
* but in that special case VM was not registered yet, so UIExtraDataManager is unaware of it. */
if (field("virtualDiskId").toString().isNull() || !field("virtualDisk").value<CMedium>().isNull())
m_machine.SetExtraData(GUI_FirstRun, "yes");
}
/* RAM size: */
m_machine.SetMemorySize(field("ram").toInt());
/* VRAM size - select maximum between recommended and minimum for fullscreen: */
m_machine.SetVRAMSize(qMax(type.GetRecommendedVRAM(), (ULONG)(VBoxGlobal::requiredVideoMemory(strTypeId) / _1M)));
/* Selecting recommended chipset type: */
m_machine.SetChipsetType(type.GetRecommendedChipset());
/* Selecting recommended Audio Controller: */
m_machine.GetAudioAdapter().SetAudioController(type.GetRecommendedAudioController());
/* And the Audio Codec: */
m_machine.GetAudioAdapter().SetAudioCodec(type.GetRecommendedAudioCodec());
/* Enabling audio by default: */
m_machine.GetAudioAdapter().SetEnabled(true);
/* Enable the OHCI and EHCI controller by default for new VMs. (new in 2.2): */
CUSBDeviceFilters usbDeviceFilters = m_machine.GetUSBDeviceFilters();
bool fOhciEnabled = false;
if (!usbDeviceFilters.isNull() && type.GetRecommendedUSB3() && m_machine.GetUSBProxyAvailable())
{
/* USB 3.0 is only available if the proper ExtPack is installed. */
CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager();
if (manager.IsExtPackUsable(GUI_ExtPackName))
{
m_machine.AddUSBController("XHCI", KUSBControllerType_XHCI);
/* xHci includes OHCI */
fOhciEnabled = true;
}
}
if ( !fOhciEnabled
&& !usbDeviceFilters.isNull() && type.GetRecommendedUSB() && m_machine.GetUSBProxyAvailable())
{
m_machine.AddUSBController("OHCI", KUSBControllerType_OHCI);
fOhciEnabled = true;
/* USB 2.0 is only available if the proper ExtPack is installed.
* Note. Configuring EHCI here and providing messages about
* the missing extpack isn't exactly clean, but it is a
* necessary evil to patch over legacy compatability issues
* introduced by the new distribution model. */
CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager();
if (manager.IsExtPackUsable(GUI_ExtPackName))
m_machine.AddUSBController("EHCI", KUSBControllerType_EHCI);
}
/* Create a floppy controller if recommended: */
QString strFloppyName = getNextControllerName(KStorageBus_Floppy);
if (type.GetRecommendedFloppy())
{
m_machine.AddStorageController(strFloppyName, KStorageBus_Floppy);
CStorageController flpCtr = m_machine.GetStorageControllerByName(strFloppyName);
flpCtr.SetControllerType(KStorageControllerType_I82078);
}
/* Create recommended DVD storage controller: */
KStorageBus strDVDBus = type.GetRecommendedDVDStorageBus();
QString strDVDName = getNextControllerName(strDVDBus);
m_machine.AddStorageController(strDVDName, strDVDBus);
/* Set recommended DVD storage controller type: */
CStorageController dvdCtr = m_machine.GetStorageControllerByName(strDVDName);
KStorageControllerType dvdStorageControllerType = type.GetRecommendedDVDStorageController();
dvdCtr.SetControllerType(dvdStorageControllerType);
/* Create recommended HD storage controller if it's not the same as the DVD controller: */
KStorageBus ctrHDBus = type.GetRecommendedHDStorageBus();
KStorageControllerType hdStorageControllerType = type.GetRecommendedHDStorageController();
//.........这里部分代码省略.........
示例7: takeSnapshot
bool VBoxSnapshotsWgt::takeSnapshot()
{
/* Prepare result: */
bool fIsValid = true;
/* Get currently chosen item: */
SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;
AssertReturn(pItem, (bool)0);
/* Open a session to work with corresponding VM: */
CSession session;
if (mSessionState != KSessionState_Unlocked)
session = vboxGlobal().openExistingSession(mMachineId);
else
session = vboxGlobal().openSession(mMachineId);
fIsValid = !session.isNull();
if (fIsValid)
{
/* Get corresponding console object also: */
CConsole console = session.GetConsole();
/* Remember runtime state: */
bool fAtRuntime = mMachine.GetState() == KMachineState_Running;
/* Remember paused state: */
bool fWasPaused = mMachine.GetState() == KMachineState_Paused ||
mMachine.GetState() == KMachineState_TeleportingPausedVM;
/* Pause VM if necessary: */
if (fIsValid && fAtRuntime && !fWasPaused)
{
/* Pausing VM: */
console.Pause();
if (!console.isOk())
{
msgCenter().cannotPauseMachine(console);
fIsValid = false;
}
}
if (fIsValid)
{
/* Create take-snapshot dialog: */
QWidget *pDlgParent = windowManager().realParentWindow(this);
QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, mMachine);
windowManager().registerNewParent(pDlg, pDlgParent);
/* Assign corresponding icon: */
pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId()));
/* Search for the max available snapshot index: */
int iMaxSnapShotIndex = 0;
QString snapShotName = tr("Snapshot %1");
QRegExp regExp(QString("^") + snapShotName.arg("([0-9]+)") + QString("$"));
QTreeWidgetItemIterator iterator(mTreeWidget);
while (*iterator)
{
QString snapShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0);
int pos = regExp.indexIn(snapShot);
if (pos != -1)
iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex;
++iterator;
}
pDlg->mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1));
/* Exec the dialog: */
bool fDialogAccepted = pDlg->exec() == QDialog::Accepted;
/* Is the dialog still valid? */
if (pDlg)
{
/* Acquire variables: */
QString strSnapshotName = pDlg->mLeName->text().trimmed();
QString strSnapshotDescription = pDlg->mTeDescription->toPlainText();
/* Destroy dialog early: */
delete pDlg;
/* Was the dialog accepted? */
if (fDialogAccepted)
{
/* Prepare the take-snapshot progress: */
CProgress progress = console.TakeSnapshot(strSnapshotName, strSnapshotDescription);
if (console.isOk())
{
/* Show the take-snapshot progress: */
msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png");
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotTakeSnapshot(progress, mMachine.GetName());
fIsValid = false;
}
}
else
{
msgCenter().cannotTakeSnapshot(console, mMachine.GetName());
fIsValid = false;
}
}
else
fIsValid = false;
//.........这里部分代码省略.........
示例8: vboxGlobal
bool UINewVMWzdPage5::constructMachine()
{
CVirtualBox vbox = vboxGlobal().virtualBox();
/* OS type */
CGuestOSType type = field("type").value<CGuestOSType>();
AssertMsg(!type.isNull(), ("GuestOSType must return non-null type"));
QString typeId = type.GetId();
/* Create a machine with the default settings file location */
if (m_Machine.isNull())
{
m_Machine = vbox.CreateMachine(QString::null, // auto-compose filename
field("name").toString(),
typeId,
QString::null, // machine ID
false); // forceOverwrite
if (!vbox.isOk())
{
msgCenter().cannotCreateMachine(vbox, this);
return false;
}
/* The FirstRun wizard is to be shown only when we don't attach any hard disk or attach a new (empty) one.
* Selecting an existing hard disk will cancel the wizard. */
if (field("hardDiskId").toString().isNull() || !field("hardDisk").value<CMedium>().isNull())
m_Machine.SetExtraData(VBoxDefs::GUI_FirstRun, "yes");
}
/* RAM size */
m_Machine.SetMemorySize(field("ram").toInt());
/* VRAM size - select maximum between recommended and minimum for fullscreen */
m_Machine.SetVRAMSize (qMax (type.GetRecommendedVRAM(),
(ULONG) (VBoxGlobal::requiredVideoMemory(typeId) / _1M)));
/* Selecting recommended chipset type */
m_Machine.SetChipsetType(type.GetRecommendedChipset());
/* Selecting recommended Audio Controller */
m_Machine.GetAudioAdapter().SetAudioController(type.GetRecommendedAudioController());
/* Enabling audio by default */
m_Machine.GetAudioAdapter().SetEnabled(true);
/* Enable the OHCI and EHCI controller by default for new VMs. (new in 2.2) */
CUSBController usbController = m_Machine.GetUSBController();
if ( !usbController.isNull()
&& usbController.GetProxyAvailable())
{
usbController.SetEnabled(true);
/*
* USB 2.0 is only available if the proper ExtPack is installed.
*
* Note. Configuring EHCI here and providing messages about
* the missing extpack isn't exactly clean, but it is a
* necessary evil to patch over legacy compatability issues
* introduced by the new distribution model.
*/
CExtPackManager manager = vboxGlobal().virtualBox().GetExtensionPackManager();
if (manager.IsExtPackUsable(UI_ExtPackName))
usbController.SetEnabledEhci(true);
}
/* Create recommended DVD storage controller */
KStorageBus ctrDvdBus = type.GetRecommendedDvdStorageBus();
QString ctrDvdName = getNextControllerName(ctrDvdBus);
m_Machine.AddStorageController(ctrDvdName, ctrDvdBus);
/* Set recommended DVD storage controller type */
CStorageController dvdCtr = m_Machine.GetStorageControllerByName(ctrDvdName);
KStorageControllerType dvdStorageControllerType = type.GetRecommendedDvdStorageController();
dvdCtr.SetControllerType(dvdStorageControllerType);
/* Create recommended HD storage controller if it's not the same as the DVD controller */
KStorageBus ctrHdBus = type.GetRecommendedHdStorageBus();
KStorageControllerType hdStorageControllerType = type.GetRecommendedHdStorageController();
CStorageController hdCtr;
QString ctrHdName;
if (ctrHdBus != ctrDvdBus || hdStorageControllerType != dvdStorageControllerType)
{
ctrHdName = getNextControllerName(ctrHdBus);
m_Machine.AddStorageController(ctrHdName, ctrHdBus);
hdCtr = m_Machine.GetStorageControllerByName(ctrHdName);
hdCtr.SetControllerType(hdStorageControllerType);
/* Set the port count to 1 if SATA is used. */
if (hdStorageControllerType == KStorageControllerType_IntelAhci)
hdCtr.SetPortCount(1);
}
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());
//.........这里部分代码省略.........
示例9: createClone
bool UICloneVMWizard::createClone(const QString &strName, KCloneMode mode, bool fReinitMACs, bool fLinked /* = false */)
{
CVirtualBox vbox = vboxGlobal().virtualBox();
const QString &strSettingsFile = vbox.ComposeMachineFilename(strName, QString::null);
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())
{
const QString &strId = m_machine.GetId();
CSession session = vboxGlobal().openSession(strId);
if (session.isNull())
return false;
CConsole console = session.GetConsole();
/* Take the snapshot */
QString strSnapshotName = tr("Linked Base for %1 and %2").arg(m_machine.GetName()).arg(strName);
CProgress progress = console.TakeSnapshot(strSnapshotName, "");
if (console.isOk())
{
/* Show the "Taking Snapshot" progress dialog */
msgCenter().showModalProgressDialog(progress, m_machine.GetName(), ":/progress_snapshot_create_90px.png", this, true);
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotTakeSnapshot(progress);
return false;
}
}
else
{
msgCenter().cannotTakeSnapshot(console);
return false;
}
/* Unlock machine finally: */
session.UnlockMachine();
/* Get the new snapshot and the snapshot machine. */
const CSnapshot &newSnapshot = m_machine.FindSnapshot(strSnapshotName);
if (newSnapshot.isNull())
{
msgCenter().cannotFindSnapshotByName(this, m_machine, strSnapshotName);
return false;
}
srcMachine = newSnapshot.GetMachine();
}
/* Create a new machine object. */
CMachine cloneMachine = vbox.CreateMachine(strSettingsFile, strName, QString::null, QString::null, false);
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, mode, options);
if (!srcMachine.isOk())
{
msgCenter().cannotCreateClone(srcMachine, this);
return false;
}
/* Wait until done. */
msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_clone_90px.png", this, true);
if (progress.GetCanceled())
return false;
if (!progress.isOk() || progress.GetResultCode() != 0)
{
msgCenter().cannotCreateClone(srcMachine, progress, this);
return false;
}
/* Finally register the clone machine. */
vbox.RegisterMachine(cloneMachine);
if (!vbox.isOk())
{
msgCenter().cannotRegisterMachine(vbox, cloneMachine, this);
return false;
}
return true;
}