VirtualBox

Changeset 20630 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Jun 16, 2009 1:55:38 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48707
Message:

Python: moved waiting on client side, removed main API for event waiting, as making no sense

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r12399 r20630  
    5454#include "nsIConsoleService.h"
    5555#include "nspr.h" // PR_fprintf
     56#ifdef VBOX
     57#include "nsEventQueueUtils.h"
     58#endif
    5659
    5760#ifdef XP_WIN
     
    489492}
    490493
     494#ifdef VBOX
     495static nsIEventQueue* g_mainEventQ = nsnull;
     496
     497static PyObject*
     498PyXPCOMMethod_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
     565static void deinitVBoxPython();
     566
     567static PyObject*
     568PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args)
     569{
     570  deinitVBoxPython();
     571  return PyInt_FromLong(0);
     572}
     573#endif
     574
    491575extern PYXPCOM_EXPORT PyObject *PyXPCOMMethod_IID(PyObject *self, PyObject *args);
    492576
     
    514598        {"MakeVariant", PyXPCOMMethod_MakeVariant, 1},
    515599        {"GetVariantValue", PyXPCOMMethod_GetVariantValue, 1},
     600#ifdef VBOX
     601        {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
     602        {"DeinitCOM", PyXPCOMMethod_DeinitCOM, 1},
     603#endif
    516604        // These should no longer be used - just use the logging.getLogger('pyxpcom')...
    517605        { NULL }
     
    650738    rc = com::Initialize();
    651739
     740    if (NS_SUCCEEDED(rc))
     741    {
     742      NS_GetMainEventQ (&g_mainEventQ);
     743    }
     744
    652745    init_xpcom();
    653746  }
    654747}
    655 #endif
     748
     749static
     750void 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.

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