VirtualBox

Ignore:
Timestamp:
Jul 5, 2010 2:12:15 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63355
Message:

VBoxShell: get rid of callbacks

File:
1 edited

Legend:

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

    r30564 r30620  
    3232from optparse import OptionParser
    3333
    34 # Simple implementation of IConsoleCallback, one can use it as skeleton
    35 # for custom implementations
    36 class GuestMonitor:
    37     def __init__(self, mach):
    38         self.mach = mach
    39 
    40     def onMousePointerShapeChange(self, visible, alpha, xHot, yHot, width, height, shape):
    41         print  "%s: onMousePointerShapeChange: visible=%d shape=%d bytes" %(self.mach.name, visible,len(shape))
    42 
    43     def onMouseCapabilityChange(self, supportsAbsolute, supportsRelative, needsHostCursor):
    44         print  "%s: onMouseCapabilityChange: supportsAbsolute = %d, supportsRelative = %d, needsHostCursor = %d" %(self.mach.name, supportsAbsolute, supportsRelative, needsHostCursor)
    45 
    46     def onKeyboardLedsChange(self, numLock, capsLock, scrollLock):
    47         print  "%s: onKeyboardLedsChange capsLock=%d"  %(self.mach.name, capsLock)
    48 
    49     def onStateChange(self, state):
    50         print  "%s: onStateChange state=%d" %(self.mach.name, state)
    51 
    52     def onAdditionsStateChange(self):
    53         print  "%s: onAdditionsStateChange" %(self.mach.name)
    54 
    55     def onNetworkAdapterChange(self, adapter):
    56         print  "%s: onNetworkAdapterChange" %(self.mach.name)
    57 
    58     def onSerialPortChange(self, port):
    59         print  "%s: onSerialPortChange" %(self.mach.name)
    60 
    61     def onParallelPortChange(self, port):
    62         print  "%s: onParallelPortChange" %(self.mach.name)
    63 
    64     def onStorageControllerChange(self):
    65         print  "%s: onStorageControllerChange" %(self.mach.name)
    66 
    67     def onMediumChange(self, attachment):
    68         print  "%s: onMediumChange" %(self.mach.name)
    69 
    70     def onVRDPServerChange(self):
    71         print  "%s: onVRDPServerChange" %(self.mach.name)
    72 
    73     def onUSBControllerChange(self):
    74         print  "%s: onUSBControllerChange" %(self.mach.name)
    75 
    76     def onUSBDeviceStateChange(self, device, attached, error):
    77         print  "%s: onUSBDeviceStateChange" %(self.mach.name)
    78 
    79     def onSharedFolderChange(self, scope):
    80         print  "%s: onSharedFolderChange" %(self.mach.name)
    81 
    82     def onRuntimeError(self, fatal, id, message):
    83         print  "%s: onRuntimeError fatal=%d message=%s" %(self.mach.name, fatal, message)
    84 
    85     def onCanShowWindow(self):
    86         print  "%s: onCanShowWindow" %(self.mach.name)
    87         return True
    88 
    89     def onShowWindow(self, winId):
    90         print  "%s: onShowWindow: %d" %(self.mach.name, winId)
    91 
    92 class VBoxMonitor:
    93     def __init__(self, params):
    94         self.vbox = params[0]
    95         self.isMscom = params[1]
    96         pass
    97 
    98     def onMachineStateChange(self, id, state):
    99         print "onMachineStateChange: %s %d" %(id, state)
    100 
    101     def onMachineDataChange(self,id):
    102         print "onMachineDataChange: %s" %(id)
    103 
    104     def onExtraDataCanChange(self, id, key, value):
    105         print "onExtraDataCanChange: %s %s=>%s" %(id, key, value)
    106         # Witty COM bridge thinks if someone wishes to return tuple, hresult
    107         # is one of values we want to return
    108         if self.isMscom:
    109             return "", 0, True
    110         else:
    111             return True, ""
    112 
    113     def onExtraDataChange(self, id, key, value):
    114         print "onExtraDataChange: %s %s=>%s" %(id, key, value)
    115 
    116     def onMediaRegistered(self, id, type, registered):
    117         print "onMediaRegistered: %s" %(id)
    118 
    119     def onMachineRegistered(self, id, registred):
    120         print "onMachineRegistered: %s" %(id)
    121 
    122     def onSessionStateChange(self, id, state):
    123         print "onSessionStateChange: %s %d" %(id, state)
    124 
    125     def onSnapshotTaken(self, mach, id):
    126         print "onSnapshotTaken: %s %s" %(mach, id)
    127 
    128     def onSnapshotDeleted(self, mach, id):
    129         print "onSnapshotDeleted: %s %s" %(mach, id)
    130 
    131     def onSnapshotChange(self, mach, id):
    132         print "onSnapshotChange: %s %s" %(mach, id)
    133 
    134     def onGuestPropertyChange(self, id, name, newValue, flags):
    135        print "onGuestPropertyChange: %s: %s=%s" %(id, name, newValue)
    136 
    13734g_batchmode = False
    13835g_scripfile = None
     
    398295    exec cmds
    399296
    400 def monitorGuest(ctx, machine, console, dur):
    401     cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine)
    402     console.registerCallback(cb)
    403     if dur == -1:
    404         # not infinity, but close enough
    405         dur = 100000
    406     try:
    407         end = time.time() + dur
    408         while  time.time() < end:
    409             ctx['global'].waitForEvents(500)
    410     # We need to catch all exceptions here, otherwise callback will never be unregistered
    411     except:
    412         pass
    413     console.unregisterCallback(cb)
    414 
    415 
    416 def monitorVBox(ctx, dur):
    417     vbox = ctx['vb']
    418     isMscom = (ctx['global'].type == 'MSCOM')
    419     cb = ctx['global'].createCallback('IVirtualBoxCallback', VBoxMonitor, [vbox, isMscom])
    420     vbox.registerCallback(cb)
    421     if dur == -1:
    422         # not infinity, but close enough
    423         dur = 100000
    424     try:
    425         end = time.time() + dur
    426         while  time.time() < end:
    427             ctx['global'].waitForEvents(500)
    428     # We need to catch all exceptions here, otherwise callback will never be unregistered
    429     except:
    430         pass
    431     vbox.unregisterCallback(cb)
    432 
    433297def monitorSource(ctx, es, active, dur):
    434298    def handleEventImpl(ev):
    435299         type = ev.type
    436          print "got event: %s %s" %(str(ev.type), asEnumElem(ctx, 'VBoxEventType', type))
    437          if ev.type == ctx['global'].constants.VBoxEventType_OnMachineStateChange:
     300         print "got event: %s %s" %(str(type), asEnumElem(ctx, 'VBoxEventType', type))
     301         if type == ctx['global'].constants.VBoxEventType_OnMachineStateChange:
    438302             scev = ctx['global'].queryInterface(ev, 'IMachineStateChangeEvent')
    439303             if scev:
    440                  print "state event: mach=%s state=%s" %(scev.machineId, scev.state)
     304                 print "machine state event: mach=%s state=%s" %(scev.machineId, scev.state)
     305         elif  type == ctx['global'].constants.VBoxEventType_OnGuestPropertyChange:
     306             gpcev = ctx['global'].queryInterface(ev, 'IGuestPropertyChangeEvent')
     307             if gpcev:
     308                 print "guest property change: name=%s value=%s" %(gpcev.name, gpcev.value)
    441309         elif  type == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChange:
    442310             psev = ctx['global'].queryInterface(ev, 'IMousePointerShapeChangeEvent')
     
    480348    # We need to catch all exceptions here, otherwise listener will never be unregistered
    481349    except:
     350        traceback.print_exc()
    482351        pass
    483352    if listener and registered:
     
    645514         'ginfo':           lambda: ginfo(ctx, console, args),
    646515         'guestlambda':     lambda: args[0](ctx, mach, console, args[1:]),
    647          'monitorGuest':    lambda: monitorGuest(ctx, mach, console, args),
    648516         'save':            lambda: progressBar(ctx,console.saveState()),
    649517         'screenshot':      lambda: takeScreenshot(ctx,console,args),
     
    14331301    if len(args) > 2:
    14341302        dur = float(args[2])
    1435     cmdExistingVm(ctx, mach, 'monitorGuest', dur)
    1436     return 0
    1437 
    1438 def monitorGuest2Cmd(ctx, args):
    1439     if (len(args) < 2):
    1440         print "usage: monitorGuest2 name (duration)"
    1441         return 0
    1442     mach = argsToMach(ctx,args)
    1443     if mach == None:
    1444         return 0
    1445     dur = 5
    1446     if len(args) > 2:
    1447         dur = float(args[2])
    1448     active = True
     1303    active = False
    14491304    cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args:  monitorSource(ctx, console.eventSource, active, dur)])
    14501305    return 0
     1306
    14511307
    14521308def monitorVBoxCmd(ctx, args):
    14531309    if (len(args) > 2):
    14541310        print "usage: monitorVBox (duration)"
    1455         return 0
    1456     dur = 5
    1457     if len(args) > 1:
    1458         dur = float(args[1])
    1459     monitorVBox(ctx, dur)
    1460     return 0
    1461 
    1462 def monitorVBox2Cmd(ctx, args):
    1463     if (len(args) > 2):
    1464         print "usage: monitorVBox2 (duration)"
    14651311        return 0
    14661312    dur = 5
     
    14681314        dur = float(args[1])
    14691315    vbox = ctx['vb']
    1470     active = True
     1316    active = False
    14711317    monitorSource(ctx, vbox.eventSource, active, dur)
    14721318    return 0
     
    29392785            'guest':['Execute command for guest: guest Win32 \'console.mouse.putMouseEvent(20, 20, 0, 0, 0)\'', guestCmd, 0],
    29402786            'monitorGuest':['Monitor what happens with the guest for some time: monitorGuest Win32 10', monitorGuestCmd, 0],
    2941             'monitorGuest2':['Monitor what happens with the guest for some time: monitorGuest2 Win32 10', monitorGuest2Cmd, 0],
    29422787            'monitorVBox':['Monitor what happens with Virtual Box for some time: monitorVBox 10', monitorVBoxCmd, 0],
    2943             'monitorVBox2':['(temp)Monitor what happens with Virtual Box for some time: monitorVBox2 10', monitorVBox2Cmd, 0],
    29442788            'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win32 0 8080 80', portForwardCmd, 0],
    29452789            'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],
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