[vbox-dev] VirtualBox C API: Request for simple examples
Klaus Espenlaub
klaus.espenlaub at oracle.com
Mon May 12 15:46:25 UTC 2014
Traiano,
On 11.05.2014 19:29, Traiano Welcome wrote:
> Hi All
>
> I'm starting out to use the virtualbox C API, my objective is to carry
> out the following sequence of simple operations to automate the
> deployment of VMs on VirtualBox:
First of all - do you really really have a strict requirement that you
absolutely must use C? The C API needs a lot more effort than using C++,
simply because both COM and XPCOM are geared towards C++. Effectively
it's an attempt at wrapping the C++ functionality behind C compatible
functions, leaving the burden of doing the "object orientation" by hand,
e.g. by always passing the "this" pointer explicitly.
So... if you can, by any means go for C++. Even with our long-standing
todo to make what we internally call "COM/XPCOM glue" externally
available (it isn't today, so it's not possible to easily write one
piece of code which works both with COM and XPCOM, unlike what we do
internally in VirtualBox), C++ is a lot easier to use. Long term (or
short to medium term if someone helps with making the COM/XPCOM glue
part of the SDK) it will be possible to write API clients just how we
write them in the VirtualBox tree - totally identical code on Windows
and elsewhere.
> 1. Create and Launch a VM
> 2. Create a virtual disk and attach it to the VM
> 3. Detach a virtual disk from the VMr
> 4. Shut the VM down
The usual "why don't you provide code which does my work?" request,
which we don't take too seriously. After all the C API sample is
carefully written to cover the vital areas of a medium scale client,
which needs to do good error checking, event handling and the like. If
you ignore the rather significant effort for handling events (in two
flavors) then the sample is very straightforward: it dumps some
interesting global properties, enumerates all VMs, shows some details
about them, asks which one to start, starts the one the user selected
and then terminates.
I think this qualifies as simple :)
> I'm working through the single example C program supplied with the
> VirtualBox SDK, however, I find it's quite a complex piece of work,
> and I'd appreciate it if there were smaller more digestable examples
> for doing limited sing-purpose operations like those listed above?
There are no smaller examples, and one of the reasons is that the
VirtualBox team does NOT use the C API. It's just one of the language
bindings we offer, without an explicit recommendation.
Either way, what you're asking for isn't truly smaller than the existing
samples, as you can see from my quick code summary of tstCAPIGlue.c above.
> Any pointers to working examples of C code would be much appreciated!
Sorry, nothing like this in the VirtualBox sources. The original reason
for creating the C API was that the libvirt folks are totally allergic
against C++, and what we're recommending as proper C API use is these
days rather different to the "XPCOM only" hack we did 5 years ago and
they keep maintaining the ancient coding style.
Klaus
> Thanks in advance!
> Traiano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.virtualbox.org/pipermail/vbox-dev/attachments/20140512/254e9356/attachment.html
More information about the vbox-dev
mailing list