Changeset 20630 in vbox for trunk/src/libs/xpcom18a4
- Timestamp:
- Jun 16, 2009 1:55:38 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48707
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.