Index: trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp
===================================================================
--- trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 33852)
+++ trunk/src/VBox/Frontends/VBoxHeadless/VBoxHeadless.cpp	(revision 33963)
@@ -25,4 +25,5 @@
 
 #include <VBox/com/VirtualBox.h>
+#include <VBox/com/listeners.h>
 
 using namespace com;
@@ -91,13 +92,9 @@
  *  Handler for global events.
  */
-class VirtualBoxEventListener :
-  VBOX_SCRIPTABLE_IMPL(IEventListener)
+class VirtualBoxEventListener
 {
 public:
     VirtualBoxEventListener()
     {
-#ifndef VBOX_WITH_XPCOM
-        refcnt = 0;
-#endif
         mfNoLoggedInUsers = true;
     }
@@ -107,26 +104,6 @@
     }
 
-#ifndef VBOX_WITH_XPCOM
-    STDMETHOD_(ULONG, AddRef)()
-    {
-        return ::InterlockedIncrement(&refcnt);
-    }
-    STDMETHOD_(ULONG, Release)()
-    {
-        long cnt = ::InterlockedDecrement(&refcnt);
-        if (cnt == 0)
-            delete this;
-        return cnt;
-    }
-#endif
-    VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
-
-    NS_DECL_ISUPPORTS
-
-    STDMETHOD(HandleEvent)(IEvent * aEvent)
-    {
-        VBoxEventType_T aType = VBoxEventType_Invalid;
-
-        aEvent->COMGETTER(Type)(&aType);
+    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
+    {
         switch (aType)
         {
@@ -214,24 +191,15 @@
 
 private:
-#ifndef VBOX_WITH_XPCOM
-    long refcnt;
-#endif
-
     bool mfNoLoggedInUsers;
 };
-
 
 /**
  *  Handler for machine events.
  */
-class ConsoleEventListener :
-  VBOX_SCRIPTABLE_IMPL(IEventListener)
+class ConsoleEventListener
 {
 public:
     ConsoleEventListener()
     {
-#ifndef VBOX_WITH_XPCOM
-        refcnt = 0;
-#endif
         mLastVRDEPort = -1;
     }
@@ -241,26 +209,6 @@
     }
 
-#ifndef VBOX_WITH_XPCOM
-    STDMETHOD_(ULONG, AddRef)()
-    {
-        return ::InterlockedIncrement(&refcnt);
-    }
-    STDMETHOD_(ULONG, Release)()
-    {
-        long cnt = ::InterlockedDecrement(&refcnt);
-        if (cnt == 0)
-            delete this;
-        return cnt;
-    }
-#endif
-    VBOX_SCRIPTABLE_DISPATCH_IMPL(IEventListener)
-
-    NS_DECL_ISUPPORTS
-
-    STDMETHOD(HandleEvent)(IEvent * aEvent)
-    {
-        VBoxEventType_T aType = VBoxEventType_Invalid;
-
-        aEvent->COMGETTER(Type)(&aType);
+    STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent * aEvent)
+    {
         switch (aType)
         {
@@ -358,16 +306,12 @@
 private:
 
-#ifndef VBOX_WITH_XPCOM
-    long refcnt;
-#endif
     long mLastVRDEPort;
 };
 
-#ifdef VBOX_WITH_XPCOM
-NS_DECL_CLASSINFO(VirtualBoxEventListener)
-NS_IMPL_THREADSAFE_ISUPPORTS1_CI(VirtualBoxEventListener, IEventListener)
-NS_DECL_CLASSINFO(ConsoleEventListener)
-NS_IMPL_THREADSAFE_ISUPPORTS1_CI(ConsoleEventListener, IEventListener)
-#endif
+typedef ListenerImpl<VirtualBoxEventListener> VirtualBoxEventListenerImpl;
+typedef ListenerImpl<ConsoleEventListener> ConsoleEventListenerImpl;
+
+VBOX_LISTENER_DECLARE(VirtualBoxEventListenerImpl)
+VBOX_LISTENER_DECLARE(ConsoleEventListenerImpl)
 
 #ifdef VBOX_WITH_SAVESTATE_ON_SIGNAL
@@ -993,6 +937,5 @@
             ComPtr<IEventSource> es;
             CHECK_ERROR(console, COMGETTER(EventSource)(es.asOutParam()));
-            consoleListener = new ConsoleEventListener();
-            consoleListener->AddRef();
+            consoleListener = new ConsoleEventListenerImpl();
             com::SafeArray <VBoxEventType_T> eventTypes;
             eventTypes.push_back(VBoxEventType_OnMouseCapabilityChanged);
@@ -1149,6 +1092,5 @@
             ComPtr<IEventSource> es;
             CHECK_ERROR(virtualBox, COMGETTER(EventSource)(es.asOutParam()));
-            vboxListener = new VirtualBoxEventListener();
-            vboxListener->AddRef();
+            vboxListener = new VirtualBoxEventListenerImpl();
             com::SafeArray <VBoxEventType_T> eventTypes;
             eventTypes.push_back(VBoxEventType_OnGuestPropertyChanged);
