- Timestamp:
- Jan 23, 2014 10:10:50 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 91739
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostPower.h
r46775 r50175 30 30 class HostPowerService 31 31 { 32 public: 33 32 public: 34 33 HostPowerService(VirtualBox *aVirtualBox); 35 34 virtual ~HostPowerService(); 36 37 35 void notify(Reason_T aReason); 38 36 39 protected: 37 protected: 38 VirtualBox *mVirtualBox; 39 std::vector<ComPtr<IInternalSessionControl> > mSessionControls; 40 40 41 VirtualBox *mVirtualBox; 42 43 std::vector<ComPtr<IInternalSessionControl> > mSessionControls; 41 private: 42 bool fSavestateOnBatteryLow; 44 43 }; 45 44 -
trunk/src/VBox/Main/src-server/HostPower.cpp
r50174 r50175 36 36 AssertPtr(aVirtualBox); 37 37 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 } 38 57 } 39 58 … … 123 142 case Reason_HostBatteryLow: 124 143 { 125 LogFunc(("BATTERY LOW\n")); 144 if (fSavestateOnBatteryLow) 145 { 146 LogFunc(("BATTERY LOW -- savestate running VMs\n")); 126 147 127 mVirtualBox->getOpenedMachines(machines, &controls); 148 mVirtualBox->getOpenedMachines(machines, &controls); 149 size_t saved = 0; 128 150 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; 130 158 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 135 182 { 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")); 159 184 } 160 161 LogFunc(("Saved %d VMs\n", saved));162 185 163 186 break;
Note:
See TracChangeset
for help on using the changeset viewer.