VirtualBox

Changeset 20693 in vbox


Ignore:
Timestamp:
Jun 18, 2009 4:37:00 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
48798
Message:

Python: Windows waiting for event, additional shell command

Location:
trunk/src/VBox
Files:
2 edited

Legend:

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

    r20630 r20693  
    156156    def onShowWindow(self, winId):
    157157        print  "%s: onShowWindow: %d" %(self.mach.name, winId)
     158
     159class VBoxMonitor:
     160    def __init__(self, vbox):
     161        self.vbox = vbox
     162        pass
     163
     164    def onMachineStateChange(self, id, state):
     165        print "onMachineStateChange: %s %d" %(id, state)
     166
     167    def onMachineDataChange(self,id):
     168        print "onMachineDataChange: %s" %(id)
     169   
     170    def onExtraDataCanChange(self, id, key, value):
     171        print "onExtraDataCanChange: %s %s=>%s" %(id, key, value)
     172        return true
     173
     174    def onExtraDataChange(self, id, key, value):
     175        print "onExtraDataChange: %s %s=>%s" %(id, key, value)
     176
     177    def onMediaRegistred(self, id, type, registred):
     178        print "onMediaRegistred: %s" %(id)
     179
     180    def onMachineRegistred(self, id, registred):
     181        print "onMachineRegistred: %s" %(id)
     182
     183    def onSessionStateChange(self, id, state):
     184        print "onSessionStateChange: %s %d" %(id, state)
     185
     186    def onSnapshotTaken(self, mach, id):
     187        print "onSnapshotTaken: %s %s" %(mach, id)
     188
     189    def onSnapshotDiscarded(self, mach, id):
     190        print "onSnapshotDiscarded: %s %s" %(mach, id)
     191
     192    def onSnapshotChange(self, mach, id):
     193        print "onSnapshotChange: %s %s" %(mach, id)
     194
     195    def onGuestPropertyChange(self, id, val1, val2, val3):
     196        print "onGuestPropertyChange: %s" %(id)
     197   
     198
    158199
    159200g_hasreadline = 1
     
    304345def monitorGuest(ctx, machine, console, dur):
    305346    import time
    306     import xpcom
    307347    cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine)
    308348    console.registerCallback(cb)
     
    319359    console.unregisterCallback(cb)
    320360
    321    
     361
     362def monitorVbox(ctx, dur):
     363    import time
     364    vbox = ctx['vb']
     365    cb = ctx['global'].createCallback('IVirtualBoxCallback', VBoxMonitor, vbox)
     366    vbox.registerCallback(cb)
     367    if dur == -1:
     368        # not infinity, but close enough
     369        dur = 100000
     370    try:
     371        end = time.time() + dur
     372        while  time.time() < end:
     373            ctx['global'].waitForEvents(500)
     374    # We need to catch all exceptions here, otherwise callback will never be unregistered
     375    except Exception,e:
     376        print e
     377        if g_verbose:
     378                traceback.print_exc()
     379        pass   
     380    vbox.unregisterCallback(cb)
    322381
    323382def cmdExistingVm(ctx,mach,cmd,args):
     
    561620    return 0
    562621
     622def monitorVboxCmd(ctx, args):
     623    if (len(args) > 2):
     624        print "usage: monitorVbox (duration)"
     625        return 0
     626    dur = 5
     627    if len(args) > 1:
     628        dur = float(args[1])
     629    monitorVbox(ctx, dur)
     630    return 0
     631
    563632def evalCmd(ctx, args):
    564633   expr = ' '.join(args[1:])
     
    597666            'guest':['Execute command for guest: guest Win32 console.mouse.putMouseEvent(20, 20, 0, 0)', guestCmd],
    598667            'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd],
     668            'monitorVbox':['Monitor what happens with Virtual Box for some time: monitorVbox 10', monitorVboxCmd],
    599669            }
    600670
  • trunk/src/VBox/Main/glue/vboxapi.py

    r20630 r20693  
    9292                    return self.__dict__['_rootFake'].__getattr__(a)
    9393
     94    VBOX_TLB_GUID  = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'
     95    VBOX_TLB_LCID  = 0
     96    VBOX_TLB_MAJOR = 1
     97    VBOX_TLB_MINOR = 0
     98
    9499    def __init__(self, params):
    95100            from win32com import universal
     
    99104            import pythoncom
    100105            import win32api
    101             self.constants = PlatformMSCOM.InterfacesWrapper()
     106            self.constants = PlatformMSCOM.InterfacesWrapper()                       
    102107
    103108    def getSessionObject(self, vbox):
     
    135140        d['BaseClass'] = impl
    136141        d['arg'] = arg
     142        d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
    137143        str = ""
    138         str += "import win32com.server.util"
     144        str += "import win32com.server.util\n"
     145        #str += "from win32com import universal\n"
     146        #str += "import pythoncom\n"
     147        #str += "universal.RegisterInterfaces(tlb_guid, 0, 1, 0, ['"+iface+"'])\n"
     148
    139149        str += "class "+iface+"Impl(BaseClass):\n"
    140150        str += "   _com_interfaces_ = ['"+iface+"']\n"
    141         str += "   _typelib_guid_ = '{46137EEC-703B-4FE5-AFD4-7C9BBBBA0259}'\n"
     151        str += "   _typelib_guid_ = tlb_guid\n"
     152        str += "   _typelib_version_ = 1, 0\n"
     153        #str += "   _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"
     154        #str += "   _reg_clsid_ = '{F21202A2-959A-4149-B1C3-68B9013F3335}'\n"
     155        #str += "   _reg_progid_ = 'VirtualBox."+iface+"Impl'\n"
     156        #str += "   _reg_desc_ = 'Generated callback implementation class'\n"
     157        #str += "   _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
     158
    142159        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
    143160        str += "result = win32com.server.util.wrap("+iface+"Impl())\n"       
     
    146163
    147164    def waitForEvents(self, timeout):
    148         # not really supported yet
    149         pass
     165        from win32file import CloseHandle
     166        from win32con import DUPLICATE_SAME_ACCESS
     167        from win32api import GetCurrentThread,DuplicateHandle,GetCurrentProcess
     168        from win32event import MsgWaitForMultipleObjects, \
     169                               QS_ALLINPUT, WAIT_TIMEOUT, WAIT_OBJECT_0
     170        from pythoncom import PumpWaitingMessages
     171
     172        pid = GetCurrentProcess()
     173        handle = DuplicateHandle(pid, GetCurrentThread(), pid, 0, 0, DUPLICATE_SAME_ACCESS)
     174       
     175        handles = []
     176        handles.append(handle)
     177
     178        rc = MsgWaitForMultipleObjects(handles, 0, timeout, QS_ALLINPUT)
     179        if rc >= WAIT_OBJECT_0 and rc < WAIT_OBJECT_0+len(handles):
     180            # is it possible?
     181            print "how come?"
     182            pass
     183        elif rc==WAIT_OBJECT_0 + len(handles):
     184            # Waiting messages
     185            PumpWaitingMessages()
     186        else:
     187            pass
     188        CloseHandle(handle)
    150189
    151190    def deinit(self):
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