Changeset 30825 in vbox for trunk/src/VBox/Main/glue
- Timestamp:
- Jul 14, 2010 12:44:14 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 63641
- Location:
- trunk/src/VBox/Main/glue
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/glue/tests/TestVBox.java
r30591 r30825 16 16 import java.math.BigInteger; 17 17 18 class VBoxCallbacks extends VBoxObjectBase implements IVirtualBoxCallback19 {20 public void onGuestPropertyChange(String machineId, String name, String value, String flags)21 {22 System.out.println("onGuestPropertyChange -- VM: " + machineId + ", " + name + "->" + value);23 }24 public void onSnapshotChange(String machineId, String snapshotId)25 {26 System.out.println("onSnapshotChange -- VM: " + machineId + ", snap: " + snapshotId);27 28 }29 public void onSnapshotDeleted(String machineId, String snapshotId)30 {31 System.out.println("onSnapshotDeleted -- VM: " + machineId + ", snap: " + snapshotId);32 }33 public void onSnapshotTaken(String machineId, String snapshotId)34 {35 System.out.println("onSnapshotTaken -- VM: " + machineId + ", snap: " + snapshotId);36 }37 public void onSessionStateChange(String machineId, SessionState state)38 {39 System.out.println("onSessionStateChange -- VM: " + machineId + ", state: " + state);40 }41 public void onMachineRegistered(String machineId, Boolean registered)42 {43 System.out.println("onMachineRegistered -- VM: " + machineId + ", registered: " + registered);44 }45 public void onMediumRegistered(String mediumId, DeviceType mediumType, Boolean registered)46 {47 System.out.println("onMediumRegistered -- ID: " + mediumId + ", type=" + mediumType + ", registered: " + registered);48 }49 public void onExtraDataChange(String machineId, String key, String value)50 {51 System.out.println("onExtraDataChange -- VM: " + machineId + ": " + key+"->"+value);52 }53 public Boolean onExtraDataCanChange(String machineId, String key, String value, Holder<String> error)54 {55 return true;56 }57 public void onMachineDataChange(String machineId)58 {59 System.out.println("onMachineDataChange -- VM: " + machineId);60 }61 public void onMachineStateChange(String machineId, MachineState state)62 {63 System.out.println("onMachineStateChange -- VM: " + machineId + ", state: " + state);64 }65 }66 67 class ConsoleCallbacks extends VBoxObjectBase implements IConsoleCallback68 {69 String mach;70 ConsoleCallbacks(String mach)71 {72 this.mach = mach;73 }74 public void onMousePointerShapeChange(Boolean visible, Boolean alpha, Long xHot, Long yHot, Long width, Long height, List<Short> shape)75 {76 System.out.println("onMousePointerShapeChange -- VM: " + mach);77 }78 public void onMouseCapabilityChange(Boolean supportsAbsolute, Boolean supportsRelative, Boolean needsHostCursor)79 {80 System.out.println("onMouseCapabilityChange -- VM: " + mach+" abs="+supportsAbsolute+ " rel="+supportsRelative+" need host="+needsHostCursor);81 }82 public void onKeyboardLedsChange(Boolean numLock, Boolean capsLock, Boolean scrollLock)83 {84 System.out.println("onKeyboardLedsChange -- VM: " + mach);85 }86 public void onStateChange(org.virtualbox_3_3.MachineState state)87 {88 System.out.println("onStateChange -- VM: " + mach);89 }90 public void onAdditionsStateChange()91 {92 System.out.println("onAdditionsStateChange -- VM: " + mach);93 }94 public void onNetworkAdapterChange(org.virtualbox_3_3.INetworkAdapter networkAdapter)95 {96 System.out.println("onNetworkAdapterChange -- VM: " + mach);97 }98 public void onSerialPortChange(org.virtualbox_3_3.ISerialPort serialPort)99 {100 System.out.println("onSerialPortChange -- VM: " + mach);101 }102 public void onParallelPortChange(org.virtualbox_3_3.IParallelPort parallelPort)103 {104 System.out.println("onParallelPortChange -- VM: " + mach);105 }106 public void onStorageControllerChange()107 {108 System.out.println("onStorageControllerChange -- VM: " + mach);109 }110 public void onMediumChange(org.virtualbox_3_3.IMediumAttachment mediumAttachment)111 {112 System.out.println("onMediumChange -- VM: " + mach);113 }114 public void onCPUChange(Long cpu, Boolean add)115 {116 System.out.println("onCPUChange -- VM: " + mach);117 }118 public void onVRDPServerChange()119 {120 System.out.println("onVRDPServerChange -- VM: " + mach);121 }122 public void onRemoteDisplayInfoChange()123 {124 System.out.println("onRemoteDisplayInfoChange -- VM: " + mach);125 }126 public void onUSBControllerChange()127 {128 System.out.println("onUSBControllerChange -- VM: " + mach);129 }130 public void onUSBDeviceStateChange(org.virtualbox_3_3.IUSBDevice device, Boolean attached, org.virtualbox_3_3.IVirtualBoxErrorInfo error)131 {132 System.out.println("onUSBDeviceStateChange -- VM: " + mach);133 }134 public void onSharedFolderChange(org.virtualbox_3_3.Scope scope)135 {136 System.out.println("onSharedFolderChange -- VM: " + mach);137 }138 139 public void onRuntimeError(Boolean fatal, String id, String message)140 {141 System.out.println("onRuntimeError -- VM: " + mach);142 }143 144 public Boolean onCanShowWindow()145 {146 System.out.println("onCanShowWindow -- VM: " + mach);147 return true;148 }149 150 public BigInteger onShowWindow()151 {152 System.out.println("onShowWindow -- VM: " + mach);153 return BigInteger.ZERO;154 }155 }156 157 18 public class TestVBox 158 19 { 159 static void testCallbacks(VirtualBoxManager mgr, IVirtualBox vbox)160 {161 162 IVirtualBoxCallback cbs = new VBoxCallbacks();163 mgr.registerGlobalCallback(vbox, cbs);164 165 IMachine mach = vbox.getMachines().get(0);166 IConsoleCallback mcbs = new ConsoleCallbacks(mach.getName());167 168 ISession session = null;169 try {170 session = mgr.openMachineSession(mach);171 mgr.registerMachineCallback(session, mcbs);172 173 for (int i=0; i<100; i++)174 {175 mgr.waitForEvents(500);176 }177 178 System.out.println("done waiting");179 180 mgr.unregisterMachineCallback(session, mcbs);181 } catch (Exception e) {182 e.printStackTrace();183 } finally {184 mgr.closeMachineSession(session);185 }186 mgr.unregisterGlobalCallback(vbox, cbs);187 }188 189 190 20 static void processEvent(IEvent ev) 191 21 { … … 198 28 { 199 29 case OnMachineStateChange: 200 IMachineStateChange Event mcse = IMachineStateChangeEvent.queryInterface(ev);30 IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev); 201 31 if (mcse == null) 202 32 System.out.println("Cannot query an interface"); … … 223 53 { 224 54 // active mode for Java doesn't fully work yet, and using passive 225 // is more portable (the only mode for MSCOM and WS) and thus generally 55 // is more portable (the only mode for MSCOM and WS) and thus generally 226 56 // recommended 227 57 IEventListener listener = active ? mgr.createListener(new EventHandler()) : es.createListener(); … … 285 115 testEnumeration(mgr, vbox); 286 116 testStart(mgr, vbox); 287 //testCallbacks(mgr, vbox);288 117 testEvents(mgr, vbox.getEventSource(), false); 289 118 -
trunk/src/VBox/Main/glue/vboxapi.py
r30533 r30825 217 217 win32com.client.gencache.EnsureDispatch('VirtualBox.Session') 218 218 win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox') 219 win32com.client.gencache.EnsureDispatch('VirtualBox.CallbackWrapper')220 219 221 220 def getSessionObject(self, vbox): … … 245 244 import pythoncom 246 245 pythoncom.CoUninitialize() 247 248 def createCallback(self, iface, impl, arg):249 d = {}250 d['BaseClass'] = impl251 d['arg'] = arg252 d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID253 str = ""254 str += "import win32com.server.util\n"255 str += "import pythoncom\n"256 257 str += "class "+iface+"Impl(BaseClass):\n"258 str += " _com_interfaces_ = ['"+iface+"']\n"259 str += " _typelib_guid_ = tlb_guid\n"260 str += " _typelib_version_ = 1, 0\n"261 str += " _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER\n"262 # Maybe we'd better implement Dynamic invoke policy, to be more flexible here263 str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"264 265 # generate capitalized version of callback methods -266 # that's how Python COM looks them up267 for m in dir(impl):268 if m.startswith("on"):269 str += " "+ComifyName(m)+"=BaseClass."+m+"\n"270 271 str += " def __init__(self): BaseClass.__init__(self, arg)\n"272 str += "result = win32com.client.Dispatch('VirtualBox.CallbackWrapper')\n"273 str += "result.SetLocalObject(win32com.server.util.wrap("+iface+"Impl()))\n"274 exec (str,d,d)275 return d['result']276 246 277 247 def createListener(self, impl, arg): … … 292 262 str += " _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n" 293 263 294 # capitalized version of callbackmethod264 # capitalized version of listener method 295 265 str += " HandleEvent=BaseClass.handleEvent\n" 296 266 str += " def __init__(self): BaseClass.__init__(self, arg)\n" … … 370 340 import xpcom 371 341 xpcom._xpcom.DetachThread() 372 373 def createCallback(self, iface, impl, arg):374 d = {}375 d['BaseClass'] = impl376 d['arg'] = arg377 str = ""378 str += "import xpcom.components\n"379 str += "class "+iface+"Impl(BaseClass):\n"380 str += " _com_interfaces_ = xpcom.components.interfaces."+iface+"\n"381 str += " def __init__(self): BaseClass.__init__(self, arg)\n"382 str += "result = xpcom.components.classes['@virtualbox.org/CallbackWrapper;1'].createInstance()\n"383 str += "result.setLocalObject("+iface+"Impl())\n"384 exec (str,d,d)385 return d['result']386 342 387 343 def createListener(self, impl, arg): … … 478 434 pass 479 435 480 def createCallback(self, iface, impl, arg):481 raise Exception("no callbacks for webservices")482 483 436 def createListener(self, impl, arg): 484 437 raise Exception("no active listeners for webservices") … … 581 534 self.platform.deinitPerThread() 582 535 583 def createCallback(self, iface, impl, arg):584 return self.platform.createCallback(iface, impl, arg)585 586 536 def createListener(self, impl, arg = None): 587 537 return self.platform.createListener(impl, arg)
Note:
See TracChangeset
for help on using the changeset viewer.