VirtualBox

Changeset 22357 in vbox


Ignore:
Timestamp:
Aug 19, 2009 9:32:54 PM (15 years ago)
Author:
vboxsync
Message:

COM, Python: wrappers cleanup, some generic improvments

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/VirtualBox.h

    r22305 r22357  
    6363    ComPtr<ILocalOwner> ptr;
    6464
    65     HRESULT rc = ptr.createInprocObject(CLSID_VirtualBoxCallback);
     65    HRESULT rc = ptr.createInprocObject(CLSID_CallbackWrapper);
    6666    if (FAILED(rc))
    6767        return rc;
  • trunk/src/VBox/Main/VirtualBoxCallbackImpl.cpp

    r22305 r22357  
    2323#include "Logging.h"
    2424
    25 HRESULT VirtualBoxCallback::FinalConstruct()
     25HRESULT CallbackWrapper::FinalConstruct()
    2626{
    2727    return S_OK;
    2828}
    2929
    30 void VirtualBoxCallback::FinalRelease()
     30void CallbackWrapper::FinalRelease()
    3131{
    3232}
    3333
    3434// public initializers/uninitializers only for internal purposes
    35 HRESULT VirtualBoxCallback::init()
     35HRESULT CallbackWrapper::init()
    3636{
    3737    return S_OK;
    3838}
    3939
    40 void VirtualBoxCallback::uninit(bool aFinalRelease)
     40void CallbackWrapper::uninit(bool aFinalRelease)
    4141{
    4242}
     
    4545/////////////////////////////////////////////////////////////////////////////
    4646
    47 STDMETHODIMP VirtualBoxCallback::SetLocalObject(IUnknown *aCallback)
     47STDMETHODIMP CallbackWrapper::SetLocalObject(IUnknown *aCallback)
    4848{
    4949    if (aCallback == NULL)
     
    6868// IVirtualBoxCallback methods
    6969/////////////////////////////////////////////////////////////////////////////
    70 STDMETHODIMP VirtualBoxCallback::OnMachineStateChange(IN_BSTR machineId, MachineState_T state)
     70STDMETHODIMP CallbackWrapper::OnMachineStateChange(IN_BSTR machineId, MachineState_T state)
    7171{
    7272    if (mVBoxCallback.isNull())
     
    7676}
    7777
    78 STDMETHODIMP VirtualBoxCallback::OnMachineDataChange(IN_BSTR machineId)
     78STDMETHODIMP CallbackWrapper::OnMachineDataChange(IN_BSTR machineId)
    7979{
    8080    AutoReadLock alock(this);
     
    8787
    8888
    89 STDMETHODIMP VirtualBoxCallback::OnExtraDataCanChange(IN_BSTR machineId, IN_BSTR key, IN_BSTR value,
     89STDMETHODIMP CallbackWrapper::OnExtraDataCanChange(IN_BSTR machineId, IN_BSTR key, IN_BSTR value,
    9090                                           BSTR *error, BOOL *changeAllowed)
    9191{
     
    9696}
    9797
    98 STDMETHODIMP VirtualBoxCallback::OnExtraDataChange(IN_BSTR machineId, IN_BSTR key, IN_BSTR value)
     98STDMETHODIMP CallbackWrapper::OnExtraDataChange(IN_BSTR machineId, IN_BSTR key, IN_BSTR value)
    9999{
    100100    if (mVBoxCallback.isNull())
     
    104104}
    105105
    106 STDMETHODIMP VirtualBoxCallback::OnMediaRegistered(IN_BSTR mediaId, DeviceType_T mediaType,
     106STDMETHODIMP CallbackWrapper::OnMediaRegistered(IN_BSTR mediaId, DeviceType_T mediaType,
    107107                              BOOL registered)
    108108{
     
    114114
    115115
    116 STDMETHODIMP VirtualBoxCallback::OnMachineRegistered(IN_BSTR aMachineId, BOOL registered)
     116STDMETHODIMP CallbackWrapper::OnMachineRegistered(IN_BSTR aMachineId, BOOL registered)
    117117{
    118118    if (mVBoxCallback.isNull())
     
    122122}
    123123
    124 STDMETHODIMP VirtualBoxCallback::OnSessionStateChange(IN_BSTR aMachineId, SessionState_T state)
     124STDMETHODIMP CallbackWrapper::OnSessionStateChange(IN_BSTR aMachineId, SessionState_T state)
    125125{
    126126    if (mVBoxCallback.isNull())
     
    130130}
    131131
    132 STDMETHODIMP VirtualBoxCallback::OnSnapshotTaken(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
     132STDMETHODIMP CallbackWrapper::OnSnapshotTaken(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
    133133{
    134134    if (mVBoxCallback.isNull())
     
    138138}
    139139
    140 STDMETHODIMP VirtualBoxCallback::OnSnapshotDiscarded(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
     140STDMETHODIMP CallbackWrapper::OnSnapshotDiscarded(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
    141141{
    142142    if (mVBoxCallback.isNull())
     
    146146}
    147147
    148 STDMETHODIMP VirtualBoxCallback::OnSnapshotChange(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
     148STDMETHODIMP CallbackWrapper::OnSnapshotChange(IN_BSTR aMachineId, IN_BSTR aSnapshotId)
    149149{
    150150    if (mVBoxCallback.isNull())
     
    154154}
    155155
    156 STDMETHODIMP VirtualBoxCallback::OnGuestPropertyChange(IN_BSTR aMachineId, IN_BSTR key, IN_BSTR value, IN_BSTR flags)
     156STDMETHODIMP CallbackWrapper::OnGuestPropertyChange(IN_BSTR aMachineId, IN_BSTR key, IN_BSTR value, IN_BSTR flags)
    157157{
    158158    if (mVBoxCallback.isNull())
     
    163163
    164164
    165 STDMETHODIMP VirtualBoxCallback::OnMousePointerShapeChange(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
    166                                          ULONG width, ULONG height, BYTE *shape)
     165// IConsoleCallback methods
     166/////////////////////////////////////////////////////////////////////////////
     167STDMETHODIMP CallbackWrapper::OnMousePointerShapeChange(BOOL visible, BOOL alpha, ULONG xHot, ULONG yHot,
     168                                                        ULONG width, ULONG height, BYTE *shape)
    167169{
    168170    if (mConsoleCallback.isNull())
     
    173175
    174176
    175 STDMETHODIMP VirtualBoxCallback::OnMouseCapabilityChange(BOOL supportsAbsolute, BOOL needsHostCursor)
     177STDMETHODIMP CallbackWrapper::OnMouseCapabilityChange(BOOL supportsAbsolute, BOOL needsHostCursor)
    176178{
    177179    if (mConsoleCallback.isNull())
     
    181183}
    182184
    183 STDMETHODIMP  VirtualBoxCallback::OnKeyboardLedsChange(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
     185STDMETHODIMP  CallbackWrapper::OnKeyboardLedsChange(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
    184186{
    185187    if (mConsoleCallback.isNull())
     
    189191}
    190192
    191 STDMETHODIMP VirtualBoxCallback::OnStateChange(MachineState_T machineState)
     193STDMETHODIMP CallbackWrapper::OnStateChange(MachineState_T machineState)
    192194{
    193195    if (mConsoleCallback.isNull())
     
    197199}
    198200
    199 STDMETHODIMP VirtualBoxCallback::OnAdditionsStateChange()
     201STDMETHODIMP CallbackWrapper::OnAdditionsStateChange()
    200202{
    201203    if (mConsoleCallback.isNull())
     
    205207}
    206208
    207 STDMETHODIMP VirtualBoxCallback::OnDVDDriveChange()
     209STDMETHODIMP CallbackWrapper::OnDVDDriveChange()
    208210{
    209211    if (mConsoleCallback.isNull())
     
    213215}
    214216
    215 STDMETHODIMP VirtualBoxCallback::OnFloppyDriveChange()
     217STDMETHODIMP CallbackWrapper::OnFloppyDriveChange()
    216218{
    217219    if (mConsoleCallback.isNull())
     
    221223}
    222224
    223 STDMETHODIMP VirtualBoxCallback::OnNetworkAdapterChange(INetworkAdapter *aNetworkAdapter)
     225STDMETHODIMP CallbackWrapper::OnNetworkAdapterChange(INetworkAdapter *aNetworkAdapter)
    224226{
    225227    if (mConsoleCallback.isNull())
     
    229231}
    230232
    231 STDMETHODIMP VirtualBoxCallback::OnSerialPortChange(ISerialPort *aSerialPort)
     233STDMETHODIMP CallbackWrapper::OnSerialPortChange(ISerialPort *aSerialPort)
    232234{
    233235    if (mConsoleCallback.isNull())
     
    237239}
    238240
    239 STDMETHODIMP VirtualBoxCallback::OnParallelPortChange(IParallelPort *aParallelPort)
     241STDMETHODIMP CallbackWrapper::OnParallelPortChange(IParallelPort *aParallelPort)
    240242{
    241243    if (mConsoleCallback.isNull())
     
    244246    return mConsoleCallback->OnParallelPortChange(aParallelPort);
    245247}
    246 STDMETHODIMP VirtualBoxCallback::OnVRDPServerChange()
     248STDMETHODIMP CallbackWrapper::OnVRDPServerChange()
    247249{
    248250    if (mConsoleCallback.isNull())
     
    252254}
    253255
    254 STDMETHODIMP VirtualBoxCallback::OnUSBControllerChange()
     256STDMETHODIMP CallbackWrapper::OnUSBControllerChange()
    255257{
    256258    if (mConsoleCallback.isNull())
     
    260262}
    261263
    262 STDMETHODIMP VirtualBoxCallback::OnUSBDeviceStateChange(IUSBDevice *aDevice,
     264STDMETHODIMP CallbackWrapper::OnUSBDeviceStateChange(IUSBDevice *aDevice,
    263265                                                        BOOL aAttached,
    264266                                                        IVirtualBoxErrorInfo *aError)
     
    270272}
    271273
    272 STDMETHODIMP VirtualBoxCallback::OnSharedFolderChange(Scope_T aScope)
     274STDMETHODIMP CallbackWrapper::OnSharedFolderChange(Scope_T aScope)
    273275{
    274276    if (mConsoleCallback.isNull())
     
    278280}
    279281
    280 STDMETHODIMP VirtualBoxCallback::OnStorageControllerChange()
     282STDMETHODIMP CallbackWrapper::OnStorageControllerChange()
    281283{
    282284    if (mConsoleCallback.isNull())
     
    286288}
    287289
    288 STDMETHODIMP VirtualBoxCallback::OnRuntimeError(BOOL fFatal, IN_BSTR id, IN_BSTR message)
     290STDMETHODIMP CallbackWrapper::OnRuntimeError(BOOL fFatal, IN_BSTR id, IN_BSTR message)
    289291{
    290292    if (mConsoleCallback.isNull())
     
    294296}
    295297
    296 STDMETHODIMP VirtualBoxCallback::OnCanShowWindow(BOOL *canShow)
     298STDMETHODIMP CallbackWrapper::OnCanShowWindow(BOOL *canShow)
    297299{
    298300    if (mConsoleCallback.isNull())
     
    302304}
    303305
    304 STDMETHODIMP VirtualBoxCallback::OnShowWindow(ULONG64 *winId)
     306STDMETHODIMP CallbackWrapper::OnShowWindow(ULONG64 *winId)
    305307{
    306308    if (mConsoleCallback.isNull())
  • trunk/src/VBox/Main/glue/vboxapi.py

    r22305 r22357  
    218218            win32com.client.gencache.EnsureDispatch('VirtualBox.Session')
    219219            win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBox')
    220             win32com.client.gencache.EnsureDispatch('VirtualBox.VirtualBoxCallback')
     220            win32com.client.gencache.EnsureDispatch('VirtualBox.CallbackWrapper')
    221221
    222222    def getSessionObject(self, vbox):
     
    261261        str += "   _typelib_version_ = 1, 0\n"
    262262
    263         # generate capitalized version of callbacks - that's how Python COM
    264         # looks them up on Windows
     263        # generate capitalized version of callback methods -
     264        # that's how Python COM looks them up
    265265        for m in dir(impl):
    266266           if m.startswith("on"):
     
    268268
    269269        str += "   def __init__(self): BaseClass.__init__(self, arg)\n"
    270         str += "result = win32com.client.Dispatch('VirtualBox.VirtualBoxCallback')\n"
    271         str += "result.SetLocalObject(win32com.server.util.wrap("+iface+"Impl())\n"
     270        str += "result = win32com.client.Dispatch('VirtualBox.CallbackWrapper')\n"
     271        str += "result.SetLocalObject("+iface+"Impl())\n"
    272272        exec (str,d,d)
    273273        return d['result']
     
    330330
    331331    def initPerThread(self):
    332         pass
     332        import xpcom
     333        xpcom._xpcom.AttachThread()
    333334
    334335    def deinitPerThread(self):
    335         pass
     336        import xpcom
     337        xpcom._xpcom.DetachThread()
    336338
    337339    def createCallback(self, iface, impl, arg):
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r22323 r22357  
    10811081    <desc>
    10821082      The ILocalOwner interface allows to register local objects
    1083       (created without COM calls). Once registered, calls to methods
    1084       of such objects can be made from remote COM processes.
     1083      (created without COM calls, but with new()).
     1084      Once registered, calls to methods of such objects can be made
     1085      from remote COM processes.
    10851086      The main usecase is the event callback implementation where
    10861087      API clients provide callback objects.
     
    1314813149      <interface name="ISession" default="yes"/>
    1314913150    </class>
    13150     <class name="VirtualBoxCallback" uuid="49EE8561-5563-4715-B18C-A4B1A490DAFE"
     13151    <class name="CallbackWrapper" uuid="49EE8561-5563-4715-B18C-A4B1A490DAFE"
    1315113152           namespace="virtualbox.org">
    13152       <interface name="IVirtualBoxCallback" default="yes"/>
    13153       <interface name="ILocalOwner"/>
     13153      <interface name="ILocalOwner" default="yes"/>
     13154      <interface name="IVirtualBoxCallback"/>
     13155      <interface name="IConsoleCallback"/>
    1315413156    </class>
    1315513157  </module>
  • trunk/src/VBox/Main/include/VirtualBoxCallbackImpl.h

    r22306 r22357  
    2323#endif
    2424
    25 class ATL_NO_VTABLE VirtualBoxCallback :
     25class ATL_NO_VTABLE CallbackWrapper :
    2626    public VirtualBoxBase,
    27     public VirtualBoxSupportErrorInfoImpl<VirtualBoxCallback, IVirtualBoxCallback>,
    28     public VirtualBoxSupportTranslation<VirtualBoxCallback>,
     27    public VirtualBoxSupportErrorInfoImpl<CallbackWrapper, IVirtualBoxCallback>,
     28    public VirtualBoxSupportTranslation<CallbackWrapper>,
    2929    VBOX_SCRIPTABLE_IMPL(ILocalOwner),
    3030    VBOX_SCRIPTABLE_IMPL(IConsoleCallback),
    3131    VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback)
    3232#ifdef RT_OS_WINDOWS
    33     , public CComCoClass<VirtualBoxCallback, &CLSID_VirtualBoxCallback>
     33    , public CComCoClass<CallbackWrapper, &CLSID_CallbackWrapper>
    3434#endif
    3535{
     
    3939
    4040    DECLARE_REGISTRY_RESOURCEID(IDR_VIRTUALBOX)
    41     DECLARE_NOT_AGGREGATABLE(VirtualBoxCallback)
     41    DECLARE_NOT_AGGREGATABLE(CallbackWrapper)
    4242
    4343    DECLARE_PROTECT_FINAL_CONSTRUCT()
     
    103103
    104104    // for VirtualBoxSupportErrorInfoImpl
    105     static const wchar_t *getComponentName() { return L"VirtualBoxCallback"; }
     105    static const wchar_t *getComponentName() { return L"CallbackWrapper"; }
    106106
    107107private:
  • trunk/src/VBox/Main/xpcom/module.cpp

    r22305 r22357  
    8080NS_DECL_CLASSINFO(Console)
    8181NS_IMPL_THREADSAFE_ISUPPORTS1_CI(Console, IConsole)
    82 NS_DECL_CLASSINFO(VirtualBoxCallback)
    83 NS_IMPL_THREADSAFE_ISUPPORTS3_CI(VirtualBoxCallback, IVirtualBoxCallback, IConsoleCallback, ILocalOwner)
     82NS_DECL_CLASSINFO(CallbackWrapper)
     83NS_IMPL_THREADSAFE_ISUPPORTS3_CI(CallbackWrapper, IVirtualBoxCallback, IConsoleCallback, ILocalOwner)
    8484/**
    8585 *  Singleton class factory that holds a reference to the created instance
     
    136136NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC (Session)
    137137
    138 NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC (VirtualBoxCallback)
     138NS_GENERIC_FACTORY_CONSTRUCTOR_WITH_RC (CallbackWrapper)
    139139
    140140
     
    159159    },
    160160    {
    161         "VirtualBoxCallback component", // description
    162         NS_VIRTUALBOXCALLBACK_CID, NS_VIRTUALBOXCALLBACK_CONTRACTID, // CID/ContractID
    163         VirtualBoxCallbackConstructor, // constructor function
     161        "CallbackWrapper component", // description
     162        NS_CALLBACKWRAPPER_CID, NS_CALLBACKWRAPPER_CONTRACTID, // CID/ContractID
     163        CallbackWrapperConstructor, // constructor function
    164164        NULL, // registration function
    165165        NULL, // deregistration function
    166 //        SessionClassFactory::releaseInstance,
    167166        NULL, // destructor function
    168         NS_CI_INTERFACE_GETTER_NAME(VirtualBoxCallback), // interfaces function
     167        NS_CI_INTERFACE_GETTER_NAME(CallbackWrapper), // interfaces function
    169168        NULL, // language helper
    170         &NS_CLASSINFO_NAME(VirtualBoxCallback) // global class info & flags
     169        &NS_CLASSINFO_NAME(CallbackWrapper) // global class info & flags
    171170    }
    172171
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp

    r22164 r22357  
    16041604      // send address of the instance wrapper, and set the low bit to indicate
    16051605      // to the remote party that this is a remote instance wrapper.
    1606       PtrBits bits = ((PtrBits)(uintptr_t) wrapper) | PTRBITS_REMOTE_BIT;
     1606      PtrBits bits = ((PtrBits)(uintptr_t) wrapper);
     1607      NS_ASSERTION((bits & PTRBITS_REMOTE_BIT) == 0, "remote bit wrong)");
     1608      bits |= PTRBITS_REMOTE_BIT;
    16071609      writer.PutBytes(&bits, sizeof(bits));
    16081610    }
  • trunk/src/libs/xpcom18a4/python/src/module/_xpcom.cpp

    r21300 r22357  
    493493
    494494#ifdef VBOX
     495
    495496static nsIEventQueue* g_mainEventQ = nsnull;
    496497
     
    575576PyXPCOMMethod_DeinitCOM(PyObject *self, PyObject *args)
    576577{
    577   Py_BEGIN_ALLOW_THREADS;
    578   deinitVBoxPython();
    579   Py_END_ALLOW_THREADS;
    580   return PyInt_FromLong(0);
     578    Py_BEGIN_ALLOW_THREADS;
     579    deinitVBoxPython();
     580    Py_END_ALLOW_THREADS;
     581    return PyInt_FromLong(0);
     582}
     583
     584static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
     585
     586static PyObject*
     587PyXPCOMMethod_AttachThread(PyObject *self, PyObject *args)
     588{
     589    nsresult rv;
     590    PRInt32  result = 0;
     591    nsCOMPtr<nsIEventQueueService> eqs;
     592
     593    // Create the Event Queue for this thread...
     594    Py_BEGIN_ALLOW_THREADS;
     595    eqs =
     596      do_GetService(kEventQueueServiceCID, &rv);
     597    Py_END_ALLOW_THREADS;
     598    if (NS_FAILED(rv))
     599    {
     600      result = 1;
     601      goto done;
     602    }
     603
     604    Py_BEGIN_ALLOW_THREADS;
     605    rv = eqs->CreateThreadEventQueue();
     606    Py_END_ALLOW_THREADS;
     607    if (NS_FAILED(rv))
     608    {
     609      result = 2;
     610      goto done;
     611    }
     612
     613 done:
     614    /** @todo: better throw an exception on error */
     615    return PyInt_FromLong(result);
     616}
     617
     618static PyObject*
     619PyXPCOMMethod_DetachThread(PyObject *self, PyObject *args)
     620{
     621    nsresult rv;
     622    PRInt32  result = 0;
     623    nsCOMPtr<nsIEventQueueService> eqs;
     624
     625    // Destroy the Event Queue for this thread...
     626    Py_BEGIN_ALLOW_THREADS;
     627    eqs =
     628      do_GetService(kEventQueueServiceCID, &rv);
     629    Py_END_ALLOW_THREADS;
     630    if (NS_FAILED(rv))
     631    {
     632      result = 1;
     633      goto done;
     634    }
     635
     636    Py_BEGIN_ALLOW_THREADS;
     637    rv = eqs->DestroyThreadEventQueue();
     638    Py_END_ALLOW_THREADS;
     639    if (NS_FAILED(rv))
     640    {
     641      result = 2;
     642      goto done;
     643    }
     644
     645 done:
     646    /** @todo: better throw an exception on error */
     647    return PyInt_FromLong(result);
    581648}
    582649#endif
     
    609676#ifdef VBOX
    610677        {"WaitForEvents", PyXPCOMMethod_WaitForEvents, 1},
    611         {"DeinitCOM", PyXPCOMMethod_DeinitCOM, 1},
     678        {"DeinitCOM",     PyXPCOMMethod_DeinitCOM, 1},
     679        {"AttachThread",  PyXPCOMMethod_AttachThread, 1},
     680        {"DetachThread",  PyXPCOMMethod_DetachThread, 1},
    612681#endif
    613682        // These should no longer be used - just use the logging.getLogger('pyxpcom')...
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