Session management and Event handling

Discussion about using the VirtualBox API, Tutorials, Samples.
Post Reply
sadim
Posts: 4
Joined: 9. Aug 2014, 21:11

Session management and Event handling

Post by sadim »

Hello,

I have questions about the session management and the event handling.
I write a simple application to control vm machines. I found two ways to get an session

(oVBoxMgr is an instance of VirtualBoxManager)
oVBoxMgr.openMachineSession(mach, True) and oVBoxMgr.getSessionObject(vbox)

Both functions give me a session but what are the differences?

The following things i have found out:
  • openMachineSession(mach, True)
    - Locks the machine
    - need closeMachineSession(session) at the end (unlock the machine and...?)
  • getSessionObject(vbox)
    - doesn't locks the machine
    - need lockMachine to locks the machine
    - need session.unlockMachine() at the end to unlock the machine
Is that correct? Why are there these two possibilities? Where can I find the implementation of these functions?

My second question is about the event handling.
Is there an example implementation in python for e.g. listen to an IMachineDataChangeEvent?
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Session management and Event handling

Post by noteirak »

The first method is just a convenient method but is not directly used in the SDK howto documentation, so I would guess it's an internal method that Devs use and can change at anytime.
The second method is the proper way of doing it and I would recommend to only use that one.

As for the event listening, I don't know how it would translate into Python but to get that event you need to either listen on the general Virtualbox object or on the virtualbox machine object directly.
The SDK PDF tells you how to manage this but in any case you'll need to use the getEventSource() on either IVirtualbox or IMachine objects.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
sadim
Posts: 4
Joined: 9. Aug 2014, 21:11

Re: Session management and Event handling

Post by sadim »

Thanks a lot for the explanation.
Post Reply