VirtualBox

Changeset 50220 in vbox for trunk


Ignore:
Timestamp:
Jan 24, 2014 1:46:27 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
91800
Message:

Main/HostPower: another shot at savestate-on-battery-low

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

Legend:

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

    r50175 r50220  
    3838    VirtualBox *mVirtualBox;
    3939    std::vector<ComPtr<IInternalSessionControl> > mSessionControls;
    40 
    41   private:
    42     bool fSavestateOnBatteryLow;
    4340};
    4441
  • trunk/src/VBox/Main/src-server/HostPower.cpp

    r50216 r50220  
    5353        case Reason_HostSuspend:
    5454        {
    55             LogFunc(("SUSPEND\n"));
     55            LogFunc(("HOST SUSPEND\n"));
    5656
    5757#ifdef VBOX_WITH_RESOURCE_USAGE_API
     
    8181            }
    8282
    83             LogFunc(("Suspended %d VMs\n", mSessionControls.size()));
    84 
     83            LogRel(("Host suspending: Paused %d VMs\n", mSessionControls.size()));
    8584            break;
    8685        }
     
    8887        case Reason_HostResume:
    8988        {
    90             LogFunc(("RESUME\n"));
     89            LogFunc(("HOST RESUME\n"));
    9190
    9291            size_t resumed = 0;
     
    106105            }
    107106
    108             LogFunc(("Resumed %d VMs\n", resumed));
     107            LogRel(("Host resumed: Resumed %d VMs\n", resumed));
    109108
    110109#ifdef VBOX_WITH_RESOURCE_USAGE_API
     
    117116
    118117            mSessionControls.clear();
    119 
    120118            break;
    121119        }
     
    123121        case Reason_HostBatteryLow:
    124122        {
     123            LogFunc(("BATTERY LOW\n"));
     124
    125125            Bstr value;
    126             HRESULT hrc = mVirtualBox->GetExtraData(Bstr("VBoxInternal2/SavestateOnBatteryLow").raw(),
    127                                                          value.asOutParam());
    128             if (   SUCCEEDED(hrc)
    129                 && value != "0")
    130             {
    131                 LogFunc(("BATTERY LOW -- savestate running VMs\n"));
    132 
    133                 mVirtualBox->getOpenedMachines(machines, &controls);
    134                 size_t saved = 0;
    135 
    136                 /* save running VMs */
    137                 for (VirtualBox::InternalControlList::const_iterator it = controls.begin();
    138                      it != controls.end();
    139                      ++it)
     126            rc = mVirtualBox->GetExtraData(Bstr("VBoxInternal2/SavestateOnBatteryLow").raw(),
     127                                           value.asOutParam());
     128            int fGlobal = 0;
     129            if (SUCCEEDED(rc))
     130            {
     131                if (value != "0")
     132                    fGlobal = 1;
     133                else if (value == "0")
     134                    fGlobal = -1;
     135            }
     136
     137            mVirtualBox->getOpenedMachines(machines, &controls);
     138            size_t saved = 0;
     139
     140            /* save running VMs */
     141            SessionMachinesList::const_iterator it2 = machines.begin();
     142            for (VirtualBox::InternalControlList::const_iterator it = controls.begin();
     143                 it != controls.end() && it2 != machines.end();
     144                 ++it, ++it2)
     145            {
     146                ComPtr<SessionMachine> pMachine = *it2;
     147                rc = pMachine->GetExtraData(Bstr("VBoxInternal2/SavestateOnBatteryLow").raw(),
     148                                            value.asOutParam());
     149                int fPerVM = 0;
     150                if (SUCCEEDED(rc))
     151                {
     152                    /* per-VM overrides global */
     153                    if (value != "0")
     154                        fPerVM = 2;
     155                    else if (value == "0")
     156                        fPerVM = -2;
     157                }
     158
     159                /* default is true */
     160                if (fGlobal + fPerVM >= 0)
    140161                {
    141162                    ComPtr<IInternalSessionControl> pControl = *it;
     
    146167                    rc = pControl->SaveStateWithReason(Reason_HostBatteryLow, progress.asOutParam());
    147168                    if (FAILED(rc))
     169                    {
     170                        LogRel(("SaveState '%s' failed with %Rhrc\n", pMachine->getName().c_str(), rc));
    148171                        continue;
     172                    }
    149173
    150174                    /* Wait until the operation has been completed. */
     
    160184
    161185                    if (SUCCEEDED(rc))
     186                    {
     187                        LogRel(("SaveState '%s' succeeded\n", pMachine->getName().c_str()));
    162188                        ++saved;
     189                    }
    163190                }
    164                 LogFunc(("Saved %d VMs\n", saved));
    165             }
    166             else
    167             {
    168                 LogFunc(("BATTERY LOW -- no action\n"));
    169             }
    170 
     191                LogRel(("Battery Low: Saved %d VMs\n", saved));
     192            }
    171193            break;
    172194        }
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