VirtualBox

Changeset 20598 in vbox


Ignore:
Timestamp:
Jun 15, 2009 6:08:09 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48645
Message:

Main: implmented waitForEvents(aTimeout) API for XPCOM targets, added command to VBox shell using this API

Location:
trunk/src/VBox
Files:
6 edited

Legend:

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

    r20332 r20598  
    9696            })
    9797        return out
     98
     99# Simple implementation of IConsoleCallback, one can use it as skeleton
     100# for custom implementations
     101class GuestMonitor:
     102    def __init__(self, mach):
     103        self.mach = mach
     104
     105    def onMousePointerShapeChange(self, visible, alpha, xHot, yHot, width, height, shape):
     106        print  "%s: onMousePointerShapeChange: visible=%d" %(self.mach.name, visible)
     107    def onMouseCapabilityChange(self, supportsAbsolute, needsHostCursor):
     108        print  "%s: onMouseCapabilityChange: needsHostCursor=%d" %(self.mach.name, needsHostCursor)
     109
     110    def onKeyboardLedsChange(self, numLock, capsLock, scrollLock):
     111        print  "%s: onKeyboardLedsChange capsLock=%d"  %(self.mach.name, capsLock)
     112
     113    def onStateChange(self, state):
     114        print  "%s: onStateChange state=%d" %(self.mach.name, state)
     115
     116    def onAdditionsStateChange(self):
     117        print  "%s: onAdditionsStateChange" %(self.mach.name)
     118
     119    def onDVDDriveChange(self):
     120        print  "%s: onDVDDriveChange" %(self.mach.name)
     121
     122    def onFloppyDriveChange(self):
     123        print  "%s: onFloppyDriveChange" %(self.mach.name)
     124
     125    def onNetworkAdapterChange(self, adapter):
     126        print  "%s: onNetworkAdapterChange" %(self.mach.name)
     127
     128    def onSerialPortChange(self, port):
     129        print  "%s: onSerialPortChange" %(self.mach.name)
     130
     131    def onParallelPortChange(self, port):
     132        print  "%s: onParallelPortChange" %(self.mach.name)
     133
     134    def onStorageControllerChange(self):
     135        print  "%s: onStorageControllerChange" %(self.mach.name)
     136
     137    def onVRDPServerChange(self):
     138        print  "%s: onVRDPServerChange" %(self.mach.name)
     139
     140    def onUSBControllerChange(self):
     141        print  "%s: onUSBControllerChange" %(self.mach.name)
     142
     143    def onUSBDeviceStateChange(self, device, attached, error):
     144        print  "%s: onUSBDeviceStateChange" %(self.mach.name)
     145
     146    def onSharedFolderChange(self, scope):
     147        print  "%s: onSharedFolderChange" %(self.mach.name)
     148
     149    def onRuntimeError(self, fatal, id, message):
     150        print  "%s: onRuntimeError fatal=%d message=%s" %(self.mach.name, fatal, message)
     151
     152    def onCanShowWindow(self):
     153        print  "%s: onCanShowWindow" %(self.mach.name)
     154        return true
     155
     156    def onShowWindow(self, winId):
     157        print  "%s: onShowWindow: %d" %(self.mach.name, winId)
    98158
    99159g_hasreadline = 1
     
    242302    exec cmds
    243303
     304def monitorGuest(ctx, machine, console, dur):
     305    import time
     306    cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine)
     307    console.registerCallback(cb)
     308    if dur == -1:
     309        # not infinity, but close enough
     310        dur = 100000
     311    end = time.clock() + dur
     312    while  time.clock() < end:
     313        ctx['vb'].waitForEvents(100)
     314    console.unregisterCallback(cb)
     315
    244316def cmdExistingVm(ctx,mach,cmd,args):
    245317    mgr=ctx['mgr']
     
    267339         'powerdown':  lambda: console.powerDown(),
    268340         'stats':      lambda: guestStats(ctx, mach),
    269          'guest':      lambda: guestExec(ctx, mach, console, args)
     341         'guest':      lambda: guestExec(ctx, mach, console, args),
     342         'monitorGuest': lambda: monitorGuest(ctx, mach, console, args)
    270343         }
    271344    try:
     
    467540   return 0
    468541
     542
     543def monitorGuestCmd(ctx, args):
     544    if (len(args) < 2):
     545        print "usage: monitorGuest name (duration)"
     546        return 0
     547    mach = argsToMach(ctx,args)
     548    if mach == None:
     549        return 0
     550    dur = 5
     551    if len(args) > 2:
     552        dur = float(args[2])
     553    cmdExistingVm(ctx, mach, 'monitorGuest', dur)
     554    return 0
    469555
    470556def evalCmd(ctx, args):
     
    503589            'host':['Show host information', hostCmd],
    504590            'guest':['Execute command for guest: guest Win32 console.mouse.putMouseEvent(20, 20, 0, 0)', guestCmd],
     591            'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd],
    505592            }
    506593
     
    537624        try:
    538625            cmd = raw_input("vbox> ")
     626            vbox.waitForEvents(0)
    539627            done = runCommand(ctx, cmd)
    540628            if done != 0: break
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r19750 r20598  
    18891889    LogFlowThisFunc (("aCallback=%p, rc=%08X\n", aCallback, rc));
    18901890    return rc;
     1891}
     1892
     1893
     1894STDMETHODIMP 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
    18911903}
    18921904
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20579 r20598  
    131131        pythoncom.CoUninitialize()
    132132
    133     def createCallback(self, iface, impl):       
     133    def createCallback(self, iface, impl, arg):       
    134134        d = {}
    135135        d['BaseClass'] = impl
     136        d['arg'] = arg
    136137        str = ""
    137138        str += "import win32com.server.util"
     
    139140        str += "   _com_interfaces_ = ['"+iface+"']\n"
    140141        str += "   _typelib_guid_ = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'\n"
    141         str += "   def __init__(self): pass\n"
     142        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
    142143        str += "result = win32com.server.util.wrap("+iface+"Impl())\n"       
    143144        exec (str,d,d)
     
    178179        pass
    179180
    180     def createCallback(self, iface, impl):       
     181    def createCallback(self, iface, impl, arg):
    181182        d = {}
    182183        d['BaseClass'] = impl
     184        d['arg'] = arg
    183185        str = ""
    184186        str += "import xpcom.components\n"
    185187        str += "class "+iface+"Impl(BaseClass):\n"
    186188        str += "   _com_interfaces_ = xpcom.components.interfaces."+iface+"\n"
    187         str += "   def __init__(self): pass\n"
     189        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
    188190        str += "result = "+iface+"Impl()\n"
    189191        exec (str,d,d)
     
    231233        pass
    232234
    233     def createCallback(self, iface, impl):
     235    def createCallback(self, iface, impl, arg):
    234236        raise Exception("no callbacks for webservices")
    235237
     
    284286        self.platform.deinitPerThread()
    285287
    286     def createCallback(self, iface, impl):
    287         return self.platform.createCallback(iface, impl)
     288    def createCallback(self, iface, impl, arg):
     289        return self.platform.createCallback(iface, impl, arg)
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r20381 r20598  
    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>
    26462661      </param>
    26472662    </method>
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

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

    r20081 r20598  
    244244static PRBool volatile gKeepRunning = PR_TRUE;
    245245
     246nsresult 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
    246310/////////////////////////////////////////////////////////////////////////////
    247311
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