VirtualBox

Changeset 33963 in vbox


Ignore:
Timestamp:
Nov 11, 2010 10:23:42 AM (14 years ago)
Author:
vboxsync
Message:

Main: moved listeners to location usable by fronends, rework

Location:
trunk
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp

    r33852 r33963  
    2525
    2626#include <VBox/com/VirtualBox.h>
     27#include <VBox/com/listeners.h>
    2728
    2829using namespace com;
     
    9192 *  Handler for global events.
    9293 */
    93 class VirtualBoxEventListener :
    94   VBOX_SCRIPTABLE_IMPL(IEventListener)
     94class VirtualBoxEventListener
    9595{
    9696public:
    9797    VirtualBoxEventListener()
    9898    {
    99 #ifndef VBOX_WITH_XPCOM
    100         refcnt = 0;
    101 #endif
    10299        mfNoLoggedInUsers = true;
    103100    }
     
    107104    }
    108105
    109 #ifndef VBOX_WITH_XPCOM
    110     STDMETHOD_(ULONG, AddRef)()
    111     {
    112         return ::InterlockedIncrement(&refcnt);
    113     }
    114     STDMETHOD_(ULONG, Release)()
    115     {
    116         long cnt = ::InterlockedDecrement(&refcnt);
    117         if (cnt == 0)
    118             delete this;
    119         return cnt;
    120     }
    121 #endif
    122     VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
    123 
    124     NS_DECL_ISUPPORTS
    125 
    126     STDMETHOD(HandleEvent)(IEvent * aEvent)
    127     {
    128         VBoxEventType_T aType = VBoxEventType_Invalid;
    129 
    130         aEvent->COMGETTER(Type)(&aType);
     106    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
     107    {
    131108        switch (aType)
    132109        {
     
    214191
    215192private:
    216 #ifndef VBOX_WITH_XPCOM
    217     long refcnt;
    218 #endif
    219 
    220193    bool mfNoLoggedInUsers;
    221194};
    222 
    223195
    224196/**
    225197 *  Handler for machine events.
    226198 */
    227 class ConsoleEventListener :
    228   VBOX_SCRIPTABLE_IMPL(IEventListener)
     199class ConsoleEventListener
    229200{
    230201public:
    231202    ConsoleEventListener()
    232203    {
    233 #ifndef VBOX_WITH_XPCOM
    234         refcnt = 0;
    235 #endif
    236204        mLastVRDEPort = -1;
    237205    }
     
    241209    }
    242210
    243 #ifndef VBOX_WITH_XPCOM
    244     STDMETHOD_(ULONG, AddRef)()
    245     {
    246         return ::InterlockedIncrement(&refcnt);
    247     }
    248     STDMETHOD_(ULONG, Release)()
    249     {
    250         long cnt = ::InterlockedDecrement(&refcnt);
    251         if (cnt == 0)
    252             delete this;
    253         return cnt;
    254     }
    255 #endif
    256     VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
    257 
    258     NS_DECL_ISUPPORTS
    259 
    260     STDMETHOD(HandleEvent)(IEvent * aEvent)
    261     {
    262         VBoxEventType_T aType = VBoxEventType_Invalid;
    263 
    264         aEvent->COMGETTER(Type)(&aType);
     211    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
     212    {
    265213        switch (aType)
    266214        {
     
    358306private:
    359307
    360 #ifndef VBOX_WITH_XPCOM
    361     long refcnt;
    362 #endif
    363308    long mLastVRDEPort;
    364309};
    365310
    366 #ifdef VBOX_WITH_XPCOM
    367 NS_DECL_CLASSINFO(VirtualBoxEventListener)
    368 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VirtualBoxEventListener, IEventListener)
    369 NS_DECL_CLASSINFO(ConsoleEventListener)
    370 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(ConsoleEventListener, IEventListener)
    371 #endif
     311typedef ListenerImpl<VirtualBoxEventListener> VirtualBoxEventListenerImpl;
     312typedef ListenerImpl<ConsoleEventListener> ConsoleEventListenerImpl;
     313
     314VBOX_LISTENER_DECLARE(VirtualBoxEventListenerImpl)
     315VBOX_LISTENER_DECLARE(ConsoleEventListenerImpl)
    372316
    373317#ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
     
    993937            ComPtr<IEventSource> es;
    994938            CHECK_ERROR(console, COMGETTER(EventSource)(es.asOutParam()));
    995             consoleListener = new ConsoleEventListener();
    996             consoleListener->AddRef();
     939            consoleListener = new ConsoleEventListenerImpl();
    997940            com::SafeArray <VBoxEventType_T> eventTypes;
    998941            eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
     
    11491092            ComPtr<IEventSource> es;
    11501093            CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam()));
    1151             vboxListener = new VirtualBoxEventListener();
    1152             vboxListener->AddRef();
     1094            vboxListener = new VirtualBoxEventListenerImpl();
    11531095            com::SafeArray <VBoxEventType_T> eventTypes;
    11541096            eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged);
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r33916 r33963  
    233233 * Event handler for VirtualBox events
    234234 */
    235 class VBoxSDLEventListener :
    236   VBOX_SCRIPTABLE_IMPL(IEventListener)
     235class VBoxSDLEventListener
    237236{
    238237public:
    239238    VBoxSDLEventListener()
    240239    {
    241 #if defined(RT_OS_WINDOWS)
    242         refcnt = 0;
    243 #endif
    244240    }
    245241
     
    248244    }
    249245
    250 #ifdef RT_OS_WINDOWS
    251     STDMETHOD_(ULONG, AddRef)()
    252     {
    253         return ::InterlockedIncrement(&refcnt);
    254     }
    255     STDMETHOD_(ULONG, Release)()
    256     {
    257         long cnt = ::InterlockedDecrement(&refcnt);
    258         if (cnt == 0)
    259             delete this;
    260         return cnt;
    261     }
    262 #endif
    263     VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
    264 
    265     NS_DECL_ISUPPORTS
    266 
    267 
    268     STDMETHOD(HandleEvent)(IEvent * aEvent)
    269     {
    270         VBoxEventType_T aType = VBoxEventType_Invalid;
    271 
    272         aEvent->COMGETTER(Type)(&aType);
     246    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
     247    {
    273248        switch (aType)
    274249        {
     
    312287        return S_OK;
    313288    }
    314 
    315 private:
    316 #ifdef RT_OS_WINDOWS
    317     long refcnt;
    318 #endif
    319 
    320289};
    321290
     
    323292 * Event handler for machine events
    324293 */
    325 class VBoxSDLConsoleEventListener :
    326     VBOX_SCRIPTABLE_IMPL(IEventListener)
     294class VBoxSDLConsoleEventListener
    327295{
    328296public:
    329297    VBoxSDLConsoleEventListener() : m_fIgnorePowerOffEvents(false)
    330298    {
    331 #if defined(RT_OS_WINDOWS)
    332         refcnt = 0;
    333 #endif
    334299    }
    335300
     
    338303    }
    339304
    340 #ifdef RT_OS_WINDOWS
    341     STDMETHOD_(ULONG, AddRef)()
    342     {
    343         return ::InterlockedIncrement(&refcnt);
    344     }
    345     STDMETHOD_(ULONG, Release)()
    346     {
    347         long cnt = ::InterlockedDecrement(&refcnt);
    348         if (cnt == 0)
    349             delete this;
    350         return cnt;
    351     }
    352 #endif
    353     VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
    354 
    355     NS_DECL_ISUPPORTS
    356 
    357     STDMETHOD(HandleEvent)(IEvent * aEvent)
    358     {
    359         VBoxEventType_T aType = VBoxEventType_Invalid;
    360 
    361         aEvent->COMGETTER(Type)(&aType);
     305    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
     306    {
    362307        // likely all this double copy is now excessive, and we can just use existing event object
    363308        // @todo: eliminate it
     
    567512
    568513private:
    569 #ifdef RT_OS_WINDOWS
    570     long refcnt;
    571 #endif
    572514    bool m_fIgnorePowerOffEvents;
    573515};
    574516
    575 #ifdef VBOX_WITH_XPCOM
    576 NS_DECL_CLASSINFO(VBoxSDLEventListener)
    577 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxSDLEventListener, IEventListener)
    578 NS_DECL_CLASSINFO(VBoxSDLConsoleEventListener)
    579 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VBoxSDLConsoleEventListener, IEventListener)
    580 #endif /* VBOX_WITH_XPCOM */
    581517
    582518static void show_usage()
  • trunk/src/VBox/Main/ConsoleImpl.cpp

    r33959 r33963  
    7373#include <VBox/com/array.h>
    7474#include "VBox/com/ErrorInfo.h"
     75#include <VBox/com/listeners.h>
    7576
    7677#include <iprt/asm.h>
  • trunk/src/VBox/Main/ConsoleVRDPServer.cpp

    r33959 r33963  
    3434#include <VBox/err.h>
    3535#include <VBox/RemoteDesktop/VRDEOrders.h>
     36#include <VBox/com/listeners.h>
    3637
    3738class VRDPConsoleListener
  • trunk/src/VBox/Main/include/EventImpl.h

    r33959 r33963  
    230230};
    231231
    232 #define NS_IMPL_QUERY_HEAD_INLINE()                                   \
    233 NS_IMETHODIMP QueryInterface(REFNSIID aIID, void** aInstancePtr)      \
    234 {                                                                     \
    235   NS_ASSERTION(aInstancePtr,                                          \
    236                "QueryInterface requires a non-NULL destination!");    \
    237   nsISupports* foundInterface;
    238 
    239 #ifndef RT_OS_WINDOWS
    240 #define NS_INTERFACE_MAP_BEGIN_INLINE()      NS_IMPL_QUERY_HEAD_INLINE()
    241 #define NS_IMPL_QUERY_INTERFACE1_INLINE(_i1)                                 \
    242   NS_INTERFACE_MAP_BEGIN_INLINE()                                            \
    243     NS_INTERFACE_MAP_ENTRY(_i1)                                              \
    244     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, _i1)                       \
    245   NS_INTERFACE_MAP_END
    246 #endif
    247 
    248 template <class T, class TParam = void* >
    249 class ListenerImpl : VBOX_SCRIPTABLE_IMPL(IEventListener)
    250 {
    251     T                 mListener;
    252     volatile uint32_t mRefCnt;
    253 
    254     virtual ~ListenerImpl()
    255     {}
    256 
    257 public:
    258     ListenerImpl(TParam param)
    259     : mListener(param), mRefCnt(1)
    260     {
    261     }
    262 
    263     /* On Windows QI implemented by VBOX_SCRIPTABLE_DISPATCH_IMPL */
    264 #ifndef RT_OS_WINDOWS
    265     NS_IMPL_QUERY_INTERFACE1_INLINE(IEventListener)
    266 #endif
    267 
    268 #ifdef RT_OS_WINDOWS
    269     STDMETHOD_(ULONG, AddRef)()
    270 #else
    271     NS_IMETHOD_(nsrefcnt) AddRef(void)
    272 #endif
    273     {
    274         return ASMAtomicIncU32(&mRefCnt);
    275     }
    276 
    277 #ifdef RT_OS_WINDOWS
    278     STDMETHOD_(ULONG, Release)()
    279 #else
    280     NS_IMETHOD_(nsrefcnt) Release(void)
    281 #endif
    282     {
    283         uint32_t cnt = ::ASMAtomicDecU32(&mRefCnt);
    284         if (cnt == 0)
    285             delete this;
    286         return cnt;
    287     }
    288 
    289     VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
    290 
    291     STDMETHOD(HandleEvent)(IEvent * aEvent)
    292     {
    293         VBoxEventType_T aType = VBoxEventType_Invalid;
    294         aEvent->COMGETTER(Type)(&aType);
    295         return mListener.HandleEvent(aType, aEvent);
    296     }
    297 };
    298 
    299 #ifdef VBOX_WITH_XPCOM
    300 #define VBOX_LISTENER_DECLARE(klazz) NS_DECL_CLASSINFO(klazz)
    301 #else
    302 #define VBOX_LISTENER_DECLARE(klazz)
    303 #endif
    304 
    305232#endif // ____H_EVENTIMPL
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