VirtualBox

Changeset 20630 in vbox


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

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r20598 r20630  
    304304def monitorGuest(ctx, machine, console, dur):
    305305    import time
     306    import xpcom
    306307    cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine)
    307308    console.registerCallback(cb)
     
    309310        # not infinity, but close enough
    310311        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   
    314319    console.unregisterCallback(cb)
     320
     321   
    315322
    316323def cmdExistingVm(ctx,mach,cmd,args):
     
    624631        try:
    625632            cmd = raw_input("vbox> ")
    626             vbox.waitForEvents(0)
    627633            done = runCommand(ctx, cmd)
    628634            if done != 0: break
     
    662668           }
    663669    interpret(ctx)
     670    g_virtualBoxManager.deinit()
    664671    del g_virtualBoxManager
    665672
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r20598 r20630  
    18911891}
    18921892
    1893 
    1894 STDMETHODIMP VirtualBox::WaitForEvents(LONG aTimeout)
    1895 {
    1896 #ifdef RT_OS_WINDOWS
    1897     ReturnComNotImplemented();
    1898 #else
    1899     extern nsresult XPCOM_waitForEvents(PRInt32 aTimeout);
    1900 
    1901     return XPCOM_waitForEvents(aTimeout);
    1902 #endif
    1903 }
    19041893
    19051894STDMETHODIMP VirtualBox::WaitForPropertyChange (IN_BSTR /* aWhat */, ULONG /* aTimeout */,
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20598 r20630  
    145145        return d['result']
    146146
     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
    147156class PlatformXPCOM:
    148157    def __init__(self, params):
     
    192201        return d['result']
    193202
     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()
    194210
    195211class PlatformWEBSERVICE:
     
    235251    def createCallback(self, iface, impl, arg):
    236252        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
    237261
    238262class SessionManager:
     
    269293
    270294    def __del__(self):
     295        deinit(self)
     296
     297    def deinit(self):
    271298        if hasattr(self, "vbox"):
    272299            del self.vbox
     300        if hasattr(self, "platform"):
     301            self.platform.deinit()
    273302
    274303    def initPerThread(self):
     
    288317    def createCallback(self, iface, impl, arg):
    289318        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  
    26442644      <param name="callback" type="IVirtualBoxCallback" dir="in">
    26452645        <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 loop
    2653         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>
    26612646      </param>
    26622647    </method>
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r20598 r20630  
    180180    STDMETHOD(UnregisterCallback) (IVirtualBoxCallback *aCallback);
    181181
    182     STDMETHOD(WaitForEvents) (LONG aTimeout);   
    183182    STDMETHOD(WaitForPropertyChange) (IN_BSTR aWhat, ULONG aTimeout,
    184183                                      BSTR *aChanged, BSTR *aValues);
  • trunk/src/VBox/Main/xpcom/server.cpp

    r20598 r20630  
    244244static PRBool volatile gKeepRunning = PR_TRUE;
    245245
    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 
    310246/////////////////////////////////////////////////////////////////////////////
    311247
     
    776712
    777713/**
    778  * Hhelper function to register self components upon start-up
     714 * Helper function to register self components upon start-up
    779715 * of the out-of-proc server.
    780716 */
  • 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.

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