Changeset 13705 in vbox
- Timestamp:
- Oct 31, 2008 9:00:15 AM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
-
HostPower.cpp (modified) (5 diffs)
-
include/HostPower.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostPower.cpp
r13680 r13705 24 24 * Header Files * 25 25 *******************************************************************************/ 26 #include <iprt/mem.h> 26 27 #include <VBox/com/ptr.h> 27 28 #include "HostPower.h" 28 29 #include "Logging.h" 29 30 30 HostPowerService::HostPowerService(VirtualBox *aVirtualBox) 31 HostPowerService::HostPowerService(VirtualBox *aVirtualBox) : aMachineSuspended(NULL), cbMachineSuspended(0) 31 32 { 32 33 mVirtualBox = aVirtualBox; … … 40 41 void HostPowerService::notify(HostPowerEvent event) 41 42 { 43 VirtualBox::SessionMachineVector machines; 44 mVirtualBox->getOpenedMachines (machines); 45 42 46 switch (event) 43 47 { 44 48 case HostPowerEvent_Suspend: 49 if (machines.size()) 50 aMachineSuspended = (BOOL *)RTMemAllocZ(sizeof(BOOL) * machines.size()); 51 52 cbMachineSuspended = machines.size(); 53 54 for (size_t i = 0; i < machines.size(); i++) 55 processEvent(machines[i], HostPowerEvent_Suspend, (aMachineSuspended) ? &aMachineSuspended[i] : NULL); 56 45 57 Log(("HostPowerService::notify SUSPEND\n")); 46 58 break; … … 48 60 case HostPowerEvent_Resume: 49 61 Log(("HostPowerService::notify RESUME\n")); 62 63 if (aMachineSuspended) 64 { 65 /* It's possible (in theory) that machines are created or destroyed between the suspend notification and the actual host suspend. 66 * Ignore this edge case and just make sure not to access invalid data. 67 */ 68 cbMachineSuspended = RT_MIN(machines.size(), cbMachineSuspended); 69 70 for (size_t i = 0; i < cbMachineSuspended; i++) 71 processEvent(machines[i], HostPowerEvent_Resume, &aMachineSuspended[i]); 72 73 RTMemFree(aMachineSuspended); 74 cbMachineSuspended = 0; 75 aMachineSuspended = NULL; 76 } 50 77 break; 51 78 52 79 case HostPowerEvent_BatteryLow: 53 80 Log(("HostPowerService::notify BATTERY LOW\n")); 81 for (size_t i = 0; i < machines.size(); i++) 82 processEvent(machines[i], HostPowerEvent_BatteryLow, NULL); 54 83 break; 55 84 } 56 57 VirtualBox::SessionMachineVector machines;58 mVirtualBox->getOpenedMachines (machines);59 60 for (size_t i = 0; i < machines.size(); i++)61 processEvent(machines[i], event);62 85 63 86 machines.clear(); 64 87 } 65 88 66 HRESULT HostPowerService::processEvent(SessionMachine *machine, HostPowerEvent event )89 HRESULT HostPowerService::processEvent(SessionMachine *machine, HostPowerEvent event, BOOL *pMachineSuspended) 67 90 { 68 91 MachineState_T state; … … 72 95 CheckComRCReturnRC (rc); 73 96 74 if (state == MachineState_Running) 97 /* Valid combinations: 98 * running & suspend or battery low notification events 99 * pause & resume or battery low notification events 100 */ 101 if ( (state == MachineState_Running && event != HostPowerEvent_Resume) 102 || (state == MachineState_Paused && event != HostPowerEvent_Suspend)) 75 103 { 76 104 ComPtr <ISession> session; … … 100 128 case HostPowerEvent_Suspend: 101 129 rc = console->Pause(); 130 if ( SUCCEEDED(rc) 131 && pMachineSuspended) 132 *pMachineSuspended = TRUE; 102 133 break; 134 103 135 case HostPowerEvent_Resume: 136 Assert(pMachineSuspended); 137 if (*pMachineSuspended == TRUE) 138 rc = console->Resume(); 139 break; 140 104 141 case HostPowerEvent_BatteryLow: 142 { 143 ComPtr<IProgress> progress; 144 145 rc = console->SaveState(progress.asOutParam()); 146 if (SUCCEEDED(rc)) 147 { 148 /* Wait until the operation has been completed. */ 149 progress->WaitForCompletion(-1); 150 151 progress->COMGETTER(ResultCode)(&rc); 152 AssertMsg(SUCCEEDED(rc), ("SaveState WaitForCompletion failed with %x\n", rc)); 153 } 154 105 155 break; 106 156 } 157 158 } /* switch (event) */ 107 159 } 108 160 } 109 161 fail: 110 162 session->Close(); 111 112 163 } 113 164 return rc; -
trunk/src/VBox/Main/include/HostPower.h
r13688 r13705 42 42 43 43 void notify(HostPowerEvent event); 44 HRESULT processEvent(SessionMachine *machine, HostPowerEvent event );44 HRESULT processEvent(SessionMachine *machine, HostPowerEvent event, BOOL *paMachineSuspended); 45 45 46 46 protected: 47 47 ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox; 48 49 BOOL *aMachineSuspended; 50 size_t cbMachineSuspended; 48 51 }; 49 52
Note:
See TracChangeset
for help on using the changeset viewer.

