[vbox-dev] XPCOM EventListener

Klaus Espenlaub klaus.espenlaub at oracle.com
Tue Nov 7 20:51:06 UTC 2017

Hi Rūdolfs,

On 07.11.2017 01:14, Rūdolfs Bundulis wrote:
> Hi Klaus,
> thanks for the response. Yeah the example seems very similar. The
> thing i was wondering about - the xpcom samples do stuff with
> the nsIEventQueue,
> which I only instantiate but do not poll in any way (there are so many
> sources involving this that I got confused). Should I be doing something -
> like calling the EventLoop() method to actually make the events route?
> Since everything else apart the event callbacks (which I didn't need
> so far,
> but now I need to know when the machine has been stopped) was working
> fine I just didn't care. But if running/polling this queue actually pumps
> some internal event loop which in turn fires the callbacks that could
> be the thing I'm missing.
Running the event queue is a must have for anything more complicated
than doing a few API calls and then immediately terminating. Many
activities in XPCOM are bolted to events (which are processed internally
by XPCOM), and not doing it causes excessive memory consumption and
strange malfunctions, especially if your API client doesn't do much else
than waiting for API level event callbacks to arrive. I don't have any
real evidence why it would cause callbacks to be not invoked (e.g.
"VBoxManage guestcontrol watch" also creates active listeners and is
simply waiting until Ctrl-C is pressed, with some sleeping but not
caring about the event queue, which is not ideal).

Can't guarantee that it'll help.


> 2017-11-06 22:39 GMT+02:00 Klaus Espenlaub <klaus.espenlaub at oracle.com
> <mailto:klaus.espenlaub at oracle.com>>:
>     Hi Rūdolfs,
>     On 05.11.2017 17:05, Rūdolfs Bundulis wrote:
>     > Hi,
>     >
>     > I'm having issues adding an active event listener via the XPCOM api.
>     > I've created a class from the template in the documentation:
>     >
>     [...]
>     >
>     > and put the NS_IMPL_ISUPPORTS1(CVirtualBoxEventListener,
>     > IEventListener) macro in my cpp file. But the HandleEvent method is
>     > never called. I register the listener by getting the event
>     source from
>     > the console object like this (sorry for all the macros, that I have
>     > for exception handling):
>     >
>     [...]
>     >
>     > No events are triggered but on shutdown the VBOX XPCOM runtime
>     > actually releases the object so it seems that it is aware of it.
>     With
>     > active mode, is there anything else I should be calling? I looked up
>     > some python examples which do call a python VBOX API method
>     > waitForEvents. Is there something similar in the C++ XPCOM API?
>     Most python examples I'm aware of use passive event delivery, so
>     aren't
>     relevant when you've decided to go for active event delivery. Also the
>     VirtualBox GUI is not a good example any more since it's been
>     converted
>     to passive event delivery a while ago (IIRC 5.0 still had the active
>     variant), so let's go for one of the most simple places I could find,
>     VBoxSDL:
>     https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp
>     <https://www.virtualbox.org/browser/vbox/trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp>
>     Still it uses templates (ListenerImpl<>)  and lots of magic
>     wrappers to
>     abstract over the differences between COM and XPCOM (which lots of
>     people would like to use but so far we didn't manage to include in a
>     sensible way in the SDK package), which needs way more apologies than
>     your couple of comparably harmless macros for error checking. The
>     ListenerImpl<> template is defined in
>     https://www.virtualbox.org/browser/vbox/trunk/include/VBox/com/listeners.h
>     <https://www.virtualbox.org/browser/vbox/trunk/include/VBox/com/listeners.h>
>     and the rest (if you really need to know) in the same directory.
>     The C bindings example would have both active and passive event
>     delivery
>     as compile-time option, but that's too low level I assume...
>     Hope this gives enough inspiration to identify the problem - your code
>     didn't look far off the track.
>     Klaus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20171107/f44370ea/attachment.html>

More information about the vbox-dev mailing list