Changeset 35722 in vbox for trunk/include/VBox/com
- Timestamp:
- Jan 26, 2011 4:37:16 PM (14 years ago)
- Location:
- trunk/include/VBox/com
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/defs.h
r35638 r35722 508 508 STDMETHOD(QueryInterface)(REFIID riid , void **ppObj) \ 509 509 { \ 510 if (riid == IID_##iface) \ 511 { \ 512 *ppObj = (iface*)this; \ 513 AddRef(); \ 514 return S_OK; \ 515 } \ 510 516 if (riid == IID_IUnknown) \ 511 517 { \ … … 520 526 return S_OK; \ 521 527 } \ 522 if (riid == IID_##iface) \523 { \524 *ppObj = (iface*)this; \525 AddRef(); \526 return S_OK; \527 } \528 528 *ppObj = NULL; \ 529 529 return E_NOINTERFACE; \ -
trunk/include/VBox/com/listeners.h
r33976 r35722 30 30 #include <VBox/com/com.h> 31 31 #include <VBox/com/defs.h> 32 #include <iprt/asm.h>33 32 34 33 #ifdef VBOX_WITH_XPCOM … … 48 47 49 48 template <class T, class TParam = void* > 50 class ListenerImpl : VBOX_SCRIPTABLE_IMPL(IEventListener) 49 class ListenerImpl : 50 public CComObjectRootEx<CComMultiThreadModel>, 51 VBOX_SCRIPTABLE_IMPL(IEventListener) 51 52 { 52 T mListener; 53 volatile uint32_t mRefCnt; 53 T* mListener; 54 55 #ifdef RT_OS_WINDOWS 56 /* FTM stuff */ 57 CComPtr <IUnknown> m_pUnkMarshaler; 58 #endif 59 60 public: 61 ListenerImpl() 62 { 63 } 54 64 55 65 virtual ~ListenerImpl() 56 {}57 58 public:59 ListenerImpl(TParam param)60 : mListener(param), mRefCnt(1)61 66 { 62 67 } 63 68 64 ListenerImpl() 65 : mRefCnt(1) 69 HRESULT init(T* aListener, TParam param) 66 70 { 71 mListener = aListener; 72 return mListener->init(param); 73 } 74 75 HRESULT init(T* aListener) 76 { 77 mListener = aListener; 78 return mListener->init(); 79 } 80 81 void uninit() 82 { 83 if (mListener) 84 { 85 mListener->uninit(); 86 delete mListener; 87 mListener = 0; 88 } 89 } 90 91 HRESULT FinalConstruct() 92 { 93 #ifdef RT_OS_WINDOWS 94 return CoCreateFreeThreadedMarshaler(this, &m_pUnkMarshaler.p); 95 #else 96 mRefCnt = 1; 97 return S_OK; 98 #endif 99 } 100 101 void FinalRelease() 102 { 103 uninit(); 104 #ifdef RT_OS_WINDOWS 105 m_pUnkMarshaler.Release(); 106 #endif 67 107 } 68 108 69 109 T* getWrapped() 70 110 { 71 return &mListener;111 return mListener; 72 112 } 73 113 74 /* On Windows QI implemented by VBOX_SCRIPTABLE_DISPATCH_IMPL*/114 /* On Windows QI implemented by COM_MAP() */ 75 115 #ifndef RT_OS_WINDOWS 76 116 NS_IMPL_QUERY_INTERFACE1_INLINE(IEventListener) 77 117 #endif 118 119 DECLARE_NOT_AGGREGATABLE(ListenerImpl) 78 120 79 #ifdef RT_OS_WINDOWS 80 STDMETHOD_(ULONG, AddRef)() 81 #else 82 NS_IMETHOD_(nsrefcnt) AddRef(void) 83 #endif 84 { 85 return ASMAtomicIncU32(&mRefCnt); 86 } 121 DECLARE_PROTECT_FINAL_CONSTRUCT() 87 122 88 #ifdef RT_OS_WINDOWS 89 STDMETHOD_(ULONG, Release)() 90 #else 91 NS_IMETHOD_(nsrefcnt) Release(void) 92 #endif 93 { 94 uint32_t cnt = ::ASMAtomicDecU32(&mRefCnt); 95 if (cnt == 0) 96 delete this; 97 return cnt; 98 } 123 BEGIN_COM_MAP(ListenerImpl) 124 COM_INTERFACE_ENTRY(IEventListener) 125 COM_INTERFACE_ENTRY2(IDispatch, IEventListener) 126 COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p) 127 END_COM_MAP() 99 128 100 VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)101 129 102 130 STDMETHOD(HandleEvent)(IEvent * aEvent) … … 104 132 VBoxEventType_T aType = VBoxEventType_Invalid; 105 133 aEvent->COMGETTER(Type)(&aType); 106 return mListener .HandleEvent(aType, aEvent);134 return mListener->HandleEvent(aType, aEvent); 107 135 } 108 136 };
Note:
See TracChangeset
for help on using the changeset viewer.