Changeset 20693 in vbox
- Timestamp:
- Jun 18, 2009 4:37:00 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 48798
- Location:
- trunk/src/VBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxShell/vboxshell.py
r20630 r20693 156 156 def onShowWindow(self, winId): 157 157 print "%s: onShowWindow: %d" %(self.mach.name, winId) 158 159 class 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 158 199 159 200 g_hasreadline = 1 … … 304 345 def monitorGuest(ctx, machine, console, dur): 305 346 import time 306 import xpcom307 347 cb = ctx['global'].createCallback('IConsoleCallback', GuestMonitor, machine) 308 348 console.registerCallback(cb) … … 319 359 console.unregisterCallback(cb) 320 360 321 361 362 def 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) 322 381 323 382 def cmdExistingVm(ctx,mach,cmd,args): … … 561 620 return 0 562 621 622 def 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 563 632 def evalCmd(ctx, args): 564 633 expr = ' '.join(args[1:]) … … 597 666 'guest':['Execute command for guest: guest Win32 console.mouse.putMouseEvent(20, 20, 0, 0)', guestCmd], 598 667 '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], 599 669 } 600 670 -
trunk/src/VBox/Main/glue/vboxapi.py
r20630 r20693 92 92 return self.__dict__['_rootFake'].__getattr__(a) 93 93 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 94 99 def __init__(self, params): 95 100 from win32com import universal … … 99 104 import pythoncom 100 105 import win32api 101 self.constants = PlatformMSCOM.InterfacesWrapper() 106 self.constants = PlatformMSCOM.InterfacesWrapper() 102 107 103 108 def getSessionObject(self, vbox): … … 135 140 d['BaseClass'] = impl 136 141 d['arg'] = arg 142 d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID 137 143 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 139 149 str += "class "+iface+"Impl(BaseClass):\n" 140 150 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 142 159 str += " def __init__(self): BaseClass.__init__(self, arg)\n" 143 160 str += "result = win32com.server.util.wrap("+iface+"Impl())\n" … … 146 163 147 164 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) 150 189 151 190 def deinit(self):
Note:
See TracChangeset
for help on using the changeset viewer.