VirtualBox

Changeset 47831 in vbox


Ignore:
Timestamp:
Aug 18, 2013 4:19:10 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88092
Message:

VirtualBox: Added --restore-current command line option. Changed relate cannotRestoreSnapshot() methods to return false so we can save 3-4 unnecessary lines in the usual error paths. Added --no-aggressive-caching command line option to delay media caching when starting VMs.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r47510 r47831  
    849849}
    850850
    851 void UIMessageCenter::cannotRestoreSnapshot(const CConsole &console, const QString &strSnapshotName, const QString &strMachineName) const
     851bool UIMessageCenter::cannotRestoreSnapshot(const CConsole &console, const QString &strSnapshotName, const QString &strMachineName) const
    852852{
    853853    error(0, MessageType_Error,
     
    855855             .arg(strSnapshotName, strMachineName),
    856856          formatErrorInfo(console));
    857 }
    858 
    859 void UIMessageCenter::cannotRestoreSnapshot(const CProgress &progress, const QString &strSnapshotName, const QString &strMachineName) const
     857    return false;
     858}
     859
     860bool UIMessageCenter::cannotRestoreSnapshot(const CProgress &progress, const QString &strSnapshotName, const QString &strMachineName) const
    860861{
    861862    error(0, MessageType_Error,
     
    863864             .arg(strSnapshotName, strMachineName),
    864865          formatErrorInfo(progress));
     866    return false;
    865867}
    866868
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r47510 r47831  
    205205    void cannotTakeSnapshot(const CConsole &console, const QString &strMachineName, QWidget *pParent = 0) const;
    206206    void cannotTakeSnapshot(const CProgress &progress, const QString &strMachineName, QWidget *pParent = 0) const;
    207     void cannotRestoreSnapshot(const CConsole &console, const QString &strSnapshotName, const QString &strMachineName) const;
    208     void cannotRestoreSnapshot(const CProgress &progress, const QString &strSnapshotName, const QString &strMachineName) const;
     207    bool cannotRestoreSnapshot(const CConsole &console, const QString &strSnapshotName, const QString &strMachineName) const;
     208    bool cannotRestoreSnapshot(const CProgress &progress, const QString &strSnapshotName, const QString &strMachineName) const;
    209209    void cannotRemoveSnapshot(const CConsole &console, const QString &strSnapshotName, const QString &strMachineName) const;
    210210    void cannotRemoveSnapshot(const CProgress &progress, const QString &strSnapshotName, const QString &strMachineName) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r47775 r47831  
    107107#include "CMediumFormat.h"
    108108#include "CSharedFolder.h"
     109#include "CConsole.h"
     110#include "CSnapshot.h"
    109111
    110112/* Other VBox includes: */
     
    266268    , mMediaEnumThread (NULL)
    267269    , mIsKWinManaged (false)
     270#if defined(DEBUG_bird)
     271    , mAgressiveCaching(false)
     272#else
     273    , mAgressiveCaching(true)
     274#endif
     275    , mRestoreCurrentSnapshot(false)
    268276    , mDisablePatm(false)
    269277    , mDisableCsam(false)
     
    384392    AssertMsg(mValid, ("VBoxGlobal is invalid"));
    385393    AssertMsg(!m_pVirtualMachine, ("Machine already started"));
     394
     395    /* Restore current snapshot if asked to do so: */
     396    if (mRestoreCurrentSnapshot)
     397    {
     398        CSession session = vboxGlobal().openSession(strMachineId, KLockType_VM);
     399        if (session.isNull())
     400            return false;
     401
     402        CConsole  console  = session.GetConsole();
     403        CMachine  machine  = session.GetMachine();
     404        CSnapshot snapshot = machine.GetCurrentSnapshot();
     405        CProgress progress = console.RestoreSnapshot(snapshot);
     406        if (!console.isOk())
     407            return msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), machine.GetName());
     408
     409        /* Show the snapshot-discard progress: */
     410        msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
     411        if (progress.GetResultCode() != 0)
     412            return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
     413        session.UnlockMachine();
     414
     415        /* Clear the restore flag so media enum can be started, should be safe now. */
     416        mRestoreCurrentSnapshot = false;
     417    }
    386418
    387419    /* Create VM session: */
     
    948980    {
    949981        /* Medium may be new and not already in the media list, request refresh */
    950         startEnumeratingMedia();
     982        startEnumeratingMedia(true /*fReallyNecessary*/);
    951983        if (!findMedium (cmedium, medium))
    952984            /* Medium might be deleted already, return null string */
     
    17361768 * described above.
    17371769 *
     1770 * @param   fReallyNecessary    Whether the caller actually needs the media info
     1771 *                              now, or is just trying to be nice and start the
     1772 *                              IPC storm... er... caching process early.
     1773 *
    17381774 * @sa #currentMediaList()
    17391775 * @sa #isMediaEnumerationStarted()
    17401776 */
    1741 void VBoxGlobal::startEnumeratingMedia()
     1777void VBoxGlobal::startEnumeratingMedia(bool fReallyNecessary)
    17421778{
    17431779    AssertReturnVoid (mValid);
     
    17491785    /* Ignore the request during VBoxGlobal cleanup: */
    17501786    if (m_sfCleanupInProgress)
     1787        return;
     1788
     1789    /* If asked to restore snapshot, don't do this till *after* we're done
     1790     * restoring or the code with have a heart attack. */
     1791    if (shouldRestoreCurrentSnapshot())
     1792        return;
     1793
     1794    /* Developer doesn't want any unnecessary media caching! */
     1795    if (!fReallyNecessary && !agressiveCaching())
    17511796        return;
    17521797
     
    44554500            }
    44564501        }
    4457         else if (!::strcmp (arg, "--no-startvm-errormsgbox"))
     4502        else if (!::strcmp(arg, "--no-startvm-errormsgbox"))
    44584503            mShowStartVMErrors = false;
     4504        else if (!::strcmp(arg, "--aggressive-caching"))
     4505            mAgressiveCaching = true;
     4506        else if (!::strcmp(arg, "--no-aggressive-caching"))
     4507            mAgressiveCaching = false;
     4508        else if (!::strcmp(arg, "--restore-current"))
     4509            mRestoreCurrentSnapshot = true;
    44594510        else if (!::strcmp(arg, "--disable-patm"))
    44604511            mDisablePatm = true;
     
    44754526        }
    44764527#ifdef VBOX_WITH_DEBUGGER_GUI
    4477         else if (!::strcmp (arg, "-dbg") || !::strcmp (arg, "--dbg"))
     4528        else if (!::strcmp(arg, "-dbg") || !::strcmp (arg, "--dbg"))
    44784529            setDebuggerVar(&mDbgEnabled, true);
    44794530        else if (!::strcmp( arg, "-debug") || !::strcmp (arg, "--debug"))
     
    44854536            mStartPaused = true;
    44864537        }
    4487         else if (!::strcmp (arg, "--debug-command-line"))
     4538        else if (!::strcmp(arg, "--debug-command-line"))
    44884539        {
    44894540            setDebuggerVar(&mDbgEnabled, true);
     
    44924543            mStartPaused = true;
    44934544        }
    4494         else if (!::strcmp (arg, "--debug-statistics"))
     4545        else if (!::strcmp(arg, "--debug-statistics"))
    44954546        {
    44964547            setDebuggerVar(&mDbgEnabled, true);
     
    44994550            mStartPaused = true;
    45004551        }
    4501         else if (!::strcmp (arg, "-no-debug") || !::strcmp (arg, "--no-debug"))
     4552        else if (!::strcmp(arg, "-no-debug") || !::strcmp(arg, "--no-debug"))
    45024553        {
    45034554            setDebuggerVar(&mDbgEnabled, false);
     
    45074558        }
    45084559        /* Not quite debug options, but they're only useful with the debugger bits. */
    4509         else if (!::strcmp (arg, "--start-paused"))
     4560        else if (!::strcmp(arg, "--start-paused"))
    45104561            mStartPaused = true;
    4511         else if (!::strcmp (arg, "--start-running"))
     4562        else if (!::strcmp(arg, "--start-running"))
    45124563            mStartPaused = false;
    45134564#endif
     
    45764627     * but this method should be run anyway just to enumerate null UIMedium object,
    45774628     * used by some VBox smart widgets, like VBoxMediaComboBox: */
    4578     vboxGlobal().startEnumeratingMedia();
     4629    vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
    45794630
    45804631    /* Prepare global settings change handler: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r47478 r47831  
    124124    const QRect availableGeometry(int iScreen = 0) const;
    125125
     126    bool agressiveCaching() const { return mAgressiveCaching; }
     127    bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
    126128    bool isPatmDisabled() const { return mDisablePatm; }
    127129    bool isCsamDisabled() const { return mDisableCsam; }
     
    239241    CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
    240242
    241     void startEnumeratingMedia();
     243    void startEnumeratingMedia(bool fReallyNecessary);
    242244
    243245    void reloadProxySettings();
     
    474476    bool mIsKWinManaged;
    475477
     478    /** The --aggressive-caching / --no-aggressive-caching option. */
     479    bool mAgressiveCaching;
     480    /** The --restore-current option. */
     481    bool mRestoreCurrentSnapshot;
    476482    /** The --disable-patm option. */
    477483    bool mDisablePatm;
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r46430 r47831  
    251251            "  --rmode %-18s select different render mode (default is %s)\n"
    252252            "  --no-startvm-errormsgbox   do not show a message box for VM start errors\n"
     253            "  --restore-current          restore the current snapshot before starting\n"
     254            "  --no-aggressive-caching    delays caching media info in VM processes\n"
    253255# ifdef VBOX_GUI_WITH_PIDFILE
    254256            "  --pidfile <file>           create a pidfile file when a VM is up and running\n"
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp

    r46831 r47831  
    511511
    512512    if (aRefresh && !vboxGlobal().isMediaEnumerationStarted())
    513         vboxGlobal().startEnumeratingMedia();
     513        vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
    514514    else
    515515    {
     
    616616{
    617617    /* Start enumerating media */
    618     vboxGlobal().startEnumeratingMedia();
     618    vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
    619619}
    620620
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp

    r47478 r47831  
    383383
    384384    /* Cache IMedium data: */
    385     vboxGlobal().startEnumeratingMedia();
     385    vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
    386386
    387387    /* Load machine settings: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r47478 r47831  
    376376                CSnapshot snapshot = machine.GetCurrentSnapshot();
    377377                CProgress progress = console.RestoreSnapshot(snapshot);
    378                 if (console.isOk())
    379                 {
    380                     /* Show the snapshot-discard progress: */
    381                     msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
    382                     if (progress.GetResultCode() != 0)
    383                     {
    384                         /* Failed in progress: */
    385                         msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
    386                         return false;
    387                     }
    388                 }
    389                 else
    390                 {
    391                     /* Failed in console: */
    392                     msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), machine.GetName());
    393                     return false;
    394                 }
     378                if (!console.isOk())
     379                    return msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), machine.GetName());
     380
     381                /* Show the snapshot-discard progress: */
     382                msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png");
     383                if (progress.GetResultCode() != 0)
     384                    return msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), machine.GetName());
    395385            }
    396386        }
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp

    r47573 r47831  
    17351735     * lasted point, where we can start. The rest of the media checking is done
    17361736     * in a background thread. */
    1737     vboxGlobal().startEnumeratingMedia();
     1737    vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
    17381738
    17391739    /* Initialize pixmap pool */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp

    r44528 r47831  
    9090{
    9191    if (!vboxGlobal().isMediaEnumerationStarted())
    92         vboxGlobal().startEnumeratingMedia();
     92        vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
    9393    else
    9494        refresh();
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette