VirtualBox

Changeset 41914 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jun 26, 2012 9:17:43 AM (13 years ago)
Author:
vboxsync
Message:

Main: Implement API to configure autostart/-stop for virtual machines

Location:
trunk/src/VBox/Main
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r41888 r41914  
    36673667  </enum>
    36683668
     3669  <enum
     3670    name="AutostopType" extends="$unknown"
     3671    uuid="6bb96740-cf34-470d-aab2-2cd48ea2e10e"
     3672    >
     3673
     3674    <desc>
     3675    Autostop types, used with <link to="IMachine::autostopType" />.
     3676    </desc>
     3677
     3678    <const name="Disabled"           value="1">
     3679      <desc>Stopping the VM during system shutdown is disabled.</desc>
     3680    </const>
     3681    <const name="SaveState"          value="2">
     3682      <desc>The state of the VM will be saved when the system shuts down.</desc>
     3683    </const>
     3684    <const name="PowerOff"           value="3">
     3685      <desc>The VM is powered off when the system shuts down.</desc>
     3686    </const>
     3687    <const name="AcpiShutdown"       value="4">
     3688      <desc>An ACPI shutdown event is generated.</desc>
     3689    </const>
     3690
     3691  </enum>
     3692
    36693693
    36703694  <interface
    36713695    name="IMachine" extends="$unknown"
    3672     uuid="e7c78fee-f20d-4b4f-ac28-37af30d79ddf"
     3696    uuid="d6406544-910e-43b2-a8fb-5528e56ce3b4"
    36733697    wsmap="managed"
    36743698    >
     
    43194343        business accessing the VMCPU or VM structures, and are therefore unable
    43204344        to get any pointers to these.
     4345      </desc>
     4346    </attribute>
     4347
     4348    <attribute name="autostartEnabled" type="boolean">
     4349      <desc>
     4350        Enables autostart of the VM during system boot.
     4351      </desc>
     4352    </attribute>
     4353
     4354    <attribute name="autostartDelay" type="unsigned long">
     4355      <desc>
     4356        Number of seconds to wait until the VM should be started during system boot.
     4357      </desc>
     4358    </attribute>
     4359
     4360    <attribute name="autostopType" type="AutostopType">
     4361      <desc>
     4362        Action type to do when the system is shutting down.
    43214363      </desc>
    43224364    </attribute>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r41371 r41914  
    300300
    301301        settings::Debugging  mDebugging;
     302        settings::Autostart  mAutostart;
    302303    };
    303304
     
    477478    STDMETHOD(COMGETTER(AllowTracingToAccessVM))(BOOL *pfAllow);
    478479    STDMETHOD(COMSETTER(AllowTracingToAccessVM))(BOOL fAllow);
     480    STDMETHOD(COMGETTER(AutostartEnabled))(BOOL *pfEnabled);
     481    STDMETHOD(COMSETTER(AutostartEnabled))(BOOL fEnabled);
     482    STDMETHOD(COMGETTER(AutostartDelay))(ULONG *puDelay);
     483    STDMETHOD(COMSETTER(AutostartDelay))(ULONG uDelay);
     484    STDMETHOD(COMGETTER(AutostopType))(AutostopType_T *penmAutostopType);
     485    STDMETHOD(COMSETTER(AutostopType))(AutostopType_T enmAutostopType);
    479486
    480487    // IMachine methods
     
    795802                         const Guid &aCurSnapshotId,
    796803                         Snapshot *aParentSnapshot);
    797     HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg);
     804    HRESULT loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
     805                         const settings::Autostart *pAutostart);
    798806    HRESULT loadDebugging(const settings::Debugging *pDbg);
     807    HRESULT loadAutostart(const settings::Autostart *pAutostart);
    799808    HRESULT loadStorageControllers(const settings::Storage &data,
    800809                                   const Guid *puuidRegistry,
     
    836845    void copyMachineDataToSettings(settings::MachineConfigFile &config);
    837846    HRESULT saveAllSnapshots(settings::MachineConfigFile &config);
    838     HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg);
     847    HRESULT saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
     848                         settings::Autostart *pAutostart);
    839849    HRESULT saveStorageControllers(settings::Storage &data);
    840850    HRESULT saveStorageDevices(ComObjPtr<StorageController> aStorageController,
     
    12061216                             const settings::Hardware &hardware,
    12071217                             const settings::Debugging *pDbg,
     1218                             const settings::Autostart *pAutostart,
    12081219                             const settings::Storage &storage,
    12091220                             IN_GUID aSnapshotId,
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r41774 r41914  
    65486548}
    65496549
     6550STDMETHODIMP Machine::COMGETTER(AutostartEnabled)(BOOL *pfEnabled)
     6551{
     6552    CheckComArgOutPointerValid(pfEnabled);
     6553    AutoCaller autoCaller(this);
     6554    HRESULT hrc = autoCaller.rc();
     6555    if (SUCCEEDED(hrc))
     6556    {
     6557        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     6558        *pfEnabled = mHWData->mAutostart.fAutostartEnabled;
     6559    }
     6560    return hrc;
     6561}
     6562
     6563STDMETHODIMP Machine::COMSETTER(AutostartEnabled)(BOOL fEnabled)
     6564{
     6565    AutoCaller autoCaller(this);
     6566    HRESULT hrc = autoCaller.rc();
     6567    if (SUCCEEDED(hrc))
     6568    {
     6569        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     6570        hrc = checkStateDependency(MutableStateDep);
     6571        if (SUCCEEDED(hrc))
     6572        {
     6573            hrc = mHWData.backupEx();
     6574            if (SUCCEEDED(hrc))
     6575            {
     6576                setModified(IsModified_MachineData);
     6577                mHWData->mAutostart.fAutostartEnabled = fEnabled != FALSE;
     6578            }
     6579        }
     6580    }
     6581    return hrc;
     6582}
     6583
     6584STDMETHODIMP Machine::COMGETTER(AutostartDelay)(ULONG *puDelay)
     6585{
     6586    CheckComArgOutPointerValid(puDelay);
     6587    AutoCaller autoCaller(this);
     6588    HRESULT hrc = autoCaller.rc();
     6589    if (SUCCEEDED(hrc))
     6590    {
     6591        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     6592        *puDelay = mHWData->mAutostart.uAutostartDelay;
     6593    }
     6594    return hrc;
     6595}
     6596
     6597STDMETHODIMP Machine::COMSETTER(AutostartDelay)(ULONG uDelay)
     6598{
     6599    AutoCaller autoCaller(this);
     6600    HRESULT hrc = autoCaller.rc();
     6601    if (SUCCEEDED(hrc))
     6602    {
     6603        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     6604        hrc = checkStateDependency(MutableStateDep);
     6605        if (SUCCEEDED(hrc))
     6606        {
     6607            hrc = mHWData.backupEx();
     6608            if (SUCCEEDED(hrc))
     6609            {
     6610                setModified(IsModified_MachineData);
     6611                mHWData->mAutostart.uAutostartDelay = uDelay;
     6612            }
     6613        }
     6614    }
     6615    return hrc;
     6616}
     6617
     6618STDMETHODIMP Machine::COMGETTER(AutostopType)(AutostopType_T *penmAutostopType)
     6619{
     6620    CheckComArgOutPointerValid(penmAutostopType);
     6621    AutoCaller autoCaller(this);
     6622    HRESULT hrc = autoCaller.rc();
     6623    if (SUCCEEDED(hrc))
     6624    {
     6625        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     6626        *penmAutostopType = mHWData->mAutostart.enmAutostopType;
     6627    }
     6628    return hrc;
     6629}
     6630
     6631STDMETHODIMP Machine::COMSETTER(AutostopType)(AutostopType_T enmAutostopType)
     6632{
     6633    AutoCaller autoCaller(this);
     6634    HRESULT hrc = autoCaller.rc();
     6635    if (SUCCEEDED(hrc))
     6636    {
     6637        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     6638        hrc = checkStateDependency(MutableStateDep);
     6639        if (SUCCEEDED(hrc))
     6640        {
     6641            hrc = mHWData.backupEx();
     6642            if (SUCCEEDED(hrc))
     6643            {
     6644                setModified(IsModified_MachineData);
     6645                mHWData->mAutostart.enmAutostopType = enmAutostopType;
     6646            }
     6647        }
     6648    }
     6649    return hrc;
     6650}
    65506651
    65516652
     
    78937994
    78947995    // hardware data
    7895     rc = loadHardware(config.hardwareMachine, &config.debugging);
     7996    rc = loadHardware(config.hardwareMachine, &config.debugging, &config.autostart);
    78967997    if (FAILED(rc)) return rc;
    78977998
     
    79648065                                            data.hardware,
    79658066                                            &data.debugging,
     8067                                            &data.autostart,
    79668068                                            data.storage,
    79678069                                            data.uuid.ref(),
     
    80118113 *  Loads settings into mHWData.
    80128114 *
    8013  *  @param data     Reference to the hardware settings.
    8014  *  @param pDbg     Pointer to the debugging settings.
     8115 *  @param data           Reference to the hardware settings.
     8116 *  @param pDbg           Pointer to the debugging settings.
     8117 *  @param pAutostart     Pointer to the autostart settings.
    80158118 */
    8016 HRESULT Machine::loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg)
     8119HRESULT Machine::loadHardware(const settings::Hardware &data, const settings::Debugging *pDbg,
     8120                              const settings::Autostart *pAutostart)
    80178121{
    80188122    AssertReturn(!isSessionMachine(), E_FAIL);
     
    82668370        if (FAILED(rc))
    82678371            return rc;
     8372
     8373        mHWData->mAutostart = *pAutostart;
    82688374    }
    82698375    catch(std::bad_alloc &)
     
    91069212    /// @todo Live Migration:        config.fTeleported = (mData->mMachineState == MachineState_Teleported);
    91079213
    9108     HRESULT rc = saveHardware(config.hardwareMachine, &config.debugging);
     9214    HRESULT rc = saveHardware(config.hardwareMachine, &config.debugging, &config.autostart);
    91099215    if (FAILED(rc)) throw rc;
    91109216
     
    91799285 *  given node is empty.
    91809286 *
    9181  *  @param data     Reference to the settings object for the hardware config.
    9182  *  @param pDbg     Pointer to the settings object for the debugging config
    9183  *                  which happens to live in mHWData.
     9287 *  @param data           Reference to the settings object for the hardware config.
     9288 *  @param pDbg           Pointer to the settings object for the debugging config
     9289 *                        which happens to live in mHWData.
     9290 *  @param pAutostart     Pointer to the settings object for the autostart config
     9291 *                        which happens to live in mHWData.
    91849292 */
    9185 HRESULT Machine::saveHardware(settings::Hardware &data, settings::Debugging *pDbg)
     9293HRESULT Machine::saveHardware(settings::Hardware &data, settings::Debugging *pDbg,
     9294                              settings::Autostart *pAutostart)
    91869295{
    91879296    HRESULT rc = S_OK;
     
    94179526
    94189527        *pDbg = mHWData->mDebugging;
     9528        *pAutostart = mHWData->mAutostart;
    94199529    }
    94209530    catch(std::bad_alloc &)
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r40565 r41914  
    773773        data.strStateFile.setNull();
    774774
    775     HRESULT rc = m->pMachine->saveHardware(data.hardware, &data.debugging);
     775    HRESULT rc = m->pMachine->saveHardware(data.hardware, &data.debugging, &data.autostart);
    776776    if (FAILED(rc)) return rc;
    777777
     
    10811081                                          const settings::Hardware &hardware,
    10821082                                          const settings::Debugging *pDbg,
     1083                                          const settings::Autostart *pAutostart,
    10831084                                          const settings::Storage &storage,
    10841085                                          IN_GUID aSnapshotId,
     
    11571158    /* load hardware and harddisk settings */
    11581159
    1159     HRESULT rc = loadHardware(hardware, pDbg);
     1160    HRESULT rc = loadHardware(hardware, pDbg, pAutostart);
    11601161    if (SUCCEEDED(rc))
    11611162        rc = loadStorageControllers(storage,
  • trunk/src/VBox/Main/xml/Settings.cpp

    r41842 r41914  
    17631763                  && (llChildSnapshots      == s.llChildSnapshots)          // deep compare
    17641764                  && debugging              == s.debugging
     1765                  && autostart              == s.autostart
    17651766                )
    17661767           );
     
    31983199
    31993200/**
     3201 * Called for reading the <Autostart> element under <Machine> or <Snapshot>.
     3202 */
     3203void MachineConfigFile::readAutostart(const xml::ElementNode *pElmAutostart, Autostart *pAutostart)
     3204{
     3205    Utf8Str strAutostop;
     3206
     3207    if (!pElmAutostart || m->sv < SettingsVersion_v1_13)
     3208        return;
     3209
     3210    pElmAutostart->getAttributeValue("enabled", pAutostart->fAutostartEnabled);
     3211    pElmAutostart->getAttributeValue("delay", pAutostart->uAutostartDelay);
     3212    pElmAutostart->getAttributeValue("autostop", strAutostop);
     3213    if (strAutostop == "Disabled")
     3214        pAutostart->enmAutostopType = AutostopType_Disabled;
     3215    else if (strAutostop == "SaveState")
     3216        pAutostart->enmAutostopType = AutostopType_SaveState;
     3217    else if (strAutostop == "PowerOff")
     3218        pAutostart->enmAutostopType = AutostopType_PowerOff;
     3219    else if (strAutostop == "AcpiShutdown")
     3220        pAutostart->enmAutostopType = AutostopType_AcpiShutdown;
     3221    else
     3222        throw ConfigFileError(this, pElmAutostart, N_("Invalid value '%s' for Autostart/@autostop attribute"), strAutostop.c_str());
     3223}
     3224
     3225/**
    32003226 * Called initially for the <Snapshot> element under <Machine>, if present,
    32013227 * to store the snapshot's data into the given Snapshot structure (which is
     
    32713297
    32723298    readDebugging(elmSnapshot.findChildElement("Debugging"), &snap.debugging);
     3299    readAutostart(elmSnapshot.findChildElement("Autostart"), &snap.autostart);
    32733300}
    32743301
     
    34213448            else if (pelmMachineChild->nameEquals("Debugging"))
    34223449                readDebugging(pelmMachineChild, &debugging);
     3450            else if (pelmMachineChild->nameEquals("Autostart"))
     3451                readAutostart(pelmMachineChild, &autostart);
    34233452        }
    34243453
     
    43734402
    43744403/**
     4404 * Creates a <Autostart> node under elmParent and then writes out the XML
     4405 * keys under that. Called for both the <Machine> node and for snapshots.
     4406 *
     4407 * @param pElmParent    Pointer to the parent element.
     4408 * @param pAutostart    Pointer to the autostart settings.
     4409 */
     4410void MachineConfigFile::buildAutostartXML(xml::ElementNode *pElmParent, const Autostart *pAutostart)
     4411{
     4412    const char *pcszAutostop = NULL;
     4413
     4414    if (m->sv < SettingsVersion_v1_13 || pAutostart->areDefaultSettings())
     4415        return;
     4416
     4417    xml::ElementNode *pElmAutostart = pElmParent->createChild("Autostart");
     4418    pElmAutostart->setAttribute("enabled", pAutostart->fAutostartEnabled);
     4419    pElmAutostart->setAttribute("delay", pAutostart->uAutostartDelay);
     4420
     4421    switch (pAutostart->enmAutostopType)
     4422    {
     4423        case AutostopType_Disabled:     pcszAutostop = "Disabled";     break;
     4424        case AutostopType_SaveState:    pcszAutostop = "SaveState";    break;
     4425        case AutostopType_PowerOff:     pcszAutostop = "PowerOff";     break;
     4426        case AutostopType_AcpiShutdown: pcszAutostop = "AcpiShutdown"; break;
     4427        default:         Assert(false); pcszAutostop = "Disabled";     break;
     4428    }
     4429    pElmAutostart->setAttribute("autostop", pcszAutostop);
     4430}
     4431
     4432/**
    43754433 * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
    43764434 * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
     
    44024460                                    // since snapshots never get written then
    44034461    buildDebuggingXML(pelmSnapshot, &snap.debugging);
     4462    buildAutostartXML(pelmSnapshot, &snap.autostart);
    44044463
    44054464    if (snap.llChildSnapshots.size())
     
    45504609                               pllElementsWithUuidAttributes);
    45514610    buildDebuggingXML(&elmMachine, &debugging);
     4611    buildAutostartXML(&elmMachine, &autostart);
    45524612}
    45534613
     
    46674727    if (m->sv < SettingsVersion_v1_13)
    46684728    {
    4669         // VirtualBox 4.2 adds tracing.
    4670         if (!debugging.areDefaultSettings())
     4729        // VirtualBox 4.2 adds tracing and autostart.
     4730        if (   !debugging.areDefaultSettings()
     4731            || !autostart.areDefaultSettings())
    46714732            m->sv = SettingsVersion_v1_13;
    46724733    }
Note: See TracChangeset for help on using the changeset viewer.

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