Changeset 20598 in vbox
- Timestamp:
- Jun 15, 2009 6:08:09 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48645
- Location:
- trunk/src/VBox
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r20332 r20598 96 96 }) 97 97 return out 98 99 # Simple implementation of IConsoleCallback, one can use it as skeleton 100 # for custom implementations 101 class GuestMonitor: 102 def __init__(self, mach): 103 self.mach = mach 104 105 def onMousePointerShapeChange(self, visible, alpha, xHot, yHot, width, height, shape): 106 print "%s: onMousePointerShapeChange: visible=%d" %(self.mach.name, visible) 107 def onMouseCapabilityChange(self, supportsAbsolute, needsHostCursor): 108 print "%s: onMouseCapabilityChange: needsHostCursor=%d" %(self.mach.name, needsHostCursor) 109 110 def onKeyboardLedsChange(self, numLock, capsLock, scrollLock): 111 print "%s: onKeyboardLedsChange capsLock=%d" %(self.mach.name, capsLock) 112 113 def onStateChange(self, state): 114 print "%s: onStateChange state=%d" %(self.mach.name, state) 115 116 def onAdditionsStateChange(self): 117 print "%s: onAdditionsStateChange" %(self.mach.name) 118 119 def onDVDDriveChange(self): 120 print "%s: onDVDDriveChange" %(self.mach.name) 121 122 def onFloppyDriveChange(self): 123 print "%s: onFloppyDriveChange" %(self.mach.name) 124 125 def onNetworkAdapterChange(self, adapter): 126 print "%s: onNetworkAdapterChange" %(self.mach.name) 127 128 def onSerialPortChange(self, port): 129 print "%s: onSerialPortChange" %(self.mach.name) 130 131 def onParallelPortChange(self, port): 132 print "%s: onParallelPortChange" %(self.mach.name) 133 134 def onStorageControllerChange(self): 135 print "%s: onStorageControllerChange" %(self.mach.name) 136 137 def onVRDPServerChange(self): 138 print "%s: onVRDPServerChange" %(self.mach.name) 139 140 def onUSBControllerChange(self): 141 print "%s: onUSBControllerChange" %(self.mach.name) 142 143 def onUSBDeviceStateChange(self, device, attached, error): 144 print "%s: onUSBDeviceStateChange" %(self.mach.name) 145 146 def onSharedFolderChange(self, scope): 147 print "%s: onSharedFolderChange" %(self.mach.name) 148 149 def onRuntimeError(self, fatal, id, message): 150 print "%s: onRuntimeError fatal=%d message=%s" %(self.mach.name, fatal, message) 151 152 def onCanShowWindow(self): 153 print "%s: onCanShowWindow" %(self.mach.name) 154 return true 155 156 def onShowWindow(self, winId): 157 print "%s: onShowWindow: %d" %(self.mach.name, winId) 98 158 99 159 g_hasreadline = 1 … … 242 302 exec cmds 243 303 304 def monitorGuest(ctx, machine, console, dur): 305 import time 306 cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine) 307 console.registerCallback(cb) 308 if dur == -1: 309 # not infinity, but close enough 310 dur = 100000 311 end = time.clock() + dur 312 while time.clock() < end: 313 ctx['vb'].waitForEvents(100) 314 console.unregisterCallback(cb) 315 244 316 def cmdExistingVm(ctx,mach,cmd,args): 245 317 mgr=ctx['mgr'] … … 267 339 'powerdown': lambda: console.powerDown(), 268 340 'stats': lambda: guestStats(ctx, mach), 269 'guest': lambda: guestExec(ctx, mach, console, args) 341 'guest': lambda: guestExec(ctx, mach, console, args), 342 'monitorGuest': lambda: monitorGuest(ctx, mach, console, args) 270 343 } 271 344 try: … … 467 540 return 0 468 541 542 543 def monitorGuestCmd(ctx, args): 544 if (len(args) < 2): 545 print "usage: monitorGuest name (duration)" 546 return 0 547 mach = argsToMach(ctx,args) 548 if mach == None: 549 return 0 550 dur = 5 551 if len(args) > 2: 552 dur = float(args[2]) 553 cmdExistingVm(ctx, mach, 'monitorGuest', dur) 554 return 0 469 555 470 556 def evalCmd(ctx, args): … … 503 589 'host':['Show host information', hostCmd], 504 590 'guest':['Execute command for guest: guest Win32 console.mouse.putMouseEvent(20, 20, 0, 0)', guestCmd], 591 'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd], 505 592 } 506 593 … … 537 624 try: 538 625 cmd = raw_input("vbox> ") 626 vbox.waitForEvents(0) 539 627 done = runCommand(ctx, cmd) 540 628 if done != 0: break -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r19750 r20598 1889 1889 LogFlowThisFunc (("aCallback=%p, rc=%08X\n", aCallback, rc)); 1890 1890 return rc; 1891 } 1892 1893 1894 STDMETHODIMP VirtualBox::WaitForEvents(LONG aTimeout) 1895 { 1896 #ifdef RT_OS_WINDOWS 1897 ReturnComNotImplemented(); 1898 #else 1899 extern nsresult XPCOM_waitForEvents(PRInt32 aTimeout); 1900 1901 return XPCOM_waitForEvents(aTimeout); 1902 #endif 1891 1903 } 1892 1904 -
trunk/src/VBox/Main/glue/vboxapi.py
r20579 r20598 131 131 pythoncom.CoUninitialize() 132 132 133 def createCallback(self, iface, impl ):133 def createCallback(self, iface, impl, arg): 134 134 d = {} 135 135 d['BaseClass'] = impl 136 d['arg'] = arg 136 137 str = "" 137 138 str += "import win32com.server.util" … … 139 140 str += " _com_interfaces_ = ['"+iface+"']\n" 140 141 str += " _typelib_guid_ = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'\n" 141 str += " def __init__(self): pass\n"142 str += " def __init__(self): BaseClass.__init__(self, arg)\n" 142 143 str += "result = win32com.server.util.wrap("+iface+"Impl())\n" 143 144 exec (str,d,d) … … 178 179 pass 179 180 180 def createCallback(self, iface, impl ):181 def createCallback(self, iface, impl, arg): 181 182 d = {} 182 183 d['BaseClass'] = impl 184 d['arg'] = arg 183 185 str = "" 184 186 str += "import xpcom.components\n" 185 187 str += "class "+iface+"Impl(BaseClass):\n" 186 188 str += " _com_interfaces_ = xpcom.components.interfaces."+iface+"\n" 187 str += " def __init__(self): pass\n"189 str += " def __init__(self): BaseClass.__init__(self, arg)\n" 188 190 str += "result = "+iface+"Impl()\n" 189 191 exec (str,d,d) … … 231 233 pass 232 234 233 def createCallback(self, iface, impl ):235 def createCallback(self, iface, impl, arg): 234 236 raise Exception("no callbacks for webservices") 235 237 … … 284 286 self.platform.deinitPerThread() 285 287 286 def createCallback(self, iface, impl ):287 return self.platform.createCallback(iface, impl )288 def createCallback(self, iface, impl, arg): 289 return self.platform.createCallback(iface, impl, arg) -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r20381 r20598 2644 2644 <param name="callback" type="IVirtualBoxCallback" dir="in"> 2645 2645 <desc>Callback object to unregister.</desc> 2646 </param> 2647 </method> 2648 2649 <method name="waitForEvents"> 2650 <desc> 2651 Blocking wait for events to happen and process them, if any. 2652 One may wish to call this method from the main even loop 2653 to wait for acitivity from VirtualBox, such as callback calling. 2654 </desc> 2655 <param name="timeout" type="long" dir="in"> 2656 <desc> 2657 Wait timeout in milliseconds. 2658 Specify -1 for an indefinite wait. 2659 Specify 0 for immediate return if no events to process. 2660 </desc> 2646 2661 </param> 2647 2662 </method> -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r19239 r20598 180 180 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback); 181 181 182 STDMETHOD(WaitForEvents) (LONG aTimeout); 182 183 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout, 183 184 BSTR *aChanged, BSTR *aValues); -
trunk/src/VBox/Main/xpcom/server.cpp
r20081 r20598 244 244 static PRBool volatile gKeepRunning = PR_TRUE; 245 245 246 nsresult XPCOM_waitForEvents(PRInt32 aTimeout) 247 { 248 nsIEventQueue* q = gEventQ; 249 PRBool hasEvents = false; 250 nsresult rc; 251 252 if (!gKeepRunning || !q) 253 return NS_OK; 254 255 rc = q->PendingEvents(&hasEvents); 256 if (NS_FAILED (rc)) 257 return NS_ERROR_FAILURE; 258 259 if (hasEvents) 260 { 261 q->ProcessPendingEvents(); 262 return NS_OK; 263 } 264 265 if (aTimeout == 0) 266 return NS_OK; 267 268 PRInt32 fd; 269 fd = q->GetEventQueueSelectFD(); 270 271 if (fd < 0 && aTimeout == -1) 272 { 273 /* fallback */ 274 PLEvent *pEvent = NULL; 275 rc = q->WaitForEvent(&pEvent); 276 if (NS_SUCCEEDED(rc)) 277 q->HandleEvent(pEvent); 278 279 q->ProcessPendingEvents(); 280 return NS_OK; 281 } 282 283 /* Cannot perform timed wait otherwise */ 284 AssertReturn(fd >= 0, NS_ERROR_FAILURE); 285 286 fd_set fdsetR, fdsetE; 287 struct timeval tv; 288 289 FD_ZERO(&fdsetR); 290 FD_SET(fd, &fdsetR); 291 292 fdsetE = fdsetR; 293 if (aTimeout > 0) 294 { 295 /* LogRel(("sleep %d\n", aTimeout)); */ 296 tv.tv_sec = (PRInt64)aTimeout / 1000; 297 tv.tv_usec = ((PRInt64)aTimeout % 1000) * 1000; 298 } 299 300 /** @todo: What to do for XPCOM platforms w/o select() ? */ 301 int n = select(fd + 1, &fdsetR, NULL, &fdsetE, aTimeout < 0 ? NULL : &tv); 302 rc = (n >= 0) ? NS_OK : NS_ERROR_FAILURE; 303 304 /* process pending events, no matter what */ 305 q->ProcessPendingEvents(); 306 307 return rc; 308 } 309 246 310 ///////////////////////////////////////////////////////////////////////////// 247 311
Note:
See TracChangeset
for help on using the changeset viewer.