VirtualBox

Changeset 30825 in vbox for trunk/src/VBox/Main/glue


Ignore:
Timestamp:
Jul 14, 2010 12:44:14 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
63641
Message:

Main: callbacks removal

Location:
trunk/src/VBox/Main/glue
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/glue/tests/TestVBox.java

    r30591 r30825  
    1616import java.math.BigInteger;
    1717
    18 class VBoxCallbacks extends VBoxObjectBase implements IVirtualBoxCallback
    19 {
    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 IConsoleCallback
    68 {
    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 
    15718public class TestVBox
    15819{
    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 
    19020    static void processEvent(IEvent ev)
    19121    {
     
    19828        {
    19929            case OnMachineStateChange:
    200                 IMachineStateChangeEvent mcse = IMachineStateChangeEvent.queryInterface(ev);
     30                IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev);
    20131                if (mcse == null)
    20232                    System.out.println("Cannot query an interface");
     
    22353    {
    22454        // 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
    22656        // recommended
    22757        IEventListener listener = active ? mgr.createListener(new EventHandler()) : es.createListener();
     
    285115            testEnumeration(mgr, vbox);
    286116            testStart(mgr, vbox);
    287             //testCallbacks(mgr, vbox);
    288117            testEvents(mgr, vbox.getEventSource(), false);
    289118
  • trunk/src/VBox/Main/glue/vboxapi.py

    r30533 r30825  
    217217            win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
    218218            win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
    219             win32com.client.gencache.EnsureDispatch('VirtualBox.CallbackWrapper')
    220219
    221220    def getSessionObject(self, vbox):
     
    245244        import pythoncom
    246245        pythoncom.CoUninitialize()
    247 
    248     def createCallback(self, iface, impl, arg):
    249         d = {}
    250         d['BaseClass'] = impl
    251         d['arg'] = arg
    252         d['tlb_guid'] = PlatformMSCOM.VBOX_TLB_GUID
    253         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 here
    263         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 up
    267         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']
    276246
    277247    def createListener(self, impl, arg):
     
    292262        str += "   _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy'\n"
    293263
    294         # capitalized version of callback method
     264        # capitalized version of listener method
    295265        str += "   HandleEvent=BaseClass.handleEvent\n"
    296266        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
     
    370340        import xpcom
    371341        xpcom._xpcom.DetachThread()
    372 
    373     def createCallback(self, iface, impl, arg):
    374         d = {}
    375         d['BaseClass'] = impl
    376         d['arg'] = arg
    377         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']
    386342
    387343    def createListener(self, impl, arg):
     
    478434        pass
    479435
    480     def createCallback(self, iface, impl, arg):
    481         raise Exception("no callbacks for webservices")
    482 
    483436    def createListener(self, impl, arg):
    484437        raise Exception("no active listeners for webservices")
     
    581534        self.platform.deinitPerThread()
    582535
    583     def createCallback(self, iface, impl, arg):
    584         return self.platform.createCallback(iface, impl, arg)
    585 
    586536    def createListener(self, impl, arg = None):
    587537        return self.platform.createListener(impl, arg)
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette