[vbox-dev] Passive event handling

Klaus Espenlaub klaus.espenlaub at oracle.com
Mon Oct 1 07:38:27 PDT 2012

Hi Ian,

On 01.10.2012 14:58, Ian Moore wrote:
> Hello,
> I'm having some trouble following the passive event mechanism logic. I'm
> working on a web application and it will periodically poll vboxwebsrv
> for events. While this works well with the vbox event source, I'm not
> quite sure how to implement this for individual machine console events.
> Should it go like this:
> 1. Create an event listener when a running machine is selected
> --- machine = vbox->findMachine(...)
> --- session = websessionManager->getSessionObject()
> --- listener = session->console->eventSource->createListener()
> --- session->console->eventSource->registerListener(listener,...,false)
> --- session->unlock(machine)
> 2. Then periodically poll for events. Each poll cycle would
> --- machine = vbox->findMachine(...)
> --- session = websessionManager->getSessionObject()
> --- while(event = session->console->eventSource->getEvent(listener
> created in step #1)) { ... }
> --- session->unlock(machine)
> Should I leave the shared lock in place (leaving session->console
> available) until the machine is deselected or stopped? I tried looking
> through the VirtualBox source, but was unable to determine how it should
> work.

The preferred approach is to remember the EventSource reference as long 
as possible (ideally straight from step 1). You will get the same event 
source reference for the same VM anyway when you query it again later. 
I'd avoid session->console->eventSource chains to reduce the overhead 
per call.

You do not have to keep the session locked while waiting for events. 
Event signalling is completely independent of sessions. The listener is 
where the "identity" of the client is kept

It's quite simple overall, but there are very few larger scale examples 
(the C++ based clients still use mostly callbacks) so it's 
understandable that there are some questions.


> Thank you for any help!

More information about the vbox-dev mailing list