496
static nsIEventQueue* g_mainEventQ = nsnull;
496
# include <VBox/com/EventQueue.h>
497
# include <iprt/err.h>
499
500
PyXPCOMMethod_WaitForEvents(PyObject *self, PyObject *args)
501
502
PRInt32 aTimeout;
503
504
if (!PyArg_ParseTuple(args, "i", &aTimeout))
506
nsIEventQueue* q = g_mainEventQ;
507
PRBool hasEvents = PR_FALSE;
509
PRInt32 fd, result = 0;
517
rc = q->PendingEvents(&hasEvents);
524
fd = q->GetEventQueueSelectFD();
525
if (fd < 0 && aTimeout < 0)
528
PLEvent *pEvent = NULL;
529
Py_BEGIN_ALLOW_THREADS
530
rc = q->WaitForEvent(&pEvent);
532
if (NS_SUCCEEDED(rc))
533
q->HandleEvent(pEvent);
537
/* Cannot perform timed wait otherwise */
541
* @todo: maybe need some way to implement timed wait on Darwin,
542
* just return immediately instead
505
return NULL; /** @todo throw exception */
508
com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
509
NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
550
fd_set fdsetR, fdsetE;
559
tv.tv_sec = (PRInt64)aTimeout / 1000;
560
tv.tv_usec = ((PRInt64)aTimeout % 1000) * 1000;
563
/** @todo: What to do for XPCOM platforms w/o select() ? */
564
Py_BEGIN_ALLOW_THREADS;
565
int n = select(fd + 1, &fdsetR, NULL, &fdsetE, aTimeout < 0 ? NULL : &tv);
566
result = (n == 0) ? 1 : 0;
567
Py_END_ALLOW_THREADS;
570
q->ProcessPendingEvents();
572
return PyInt_FromLong(result);
575
PR_STATIC_CALLBACK(void *) PyHandleEvent(PLEvent *ev)
580
PR_STATIC_CALLBACK(void) PyDestroyEvent(PLEvent *ev)
513
Py_BEGIN_ALLOW_THREADS
514
rc = aEventQ->processEventQueue(aTimeout < 0 ? RT_INDEFINITE_WAIT : (uint32_t)aTimeout);
517
return PyInt_FromLong(0);
519
if ( rc == VERR_TIMEOUT
520
|| rc == VERR_INTERRUPTED)
521
return PyInt_FromLong(1);
523
return NULL; /** @todo throw correct exception */
586
527
PyXPCOMMethod_InterruptWait(PyObject *self, PyObject *args)
588
nsIEventQueue* q = g_mainEventQ;
592
PLEvent *ev = new PLEvent();
598
q->InitEvent (ev, NULL, PyHandleEvent, PyDestroyEvent);
599
rc = q->PostEvent (ev);
607
return PyInt_FromLong(result);
529
com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
530
NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
534
aEventQ->interruptEventQueueProcessing();
536
return PyInt_FromLong(0);
610
539
static void deinitVBoxPython();
613
542
PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args)
615
544
Py_BEGIN_ALLOW_THREADS;