Changeset 33963 in vbox
- Timestamp:
- Nov 11, 2010 10:23:42 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
r33852 r33963 25 25 26 26 #include <VBox/com/VirtualBox.h> 27 #include <VBox/com/listeners.h> 27 28 28 29 using namespace com; … … 91 92 * Handler for global events. 92 93 */ 93 class VirtualBoxEventListener : 94 VBOX_SCRIPTABLE_IMPL(IEventListener) 94 class VirtualBoxEventListener 95 95 { 96 96 public: 97 97 VirtualBoxEventListener() 98 98 { 99 #ifndef VBOX_WITH_XPCOM100 refcnt = 0;101 #endif102 99 mfNoLoggedInUsers = true; 103 100 } … … 107 104 } 108 105 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 { 131 108 switch (aType) 132 109 { … … 214 191 215 192 private: 216 #ifndef VBOX_WITH_XPCOM217 long refcnt;218 #endif219 220 193 bool mfNoLoggedInUsers; 221 194 }; 222 223 195 224 196 /** 225 197 * Handler for machine events. 226 198 */ 227 class ConsoleEventListener : 228 VBOX_SCRIPTABLE_IMPL(IEventListener) 199 class ConsoleEventListener 229 200 { 230 201 public: 231 202 ConsoleEventListener() 232 203 { 233 #ifndef VBOX_WITH_XPCOM234 refcnt = 0;235 #endif236 204 mLastVRDEPort = -1; 237 205 } … … 241 209 } 242 210 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 { 265 213 switch (aType) 266 214 { … … 358 306 private: 359 307 360 #ifndef VBOX_WITH_XPCOM361 long refcnt;362 #endif363 308 long mLastVRDEPort; 364 309 }; 365 310 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 311 typedef ListenerImpl<VirtualBoxEventListener> VirtualBoxEventListenerImpl; 312 typedef ListenerImpl<ConsoleEventListener> ConsoleEventListenerImpl; 313 314 VBOX_LISTENER_DECLARE(VirtualBoxEventListenerImpl) 315 VBOX_LISTENER_DECLARE(ConsoleEventListenerImpl) 372 316 373 317 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL … … 993 937 ComPtr<IEventSource> es; 994 938 CHECK_ERROR(console, COMGETTER(EventSource)(es.asOutParam())); 995 consoleListener = new ConsoleEventListener(); 996 consoleListener->AddRef(); 939 consoleListener = new ConsoleEventListenerImpl(); 997 940 com::SafeArray <VBoxEventType_T> eventTypes; 998 941 eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged); … … 1149 1092 ComPtr<IEventSource> es; 1150 1093 CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam())); 1151 vboxListener = new VirtualBoxEventListener(); 1152 vboxListener->AddRef(); 1094 vboxListener = new VirtualBoxEventListenerImpl(); 1153 1095 com::SafeArray <VBoxEventType_T> eventTypes; 1154 1096 eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged); -
trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
r33916 r33963 233 233 * Event handler for VirtualBox events 234 234 */ 235 class VBoxSDLEventListener : 236 VBOX_SCRIPTABLE_IMPL(IEventListener) 235 class VBoxSDLEventListener 237 236 { 238 237 public: 239 238 VBoxSDLEventListener() 240 239 { 241 #if defined(RT_OS_WINDOWS)242 refcnt = 0;243 #endif244 240 } 245 241 … … 248 244 } 249 245 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 { 273 248 switch (aType) 274 249 { … … 312 287 return S_OK; 313 288 } 314 315 private:316 #ifdef RT_OS_WINDOWS317 long refcnt;318 #endif319 320 289 }; 321 290 … … 323 292 * Event handler for machine events 324 293 */ 325 class VBoxSDLConsoleEventListener : 326 VBOX_SCRIPTABLE_IMPL(IEventListener) 294 class VBoxSDLConsoleEventListener 327 295 { 328 296 public: 329 297 VBoxSDLConsoleEventListener() : m_fIgnorePowerOffEvents(false) 330 298 { 331 #if defined(RT_OS_WINDOWS)332 refcnt = 0;333 #endif334 299 } 335 300 … … 338 303 } 339 304 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 { 362 307 // likely all this double copy is now excessive, and we can just use existing event object 363 308 // @todo: eliminate it … … 567 512 568 513 private: 569 #ifdef RT_OS_WINDOWS570 long refcnt;571 #endif572 514 bool m_fIgnorePowerOffEvents; 573 515 }; 574 516 575 #ifdef VBOX_WITH_XPCOM576 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 */581 517 582 518 static void show_usage() -
trunk/src/VBox/Main/ConsoleImpl.cpp
r33959 r33963 73 73 #include <VBox/com/array.h> 74 74 #include "VBox/com/ErrorInfo.h" 75 #include <VBox/com/listeners.h> 75 76 76 77 #include <iprt/asm.h> -
trunk/src/VBox/Main/ConsoleVRDPServer.cpp
r33959 r33963 34 34 #include <VBox/err.h> 35 35 #include <VBox/RemoteDesktop/VRDEOrders.h> 36 #include <VBox/com/listeners.h> 36 37 37 38 class VRDPConsoleListener -
trunk/src/VBox/Main/include/EventImpl.h
r33959 r33963 230 230 }; 231 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_WINDOWS240 #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_END246 #endif247 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_WINDOWS265 NS_IMPL_QUERY_INTERFACE1_INLINE(IEventListener)266 #endif267 268 #ifdef RT_OS_WINDOWS269 STDMETHOD_(ULONG, AddRef)()270 #else271 NS_IMETHOD_(nsrefcnt) AddRef(void)272 #endif273 {274 return ASMAtomicIncU32(&mRefCnt);275 }276 277 #ifdef RT_OS_WINDOWS278 STDMETHOD_(ULONG, Release)()279 #else280 NS_IMETHOD_(nsrefcnt) Release(void)281 #endif282 {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_XPCOM300 #define VBOX_LISTENER_DECLARE(klazz) NS_DECL_CLASSINFO(klazz)301 #else302 #define VBOX_LISTENER_DECLARE(klazz)303 #endif304 305 232 #endif // ____H_EVENTIMPL
Note:
See TracChangeset
for help on using the changeset viewer.