Changeset 33959 in vbox
- Timestamp:
- Nov 11, 2010 9:41:52 AM (14 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl.cpp
r33952 r33959 255 255 inline static const char *networkAdapterTypeToName(NetworkAdapterType_T adapterType); 256 256 257 class VmEventListener : 258 VBOX_SCRIPTABLE_IMPL(IEventListener) 259 { 257 class VmEventListener { 260 258 public: 261 259 VmEventListener(Console *aConsole) 262 260 { 263 #ifndef VBOX_WITH_XPCOM264 refcnt = 0;265 #endif266 261 mfNoLoggedInUsers = true; 267 262 mConsole = aConsole; … … 272 267 } 273 268 274 #ifndef VBOX_WITH_XPCOM 275 STDMETHOD_(ULONG, AddRef)() 276 { 277 return ::InterlockedIncrement(&refcnt); 278 } 279 STDMETHOD_(ULONG, Release)() 280 { 281 long cnt = ::InterlockedDecrement(&refcnt); 282 if (cnt == 0) 283 delete this; 284 return cnt; 285 } 286 #endif 287 VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener) 288 289 NS_DECL_ISUPPORTS 290 291 STDMETHOD(HandleEvent)(IEvent * aEvent) 292 { 293 VBoxEventType_T aType = VBoxEventType_Invalid; 294 aEvent->COMGETTER(Type)(&aType); 269 STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent) 270 { 295 271 switch(aType) 296 272 { … … 337 313 } 338 314 private: 339 #ifndef VBOX_WITH_XPCOM340 long refcnt;341 #endif342 343 315 bool mfNoLoggedInUsers; 344 316 Console *mConsole; 345 317 }; 346 318 347 #ifdef VBOX_WITH_XPCOM 348 NS_DECL_CLASSINFO(VmEventListener) 349 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VmEventListener, IEventListener) 350 #endif 319 typedef ListenerImpl<VmEventListener, Console*> VmEventListenerImpl; 320 321 VBOX_LISTENER_DECLARE(VmEventListenerImpl) 351 322 352 323 // ConsoleCallbackRegistration … … 600 571 rc = virtualbox->COMGETTER(EventSource)(es.asOutParam()); 601 572 AssertComRC(rc); 602 mVmListner = new VmEventListener(this); 603 mVmListner->AddRef(); 573 mVmListner = new VmEventListenerImpl(this); 604 574 com::SafeArray <VBoxEventType_T> eventTypes; 605 575 eventTypes.push_back(VBoxEventType_OnNATRedirectEvent); -
trunk/src/VBox/Main/ConsoleVRDPServer.cpp
r33676 r33959 35 35 #include <VBox/RemoteDesktop/VRDEOrders.h> 36 36 37 class VRDPConsoleListener : 38 VBOX_SCRIPTABLE_IMPL(IEventListener) 37 class VRDPConsoleListener 39 38 { 40 39 public: … … 42 41 : m_server(server) 43 42 { 44 #ifndef VBOX_WITH_XPCOM 45 refcnt = 0; 46 #endif /* !VBOX_WITH_XPCOM */ 47 } 48 49 virtual ~VRDPConsoleListener() {} 50 51 NS_DECL_ISUPPORTS 52 53 #ifndef VBOX_WITH_XPCOM 54 STDMETHOD_(ULONG, AddRef)() { 55 return ::InterlockedIncrement(&refcnt); 56 } 57 STDMETHOD_(ULONG, Release)() 58 { 59 long cnt = ::InterlockedDecrement(&refcnt); 60 if (cnt == 0) 61 delete this; 62 return cnt; 63 } 64 STDMETHOD(QueryInterface)(REFIID riid , void **ppObj) 65 { 66 if (riid == IID_IUnknown) { 67 *ppObj = (IUnknown*)this; 68 AddRef(); 69 return S_OK; 70 } 71 if (riid == IID_IEventListener) { 72 *ppObj = (IEventListener*)this; 73 AddRef(); 74 return S_OK; 75 } 76 *ppObj = NULL; 77 return E_NOINTERFACE; 78 } 79 #endif /* !VBOX_WITH_XPCOM */ 80 81 82 STDMETHOD(HandleEvent)(IEvent * aEvent) 83 { 84 VBoxEventType_T aType = VBoxEventType_Invalid; 85 86 aEvent->COMGETTER(Type)(&aType); 43 } 44 45 STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent) 46 { 87 47 switch (aType) 88 48 { … … 145 105 ULONG width, ULONG height, ComSafeArrayIn(BYTE,shape)); 146 106 ConsoleVRDPServer *m_server; 147 #ifndef VBOX_WITH_XPCOM148 long refcnt;149 #endif /* !VBOX_WITH_XPCOM */150 107 }; 151 108 152 #ifdef VBOX_WITH_XPCOM 153 #include <nsMemory.h> 154 NS_DECL_CLASSINFO(VRDPConsoleListener) 155 NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VRDPConsoleListener, IEventListener) 156 #endif /* VBOX_WITH_XPCOM */ 109 typedef ListenerImpl<VRDPConsoleListener, ConsoleVRDPServer*> VRDPConsoleListenerImpl; 110 111 VBOX_LISTENER_DECLARE(VRDPConsoleListenerImpl) 157 112 158 113 #ifdef DEBUG_sunlover … … 1220 1175 ComPtr<IEventSource> es; 1221 1176 console->COMGETTER(EventSource)(es.asOutParam()); 1222 mConsoleListener = new VRDPConsoleListener(this); 1223 mConsoleListener->AddRef(); 1177 mConsoleListener = new VRDPConsoleListenerImpl(this); 1224 1178 com::SafeArray <VBoxEventType_T> eventTypes; 1225 1179 eventTypes.push_back(VBoxEventType_OnMousePointerShapeChanged); -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r33952 r33959 15595 15595 15596 15596 <interface 15597 name="INATRedirectEvent" extends="I Event"15598 uuid=" b566336e-ec24-11df-8fbd-f71b6f29dd03"15597 name="INATRedirectEvent" extends="IMachineEvent" 15598 uuid="57DE97D7-3CBB-42A0-888F-610D5832D16B" 15599 15599 wsmap="managed" autogen="VBoxEvent" id="OnNATRedirectEvent" 15600 15600 > … … 15602 15602 Notification when NAT redirect rule added or removed. 15603 15603 </desc> 15604 <attribute name="machineId" type="uuid" mod="string" readonly="yes">15605 <desc>15606 Machine id where redirect event is occured.15607 </desc>15608 </attribute>15609 15604 <attribute name="slot" type="unsigned long" readonly="yes"> 15610 15605 <desc> -
trunk/src/VBox/Main/include/EventImpl.h
r33298 r33959 20 20 21 21 #include "VirtualBoxBase.h" 22 #include <iprt/asm.h> 22 23 23 24 class ATL_NO_VTABLE VBoxEvent : … … 229 230 }; 230 231 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 231 305 #endif // ____H_EVENTIMPL
Note:
See TracChangeset
for help on using the changeset viewer.