VirtualBox

Changeset 50175 in vbox for trunk/src


Ignore:
Timestamp:
Jan 23, 2014 10:10:50 AM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
91739
Message:

Main/HostPower: Introduced global extradata item HostPower/SavestateOnBatteryLow which can be set to "0" to disable automatic VM savestate if the battery reached a critical level

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

Legend:

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

    r46775 r50175  
    3030class HostPowerService
    3131{
    32 public:
    33 
     32  public:
    3433    HostPowerService(VirtualBox *aVirtualBox);
    3534    virtual ~HostPowerService();
    36 
    3735    void notify(Reason_T aReason);
    3836
    39 protected:
     37  protected:
     38    VirtualBox *mVirtualBox;
     39    std::vector<ComPtr<IInternalSessionControl> > mSessionControls;
    4040
    41     VirtualBox *mVirtualBox;
    42 
    43     std::vector<ComPtr<IInternalSessionControl> > mSessionControls;
     41  private:
     42    bool fSavestateOnBatteryLow;
    4443};
    4544
  • trunk/src/VBox/Main/src-server/HostPower.cpp

    r50174 r50175  
    3636    AssertPtr(aVirtualBox);
    3737    mVirtualBox = aVirtualBox;
     38
     39    // keep this in sync with the host-specific implementations
     40#if defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN)
     41    Bstr bstrValue;
     42    HRESULT hrc = mVirtualBox->GetExtraData(Bstr("HostPower/SavestateOnBatteryLow").raw(),
     43                                            bstrValue.asOutParam());
     44    if (   SUCCEEDED(hrc)
     45        && (   bstrValue.isEmpty()
     46            || bstrValue != "0"))
     47    {
     48        fSavestateOnBatteryLow = true;
     49        LogRel(("Power: BatteryLow event will trigger VM savestate\n"));
     50    }
     51    else
     52#endif
     53    {
     54        fSavestateOnBatteryLow = false;
     55        LogRel(("Power: BatteryLow will be ignored\n"));
     56    }
    3857}
    3958
     
    123142        case Reason_HostBatteryLow:
    124143        {
    125             LogFunc(("BATTERY LOW\n"));
     144            if (fSavestateOnBatteryLow)
     145            {
     146                LogFunc(("BATTERY LOW -- savestate running VMs\n"));
    126147
    127             mVirtualBox->getOpenedMachines(machines, &controls);
     148                mVirtualBox->getOpenedMachines(machines, &controls);
     149                size_t saved = 0;
    128150
    129             size_t saved = 0;
     151                /* save running VMs */
     152                for (VirtualBox::InternalControlList::const_iterator it = controls.begin();
     153                     it != controls.end();
     154                     ++it)
     155                {
     156                    ComPtr<IInternalSessionControl> pControl = *it;
     157                    ComPtr<IProgress> progress;
    130158
    131             /* save running VMs */
    132             for (VirtualBox::InternalControlList::const_iterator it = controls.begin();
    133                  it != controls.end();
    134                  ++it)
     159                    /* note that SaveStateWithReason() will simply return a failure
     160                     * if the VM is in an inappropriate state */
     161                    rc = pControl->SaveStateWithReason(Reason_HostBatteryLow, progress.asOutParam());
     162                    if (FAILED(rc))
     163                        continue;
     164
     165                    /* Wait until the operation has been completed. */
     166                    rc = progress->WaitForCompletion(-1);
     167                    if (SUCCEEDED(rc))
     168                    {
     169                        LONG iRc;
     170                        progress->COMGETTER(ResultCode)(&iRc);
     171                        rc = iRc;
     172                    }
     173
     174                    AssertMsg(SUCCEEDED(rc), ("SaveState WaitForCompletion failed with %Rhrc (%#08X)\n", rc, rc));
     175
     176                    if (SUCCEEDED(rc))
     177                        ++saved;
     178                }
     179                LogFunc(("Saved %d VMs\n", saved));
     180            }
     181            else
    135182            {
    136                 ComPtr<IInternalSessionControl> pControl = *it;
    137 
    138                 ComPtr<IProgress> progress;
    139 
    140                 /* note that SaveStateWithReason() will simply return a failure
    141                  * if the VM is in an inappropriate state */
    142                 rc = pControl->SaveStateWithReason(Reason_HostBatteryLow, progress.asOutParam());
    143                 if (FAILED(rc))
    144                     continue;
    145 
    146                 /* Wait until the operation has been completed. */
    147                 rc = progress->WaitForCompletion(-1);
    148                 if (SUCCEEDED(rc))
    149                 {
    150                     LONG iRc;
    151                     progress->COMGETTER(ResultCode)(&iRc);
    152                     rc = iRc;
    153                 }
    154 
    155                 AssertMsg(SUCCEEDED(rc), ("SaveState WaitForCompletion failed with %Rhrc (%#08X)\n", rc, rc));
    156 
    157                 if (SUCCEEDED(rc))
    158                     ++saved;
     183                LogFunc(("BATTERY LOW -- no action\n"));
    159184            }
    160 
    161             LogFunc(("Saved %d VMs\n", saved));
    162185
    163186            break;
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