Changeset 30620 in vbox for trunk/src/VBox/Frontends/VBoxShell
- Timestamp:
- Jul 5, 2010 2:12:15 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63355
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r30564 r30620 32 32 from optparse import OptionParser 33 33 34 # Simple implementation of IConsoleCallback, one can use it as skeleton35 # for custom implementations36 class GuestMonitor:37 def __init__(self, mach):38 self.mach = mach39 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 True88 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 pass97 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, hresult107 # is one of values we want to return108 if self.isMscom:109 return "", 0, True110 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 137 34 g_batchmode = False 138 35 g_scripfile = None … … 398 295 exec cmds 399 296 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 enough405 dur = 100000406 try:407 end = time.time() + dur408 while time.time() < end:409 ctx['global'].waitForEvents(500)410 # We need to catch all exceptions here, otherwise callback will never be unregistered411 except:412 pass413 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 enough423 dur = 100000424 try:425 end = time.time() + dur426 while time.time() < end:427 ctx['global'].waitForEvents(500)428 # We need to catch all exceptions here, otherwise callback will never be unregistered429 except:430 pass431 vbox.unregisterCallback(cb)432 433 297 def monitorSource(ctx, es, active, dur): 434 298 def handleEventImpl(ev): 435 299 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: 438 302 scev = ctx['global'].queryInterface(ev, 'IMachineStateChangeEvent') 439 303 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) 441 309 elif type == ctx['global'].constants.VBoxEventType_OnMousePointerShapeChange: 442 310 psev = ctx['global'].queryInterface(ev, 'IMousePointerShapeChangeEvent') … … 480 348 # We need to catch all exceptions here, otherwise listener will never be unregistered 481 349 except: 350 traceback.print_exc() 482 351 pass 483 352 if listener and registered: … … 645 514 'ginfo': lambda: ginfo(ctx, console, args), 646 515 'guestlambda': lambda: args[0](ctx, mach, console, args[1:]), 647 'monitorGuest': lambda: monitorGuest(ctx, mach, console, args),648 516 'save': lambda: progressBar(ctx,console.saveState()), 649 517 'screenshot': lambda: takeScreenshot(ctx,console,args), … … 1433 1301 if len(args) > 2: 1434 1302 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 1449 1304 cmdExistingVm(ctx, mach, 'guestlambda', [lambda ctx,mach,console,args: monitorSource(ctx, console.eventSource, active, dur)]) 1450 1305 return 0 1306 1451 1307 1452 1308 def monitorVBoxCmd(ctx, args): 1453 1309 if (len(args) > 2): 1454 1310 print "usage: monitorVBox (duration)" 1455 return 01456 dur = 51457 if len(args) > 1:1458 dur = float(args[1])1459 monitorVBox(ctx, dur)1460 return 01461 1462 def monitorVBox2Cmd(ctx, args):1463 if (len(args) > 2):1464 print "usage: monitorVBox2 (duration)"1465 1311 return 0 1466 1312 dur = 5 … … 1468 1314 dur = float(args[1]) 1469 1315 vbox = ctx['vb'] 1470 active = True1316 active = False 1471 1317 monitorSource(ctx, vbox.eventSource, active, dur) 1472 1318 return 0 … … 2939 2785 'guest':['Execute command for guest: guest Win32 \'console.mouse.putMouseEvent(20, 20, 0, 0, 0)\'', guestCmd, 0], 2940 2786 '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],2942 2787 '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],2944 2788 'portForward':['Setup permanent port forwarding for a VM, takes adapter number host port and guest port: portForward Win32 0 8080 80', portForwardCmd, 0], 2945 2789 'showLog':['Show log file of the VM, : showLog Win32', showLogCmd, 0],
Note:
See TracChangeset
for help on using the changeset viewer.