Changeset 20630 in vbox
- Timestamp:
- Jun 16, 2009 1:55:38 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48707
- Location:
- trunk/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r20598 r20630 304 304 def monitorGuest(ctx, machine, console, dur): 305 305 import time 306 import xpcom 306 307 cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine) 307 308 console.registerCallback(cb) … … 309 310 # not infinity, but close enough 310 311 dur = 100000 311 end = time.clock() + dur 312 while time.clock() < end: 313 ctx['vb'].waitForEvents(100) 312 try: 313 end = time.time() + dur 314 while time.time() < end: 315 ctx['global'].waitForEvents(500) 316 # We need to catch all exceptions here, otherwise callback will never be unregistered 317 except: 318 pass 314 319 console.unregisterCallback(cb) 320 321 315 322 316 323 def cmdExistingVm(ctx,mach,cmd,args): … … 624 631 try: 625 632 cmd = raw_input("vbox> ") 626 vbox.waitForEvents(0)627 633 done = runCommand(ctx, cmd) 628 634 if done != 0: break … … 662 668 } 663 669 interpret(ctx) 670 g_virtualBoxManager.deinit() 664 671 del g_virtualBoxManager 665 672 -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r20598 r20630 1891 1891 } 1892 1892 1893 1894 STDMETHODIMP VirtualBox::WaitForEvents(LONG aTimeout)1895 {1896 #ifdef RT_OS_WINDOWS1897 ReturnComNotImplemented();1898 #else1899 extern nsresult XPCOM_waitForEvents(PRInt32 aTimeout);1900 1901 return XPCOM_waitForEvents(aTimeout);1902 #endif1903 }1904 1893 1905 1894 STDMETHODIMP VirtualBox::WaitForPropertyChange (IN_BSTR /* aWhat */, ULONG /* aTimeout */, -
trunk/src/VBox/Main/glue/vboxapi.py
r20598 r20630 145 145 return d['result'] 146 146 147 def waitForEvents(self, timeout): 148 # not really supported yet 149 pass 150 151 def deinit(self): 152 import pythoncom 153 pythoncom.CoUninitialize() 154 pass 155 147 156 class PlatformXPCOM: 148 157 def __init__(self, params): … … 192 201 return d['result'] 193 202 203 def waitForEvents(self, timeout): 204 import xpcom 205 xpcom._xpcom.WaitForEvents(timeout) 206 207 def deinit(self): 208 import xpcom 209 xpcom._xpcom.DeinitCOM() 194 210 195 211 class PlatformWEBSERVICE: … … 235 251 def createCallback(self, iface, impl, arg): 236 252 raise Exception("no callbacks for webservices") 253 254 def waitForEvents(self, timeout): 255 # Webservices cannot do that 256 pass 257 258 def deinit(self): 259 # should we do something about it? 260 pass 237 261 238 262 class SessionManager: … … 269 293 270 294 def __del__(self): 295 deinit(self) 296 297 def deinit(self): 271 298 if hasattr(self, "vbox"): 272 299 del self.vbox 300 if hasattr(self, "platform"): 301 self.platform.deinit() 273 302 274 303 def initPerThread(self): … … 288 317 def createCallback(self, iface, impl, arg): 289 318 return self.platform.createCallback(iface, impl, arg) 319 320 def waitForEvents(self, timeout): 321 return self.platform.waitForEvents(timeout) -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r20598 r20630 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 loop2653 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>2661 2646 </param> 2662 2647 </method> -
trunk/src/VBox/Main/include/VirtualBoxImpl.h
r20598 r20630 180 180 STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback); 181 181 182 STDMETHOD(WaitForEvents) (LONG aTimeout);183 182 STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout, 184 183 BSTR *aChanged, BSTR *aValues); -
trunk/src/VBox/Main/xpcom/server.cpp
r20598 r20630 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 310 246 ///////////////////////////////////////////////////////////////////////////// 311 247 … … 776 712 777 713 /** 778 * H helper function to register self components upon start-up714 * Helper function to register self components upon start-up 779 715 * of the out-of-proc server. 780 716 */ -
trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp
r12399 r20630 54 54 #include "nsIConsoleService.h" 55 55 #include "nspr.h" // PR_fprintf 56 #ifdef VBOX 57 #include "nsEventQueueUtils.h" 58 #endif 56 59 57 60 #ifdef XP_WIN … … 489 492 } 490 493 494 #ifdef VBOX 495 static nsIEventQueue* g_mainEventQ = nsnull; 496 497 static PyObject* 498 PyXPCOMMethod_WaitForEvents(PyObject *self, PyObject *args) 499 { 500 PRInt32 aTimeout; 501 502 if (!PyArg_ParseTuple(args, "i", &aTimeout)) 503 return NULL; 504 505 nsIEventQueue* q = g_mainEventQ; 506 PRBool hasEvents = PR_FALSE; 507 nsresult rc; 508 PRInt32 fd, result = 0; 509 510 if (q == nsnull) 511 return NULL; 512 513 if (aTimeout == 0) 514 goto ok; 515 516 rc = q->PendingEvents(&hasEvents); 517 if (NS_FAILED (rc)) 518 return NULL; 519 520 if (hasEvents) 521 goto ok; 522 523 fd = q->GetEventQueueSelectFD(); 524 if (fd < 0 && aTimeout < 0) 525 { 526 /* fallback */ 527 PLEvent *pEvent = NULL; 528 rc = q->WaitForEvent(&pEvent); 529 if (NS_SUCCEEDED(rc)) 530 q->HandleEvent(pEvent); 531 goto ok; 532 } 533 534 /* Cannot perform timed wait otherwise */ 535 if (fd < 0) 536 return NULL; 537 538 539 { 540 fd_set fdsetR, fdsetE; 541 struct timeval tv; 542 543 FD_ZERO(&fdsetR); 544 FD_SET(fd, &fdsetR); 545 546 fdsetE = fdsetR; 547 if (aTimeout > 0) 548 { 549 tv.tv_sec = (PRInt64)aTimeout / 1000; 550 tv.tv_usec = ((PRInt64)aTimeout % 1000) * 1000; 551 } 552 553 /** @todo: What to do for XPCOM platforms w/o select() ? */ 554 Py_BEGIN_ALLOW_THREADS; 555 int n = select(fd + 1, &fdsetR, NULL, &fdsetE, aTimeout < 0 ? NULL : &tv); 556 result = (n == 0) ? 1 : 0; 557 Py_END_ALLOW_THREADS; 558 } 559 ok: 560 q->ProcessPendingEvents(); 561 562 return PyInt_FromLong(result); 563 } 564 565 static void deinitVBoxPython(); 566 567 static PyObject* 568 PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args) 569 { 570 deinitVBoxPython(); 571 return PyInt_FromLong(0); 572 } 573 #endif 574 491 575 extern PYXPCOM_EXPORT PyObject *PyXPCOMMethod_IID(PyObject *self, PyObject *args); 492 576 … … 514 598 {"MakeVariant", PyXPCOMMethod_MakeVariant, 1}, 515 599 {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1}, 600 #ifdef VBOX 601 {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1}, 602 {"DeinitCOM", PyXPCOMMethod_DeinitCOM, 1}, 603 #endif 516 604 // These should no longer be used - just use the logging.getLogger('pyxpcom')... 517 605 { NULL } … … 650 738 rc = com::Initialize(); 651 739 740 if (NS_SUCCEEDED(rc)) 741 { 742 NS_GetMainEventQ (&g_mainEventQ); 743 } 744 652 745 init_xpcom(); 653 746 } 654 747 } 655 #endif 748 749 static 750 void deinitVBoxPython() 751 { 752 753 if (g_mainEventQ) 754 NS_RELEASE(g_mainEventQ); 755 756 com::Shutdown(); 757 } 758 #endif
Note:
See TracChangeset
for help on using the changeset viewer.