VirtualBox

Changeset 31604 in vbox


Ignore:
Timestamp:
Aug 12, 2010 3:17:54 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64728
Message:

waitForEvents: Don't return None, another test.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/vboxapi.py

    r31601 r31604  
    271271    def waitForEvents(self, timeout):
    272272        from win32api import GetCurrentThreadId
     273        from win32con import INFINITE
    273274        from win32event import MsgWaitForMultipleObjects, \
    274275                               QS_ALLINPUT, WAIT_TIMEOUT, WAIT_OBJECT_0
    275276        from pythoncom import PumpWaitingMessages
    276 
     277        import types
     278
     279        if not isinstance(timeout, types.IntType):
     280            raise TypeError("The timeout argument is not an integer")
    277281        if (self.tid != GetCurrentThreadId()):
    278282            raise Exception("wait for events from the same thread you inited!")
    279283
    280         rc = MsgWaitForMultipleObjects(self.handles, 0, timeout, QS_ALLINPUT)
     284        if timeout < 0:     cMsTimeout = INFINITE
     285        else:               cMsTimeout = timeout
     286        rc = MsgWaitForMultipleObjects(self.handles, 0, cMsTimeout, QS_ALLINPUT)
    281287        if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(self.handles):
    282288            # is it possible?
     
    559565        Returns 1 if timed out or interrupted in some way.
    560566        Returns 2 on error (like not supported for web services).
    561         Returns None or raises an exception if called on the wrong thread or if
    562         the timeout is not an integer value.
     567
     568        Raises an exception if the calling thread is not the main thread (the one
     569        that initialized VirtualBoxManager) or if the time isn't an integer.
    563570        """
    564571        return self.platform.waitForEvents(timeout)
     
    566573    def interruptWaitEvents(self):
    567574        """
    568 
    569 
     575        Interrupt a waitForEvents call.
     576        This is normally called from a worker thread.
     577
     578        Returns True on success, False on failure.
    570579        """
    571580        return self.platform.interruptWaitEvents()
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r31601 r31604  
    502502PyXPCOMMethod_WaitForEvents(PyObject *self, PyObject *args)
    503503{
    504   PRInt32 aTimeout;
    505 
    506   if (!PyArg_ParseTuple(args, "i", &aTimeout))
    507     return NULL; /** @todo throw exception */
    508 
    509   int rc;
    510   com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
    511   NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
    512   if (!aEventQ)
    513       return NULL;
    514 
    515   Py_BEGIN_ALLOW_THREADS
    516   rc = aEventQ->processEventQueue(aTimeout < 0 ? RT_INDEFINITE_WAIT : (uint32_t)aTimeout);
    517   Py_END_ALLOW_THREADS
    518   if (RT_SUCCESS(rc))
    519       return PyInt_FromLong(0);
    520 
    521   if (   rc == VERR_TIMEOUT
    522       || rc == VERR_INTERRUPTED)
    523       return PyInt_FromLong(1);
    524 
    525   return PyInt_FromLong(2);
     504    PRInt32 aTimeout;
     505
     506    if (!PyArg_ParseTuple(args, "i", &aTimeout))
     507    {
     508        PyErr_SetString(PyExc_TypeError, "the timeout argument is not an integer");
     509        return NULL;
     510    }
     511
     512    int rc;
     513    com::EventQueue* aEventQ = com::EventQueue::getMainEventQueue();
     514    NS_WARN_IF_FALSE(aEventQ != nsnull, "Null main event queue");
     515    if (!aEventQ)
     516        {
     517        PyErr_SetString(PyExc_TypeError, "the main event queue is NULL");
     518        return NULL;
     519        }
     520
     521    Py_BEGIN_ALLOW_THREADS
     522    rc = aEventQ->processEventQueue(aTimeout < 0 ? RT_INDEFINITE_WAIT : (uint32_t)aTimeout);
     523    Py_END_ALLOW_THREADS
     524    if (RT_SUCCESS(rc))
     525        return PyInt_FromLong(0);
     526
     527    if (   rc == VERR_TIMEOUT
     528        || rc == VERR_INTERRUPTED)
     529        return PyInt_FromLong(1);
     530
     531    if (rc == VERR_INVALID_CONTEXT)
     532        {
     533        PyErr_SetString(PyExc_Exception, "wrong thread, use the main thread");
     534                return NULL;
     535        }
     536
     537    return PyInt_FromLong(2);
    526538}
    527539
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette