VirtualBox

Ignore:
Timestamp:
Apr 13, 2015 3:53:01 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99520
Message:

Main/Console+Machine+Session+Snapshot: move the save state and snapshot related methods from IConsole to IMachine, with lots of unavoidable code restructuring and cleanup. Also define two new machine states (so that the "Saving" one is specifically for saving state now) which requires more changes everywhere
Frontends: necessary adjustments
doc/SDK: document the changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/MachineImpl.h

    r55168 r55214  
    125125        struct Session
    126126        {
     127            /** Type of lock which created this session */
     128            LockType_T mLockType;
     129
    127130            /** Control of the direct session opened by lockMachine() */
    128131            ComPtr<IInternalSessionControl> mDirectControl;
     
    597600    }
    598601
    599 
     602    static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcszMsg, ...);
    600603
    601604protected:
     
    712715    bool i_isControllerHotplugCapable(StorageControllerType_T enmCtrlType);
    713716
    714     struct DeleteTask;
    715     static DECLCALLBACK(int) deleteThread(RTTHREAD Thread, void *pvUser);
    716     HRESULT i_deleteTaskWorker(DeleteTask &task);
    717717    Utf8Str i_getExtraData(const Utf8Str &strKey);
    718718
     
    778778
    779779    uint64_t                        uRegistryNeedsSaving;
     780
     781    /**
     782     * Abstract base class for all Machine or SessionMachine related
     783     * asynchronous tasks. This is necessary since RTThreadCreate cannot call
     784     * a (non-static) method as its thread function, so instead we have it call
     785     * the static Machine::taskHandler, which then calls the handler() method
     786     * in here (implemented by the subclasses).
     787     */
     788    struct Task
     789    {
     790        Task(Machine *m, Progress *p, const Utf8Str &t)
     791            : m_pMachine(m),
     792              m_machineCaller(m),
     793              m_pProgress(p),
     794              m_strTaskName(t),
     795              m_machineStateBackup(m->mData->mMachineState) // save the current machine state
     796        {}
     797
     798        HRESULT createThread()
     799        {
     800            int vrc = RTThreadCreate(NULL,
     801                                     taskHandler,
     802                                     (void *)this,
     803                                     0,
     804                                     RTTHREADTYPE_MAIN_WORKER,
     805                                     0,
     806                                     m_strTaskName.c_str());
     807            if (RT_FAILURE(vrc))
     808            {
     809                HRESULT rc = Machine::i_setErrorStatic(E_FAIL, Machine::tr("Could not create thread \"%s\" (%Rrc)"), m_strTaskName.c_str(), vrc);
     810                delete this;
     811                return rc;
     812            }
     813            return S_OK;
     814        }
     815
     816        void modifyBackedUpState(MachineState_T s)
     817        {
     818            *const_cast<MachineState_T *>(&m_machineStateBackup) = s;
     819        }
     820
     821        virtual void handler() = 0;
     822
     823        ComObjPtr<Machine>       m_pMachine;
     824        AutoCaller                      m_machineCaller;
     825        ComObjPtr<Progress>             m_pProgress;
     826        Utf8Str                         m_strTaskName;
     827        const MachineState_T            m_machineStateBackup;
     828    };
     829
     830    struct DeleteConfigTask;
     831    void i_deleteConfigHandler(DeleteConfigTask &task);
     832
     833    static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
    780834
    781835    friend class SessionMachine;
     
    11311185                    const std::vector<CloneOptions_T> &aOptions,
    11321186                    ComPtr<IProgress> &aProgress);
     1187    HRESULT saveState(ComPtr<IProgress> &aProgress);
     1188    HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
     1189    HRESULT discardSavedState(BOOL aFRemoveFile);
     1190    HRESULT takeSnapshot(const com::Utf8Str &aName,
     1191                         const com::Utf8Str &aDescription,
     1192                         BOOL aPause,
     1193                         ComPtr<IProgress> &aProgress);
     1194    HRESULT deleteSnapshot(const com::Guid &aId,
     1195                           ComPtr<IProgress> &aProgress);
     1196    HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
     1197                                         ComPtr<IProgress> &aProgress);
     1198    HRESULT deleteSnapshotRange(const com::Guid &aStartId,
     1199                                const com::Guid &aEndId,
     1200                                ComPtr<IProgress> &aProgress);
     1201    HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
     1202                            ComPtr<IProgress> &aProgress);
    11331203
    11341204    // wrapped IInternalMachineControl properties
    11351205
    11361206    // wrapped IInternalMachineControl methods
    1137     HRESULT setRemoveSavedStateFile(BOOL aRemove);
    11381207    HRESULT updateState(MachineState_T aState);
    11391208    HRESULT beginPowerUp(const ComPtr<IProgress> &aProgress);
     
    11451214                                BOOL *aMatched,
    11461215                                ULONG *aMaskedInterfaces);
    1147     HRESULT captureUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
     1216    HRESULT captureUSBDevice(const com::Guid &aId,
     1217                             const com::Utf8Str &aCaptureFilename);
    11481218    HRESULT detachUSBDevice(const com::Guid &aId,
    11491219                            BOOL aDone);
     
    11521222    HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
    11531223                         ComPtr<IProgress> &aProgress);
    1154     HRESULT beginSavingState(ComPtr<IProgress> &aProgress,
    1155                              com::Utf8Str &aStateFilePath);
    1156     HRESULT endSavingState(LONG aResult,
    1157                            const com::Utf8Str &aErrMsg);
    1158     HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
    1159     HRESULT beginTakingSnapshot(const ComPtr<IConsole> &aInitiator,
    1160                                 const com::Utf8Str &aName,
    1161                                 const com::Utf8Str &aDescription,
    1162                                 const ComPtr<IProgress> &aConsoleProgress,
    1163                                 BOOL aFTakingSnapshotOnline,
    1164                                 com::Utf8Str &aStateFilePath);
    1165     HRESULT endTakingSnapshot(BOOL aSuccess);
    1166     HRESULT deleteSnapshot(const ComPtr<IConsole> &aInitiator,
    1167                            const com::Guid &aStartId,
    1168                            const com::Guid &aEndId,
    1169                            BOOL aDeleteAllChildren,
    1170                            MachineState_T *aMachineState,
    1171                            ComPtr<IProgress> &aProgress);
    11721224    HRESULT finishOnlineMergeMedium();
    1173     HRESULT restoreSnapshot(const ComPtr<IConsole> &aInitiator,
    1174                             const ComPtr<ISnapshot> &aSnapshot,
    1175                             MachineState_T *aMachineState,
    1176                             ComPtr<IProgress> &aProgress);
    11771225    HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
    11781226                                std::vector<com::Utf8Str> &aValues,
     
    12031251                               ULONG aVmNetRx,
    12041252                               ULONG aVmNetTx);
    1205 
    1206 
    1207 
    1208 
    12091253};
    12101254
     
    13021346    HRESULT i_unlockMedia();
    13031347
     1348    HRESULT i_saveStateWithReason(Reason_T aReason, ComPtr<IProgress> &aProgress);
     1349
    13041350private:
    13051351
     
    13241370    HRESULT onSessionEnd(const ComPtr<ISession> &aSession,
    13251371                         ComPtr<IProgress> &aProgress);
    1326     HRESULT beginSavingState(ComPtr<IProgress> &aProgress,
    1327                              com::Utf8Str &aStateFilePath);
    1328     HRESULT endSavingState(LONG aResult,
    1329                            const com::Utf8Str &aErrMsg);
    1330     HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
    1331     HRESULT beginTakingSnapshot(const ComPtr<IConsole> &aInitiator,
    1332                                 const com::Utf8Str &aName,
    1333                                 const com::Utf8Str &aDescription,
    1334                                 const ComPtr<IProgress> &aConsoleProgress,
    1335                                 BOOL aFTakingSnapshotOnline,
    1336                                 com::Utf8Str &aStateFilePath);
    1337     HRESULT endTakingSnapshot(BOOL aSuccess);
    1338     HRESULT deleteSnapshot(const ComPtr<IConsole> &aInitiator,
    1339                            const com::Guid &aStartId,
    1340                            const com::Guid &aEndId,
    1341                            BOOL aDeleteAllChildren,
    1342                            MachineState_T *aMachineState,
    1343                            ComPtr<IProgress> &aProgress);
    13441372    HRESULT finishOnlineMergeMedium();
    1345     HRESULT restoreSnapshot(const ComPtr<IConsole> &aInitiator,
    1346                             const ComPtr<ISnapshot> &aSnapshot,
    1347                             MachineState_T *aMachineState,
    1348                             ComPtr<IProgress> &aProgress);
    13491373    HRESULT pullGuestProperties(std::vector<com::Utf8Str> &aNames,
    13501374                                std::vector<com::Utf8Str> &aValues,
     
    13801404    {
    13811405        ConsoleTaskData()
    1382             : mLastState(MachineState_Null), mDeleteSnapshotInfo(NULL)
     1406            : mLastState(MachineState_Null),
     1407              mDeleteSnapshotInfo(NULL)
    13831408        { }
    13841409
     
    13861411        ComObjPtr<Progress> mProgress;
    13871412
    1388         // used when taking snapshot
    1389         ComObjPtr<Snapshot> mSnapshot;
    1390 
    1391         // used when deleting online snapshot
     1413        // used when deleting online snaphshot
    13921414        void *mDeleteSnapshotInfo;
    1393 
    1394         // used when saving state (either as part of a snapshot or separate)
    1395         Utf8Str strStateFilePath;
    13961415    };
    13971416
     1417    struct SaveStateTask;
    13981418    struct SnapshotTask;
     1419    struct TakeSnapshotTask;
    13991420    struct DeleteSnapshotTask;
    14001421    struct RestoreSnapshotTask;
    14011422
     1423    friend struct TakeSnapshotTask;
    14021424    friend struct DeleteSnapshotTask;
    14031425    friend struct RestoreSnapshotTask;
    14041426
    1405     HRESULT i_endSavingState(HRESULT aRC, const Utf8Str &aErrMsg);
     1427    void i_saveStateHandler(SaveStateTask &aTask);
     1428
     1429    // Override some functionality for SessionMachine, this is where the
     1430    // real action happens (the Machine methods are just dummies).
     1431    HRESULT saveState(ComPtr<IProgress> &aProgress);
     1432    HRESULT adoptSavedState(const com::Utf8Str &aSavedStateFile);
     1433    HRESULT discardSavedState(BOOL aFRemoveFile);
     1434    HRESULT takeSnapshot(const com::Utf8Str &aName,
     1435                         const com::Utf8Str &aDescription,
     1436                         BOOL aPause,
     1437                         ComPtr<IProgress> &aProgress);
     1438    HRESULT deleteSnapshot(const com::Guid &aId,
     1439                           ComPtr<IProgress> &aProgress);
     1440    HRESULT deleteSnapshotAndAllChildren(const com::Guid &aId,
     1441                                         ComPtr<IProgress> &aProgress);
     1442    HRESULT deleteSnapshotRange(const com::Guid &aStartId,
     1443                                const com::Guid &aEndId,
     1444                                ComPtr<IProgress> &aProgress);
     1445    HRESULT restoreSnapshot(const ComPtr<ISnapshot> &aSnapshot,
     1446                            ComPtr<IProgress> &aProgress);
     1447
    14061448    void i_releaseSavedStateFile(const Utf8Str &strSavedStateFile, Snapshot *pSnapshotToIgnore);
    14071449
     1450    void i_takeSnapshotHandler(TakeSnapshotTask &aTask);
     1451    static void i_takeSnapshotProgressCancelCallback(void *pvUser);
     1452    HRESULT i_finishTakingSnapshot(TakeSnapshotTask &aTask, AutoWriteLock &alock, bool aSuccess);
     1453    HRESULT i_deleteSnapshot(const com::Guid &aStartId,
     1454                             const com::Guid &aEndId,
     1455                             BOOL aDeleteAllChildren,
     1456                             ComPtr<IProgress> &aProgress);
    14081457    void i_deleteSnapshotHandler(DeleteSnapshotTask &aTask);
    14091458    void i_restoreSnapshotHandler(RestoreSnapshotTask &aTask);
     
    14511500
    14521501    int miNATNetworksStarted;
    1453 
    1454     static DECLCALLBACK(int) taskHandler(RTTHREAD thread, void *pvUser);
    14551502};
    14561503
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