VirtualBox

source: vbox/trunk/doc/manual/en_US/SDKRef.xml@ 51966

Last change on this file since 51966 was 51555, checked in by vboxsync, 10 years ago

DnD: Documentation.

File size: 247.6 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
4<book>
5 <bookinfo>
6 <title>$VBOX_PRODUCT<superscript>®</superscript></title>
7
8 <subtitle>Programming Guide and Reference</subtitle>
9
10 <edition>Version $VBOX_VERSION_STRING</edition>
11
12 <corpauthor>$VBOX_VENDOR</corpauthor>
13
14 <address>http://www.virtualbox.org</address>
15
16 <copyright>
17 <year>2004-$VBOX_C_YEAR</year>
18
19 <holder>$VBOX_VENDOR</holder>
20 </copyright>
21 </bookinfo>
22
23 <chapter>
24 <title>Introduction</title>
25
26 <para>VirtualBox comes with comprehensive support for third-party
27 developers. This Software Development Kit (SDK) contains all the
28 documentation and interface files that are needed to write code that
29 interacts with VirtualBox.</para>
30
31 <sect1>
32 <title>Modularity: the building blocks of VirtualBox</title>
33
34 <para>VirtualBox is cleanly separated into several layers, which can be
35 visualized like in the picture below:</para>
36
37 <mediaobject>
38 <imageobject>
39 <imagedata align="center" fileref="images/vbox-components.png"
40 width="12cm" />
41 </imageobject>
42 </mediaobject>
43
44 <para>The orange area represents code that runs in kernel mode, the blue
45 area represents userspace code.</para>
46
47 <para>At the bottom of the stack resides the hypervisor -- the core of
48 the virtualization engine, controlling execution of the virtual machines
49 and making sure they do not conflict with each other or whatever the
50 host computer is doing otherwise.</para>
51
52 <para>On top of the hypervisor, additional internal modules provide
53 extra functionality. For example, the RDP server, which can deliver the
54 graphical output of a VM remotely to an RDP client, is a separate module
55 that is only loosely tacked into the virtual graphics device. Live
56 Migration and Resource Monitor are additional modules currently in the
57 process of being added to VirtualBox.</para>
58
59 <para>What is primarily of interest for purposes of the SDK is the API
60 layer block that sits on top of all the previously mentioned blocks.
61 This API, which we call the <emphasis role="bold">"Main API"</emphasis>,
62 exposes the entire feature set of the virtualization engine below. It is
63 completely documented in this SDK Reference -- see <xref
64 linkend="sdkref_classes" /> and <xref linkend="sdkref_enums" /> -- and
65 available to anyone who wishes to control VirtualBox programmatically.
66 We chose the name "Main API" to differentiate it from other programming
67 interfaces of VirtualBox that may be publicly accessible.</para>
68
69 <para>With the Main API, you can create, configure, start, stop and
70 delete virtual machines, retrieve performance statistics about running
71 VMs, configure the VirtualBox installation in general, and more. In
72 fact, internally, the front-end programs
73 <computeroutput>VirtualBox</computeroutput> and
74 <computeroutput>VBoxManage</computeroutput> use nothing but this API as
75 well -- there are no hidden backdoors into the virtualization engine for
76 our own front-ends. This ensures the entire Main API is both
77 well-documented and well-tested. (The same applies to
78 <computeroutput>VBoxHeadless</computeroutput>, which is not shown in the
79 image.)</para>
80 </sect1>
81
82 <sect1 id="webservice-or-com">
83 <title>Two guises of the same "Main API": the web service or
84 COM/XPCOM</title>
85
86 <para>There are several ways in which the Main API can be called by
87 other code:<orderedlist>
88 <listitem>
89 <para>VirtualBox comes with a <emphasis role="bold">web
90 service</emphasis> that maps nearly the entire Main API. The web
91 service ships in a stand-alone executable
92 (<computeroutput>vboxwebsrv</computeroutput>) that, when running,
93 acts as an HTTP server, accepts SOAP connections and processes
94 them.</para>
95
96 <para>Since the entire web service API is publicly described in a
97 web service description file (in WSDL format), you can write
98 client programs that call the web service in any language with a
99 toolkit that understands WSDL. These days, that includes most
100 programming languages that are available: Java, C++, .NET, PHP,
101 Python, Perl and probably many more.</para>
102
103 <para>All of this is explained in detail in subsequent chapters of
104 this book.</para>
105
106 <para>There are two ways in which you can write client code that
107 uses the web service:<orderedlist>
108 <listitem>
109 <para>For Java as well as Python, the SDK contains
110 easy-to-use classes that allow you to use the web service in
111 an object-oriented, straightforward manner. We shall refer
112 to this as the <emphasis role="bold">"object-oriented web
113 service (OOWS)"</emphasis>.</para>
114
115 <para>The OO bindings for Java are described in <xref
116 linkend="javaapi" />, those for Python in <xref lang=""
117 linkend="glue-python-ws" />.</para>
118 </listitem>
119
120 <listitem>
121 <para>Alternatively, you can use the web service directly,
122 without the object-oriented client layer. We shall refer to
123 this as the <emphasis role="bold">"raw web
124 service"</emphasis>.</para>
125
126 <para>You will then have neither native object orientation
127 nor full type safety, since web services are neither
128 object-oriented nor stateful. However, in this way, you can
129 write client code even in languages for which we do not ship
130 object-oriented client code; all you need is a programming
131 language with a toolkit that can parse WSDL and generate
132 client wrapper code from it.</para>
133
134 <para>We describe this further in <xref
135 linkend="raw-webservice" />, with samples for Java and
136 Perl.</para>
137 </listitem>
138 </orderedlist></para>
139 </listitem>
140
141 <listitem>
142 <para>Internally, for portability and easier maintenance, the Main
143 API is implemented using the <emphasis role="bold">Component
144 Object Model (COM),</emphasis> an interprocess mechanism for
145 software components originally introduced by Microsoft for
146 Microsoft Windows. On a Windows host, VirtualBox will use
147 Microsoft COM; on other hosts where COM is not present, it ships
148 with XPCOM, a free software implementation of COM originally
149 created by the Mozilla project for their browsers.</para>
150
151 <para>So, if you are familiar with COM and the C++ programming
152 language (or with any other programming language that can handle
153 COM/XPCOM objects, such as Java, Visual Basic or C#), then you can
154 use the COM/XPCOM API directly. VirtualBox comes with all
155 necessary files and documentation to build fully functional COM
156 applications. For an introduction, please see <xref
157 linkend="api_com" /> below.</para>
158
159 <para>The VirtualBox front-ends (the graphical user interfaces as
160 well as the command line), which are all written in C++, use
161 COM/XPCOM to call the Main API. Technically, the web service is
162 another front-end to this COM API, mapping almost all of it to
163 SOAP clients.</para>
164 </listitem>
165 </orderedlist></para>
166
167 <para>If you wonder which way to choose, here are a few
168 comparisons:<table>
169 <title>Comparison web service vs. COM/XPCOM</title>
170
171 <tgroup cols="2">
172 <tbody>
173 <row>
174 <entry><emphasis role="bold">Web service</emphasis></entry>
175
176 <entry><emphasis role="bold">COM/XPCOM</emphasis></entry>
177 </row>
178
179 <row>
180 <entry><emphasis role="bold">Pro:</emphasis> Easy to use with
181 Java and Python with the object-oriented web service;
182 extensive support even with other languages (C++, .NET, PHP,
183 Perl and others)</entry>
184
185 <entry><emphasis role="bold">Con:</emphasis> Usable from
186 languages where COM bridge available (most languages on
187 Windows platform, Python and C++ on other hosts)</entry>
188 </row>
189
190 <row>
191 <entry><emphasis role="bold">Pro:</emphasis> Client can be on
192 remote machine</entry>
193
194 <entry><emphasis role="bold">Con: </emphasis>Client must be on
195 the same host where virtual machine is executed</entry>
196 </row>
197
198 <row>
199 <entry><emphasis role="bold">Con: </emphasis>Significant
200 overhead due to XML marshalling over the wire for each method
201 call</entry>
202
203 <entry><emphasis role="bold">Pro: </emphasis>Relatively low
204 invocation overhead</entry>
205 </row>
206 </tbody>
207 </tgroup>
208 </table></para>
209
210 <para>In the following chapters, we will describe the different ways in
211 which to program VirtualBox, starting with the method that is easiest to
212 use and then increase complexity as we go along.</para>
213 </sect1>
214
215 <sect1 id="api_soap_intro">
216 <title>About web services in general</title>
217
218 <para>Web services are a particular type of programming interface.
219 Whereas, with "normal" programming, a program calls an application
220 programming interface (API) defined by another program or the operating
221 system and both sides of the interface have to agree on the calling
222 convention and, in most cases, use the same programming language, web
223 services use Internet standards such as HTTP and XML to
224 communicate.<footnote>
225 <para>In some ways, web services promise to deliver the same thing
226 as CORBA and DCOM did years ago. However, while these previous
227 technologies relied on specific binary protocols and thus proved to
228 be difficult to use between diverging platforms, web services
229 circumvent these incompatibilities by using text-only standards like
230 HTTP and XML. On the downside (and, one could say, typical of things
231 related to XML), a lot of standards are involved before a web
232 service can be implemented. Many of the standards invented around
233 XML are used one way or another. As a result, web services are slow
234 and verbose, and the details can be incredibly messy. The relevant
235 standards here are called SOAP and WSDL, where SOAP describes the
236 format of the messages that are exchanged (an XML document wrapped
237 in an HTTP header), and WSDL is an XML format that describes a
238 complete API provided by a web service. WSDL in turn uses XML Schema
239 to describe types, which is not exactly terse either. However, as
240 you will see from the samples provided in this chapter, the
241 VirtualBox web service shields you from these details and is easy to
242 use.</para>
243 </footnote></para>
244
245 <para>In order to successfully use a web service, a number of things are
246 required -- primarily, a web service accepting connections; service
247 descriptions; and then a client that connects to that web service. The
248 connections are governed by the SOAP standard, which describes how
249 messages are to be exchanged between a service and its clients; the
250 service descriptions are governed by WSDL.</para>
251
252 <para>In the case of VirtualBox, this translates into the following
253 three components:<orderedlist>
254 <listitem>
255 <para>The VirtualBox web service (the "server"): this is the
256 <computeroutput>vboxwebsrv</computeroutput> executable shipped
257 with VirtualBox. Once you start this executable (which acts as a
258 HTTP server on a specific TCP/IP port), clients can connect to the
259 web service and thus control a VirtualBox installation.</para>
260 </listitem>
261
262 <listitem>
263 <para>VirtualBox also comes with WSDL files that describe the
264 services provided by the web service. You can find these files in
265 the <computeroutput>sdk/bindings/webservice/</computeroutput>
266 directory. These files are understood by the web service toolkits
267 that are shipped with most programming languages and enable you to
268 easily access a web service even if you don't use our
269 object-oriented client layers. VirtualBox is shipped with
270 pregenerated web service glue code for several languages (Python,
271 Perl, Java).</para>
272 </listitem>
273
274 <listitem>
275 <para>A client that connects to the web service in order to
276 control the VirtualBox installation.</para>
277
278 <para>Unless you play with some of the samples shipped with
279 VirtualBox, this needs to be written by you.</para>
280 </listitem>
281 </orderedlist></para>
282 </sect1>
283
284 <sect1 id="runvboxwebsrv">
285 <title>Running the web service</title>
286
287 <para>The web service ships in an stand-alone executable,
288 <computeroutput>vboxwebsrv</computeroutput>, that, when running, acts as
289 a HTTP server, accepts SOAP connections and processes them -- remotely
290 or from the same machine.<note>
291 <para>The web service executable is not contained with the
292 VirtualBox SDK, but instead ships with the standard VirtualBox
293 binary package for your specific platform. Since the SDK contains
294 only platform-independent text files and documentation, the binaries
295 are instead shipped with the platform-specific packages. For this
296 reason the information how to run it as a service is included in the
297 VirtualBox documentation.</para>
298 </note></para>
299
300 <para>The <computeroutput>vboxwebsrv</computeroutput> program, which
301 implements the web service, is a text-mode (console) program which,
302 after being started, simply runs until it is interrupted with Ctrl-C or
303 a kill command.</para>
304
305 <para>Once the web service is started, it acts as a front-end to the
306 VirtualBox installation of the user account that it is running under. In
307 other words, if the web service is run under the user account of
308 <computeroutput>user1</computeroutput>, it will see and manipulate the
309 virtual machines and other data represented by the VirtualBox data of
310 that user (for example, on a Linux machine, under
311 <computeroutput>/home/user1/.config/VirtualBox</computeroutput>; see the
312 VirtualBox User Manual for details on where this data is stored).</para>
313
314 <sect2 id="vboxwebsrv-ref">
315 <title>Command line options of vboxwebsrv</title>
316
317 <para>The web service supports the following command line
318 options:</para>
319
320 <itemizedlist>
321 <listitem>
322 <para><computeroutput>--help</computeroutput> (or
323 <computeroutput>-h</computeroutput>): print a brief summary of
324 command line options.</para>
325 </listitem>
326
327 <listitem>
328 <para><computeroutput>--background</computeroutput> (or
329 <computeroutput>-b</computeroutput>): run the web service as a
330 background daemon. This option is not supported on Windows
331 hosts.</para>
332 </listitem>
333
334 <listitem>
335 <para><computeroutput>--host</computeroutput> (or
336 <computeroutput>-H</computeroutput>): This specifies the host to
337 bind to and defaults to "localhost".</para>
338 </listitem>
339
340 <listitem>
341 <para><computeroutput>--port</computeroutput> (or
342 <computeroutput>-p</computeroutput>): This specifies which port to
343 bind to on the host and defaults to 18083.</para>
344 </listitem>
345
346 <listitem>
347 <para><computeroutput>--ssl</computeroutput> (or
348 <computeroutput>-s</computeroutput>): This enables SSL support.</para>
349 </listitem>
350
351 <listitem>
352 <para><computeroutput>--keyfile</computeroutput> (or
353 <computeroutput>-K</computeroutput>): This specifies the file name
354 containing the server private key and the certificate. This is a
355 mandatory parameter if SSL is enabled.</para>
356 </listitem>
357
358 <listitem>
359 <para><computeroutput>--passwordfile</computeroutput> (or
360 <computeroutput>-a</computeroutput>): This specifies the file name
361 containing the password for the server private key. If unspecified
362 or an empty string is specified this is interpreted as an empty
363 password (i.e. the private key is not protected by a password). If
364 the file name <computeroutput>-</computeroutput> is specified then
365 then the password is read from the standard input stream, otherwise
366 from the specified file. The user is responsible for appropriate
367 access rights to protect the confidential password.</para>
368 </listitem>
369
370 <listitem>
371 <para><computeroutput>--cacert</computeroutput> (or
372 <computeroutput>-c</computeroutput>): This specifies the file name
373 containing the CA certificate appropriate for the server
374 certificate.</para>
375 </listitem>
376
377 <listitem>
378 <para><computeroutput>--capath</computeroutput> (or
379 <computeroutput>-C</computeroutput>): This specifies the directory
380 containing several CA certificates appropriate for the server
381 certificate.</para>
382 </listitem>
383
384 <listitem>
385 <para><computeroutput>--dhfile</computeroutput> (or
386 <computeroutput>-D</computeroutput>): This specifies the file name
387 containing the DH key. Alternatively it can contain the number of
388 bits of the DH key to generate. If left empty, RSA is used.</para>
389 </listitem>
390
391 <listitem>
392 <para><computeroutput>--randfile</computeroutput> (or
393 <computeroutput>-r</computeroutput>): This specifies the file name
394 containing the seed for the random number generator. If left empty,
395 an operating system specific source of the seed.</para>
396 </listitem>
397
398 <listitem>
399 <para><computeroutput>--timeout</computeroutput> (or
400 <computeroutput>-t</computeroutput>): This specifies the session
401 timeout, in seconds, and defaults to 300 (five minutes). A web
402 service client that has logged on but makes no calls to the web
403 service will automatically be disconnected after the number of
404 seconds specified here, as if it had called the
405 <computeroutput>IWebSessionManager::logoff()</computeroutput>
406 method provided by the web service itself.</para>
407
408 <para>It is normally vital that each web service client call this
409 method, as the web service can accumulate large amounts of memory
410 when running, especially if a web service client does not properly
411 release managed object references. As a result, this timeout value
412 should not be set too high, especially on machines with a high
413 load on the web service, or the web service may eventually deny
414 service.</para>
415 </listitem>
416
417 <listitem>
418 <para><computeroutput>--check-interval</computeroutput> (or
419 <computeroutput>-i</computeroutput>): This specifies the interval
420 in which the web service checks for timed-out clients, in seconds,
421 and defaults to 5. This normally does not need to be
422 changed.</para>
423 </listitem>
424
425 <listitem>
426 <para><computeroutput>--threads</computeroutput> (or
427 <computeroutput>-T</computeroutput>): This specifies the maximum
428 number or worker threads, and defaults to 100. This normally does
429 not need to be changed.</para>
430 </listitem>
431
432 <listitem>
433 <para><computeroutput>--keepalive</computeroutput> (or
434 <computeroutput>-k</computeroutput>): This specifies the maximum
435 number of requests which can be sent in one web service connection,
436 and defaults to 100. This normally does not need to be changed.</para>
437 </listitem>
438
439 <listitem>
440 <para><computeroutput>--authentication</computeroutput> (or
441 <computeroutput>-A</computeroutput>): This specifies the desired
442 web service authentication method. If the parameter is not
443 specified or the empty string is specified it does not change the
444 authentication method, otherwise it is set to the specified value.
445 Using this parameter is a good measure against accidental
446 misconfiguration, as the web service ensures periodically that it
447 isn't changed.</para>
448 </listitem>
449
450 <listitem>
451 <para><computeroutput>--verbose</computeroutput> (or
452 <computeroutput>-v</computeroutput>): Normally, the web service
453 outputs only brief messages to the console each time a request is
454 served. With this option, the web service prints much more detailed
455 data about every request and the COM methods that those requests
456 are mapped to internally, which can be useful for debugging client
457 programs.</para>
458 </listitem>
459
460 <listitem>
461 <para><computeroutput>--pidfile</computeroutput> (or
462 <computeroutput>-P</computeroutput>): Name of the PID file which is
463 created when the daemon was started.</para>
464 </listitem>
465
466 <listitem>
467 <para><computeroutput>--logfile</computeroutput> (or
468 <computeroutput>-F</computeroutput>)
469 <computeroutput>&lt;file&gt;</computeroutput>: If this is
470 specified, the web service not only prints its output to the
471 console, but also writes it to the specified file. The file is
472 created if it does not exist; if it does exist, new output is
473 appended to it. This is useful if you run the web service
474 unattended and need to debug problems after they have
475 occurred.</para>
476 </listitem>
477
478 <listitem>
479 <para><computeroutput>--logrotate</computeroutput> (or
480 <computeroutput>-R</computeroutput>): Number of old log files to
481 keep, defaults to 10. Log rotation is disabled if set to 0.</para>
482 </listitem>
483
484 <listitem>
485 <para><computeroutput>--logsize</computeroutput> (or
486 <computeroutput>-S</computeroutput>): Maximum size of log file in
487 bytes, defaults to 100MB. Log rotation is triggered if the file
488 grows beyond this limit.</para>
489 </listitem>
490
491 <listitem>
492 <para><computeroutput>--loginterval</computeroutput> (or
493 <computeroutput>-I</computeroutput>): Maximum time interval to be
494 put in a log file before rotation is triggered, in seconds, and
495 defaults to one day.</para>
496 </listitem>
497 </itemizedlist>
498 </sect2>
499
500 <sect2 id="websrv_authenticate">
501 <title>Authenticating at web service logon</title>
502
503 <para>As opposed to the COM/XPCOM variant of the Main API, a client
504 that wants to use the web service must first log on by calling the
505 <computeroutput>IWebsessionManager::logon()</computeroutput> API (see
506 <xref linkend="IWebsessionManager__logon" />) that is specific to the
507 web service. Logon is necessary for the web service to be stateful;
508 internally, it maintains a session for each client that connects to
509 it.</para>
510
511 <para>The <computeroutput>IWebsessionManager::logon()</computeroutput>
512 API takes a user name and a password as arguments, which the web
513 service then passes to a customizable authentication plugin that
514 performs the actual authentication.</para>
515
516 <para>For testing purposes, it is recommended that you first disable
517 authentication with this command:<screen>VBoxManage setproperty websrvauthlibrary null</screen></para>
518
519 <para><warning>
520 <para>This will cause all logons to succeed, regardless of user
521 name or password. This should of course not be used in a
522 production environment.</para>
523 </warning>Generally, the mechanism by which clients are
524 authenticated is configurable by way of the
525 <computeroutput>VBoxManage</computeroutput> command:</para>
526
527 <para><screen>VBoxManage setproperty websrvauthlibrary default|null|&lt;library&gt;</screen></para>
528
529 <para>This way you can specify any shared object/dynamic link module
530 that conforms with the specifications for VirtualBox external
531 authentication modules as laid out in section <emphasis
532 role="bold">VRDE authentication</emphasis> of the VirtualBox User
533 Manual; the web service uses the same kind of modules as the
534 VirtualBox VRDE server. For technical details on VirtualBox external
535 authentication modules see <xref linkend="vbox-auth" /></para>
536
537 <para>By default, after installation, the web service uses the
538 VBoxAuth module that ships with VirtualBox. This module uses PAM on
539 Linux hosts to authenticate users. Any valid username/password
540 combination is accepted, it does not have to be the username and
541 password of the user running the web service daemon. Unless
542 <computeroutput>vboxwebsrv</computeroutput> runs as root, PAM
543 authentication can fail, because sometimes the file
544 <computeroutput>/etc/shadow</computeroutput>, which is used by PAM, is
545 not readable. On most Linux distribution PAM uses a suid root helper
546 internally, so make sure you test this before deploying it. One can
547 override this behavior by setting the environment variable
548 <computeroutput>VBOX_PAM_ALLOW_INACTIVE</computeroutput> which will
549 suppress failures when unable to read the shadow password file. Please
550 use this variable carefully, and only if you fully understand what
551 you're doing.</para>
552 </sect2>
553 </sect1>
554 </chapter>
555
556 <chapter>
557 <title>Environment-specific notes</title>
558
559 <para>The Main API described in <xref linkend="sdkref_classes" /> and
560 <xref linkend="sdkref_enums" /> is mostly identical in all the supported
561 programming environments which have been briefly mentioned in the
562 introduction of this book. As a result, the Main API's general concepts
563 described in <xref linkend="concepts" /> are the same whether you use the
564 object-oriented web service (OOWS) for JAX-WS or a raw web service
565 connection via, say, Perl, or whether you use C++ COM bindings.</para>
566
567 <para>Some things are different depending on your environment, however.
568 These differences are explained in this chapter.</para>
569
570 <sect1 id="glue">
571 <title>Using the object-oriented web service (OOWS)</title>
572
573 <para>As explained in <xref linkend="webservice-or-com" />, VirtualBox
574 ships with client-side libraries for Java, Python and PHP that allow you
575 to use the VirtualBox web service in an intuitive, object-oriented way.
576 These libraries shield you from the client-side complications of managed
577 object references and other implementation details that come with the
578 VirtualBox web service. (If you are interested in these complications,
579 have a look at <xref linkend="raw-webservice" />).</para>
580
581 <para>We recommend that you start your experiments with the VirtualBox
582 web service by using our object-oriented client libraries for JAX-WS, a
583 web service toolkit for Java, which enables you to write code to
584 interact with VirtualBox in the simplest manner possible.</para>
585
586 <para>As "interfaces", "attributes" and "methods" are COM concepts,
587 please read the documentation in <xref linkend="sdkref_classes" /> and
588 <xref linkend="sdkref_enums" /> with the following notes in mind.</para>
589
590 <para>The OOWS bindings attempt to map the Main API as closely as
591 possible to the Java, Python and PHP languages. In other words, objects
592 are objects, interfaces become classes, and you can call methods on
593 objects as you would on local objects.</para>
594
595 <para>The main difference remains with attributes: to read an attribute,
596 call a "getXXX" method, with "XXX" being the attribute name with a
597 capitalized first letter. So when the Main API Reference says that
598 <computeroutput>IMachine</computeroutput> has a "name" attribute (see
599 <xref linkend="IMachine__name" xreflabel="IMachine::name" />), call
600 <computeroutput>getName()</computeroutput> on an IMachine object to
601 obtain a machine's name. Unless the attribute is marked as read-only in
602 the documentation, there will also be a corresponding "set"
603 method.</para>
604
605 <sect2 id="glue-jax-ws">
606 <title>The object-oriented web service for JAX-WS</title>
607
608 <para>JAX-WS is a powerful toolkit by Sun Microsystems to build both
609 server and client code with Java. It is part of Java 6 (JDK 1.6), but
610 can also be obtained separately for Java 5 (JDK 1.5). The VirtualBox
611 SDK comes with precompiled OOWS bindings working with both Java 5 and
612 6.</para>
613
614 <para>The following sections explain how to get the JAX-WS sample code
615 running and explain a few common practices when using the JAX-WS
616 object-oriented web service.</para>
617
618 <sect3>
619 <title>Preparations</title>
620
621 <para>Since JAX-WS is already integrated into Java 6, no additional
622 preparations are needed for Java 6.</para>
623
624 <para>If you are using Java 5 (JDK 1.5.x), you will first need to
625 download and install an external JAX-WS implementation, as Java 5
626 does not support JAX-WS out of the box; for example, you can
627 download one from here: <ulink
628 url="https://jax-ws.dev.java.net/2.1.4/JAXWS2.1.4-20080502.jar">https://jax-ws.dev.java.net/2.1.4/JAXWS2.1.4-20080502.jar</ulink>.
629 Then perform the installation (<computeroutput>java -jar
630 JAXWS2.1.4-20080502.jar</computeroutput>).</para>
631 </sect3>
632
633 <sect3>
634 <title>Getting started: running the sample code</title>
635
636 <para>To run the OOWS for JAX-WS samples that we ship with the SDK,
637 perform the following steps: <orderedlist>
638 <listitem>
639 <para>Open a terminal and change to the directory where the
640 JAX-WS samples reside.<footnote>
641 <para>In
642 <computeroutput>sdk/bindings/glue/java/</computeroutput>.</para>
643 </footnote> Examine the header of
644 <computeroutput>Makefile</computeroutput> to see if the
645 supplied variables (Java compiler, Java executable) and a few
646 other details match your system settings.</para>
647 </listitem>
648
649 <listitem>
650 <para>To start the VirtualBox web service, open a second
651 terminal and change to the directory where the VirtualBox
652 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
653
654 <para>The web service now waits for connections and will run
655 until you press Ctrl+C in this second terminal. The -v
656 argument causes it to log all connections to the terminal.
657 (See <xref linkend="runvboxwebsrv" os="" /> for details on how
658 to run the web service.)</para>
659 </listitem>
660
661 <listitem>
662 <para>Back in the first terminal and still in the samples
663 directory, to start a simple client example just type:<screen>make run16</screen></para>
664
665 <para>if you're on a Java 6 system; on a Java 5 system, run
666 <computeroutput>make run15</computeroutput> instead.</para>
667
668 <para>This should work on all Unix-like systems such as Linux
669 and Solaris. For Windows systems, use commands similar to what
670 is used in the Makefile.</para>
671
672 <para>This will compile the
673 <computeroutput>clienttest.java</computeroutput> code on the
674 first call and then execute the resulting
675 <computeroutput>clienttest</computeroutput> class to show the
676 locally installed VMs (see below).</para>
677 </listitem>
678 </orderedlist></para>
679
680 <para>The <computeroutput>clienttest</computeroutput> sample
681 imitates a few typical command line tasks that
682 <computeroutput>VBoxManage</computeroutput>, VirtualBox's regular
683 command-line front-end, would provide (see the VirtualBox User
684 Manual for details). In particular, you can run:<itemizedlist>
685 <listitem>
686 <para><computeroutput>java clienttest show
687 vms</computeroutput>: show the virtual machines that are
688 registered locally.</para>
689 </listitem>
690
691 <listitem>
692 <para><computeroutput>java clienttest list
693 hostinfo</computeroutput>: show various information about the
694 host this VirtualBox installation runs on.</para>
695 </listitem>
696
697 <listitem>
698 <para><computeroutput>java clienttest startvm
699 &lt;vmname|uuid&gt;</computeroutput>: start the given virtual
700 machine.</para>
701 </listitem>
702 </itemizedlist></para>
703
704 <para>The <computeroutput>clienttest.java</computeroutput> sample
705 code illustrates common basic practices how to use the VirtualBox
706 OOWS for JAX-WS, which we will explain in more detail in the
707 following chapters.</para>
708 </sect3>
709
710 <sect3>
711 <title>Logging on to the web service</title>
712
713 <para>Before a web service client can do anything useful, two
714 objects need to be created, as can be seen in the
715 <computeroutput>clienttest</computeroutput> constructor:<orderedlist>
716 <listitem>
717 <para>An instance of <xref linkend="IWebsessionManager"
718 xreflabel="IWebsessionManager" />, which is an interface
719 provided by the web service to manage "web sessions" -- that
720 is, stateful connections to the web service with persistent
721 objects upon which methods can be invoked.</para>
722
723 <para>In the OOWS for JAX-WS, the IWebsessionManager class
724 must be constructed explicitly, and a URL must be provided in
725 the constructor that specifies where the web service (the
726 server) awaits connections. The code in
727 <computeroutput>clienttest.java</computeroutput> connects to
728 "http://localhost:18083/", which is the default.</para>
729
730 <para>The port number, by default 18083, must match the port
731 number given to the
732 <computeroutput>vboxwebsrv</computeroutput> command line; see
733 <xref linkend="vboxwebsrv-ref" />.</para>
734 </listitem>
735
736 <listitem>
737 <para>After that, the code calls <xref
738 linkend="IWebsessionManager__logon"
739 xreflabel="IWebsessionManager::logon()" />, which is the first
740 call that actually communicates with the server. This
741 authenticates the client with the web service and returns an
742 instance of <xref linkend="IVirtualBox"
743 xreflabel="IVirtualBox" />, the most fundamental interface of
744 the VirtualBox web service, from which all other functionality
745 can be derived.</para>
746
747 <para>If logon doesn't work, please take another look at <xref
748 linkend="websrv_authenticate" />.</para>
749 </listitem>
750 </orderedlist></para>
751 </sect3>
752
753 <sect3>
754 <title>Object management</title>
755
756 <para>The current OOWS for JAX-WS has certain memory management
757 related limitations. When you no longer need an object, call its
758 <xref linkend="IManagedObjectRef__release"
759 xreflabel="IManagedObjectRef::release()" /> method explicitly, which
760 frees appropriate managed reference, as is required by the raw
761 web service; see <xref linkend="managed-object-references" /> for
762 details. This limitation may be reconsidered in a future version of
763 the VirtualBox SDK.</para>
764 </sect3>
765 </sect2>
766
767 <sect2 id="glue-python-ws">
768 <title>The object-oriented web service for Python</title>
769
770 <para>VirtualBox comes with two flavors of a Python API: one for web
771 service, discussed here, and one for the COM/XPCOM API discussed in
772 <xref linkend="pycom" />. The client code is mostly similar, except
773 for the initialization part, so it is up to the application developer
774 to choose the appropriate technology. Moreover, a common Python glue
775 layer exists, abstracting out concrete platform access details, see
776 <xref linkend="glue-python" />.</para>
777
778 <para>As indicated in <xref linkend="webservice-or-com" />, the
779 COM/XPCOM API gives better performance without the SOAP overhead, and
780 does not require a web server to be running. On the other hand, the
781 COM/XPCOM Python API requires a suitable Python bridge for your Python
782 installation (VirtualBox ships the most important ones for each
783 platform<footnote>
784 <para>On On Mac OS X only the Python versions bundled with the OS
785 are officially supported. This means Python 2.3 for 10.4, Python
786 2.5 for 10.5 and Python 2.5 and 2.6 for 10.6.</para>
787 </footnote>). On Windows, you can use the Main API from Python if the Win32 extensions
788 package for Python<footnote>
789 <para>See <ulink
790 url="http://sourceforge.net/project/showfiles.php?group_id=78018">http://sourceforge.net/project/showfiles.php?group_id=78018</ulink>.</para>
791 </footnote> is installed. Version of Python Win32 extensions earlier than 2.16 are known to have bugs,
792 leading to issues with VirtualBox Python bindings, and also some early builds of Python 2.5 for Windows have issues with
793 reporting platform name on some Windows versions, so please make sure to use latest available Python
794 and Win32 extensions.</para>
795
796 <para>The VirtualBox OOWS for Python relies on the Python ZSI SOAP
797 implementation (see <ulink
798 url="http://pywebsvcs.sourceforge.net/zsi.html">http://pywebsvcs.sourceforge.net/zsi.html</ulink>),
799 which you will need to install locally before trying the examples.
800 Most Linux distributions come with package for ZSI, such as
801 <computeroutput>python-zsi</computeroutput> in Ubuntu.</para>
802
803 <para>To get started, open a terminal and change to the
804 <computeroutput>bindings/glue/python/sample</computeroutput>
805 directory, which contains an example of a simple interactive shell
806 able to control a VirtualBox instance. The shell is written using the
807 API layer, thereby hiding different implementation details, so it is
808 actually an example of code share among XPCOM, MSCOM and web services.
809 If you are interested in how to interact with the web services layer
810 directly, have a look at
811 <computeroutput>install/vboxapi/__init__.py</computeroutput> which
812 contains the glue layer for all target platforms (i.e. XPCOM, MSCOM
813 and web services).</para>
814
815 <para>To start the shell, perform the following commands: <screen>/opt/VirtualBox/vboxwebsrv -t 0
816 # start web service with object autocollection disabled
817export VBOX_PROGRAM_PATH=/opt/VirtualBox
818 # your VirtualBox installation directory
819export VBOX_SDK_PATH=/home/youruser/vbox-sdk
820 # where you've extracted the SDK
821./vboxshell.py -w </screen>See <xref linkend="vboxshell" /> for more
822 details on the shell's functionality. For you, as a VirtualBox
823 application developer, the vboxshell sample could be interesting as an
824 example of how to write code targeting both local and remote cases
825 (COM/XPCOM and SOAP). The common part of the shell is the same -- the
826 only difference is how it interacts with the invocation layer. You can
827 use the <computeroutput>connect</computeroutput> shell command to
828 connect to remote VirtualBox servers; in this case you can skip
829 starting the local web server.</para>
830 </sect2>
831
832 <sect2>
833 <title>The object-oriented web service for PHP</title>
834
835 <para>VirtualBox also comes with object-oriented web service (OOWS)
836 wrappers for PHP5. These wrappers rely on the PHP SOAP
837 Extension<footnote>
838 <para>See
839 <ulink url="https://www.php.net/soap">https://www.php.net/soap</ulink>.</para>
840 </footnote>, which can be installed by configuring PHP with
841 <computeroutput>--enable-soap</computeroutput>.</para>
842 </sect2>
843 </sect1>
844
845 <sect1 id="raw-webservice">
846 <title>Using the raw web service with any language</title>
847
848 <para>The following examples show you how to use the raw web service,
849 without the object-oriented client-side code that was described in the
850 previous chapter.</para>
851
852 <para>Generally, when reading the documentation in <xref
853 linkend="sdkref_classes" /> and <xref linkend="sdkref_enums" />, due to
854 the limitations of SOAP and WSDL lined out in <xref
855 linkend="rawws-conventions" />, please have the following notes in
856 mind:</para>
857
858 <para><orderedlist>
859 <listitem>
860 <para>Any COM method call becomes a <emphasis role="bold">plain
861 function call</emphasis> in the raw web service, with the object
862 as an additional first parameter (before the "real" parameters
863 listed in the documentation). So when the documentation says that
864 the <computeroutput>IVirtualBox</computeroutput> interface
865 supports the <computeroutput>createMachine()</computeroutput>
866 method (see <xref linkend="IVirtualBox__createMachine"
867 xreflabel="IVirtualBox::createMachine()" />), the web service
868 operation is
869 <computeroutput>IVirtualBox_createMachine(...)</computeroutput>,
870 and a managed object reference to an
871 <computeroutput>IVirtualBox</computeroutput> object must be passed
872 as the first argument.</para>
873 </listitem>
874
875 <listitem>
876 <para>For <emphasis role="bold">attributes</emphasis> in
877 interfaces, there will be at least one "get" function; there will
878 also be a "set" function, unless the attribute is "readonly". The
879 attribute name will be appended to the "get" or "set" prefix, with
880 a capitalized first letter. So, the "version" readonly attribute
881 of the <computeroutput>IVirtualBox</computeroutput> interface can
882 be retrieved by calling
883 <computeroutput>IVirtualBox_getVersion(vbox)</computeroutput>,
884 with <computeroutput>vbox</computeroutput> being the VirtualBox
885 object.</para>
886 </listitem>
887
888 <listitem>
889 <para>Whenever the API documentation says that a method (or an
890 attribute getter) returns an <emphasis
891 role="bold">object</emphasis>, it will returned a managed object
892 reference in the web service instead. As said above, managed
893 object references should be released if the web service client
894 does not log off again immediately!</para>
895 </listitem>
896 </orderedlist></para>
897
898 <para></para>
899
900 <sect2 id="webservice-java-sample">
901 <title>Raw web service example for Java with Axis</title>
902
903 <para>Axis is an older web service toolkit created by the Apache
904 foundation. If your distribution does not have it installed, you can
905 get a binary from <ulink
906 url="http://www.apache.org">http://www.apache.org</ulink>. The
907 following examples assume that you have Axis 1.4 installed.</para>
908
909 <para>The VirtualBox SDK ships with an example for Axis that, again,
910 is called <computeroutput>clienttest.java</computeroutput> and that
911 imitates a few of the commands of
912 <computeroutput>VBoxManage</computeroutput> over the wire.</para>
913
914 <para>Then perform the following steps:<orderedlist>
915 <listitem>
916 <para>Create a working directory somewhere. Under your
917 VirtualBox installation directory, find the
918 <computeroutput>sdk/webservice/samples/java/axis/</computeroutput>
919 directory and copy the file
920 <computeroutput>clienttest.java</computeroutput> to your working
921 directory.</para>
922 </listitem>
923
924 <listitem>
925 <para>Open a terminal in your working directory. Execute the
926 following command:<screen> java org.apache.axis.wsdl.WSDL2Java /path/to/vboxwebService.wsdl</screen></para>
927
928 <para>The <computeroutput>vboxwebService.wsdl</computeroutput>
929 file should be located in the
930 <computeroutput>sdk/webservice/</computeroutput>
931 directory.</para>
932
933 <para>If this fails, your Apache Axis may not be located on your
934 system classpath, and you may have to adjust the CLASSPATH
935 environment variable. Something like this:<screen>export CLASSPATH="/path-to-axis-1_4/lib/*":$CLASSPATH</screen></para>
936
937 <para>Use the directory where the Axis JAR files are located.
938 Mind the quotes so that your shell passes the "*" character to
939 the java executable without expanding. Alternatively, add a
940 corresponding <computeroutput>-classpath</computeroutput>
941 argument to the "java" call above.</para>
942
943 <para>If the command executes successfully, you should see an
944 "org" directory with subdirectories containing Java source files
945 in your working directory. These classes represent the
946 interfaces that the VirtualBox web service offers, as described
947 by the WSDL file.</para>
948
949 <para>This is the bit that makes using web services so
950 attractive to client developers: if a language's toolkit
951 understands WSDL, it can generate large amounts of support code
952 automatically. Clients can then easily use this support code and
953 can be done with just a few lines of code.</para>
954 </listitem>
955
956 <listitem>
957 <para>Next, compile the
958 <computeroutput>clienttest.java</computeroutput> source:<screen>javac clienttest.java </screen></para>
959
960 <para>This should yield a "clienttest.class" file.</para>
961 </listitem>
962
963 <listitem>
964 <para>To start the VirtualBox web service, open a second
965 terminal and change to the directory where the VirtualBox
966 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
967
968 <para>The web service now waits for connections and will run
969 until you press Ctrl+C in this second terminal. The -v argument
970 causes it to log all connections to the terminal. (See <xref
971 linkend="runvboxwebsrv" os="" /> for details on how to run the
972 web service.)</para>
973 </listitem>
974
975 <listitem>
976 <para>Back in the original terminal where you compiled the Java
977 source, run the resulting binary, which will then connect to the
978 web service:<screen>java clienttest</screen></para>
979
980 <para>The client sample will connect to the web service (on
981 localhost, but the code could be changed to connect remotely if
982 the web service was running on a different machine) and make a
983 number of method calls. It will output the version number of
984 your VirtualBox installation and a list of all virtual machines
985 that are currently registered (with a bit of seemingly random
986 data, which will be explained later).</para>
987 </listitem>
988 </orderedlist></para>
989 </sect2>
990
991 <sect2 id="raw-webservice-perl">
992 <title>Raw web service example for Perl</title>
993
994 <para>We also ship a small sample for Perl. It uses the SOAP::Lite
995 perl module to communicate with the VirtualBox web service.</para>
996
997 <para>The
998 <computeroutput>sdk/bindings/webservice/perl/lib/</computeroutput>
999 directory contains a pre-generated Perl module that allows for
1000 communicating with the web service from Perl. You can generate such a
1001 module yourself using the "stubmaker" tool that comes with SOAP::Lite,
1002 but since that tool is slow as well as sometimes unreliable, we are
1003 shipping a working module with the SDK for your convenience.</para>
1004
1005 <para>Perform the following steps:<orderedlist>
1006 <listitem>
1007 <para>If SOAP::Lite is not yet installed on your system, you
1008 will need to install the package first. On Debian-based systems,
1009 the package is called
1010 <computeroutput>libsoap-lite-perl</computeroutput>; on Gentoo,
1011 it's <computeroutput>dev-perl/SOAP-Lite</computeroutput>.</para>
1012 </listitem>
1013
1014 <listitem>
1015 <para>Open a terminal in the
1016 <computeroutput>sdk/bindings/webservice/perl/samples/</computeroutput>
1017 directory.</para>
1018 </listitem>
1019
1020 <listitem>
1021 <para>To start the VirtualBox web service, open a second
1022 terminal and change to the directory where the VirtualBox
1023 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
1024
1025 <para>The web service now waits for connections and will run
1026 until you press Ctrl+C in this second terminal. The -v argument
1027 causes it to log all connections to the terminal. (See <xref
1028 linkend="runvboxwebsrv" os="" /> for details on how to run the
1029 web service.)</para>
1030 </listitem>
1031
1032 <listitem>
1033 <para>In the first terminal with the Perl sample, run the
1034 clienttest.pl script:<screen>perl -I ../lib clienttest.pl</screen></para>
1035 </listitem>
1036 </orderedlist></para>
1037 </sect2>
1038
1039 <sect2>
1040 <title>Programming considerations for the raw web service</title>
1041
1042 <para>If you use the raw web service, you need to keep a number of
1043 things in mind, or you will sooner or later run into issues that are
1044 not immediately obvious. By contrast, the object-oriented client-side
1045 libraries described in <xref linkend="glue" /> take care of these
1046 things automatically and thus greatly simplify using the web
1047 service.</para>
1048
1049 <sect3 id="rawws-conventions">
1050 <title>Fundamental conventions</title>
1051
1052 <para>If you are familiar with other web services, you may find the
1053 VirtualBox web service to behave a bit differently to accommodate
1054 for the fact that VirtualBox web service more or less maps the
1055 VirtualBox Main COM API. The following main differences had to be
1056 taken care of:<itemizedlist>
1057 <listitem>
1058 <para>Web services, as expressed by WSDL, are not
1059 object-oriented. Even worse, they are normally stateless (or,
1060 in web services terminology, "loosely coupled"). Web service
1061 operations are entirely procedural, and one cannot normally
1062 make assumptions about the state of a web service between
1063 function calls.</para>
1064
1065 <para>In particular, this normally means that you cannot work
1066 on objects in one method call that were created by another
1067 call.</para>
1068 </listitem>
1069
1070 <listitem>
1071 <para>By contrast, the VirtualBox Main API, being expressed in
1072 COM, is object-oriented and works entirely on objects, which
1073 are grouped into public interfaces, which in turn have
1074 attributes and methods associated with them.</para>
1075 </listitem>
1076 </itemizedlist> For the VirtualBox web service, this results in
1077 three fundamental conventions:<orderedlist>
1078 <listitem>
1079 <para>All <emphasis role="bold">function names</emphasis> in
1080 the VirtualBox web service consist of an interface name and a
1081 method name, joined together by an underscore. This is because
1082 there are only functions ("operations") in WSDL, but no
1083 classes, interfaces, or methods.</para>
1084
1085 <para>In addition, all calls to the VirtualBox web service
1086 (except for logon, see below) take a <emphasis
1087 role="bold">managed object reference</emphasis> as the first
1088 argument, representing the object upon which the underlying
1089 method is invoked. (Managed object references are explained in
1090 detail below; see <xref
1091 linkend="managed-object-references" />.)</para>
1092
1093 <para>So, when one would normally code, in the pseudo-code of
1094 an object-oriented language, to invoke a method upon an
1095 object:<screen>IMachine machine;
1096result = machine.getName();</screen></para>
1097
1098 <para>In the VirtualBox web service, this looks something like
1099 this (again, pseudo-code):<screen>IMachineRef machine;
1100result = IMachine_getName(machine);</screen></para>
1101 </listitem>
1102
1103 <listitem>
1104 <para>To make the web service stateful, and objects persistent
1105 between method calls, the VirtualBox web service introduces a
1106 <emphasis role="bold">session manager</emphasis> (by way of
1107 the <xref linkend="IWebsessionManager"
1108 xreflabel="IWebsessionManager" /> interface), which manages
1109 object references. Any client wishing to interact with the web
1110 service must first log on to the session manager and in turn
1111 receives a managed object reference to an object that supports
1112 the <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />
1113 interface (the basic interface in the Main API).</para>
1114 </listitem>
1115 </orderedlist></para>
1116
1117 <para>In other words, as opposed to other web services, <emphasis
1118 role="bold">the VirtualBox web service is both object-oriented and
1119 stateful.</emphasis></para>
1120 </sect3>
1121
1122 <sect3>
1123 <title>Example: A typical web service client session</title>
1124
1125 <para>A typical short web service session to retrieve the version
1126 number of the VirtualBox web service (to be precise, the underlying
1127 Main API version number) looks like this:<orderedlist>
1128 <listitem>
1129 <para>A client logs on to the web service by calling <xref
1130 linkend="IWebsessionManager__logon"
1131 xreflabel="IWebsessionManager::logon()" /> with a valid user
1132 name and password. See <xref linkend="websrv_authenticate" />
1133 for details about how authentication works.</para>
1134 </listitem>
1135
1136 <listitem>
1137 <para>On the server side,
1138 <computeroutput>vboxwebsrv</computeroutput> creates a session,
1139 which persists until the client calls <xref
1140 linkend="IWebsessionManager__logoff"
1141 xreflabel="IWebsessionManager::logoff()" /> or the session
1142 times out after a configurable period of inactivity (see <xref
1143 linkend="vboxwebsrv-ref" />).</para>
1144
1145 <para>For the new session, the web service creates an instance
1146 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />.
1147 This interface is the most central one in the Main API and
1148 allows access to all other interfaces, either through
1149 attributes or method calls. For example, IVirtualBox contains
1150 a list of all virtual machines that are currently registered
1151 (as they would be listed on the left side of the VirtualBox
1152 main program).</para>
1153
1154 <para>The web service then creates a managed object reference
1155 for this instance of IVirtualBox and returns it to the calling
1156 client, which receives it as the return value of the logon
1157 call. Something like this:</para>
1158
1159 <screen>string oVirtualBox;
1160oVirtualBox = webservice.IWebsessionManager_logon("user", "pass");</screen>
1161
1162 <para>(The managed object reference "oVirtualBox" is just a
1163 string consisting of digits and dashes. However, it is a
1164 string with a meaning and will be checked by the web service.
1165 For details, see below. As hinted above, <xref
1166 linkend="IWebsessionManager__logon"
1167 xreflabel="IWebsessionManager::logon()" /> is the
1168 <emphasis>only</emphasis> operation provided by the web
1169 service which does not take a managed object reference as the
1170 first argument!)</para>
1171 </listitem>
1172
1173 <listitem>
1174 <para>The VirtualBox Main API documentation says that the
1175 <computeroutput>IVirtualBox</computeroutput> interface has a
1176 <xref linkend="IVirtualBox__version" xreflabel="version" />
1177 attribute, which is a string. For each attribute, there is a
1178 "get" and a "set" method in COM, which maps to according
1179 operations in the web service. So, to retrieve the "version"
1180 attribute of this <computeroutput>IVirtualBox</computeroutput>
1181 object, the web service client does this:<screen>string version;
1182version = webservice.IVirtualBox_getVersion(oVirtualBox);
1183
1184print version;</screen></para>
1185
1186 <para>And it will print
1187 "$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD".</para>
1188 </listitem>
1189
1190 <listitem>
1191 <para>The web service client calls <xref
1192 linkend="IWebsessionManager__logoff"
1193 xreflabel="IWebsessionManager::logoff()" /> with the
1194 VirtualBox managed object reference. This will clean up all
1195 allocated resources.</para>
1196 </listitem>
1197 </orderedlist></para>
1198 </sect3>
1199
1200 <sect3 id="managed-object-references">
1201 <title>Managed object references</title>
1202
1203 <para>To a web service client, a managed object reference looks like
1204 a string: two 64-bit hex numbers separated by a dash. This string,
1205 however, represents a COM object that "lives" in the web service
1206 process. The two 64-bit numbers encoded in the managed object
1207 reference represent a session ID (which is the same for all objects
1208 in the same web service session, i.e. for all objects after one
1209 logon) and a unique object ID within that session.</para>
1210
1211 <para>Managed object references are created in two
1212 situations:<orderedlist>
1213 <listitem>
1214 <para>When a client logs on, by calling <xref
1215 linkend="IWebsessionManager__logon"
1216 xreflabel="IWebsessionManager::logon()" />.</para>
1217
1218 <para>Upon logon, the websession manager creates one instance
1219 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" /> and
1220 another object of <xref linkend="ISession"
1221 xreflabel="ISession" /> representing the web service session.
1222 This can be retrieved using <xref
1223 linkend="IWebsessionManager__getSessionObject"
1224 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
1225
1226 <para>(Technically, there is always only one <xref
1227 linkend="IVirtualBox" xreflabel="IVirtualBox" /> object, which
1228 is shared between all sessions and clients, as it is a COM
1229 singleton. However, each session receives its own managed
1230 object reference to it. The <xref linkend="ISession"
1231 xreflabel="ISession" /> object, however, is created and
1232 destroyed for each session.)</para>
1233 </listitem>
1234
1235 <listitem>
1236 <para>Whenever a web service clients invokes an operation
1237 whose COM implementation creates COM objects.</para>
1238
1239 <para>For example, <xref linkend="IVirtualBox__createMachine"
1240 xreflabel="IVirtualBox::createMachine()" /> creates a new
1241 instance of <xref linkend="IMachine" xreflabel="IMachine" />;
1242 the COM object returned by the COM method call is then wrapped
1243 into a managed object reference by the web server, and this
1244 reference is returned to the web service client.</para>
1245 </listitem>
1246 </orderedlist></para>
1247
1248 <para>Internally, in the web service process, each managed object
1249 reference is simply a small data structure, containing a COM pointer
1250 to the "real" COM object, the web session ID and the object ID. This
1251 structure is allocated on creation and stored efficiently in hashes,
1252 so that the web service can look up the COM object quickly whenever
1253 a web service client wishes to make a method call. The random
1254 session ID also ensures that one web service client cannot intercept
1255 the objects of another.</para>
1256
1257 <para>Managed object references are not destroyed automatically and
1258 must be released by explicitly calling <xref
1259 linkend="IManagedObjectRef__release"
1260 xreflabel="IManagedObjectRef::release()" />. This is important, as
1261 otherwise hundreds or thousands of managed object references (and
1262 corresponding COM objects, which can consume much more memory!) can
1263 pile up in the web service process and eventually cause it to deny
1264 service.</para>
1265
1266 <para>To reiterate: The underlying COM object, which the reference
1267 points to, is only freed if the managed object reference is
1268 released. It is therefore vital that web service clients properly
1269 clean up after the managed object references that are returned to
1270 them.</para>
1271
1272 <para>When a web service client calls <xref
1273 linkend="IWebsessionManager__logoff"
1274 xreflabel="IWebsessionManager::logoff()" />, all managed object
1275 references created during the session are automatically freed. For
1276 short-lived sessions that do not create a lot of objects, logging
1277 off may therefore be sufficient, although it is certainly not "best
1278 practice".</para>
1279 </sect3>
1280
1281 <sect3>
1282 <title>Some more detail about web service operation</title>
1283
1284 <sect4 id="soap">
1285 <title>SOAP messages</title>
1286
1287 <para>Whenever a client makes a call to a web service, this
1288 involves a complicated procedure internally. These calls are
1289 remote procedure calls. Each such procedure call typically
1290 consists of two "message" being passed, where each message is a
1291 plain-text HTTP request with a standard HTTP header and a special
1292 XML document following. This XML document encodes the name of the
1293 procedure to call and the argument names and values passed to
1294 it.</para>
1295
1296 <para>To give you an idea of what such a message looks like,
1297 assuming that a web service provides a procedure called
1298 "SayHello", which takes a string "name" as an argument and returns
1299 "Hello" with a space and that name appended, the request message
1300 could look like this:</para>
1301
1302 <para><screen>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
1303&lt;SOAP-ENV:Envelope
1304 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
1305 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
1306 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1307 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1308 xmlns:test="http://test/"&gt;
1309&lt;SOAP-ENV:Body&gt;
1310 &lt;test:SayHello&gt;
1311 &lt;name&gt;Peter&lt;/name&gt;
1312 &lt;/test:SayHello&gt;
1313 &lt;/SOAP-ENV:Body&gt;
1314&lt;/SOAP-ENV:Envelope&gt;</screen>A similar message -- the "response" message
1315 -- would be sent back from the web service to the client,
1316 containing the return value "Hello Peter".</para>
1317
1318 <para>Most programming languages provide automatic support to
1319 generate such messages whenever code in that programming language
1320 makes such a request. In other words, these programming languages
1321 allow for writing something like this (in pseudo-C++ code):</para>
1322
1323 <para><screen>webServiceClass service("localhost", 18083); // server and port
1324string result = service.SayHello("Peter"); // invoke remote procedure</screen>and
1325 would, for these two pseudo-lines, automatically perform these
1326 steps:</para>
1327
1328 <para><orderedlist>
1329 <listitem>
1330 <para>prepare a connection to a web service running on port
1331 18083 of "localhost";</para>
1332 </listitem>
1333
1334 <listitem>
1335 <para>for the <computeroutput>SayHello()</computeroutput>
1336 function of the web service, generate a SOAP message like in
1337 the above example by encoding all arguments of the remote
1338 procedure call (which could involve all kinds of type
1339 conversions and complex marshalling for arrays and
1340 structures);</para>
1341 </listitem>
1342
1343 <listitem>
1344 <para>connect to the web service via HTTP and send that
1345 message;</para>
1346 </listitem>
1347
1348 <listitem>
1349 <para>wait for the web service to send a response
1350 message;</para>
1351 </listitem>
1352
1353 <listitem>
1354 <para>decode that response message and put the return value
1355 of the remote procedure into the "result" variable.</para>
1356 </listitem>
1357 </orderedlist></para>
1358 </sect4>
1359
1360 <sect4 id="wsdl">
1361 <title>Service descriptions in WSDL</title>
1362
1363 <para>In the above explanations about SOAP, it was left open how
1364 the programming language learns about how to translate function
1365 calls in its own syntax into proper SOAP messages. In other words,
1366 the programming language needs to know what operations the web
1367 service supports and what types of arguments are required for the
1368 operation's data in order to be able to properly serialize and
1369 deserialize the data to and from the web service. For example, if
1370 a web service operation expects a number in "double" floating
1371 point format for a particular parameter, the programming language
1372 cannot send to it a string instead.</para>
1373
1374 <para>For this, the Web Service Definition Language (WSDL) was
1375 invented, another XML substandard that describes exactly what
1376 operations the web service supports and, for each operation, which
1377 parameters and types are needed with each request and response
1378 message. WSDL descriptions can be incredibly verbose, and one of
1379 the few good things that can be said about this standard is that
1380 it is indeed supported by most programming languages.</para>
1381
1382 <para>So, if it is said that a programming language "supports" web
1383 services, this typically means that a programming language has
1384 support for parsing WSDL files and somehow integrating the remote
1385 procedure calls into the native language syntax -- for example,
1386 like in the Java sample shown in <xref
1387 linkend="webservice-java-sample" />.</para>
1388
1389 <para>For details about how programming languages support web
1390 services, please refer to the documentation that comes with the
1391 individual languages. Here are a few pointers:</para>
1392
1393 <orderedlist>
1394 <listitem>
1395 <para>For <emphasis role="bold">C++,</emphasis> among many
1396 others, the gSOAP toolkit is a good option. Parts of gSOAP are
1397 also used in VirtualBox to implement the VirtualBox web
1398 service.</para>
1399 </listitem>
1400
1401 <listitem>
1402 <para>For <emphasis role="bold">Java,</emphasis> there are
1403 several implementations already described in this document
1404 (see <xref linkend="glue-jax-ws" /> and <xref
1405 linkend="webservice-java-sample" />).</para>
1406 </listitem>
1407
1408 <listitem>
1409 <para><emphasis role="bold">Perl</emphasis> supports WSDL via
1410 the SOAP::Lite package. This in turn comes with a tool called
1411 <computeroutput>stubmaker.pl</computeroutput> that allows you
1412 to turn any WSDL file into a Perl package that you can import.
1413 (You can also import any WSDL file "live" by having it parsed
1414 every time the script runs, but that can take a while.) You
1415 can then code (again, assuming the above example):<screen>my $result = servicename-&gt;sayHello("Peter");</screen></para>
1416
1417 <para>A sample that uses SOAP::Lite was described in <xref
1418 linkend="raw-webservice-perl" />.</para>
1419 </listitem>
1420 </orderedlist>
1421 </sect4>
1422 </sect3>
1423 </sect2>
1424 </sect1>
1425
1426 <sect1 id="api_com">
1427 <title>Using COM/XPCOM directly</title>
1428
1429 <para>If you do not require <emphasis>remote</emphasis> procedure calls
1430 such as those offered by the VirtualBox web service, and if you know
1431 Python or C++ as well as COM, you might find it preferable to program
1432 VirtualBox's Main API directly via COM.</para>
1433
1434 <para>COM stands for "Component Object Model" and is a standard
1435 originally introduced by Microsoft in the 1990s for Microsoft Windows.
1436 It allows for organizing software in an object-oriented way and across
1437 processes; code in one process may access objects that live in another
1438 process.</para>
1439
1440 <para>COM has several advantages: it is language-neutral, meaning that
1441 even though all of VirtualBox is internally written in C++, programs
1442 written in other languages could communicate with it. COM also cleanly
1443 separates interface from implementation, so that external programs need
1444 not know anything about the messy and complicated details of VirtualBox
1445 internals.</para>
1446
1447 <para>On a Windows host, all parts of VirtualBox will use the COM
1448 functionality that is native to Windows. On other hosts (including
1449 Linux), VirtualBox comes with a built-in implementation of XPCOM, as
1450 originally created by the Mozilla project, which we have enhanced to
1451 support interprocess communication on a level comparable to Microsoft
1452 COM. Internally, VirtualBox has an abstraction layer that allows the
1453 same VirtualBox code to work both with native COM as well as our XPCOM
1454 implementation.</para>
1455
1456 <sect2 id="pycom">
1457 <title>Python COM API</title>
1458
1459 <para>On Windows, Python scripts can use COM and VirtualBox interfaces
1460 to control almost all aspects of virtual machine execution. As an
1461 example, use the following commands to instantiate the VirtualBox
1462 object and start a VM: <screen>
1463 vbox = win32com.client.Dispatch("VirtualBox.VirtualBox")
1464 session = win32com.client.Dispatch("VirtualBox.Session")
1465 mach = vbox.findMachine("uuid or name of machine to start")
1466 progress = mach.launchVMProcess(session, "gui", "")
1467 progress.waitForCompletion(-1)
1468 </screen> Also, see
1469 <computeroutput>/bindings/glue/python/samples/vboxshell.py</computeroutput>
1470 for more advanced usage scenarious. However, unless you have specific
1471 requirements, we strongly recommend to use the generic glue layer
1472 described in the next section to access MS COM objects.</para>
1473 </sect2>
1474
1475 <sect2 id="glue-python">
1476 <title>Common Python bindings layer</title>
1477
1478 <para>As different wrappers ultimately provide access to the same
1479 underlying API, and to simplify porting and development of Python
1480 application using the VirtualBox Main API, we developed a common glue
1481 layer that abstracts out most platform-specific details from the
1482 application and allows the developer to focus on application logic.
1483 The VirtualBox installer automatically sets up this glue layer for the
1484 system default Python install. See below for details on how to set up
1485 the glue layer if you want to use a different Python
1486 installation.</para>
1487
1488 <para>In this layer, the class
1489 <computeroutput>VirtualBoxManager</computeroutput> hides most
1490 platform-specific details. It can be used to access both the local
1491 (COM) and the web service based API. The following code can be used by
1492 an application to use the glue layer.</para>
1493
1494 <screen># This code assumes vboxapi.py from VirtualBox distribution
1495# being in PYTHONPATH, or installed system-wide
1496from vboxapi import VirtualBoxManager
1497
1498# This code initializes VirtualBox manager with default style
1499# and parameters
1500virtualBoxManager = VirtualBoxManager(None, None)
1501
1502# Alternatively, one can be more verbose, and initialize
1503# glue with web service backend, and provide authentication
1504# information
1505virtualBoxManager = VirtualBoxManager("WEBSERVICE",
1506 {'url':'http://myhost.com::18083/',
1507 'user':'me',
1508 'password':'secret'}) </screen>
1509
1510 <para>We supply the <computeroutput>VirtualBoxManager</computeroutput>
1511 constructor with 2 arguments: style and parameters. Style defines
1512 which bindings style to use (could be "MSCOM", "XPCOM" or
1513 "WEBSERVICE"), and if set to <computeroutput>None</computeroutput>
1514 defaults to usable platform bindings (MS COM on Windows, XPCOM on
1515 other platforms). The second argument defines parameters, passed to
1516 the platform-specific module, as we do in the second example, where we
1517 pass username and password to be used to authenticate against the web
1518 service.</para>
1519
1520 <para>After obtaining the
1521 <computeroutput>VirtualBoxManager</computeroutput> instance, one can
1522 perform operations on the IVirtualBox class. For example, the
1523 following code will a start virtual machine by name or ID:</para>
1524
1525 <screen>from vboxapi import VirtualBoxManager
1526mgr = VirtualBoxManager(None, None)
1527vbox = mgr.vbox
1528name = "Linux"
1529mach = vbox.findMachine(name)
1530session = mgr.mgr.getSessionObject(vbox)
1531progress = mach.launchVMProcess(session, "gui", "")
1532progress.waitForCompletion(-1)
1533mgr.closeMachineSession(session)
1534 </screen>
1535 <para>
1536 Following code will print all registered machines and their log folders
1537 </para>
1538 <screen>from vboxapi import VirtualBoxManager
1539mgr = VirtualBoxManager(None, None)
1540vbox = mgr.vbox
1541
1542for m in mgr.getArray(vbox, 'machines'):
1543print "Machine '%s' logs in '%s'" %(m.name, m.logFolder)
1544 </screen>
1545
1546 <para>Code above demonstrates cross-platform access to array properties
1547 (certain limitations prevent one from using
1548 <computeroutput>vbox.machines</computeroutput> to access a list of
1549 available virtual machines in case of XPCOM), and a mechanism of
1550 uniform session creation and closing
1551 (<computeroutput>mgr.mgr.getSessionObject()</computeroutput>).</para>
1552
1553 <para>In case you want to use the glue layer with a different Python
1554 installation, use these steps in a shell to add the necessary
1555 files:</para>
1556
1557 <screen> # cd VBOX_INSTALL_PATH/sdk/installer
1558 # PYTHON vboxapisetup.py install</screen>
1559 </sect2>
1560
1561 <sect2 id="cppcom">
1562 <title>C++ COM API</title>
1563
1564 <para>C++ is the language that VirtualBox itself is written in, so C++
1565 is the most direct way to use the Main API -- but it is not
1566 necessarily the easiest, as using COM and XPCOM has its own set of
1567 complications.</para>
1568
1569 <para>VirtualBox ships with sample programs that demonstrate how to
1570 use the Main API to implement a number of tasks on your host platform.
1571 These samples can be found in the
1572 <computeroutput>/bindings/xpcom/samples</computeroutput> directory for
1573 Linux, Mac OS X and Solaris and
1574 <computeroutput>/bindings/mscom/samples</computeroutput> for Windows.
1575 The two samples are actually different, because the one for Windows
1576 uses native COM, whereas the other uses our XPCOM implementation, as
1577 described above.</para>
1578
1579 <para>Since COM and XPCOM are conceptually very similar but vary in
1580 the implementation details, we have created a "glue" layer that
1581 shields COM client code from these differences. All VirtualBox uses is
1582 this glue layer, so the same code written once works on both Windows
1583 hosts (with native COM) as well as on other hosts (with our XPCOM
1584 implementation). It is recommended to always use this glue code
1585 instead of using the COM and XPCOM APIs directly, as it is very easy
1586 to make your code completely independent from the platform it is
1587 running on.<!-- A third sample,
1588 <computeroutput>tstVBoxAPIGlue.cpp</computeroutput>, illustrates how to
1589 use the glue layer.
1590--></para>
1591
1592 <para>In order to encapsulate platform differences between Microsoft
1593 COM and XPCOM, the following items should be kept in mind when using
1594 the glue layer:</para>
1595
1596 <para><orderedlist>
1597 <listitem>
1598 <para><emphasis role="bold">Attribute getters and
1599 setters.</emphasis> COM has the notion of "attributes" in
1600 interfaces, which roughly compare to C++ member variables in
1601 classes. The difference is that for each attribute declared in
1602 an interface, COM automatically provides a "get" method to
1603 return the attribute's value. Unless the attribute has been
1604 marked as "readonly", a "set" attribute is also provided.</para>
1605
1606 <para>To illustrate, the IVirtualBox interface has a "version"
1607 attribute, which is read-only and of the "wstring" type (the
1608 standard string type in COM). As a result, you can call the
1609 "get" method for this attribute to retrieve the version number
1610 of VirtualBox.</para>
1611
1612 <para>Unfortunately, the implementation differs between COM and
1613 XPCOM. Microsoft COM names the "get" method like this:
1614 <computeroutput>get_Attribute()</computeroutput>, whereas XPCOM
1615 uses this syntax:
1616 <computeroutput>GetAttribute()</computeroutput> (and accordingly
1617 for "set" methods). To hide these differences, the VirtualBox
1618 glue code provides the
1619 <computeroutput>COMGETTER(attrib)</computeroutput> and
1620 <computeroutput>COMSETTER(attrib)</computeroutput> macros. So,
1621 <computeroutput>COMGETTER(version)()</computeroutput> (note, two
1622 pairs of brackets) expands to
1623 <computeroutput>get_Version()</computeroutput> on Windows and
1624 <computeroutput>GetVersion()</computeroutput> on other
1625 platforms.</para>
1626 </listitem>
1627
1628 <listitem>
1629 <para><emphasis role="bold">Unicode conversions.</emphasis>
1630 While the rest of the modern world has pretty much settled on
1631 encoding strings in UTF-8, COM, unfortunately, uses UCS-16
1632 encoding. This requires a lot of conversions, in particular
1633 between the VirtualBox Main API and the Qt GUI, which, like the
1634 rest of Qt, likes to use UTF-8.</para>
1635
1636 <para>To facilitate these conversions, VirtualBox provides the
1637 <computeroutput>com::Bstr</computeroutput> and
1638 <computeroutput>com::Utf8Str</computeroutput> classes, which
1639 support all kinds of conversions back and forth.</para>
1640 </listitem>
1641
1642 <listitem>
1643 <para><emphasis role="bold">COM autopointers.</emphasis>
1644 Possibly the greatest pain of using COM -- reference counting --
1645 is alleviated by the
1646 <computeroutput>ComPtr&lt;&gt;</computeroutput> template
1647 provided by the <computeroutput>ptr.h</computeroutput> file in
1648 the glue layer.</para>
1649 </listitem>
1650 </orderedlist></para>
1651 </sect2>
1652
1653 <sect2 id="event-queue">
1654 <title>Event queue processing</title>
1655
1656 <para>Both VirtualBox client programs and frontends should
1657 periodically perform processing of the main event queue, and do that
1658 on the application's main thread. In case of a typical GUI Windows/Mac
1659 OS application this happens automatically in the GUI's dispatch loop.
1660 However, for CLI only application, the appropriate actions have to be
1661 taken. For C++ applications, the VirtualBox SDK provided glue method
1662 <screen>
1663 int EventQueue::processEventQueue(uint32_t cMsTimeout)
1664 </screen> can be used for both blocking and non-blocking operations.
1665 For the Python bindings, a common layer provides the method <screen>
1666 VirtualBoxManager.waitForEvents(ms)
1667 </screen> with similar semantics.</para>
1668
1669 <para>Things get somewhat more complicated for situations where an
1670 application using VirtualBox cannot directly control the main event
1671 loop and the main event queue is separated from the event queue of the
1672 programming librarly (for example in case of Qt on Unix platforms). In
1673 such a case, the application developer is advised to use a
1674 platform/toolkit specific event injection mechanism to force event
1675 queue checks either based on periodical timer events delivered to the
1676 main thread, or by using custom platform messages to notify the main
1677 thread when events are available. See the VBoxSDL and Qt (VirtualBox)
1678 frontends as examples.</para>
1679 </sect2>
1680
1681 <sect2 id="vbcom">
1682 <title>Visual Basic and Visual Basic Script (VBS) on Windows
1683 hosts</title>
1684
1685 <para>On Windows hosts, one can control some of the VirtualBox Main
1686 API functionality from VBS scripts, and pretty much everything from
1687 Visual Basic programs.<footnote>
1688 <para>The difference results from the way VBS treats COM
1689 safearrays, which are used to keep lists in the Main API. VBS
1690 expects every array element to be a
1691 <computeroutput>VARIANT</computeroutput>, which is too strict a
1692 limitation for any high performance API. We may lift this
1693 restriction for interface APIs in a future version, or
1694 alternatively provide conversion APIs.</para>
1695 </footnote></para>
1696
1697 <para>VBS is scripting language available in any recent Windows
1698 environment. As an example, the following VBS code will print
1699 VirtualBox version: <screen>
1700 set vb = CreateObject("VirtualBox.VirtualBox")
1701 Wscript.Echo "VirtualBox version " &amp; vb.version
1702 </screen> See
1703 <computeroutput>bindings/mscom/vbs/sample/vboxinfo.vbs</computeroutput>
1704 for the complete sample.</para>
1705
1706 <para>Visual Basic is a popular high level language capable of
1707 accessing COM objects. The following VB code will iterate over all
1708 available virtual machines:<screen>
1709 Dim vb As VirtualBox.IVirtualBox
1710
1711 vb = CreateObject("VirtualBox.VirtualBox")
1712 machines = ""
1713 For Each m In vb.Machines
1714 m = m &amp; " " &amp; m.Name
1715 Next
1716 </screen> See
1717 <computeroutput>bindings/mscom/vb/sample/vboxinfo.vb</computeroutput>
1718 for the complete sample.</para>
1719 </sect2>
1720
1721 <sect2 id="cbinding">
1722 <title>C binding to VirtualBox API</title>
1723
1724 <para>The VirtualBox API originally is designed as object oriented,
1725 using XPCOM or COM as the middleware, which translates natively to C++.
1726 This means that in order to use it from C there needs to be some
1727 helper code to bridge the language differences and reduce the
1728 differences between platforms.</para>
1729
1730 <sect3 id="capi_glue">
1731 <title>Cross-platform C binding to VirtualBox API</title>
1732
1733 <para>Starting with version 4.3, VirtualBox offers a C binding
1734 which allows using the same C client sources for all platforms,
1735 covering Windows, Linux, Mac OS X and Solaris. It is the
1736 preferred way to write API clients, even though the old style
1737 is still available.</para>
1738
1739 </sect3>
1740
1741 <sect3 id="c-gettingstarted">
1742 <title>Getting started</title>
1743
1744 <para>The following sections describe how to use the VirtualBox API
1745 in a C program. The necessary files are included in the SDK, in the
1746 directories <computeroutput>sdk/bindings/c/include</computeroutput>
1747 and <computeroutput>sdk/bindings/c/glue</computeroutput>.</para>
1748
1749 <para>As part of the SDK, a sample program
1750 <computeroutput>tstCAPIGlue.c</computeroutput> is provided in the
1751 directory <computeroutput>sdk/bindings/c/samples</computeroutput>
1752 which demonstrates
1753 using the C binding to initialize the API, get handles for
1754 VirtualBox and Session objects, make calls to list and start virtual
1755 machines, monitor events, and uninitialize resources when done. The
1756 sample program is trying to illustrate all relevant concepts, so it
1757 is a great source of detail information. Among many other generally
1758 useful code sequences it contains a function which shows how to
1759 retrieve error details in C code if they are available from the API
1760 call.</para>
1761
1762 <para>The sample program <computeroutput>tstCAPIGlue</computeroutput>
1763 can be built using the provided <computeroutput>Makefile</computeroutput>
1764 and can be run without arguments.</para>
1765
1766 <para>It uses the VBoxCAPIGlue library (source code is in directory
1767 <computeroutput>sdk/bindings/c/glue</computeroutput>, to be used in
1768 your API client code) to open the C binding layer during runtime,
1769 which is preferred to other means as it isolates the code which
1770 locates the necessary dynamic library, using a known working way
1771 which works on all platforms. If you encounter problems with this
1772 glue code in <computeroutput>VBoxCAPIGlue.c</computeroutput>, let the
1773 VirtualBox developers know, rather than inventing incompatible
1774 solutions.</para>
1775
1776 <para>The following sections document the important concepts needed
1777 to correctly use the C binding, as it is vital for developing API
1778 client code which manages memory correctly, updates the reference
1779 counters correctly, avoiding crashes and memory leaks. Often API
1780 clients need to handle events, so the C API specifics are also
1781 described below.</para>
1782 </sect3>
1783
1784 <sect3 id="c-initialization">
1785 <title>VirtualBox C API initialization</title>
1786
1787 <para>Just like in C++, the API and the underlying middleware needs
1788 to be initialized before it can be used. The
1789 <computeroutput>VBoxCAPI_v4_3.h</computeroutput> header provides the
1790 interface to the C binding, but you can alternatively and more
1791 conveniently also include <computeroutput>VBoxCAPIGlue.h</computeroutput>,
1792 as this avoids the VirtualBox version dependent header file name and
1793 makes sure the global variable <code>g_pVBoxFuncs</code> contains a
1794 pointer to the structure which contains the helper function pointers.
1795 Here's how to initialize the C API:<screen>#include "VBoxCAPIGlue.h"
1796...
1797IVirtualBoxClient *vboxclient = NULL;
1798IVirtualBox *vbox = NULL;
1799ISession *session = NULL;
1800HRESULT rc;
1801ULONG revision;
1802
1803/*
1804 * VBoxCGlueInit() loads the necessary dynamic library, handles errors
1805 * (producing an error message hinting what went wrong) and gives you
1806 * the pointer to the function table (g_pVBoxFuncs).
1807 *
1808 * Once you get the function table, then how and which functions
1809 * to use is explained below.
1810 *
1811 * g_pVBoxFuncs-&gt;pfnClientInitialize does all the necessary startup
1812 * action and provides us with pointers to an IVirtualBoxClient instance.
1813 * It should be matched by a call to g_pVBoxFuncs-&gt;pfnClientUninitialize()
1814 * when done.
1815 */
1816
1817if (VBoxCGlueInit())
1818{
1819 fprintf(stderr, "s: FATAL: VBoxCGlueInit failed: %s\n",
1820 argv[0], g_szVBoxErrMsg);
1821 return EXIT_FAILURE;
1822}
1823
1824g_pVBoxFuncs-&gt;pfnClientInitialize(NULL, &amp;vboxclient);
1825if (!vboxclient)
1826{
1827 fprintf(stderr, "%s: FATAL: could not get VirtualBoxClient reference\n",
1828 argv[0]);
1829 return EXIT_FAILURE;
1830}</screen></para>
1831
1832 <para>If <computeroutput>vboxclient</computeroutput> is still
1833 <computeroutput>NULL</computeroutput> this means the initializationi
1834 failed and the VirtualBox C API cannot be used.</para>
1835
1836 <para>It is possible to write C applications using multiple threads
1837 which all use the VirtualBox API, as long as you're initializing
1838 the C API in each thread which your application creates. This is done
1839 with <code>g_pVBoxFuncs->pfnClientThreadInitialize()</code> and
1840 likewise before the thread is terminated the API must be
1841 uninitialized with
1842 <code>g_pVBoxFuncs->pfnClientThreadUninitialize()</code>. You don't
1843 have to use these functions in worker threads created by COM/XPCOM
1844 (which you might observe if your code uses active event handling),
1845 everything is initialized correctly already. On Windows the C
1846 bindings create a marshaller which supports a wide range of COM
1847 threading models, from STA to MTA, so you don't have to worry about
1848 these details unless you plan to use active event handlers. See
1849 the sample code how to get this to work reliably (in other words
1850 think twice if passive event handling isn't the better solution after
1851 you looked at the sample code).</para>
1852 </sect3>
1853
1854 <sect3 id="c-invocation">
1855 <title>C API attribute and method invocation</title>
1856
1857 <para>Method invocation is straightforward. It looks pretty much
1858 like the C++ way, by using a macro which internally accesses the
1859 vtable, and additionally needs to be passed a pointer to the objecti
1860 as the first argument to serve as the
1861 <computeroutput>this</computeroutput> pointer.</para>
1862
1863 <para>Using the C binding, all method invocations return a numeric
1864 result code of type <code>HRESULT</code> (with a few exceptions
1865 which normally are not relevant).</para>
1866
1867 <para>If an interface is specified as returning an object, a pointer
1868 to a pointer to the appropriate object must be passed as the last
1869 argument. The method will then store an object pointer in that
1870 location.</para>
1871
1872 <para>Likewise, attributes (properties) can be queried or set using
1873 method invocations, using specially named methods. For each
1874 attribute there exists a getter method, the name of which is composed
1875 of <computeroutput>get_</computeroutput> followed by the capitalized
1876 attribute name. Unless the attribute is read-only, an analogous
1877 <computeroutput>set_</computeroutput> method exists. Let's apply
1878 these rules to get the <computeroutput>IVirtualBox</computeroutput>
1879 reference, an <computeroutput>ISession</computeroutput> instance
1880 reference and read the <xref linkend="IVirtualBox__revision"
1881 xreflabel="IVirtualBox::revision" /> attribute:<screen>rc = IVirtualBoxClient_get_VirtualBox(vboxclient, &amp;vbox);
1882if (FAILED(rc) || !vbox)
1883{
1884 PrintErrorInfo(argv[0], "FATAL: could not get VirtualBox reference", rc);
1885 return EXIT_FAILURE;
1886}
1887rc = IVirtualBoxClient_get_Session(vboxclient, &amp;session);
1888if (FAILED(rc) || !session)
1889{
1890 PrintErrorInfo(argv[0], "FATAL: could not get Session reference", rc);
1891 return EXIT_FAILURE;
1892}
1893
1894rc = IVirtualBox_get_Revision(vbox, &amp;revision);
1895if (SUCCEEDED(rc))
1896{
1897 printf("Revision: %u\n", revision);
1898}</screen></para>
1899
1900 <para>The convenience macros for calling a method are named by
1901 prepending the method name with the interface name (using
1902 <code>_</code>as the separator).</para>
1903
1904 <para>So far only attribute getters were illustrated, but generic
1905 method calls are straightforward, too:<screen>IMachine *machine = NULL;
1906BSTR vmname = ...;
1907...
1908/*
1909 * Calling IMachine::findMachine(...)
1910 */
1911rc = IVirtualBox_FindMachine(vbox, vmname, &amp;machine);</screen></para>
1912
1913 <para>As a more complicated example of a method invocation, let's
1914 call <xref linkend="IMachine__launchVMProcess"
1915 xreflabel="IMachine::launchVMProcess" /> which returns an
1916 IProgress object. Note again that the method name is
1917 capitalized:<screen>IProgress *progress;
1918...
1919rc = IMachine_LaunchVMProcess(
1920 machine, /* this */
1921 session, /* arg 1 */
1922 sessionType, /* arg 2 */
1923 env, /* arg 3 */
1924 &amp;progress /* Out */
1925);</screen></para>
1926
1927 <para>All objects with their methods and attributes are documented
1928 in <xref linkend="sdkref_classes" />.</para>
1929 </sect3>
1930
1931 <sect3 id="c-string-handling">
1932 <title>String handling</title>
1933
1934 <para>When dealing with strings you have to be aware of a string's
1935 encoding and ownership.</para>
1936
1937 <para>Internally, the API uses UTF-16 encoded strings. A set of
1938 conversion functions is provided to convert other encodings to and
1939 from UTF-16. The type of a UTF-16 character is
1940 <computeroutput>BSTR</computeroutput> (or its constant counterpart
1941 <computeroutput>CBSTR</computeroutput>), which is an array type,
1942 represented by a pointer to the start of the zero-terminated string.
1943 There are functions for converting between UTF-8 and UTF-16 strings
1944 available through <code>g_pVBoxFuncs</code>:<screen>int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
1945int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);</screen></para>
1946
1947 <para>The ownership of a string determines who is responsible for
1948 releasing resources associated with the string. Whenever the API
1949 creates a string (essentially for output parameters), ownership is
1950 transferred to the caller. To avoid resource leaks, the caller
1951 should release resources once the string is no longer needed.
1952 There are plenty of examples in the sample code.</para>
1953 </sect3>
1954
1955 <sect3 id="c-safearray">
1956 <title>Array handling</title>
1957
1958 <para>Arrays are handled somewhat similarly to strings, with the
1959 additional information of the number of elements in the array. The
1960 exact details of string passing depends on the platform middleware
1961 (COM/XPCOM), and therefore the C binding offers helper functions to
1962 gloss over these differences.</para>
1963
1964 <para>Passing arrays as input parameters to API methods is usually
1965 done by the following sequence, calling a hypothetical
1966 <code>IArrayDemo_PassArray</code> API method:<screen>static const ULONG aElements[] = { 1, 2, 3, 4 };
1967ULONG cElements = sizeof(aElements) / sizeof(aElements[0]);
1968SAFEARRAY *psa = NULL;
1969psa = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, cElements);
1970g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(psa, aElements, sizeof(aElements));
1971IArrayDemo_PassArray(pThis, ComSafeArrayAsInParam(psa));
1972g_pVBoxFuncs->pfnSafeArrayDestroy(psa);</screen></para>
1973
1974 <para>Likewise, getting arrays results from output parameters is done
1975 using helper functions which manage memory allocations as part of
1976 their other functionality:<screen>SAFEARRAY *psa = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc();
1977ULONG *pData;
1978ULONG cElements;
1979IArrayDemo_ReturnArray(pThis, ComSafeArrayAsOutParam(psa));
1980g_pVBoxFuncs->pfnSafeArrayCopyOutParamHelper((void **)&amp;pData, &amp;cElements, VT_I4, psa);
1981g_pVBoxFuncs->pfnSafeArrayDestroy(psa);</screen></para>
1982
1983 <para>This covers the necessary functionality for all array element
1984 types except interface references. These need special helpers to
1985 manage the reference counting correctly. The following code snippet
1986 gets the list of VMs, and passes the first IMachine reference to
1987 another API function (assuming that there is at least one element
1988 in the array, to simplify the example):<screen>SAFEARRAY psa = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc();
1989IMachine **machines = NULL;
1990ULONG machineCnt = 0;
1991ULONG i;
1992IVirtualBox_get_Machines(virtualBox, ComSafeArrayAsOutIfaceParam(machinesSA, IMachine *));
1993g_pVBoxFuncs->pfnSafeArrayCopyOutIfaceParamHelper((IUnknown ***)&amp;machines, &amp;machineCnt, machinesSA);
1994g_pVBoxFuncs->pfnSafeArrayDestroy(machinesSA);
1995/* Now "machines" contains the IMachine references, and machineCnt the
1996 * number of elements in the array. */
1997...
1998SAFEARRAY *psa = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_IUNKNOWN, 0, 1);
1999g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(psa, (void *)&amp;machines[0], sizeof(machines[0]));
2000IVirtualBox_GetMachineStates(ComSafeArrayAsInParam(psa), ...);
2001...
2002g_pVBoxFuncs->pfnSafeArrayDestroy(psa);
2003for (i = 0; i &lt; machineCnt; ++i)
2004{
2005 IMachine *machine = machines[i];
2006 IMachine_Release(machine);
2007}
2008free(machines);</screen></para>
2009
2010 <para>Handling output parameters needs more special effort than
2011 input parameters, thus only for the former there are special helpers,
2012 and the latter is handled through the generic array support.</para>
2013 </sect3>
2014
2015 <sect3 id="c-eventhandling">
2016 <title>Event handling</title>
2017
2018 <para>The VirtualBox API offers two types of event handling, active
2019 and passive, and consequently there is support for both with the
2020 C API binding. Active event handling (based on asynchronous
2021 callback invocation for event delivery) is more difficult, as it
2022 requires the construction of valid C++ objects in C, which is
2023 inherently platform and compiler dependent. Passive event handling
2024 is much simpler, it relies on an event loop, fetching events and
2025 triggering the necessary handlers explicitly in the API client code.
2026 Both approaches depend on an event loop to make sure that events
2027 get delivered in a timely manner, with differences what exactly needs
2028 to be done.</para>
2029
2030 <para>The C API sample contains code for both event handling styles,
2031 and one has to modify the appropriate <code>#define</code> to select
2032 which style is actually used by the compiled program. It allows a
2033 good comparison between the two variants, and the code sequences are
2034 probably worth reusing without much change in other API clients
2035 with only minor adaptions.</para>
2036
2037 <para>Active event handling needs to ensure that the following helper
2038 function is called frequently enough in the primary thread:
2039 <screen>g_pVBoxFuncs->pfnProcessEventQueue(cTimeoutMS);</screen></para>
2040
2041 <para>The actual event handler implementation is quite tedious, as
2042 it has to implement a complete API interface. Especially on Windows
2043 it is a lot of work to implement the complicated <code>IDispatch</code>
2044 interface, requiring to load COM type information and using it
2045 in the <code>IDispatch</code> method implementation. Overall this is
2046 quite tedious compared to passive event handling.</para>
2047
2048 <para>Passive event handling uses a similar event loop structure,
2049 which requires calling the following function in a loop, and
2050 processing the returned event appropriately:
2051 <screen>rc = IEventSource_GetEvent(pEventSource, pListener, cTimeoutMS, &amp;pEvent);</screen></para>
2052
2053 <para>After processing the event it needs to be marked as processed
2054 with the following method call:
2055 <screen>rc = IEventSource_EventProcessed(pEventSource, pListener, pEvent);</screen></para>
2056
2057 <para>This is vital for vetoable events, as they would be stuck
2058 otherwise, waiting whether the veto comes or not. It does not do any
2059 harm for other event types, and in the end is cheaper than checking
2060 if the event at hand is vetoable or not.</para>
2061
2062 <para>The general event handling concepts are described in the API
2063 specification (see <xref linkend="events" />), including how to
2064 aggregate multiple event sources for processing in one event loop.
2065 As mentioned, the sample illustrates the practical aspects of how to
2066 use both types of event handling, active and passive, from a C
2067 application. Additional hints are in the comments documenting
2068 the helper methods in <computeroutput>VBoxCAPI_v4_3.h</computeroutput>.
2069 The code complexity of active event handling (and its inherenly
2070 platform/compiler specific aspects) should be motivation to use
2071 passive event handling whereever possible.</para>
2072 </sect3>
2073
2074 <sect3 id="c-uninitialization">
2075 <title>C API uninitialization</title>
2076
2077 <para>Uninitialization is performed by
2078 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize().</computeroutput>
2079 If your program can exit from more than one place, it is a good idea
2080 to install this function as an exit handler with Standard C's
2081 <computeroutput>atexit()</computeroutput> just after calling
2082 <computeroutput>g_pVBoxFuncs-&gt;pfnClientInitialize()</computeroutput>
2083 , e.g. <screen>#include &lt;stdlib.h&gt;
2084#include &lt;stdio.h&gt;
2085
2086...
2087
2088/*
2089 * Make sure g_pVBoxFuncs-&gt;pfnClientUninitialize() is called at exit, no
2090 * matter if we return from the initial call to main or call exit()
2091 * somewhere else. Note that atexit registered functions are not
2092 * called upon abnormal termination, i.e. when calling abort() or
2093 * signal().
2094 */
2095
2096if (atexit(g_pVBoxFuncs-&gt;pfnClientUninitialize()) != 0) {
2097 fprintf(stderr, "failed to register g_pVBoxFuncs-&gt;pfnClientUninitialize()\n");
2098 exit(EXIT_FAILURE);
2099}</screen></para>
2100
2101 <para>Another idea would be to write your own <computeroutput>void
2102 myexit(int status)</computeroutput> function, calling
2103 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2104 followed by the real <computeroutput>exit()</computeroutput>, and
2105 use it instead of <computeroutput>exit()</computeroutput> throughout
2106 your program and at the end of
2107 <computeroutput>main.</computeroutput></para>
2108
2109 <para>If you expect the program to be terminated by a signal (e.g.
2110 user types CTRL-C sending SIGINT) you might want to install a signal
2111 handler setting a flag noting that a signal was sent and then
2112 calling
2113 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2114 later on, <emphasis>not</emphasis> from the handler itself.</para>
2115
2116 <para>That said, if a client program forgets to call
2117 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2118 before it terminates, there is a mechanism in place which will
2119 eventually release references held by the client. On Windows it can
2120 take quite a while, in the order of 6-7 minutes.</para>
2121 </sect3>
2122
2123 <sect3 id="c-linking">
2124 <title>Compiling and linking</title>
2125
2126 <para>A program using the C binding has to open the library during
2127 runtime using the help of glue code provided and as shown in the
2128 example <computeroutput>tstCAPIGlue.c</computeroutput>.
2129 Compilation and linking can be achieved with a makefile fragment
2130 similar to:<screen># Where is the SDK directory?
2131PATH_SDK = ../../..
2132CAPI_INC = -I$(PATH_SDK)/bindings/c/include
2133ifeq ($(BUILD_PLATFORM),win)
2134PLATFORM_INC = -I$(PATH_SDK)/bindings/mscom/include
2135PLATFORM_LIB = $(PATH_SDK)/bindings/mscom/lib
2136else
2137PLATFORM_INC = -I$(PATH_SDK)/bindings/xpcom/include
2138PLATFORM_LIB = $(PATH_SDK)/bindings/xpcom/lib
2139endif
2140GLUE_DIR = $(PATH_SDK)/bindings/c/glue
2141GLUE_INC = -I$(GLUE_DIR)
2142
2143# Compile Glue Library
2144VBoxCAPIGlue.o: $(GLUE_DIR)/VBoxCAPIGlue.c
2145 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2146
2147# Compile interface ID list
2148VirtualBox_i.o: $(PLATFORM_LIB)/VirtualBox_i.c
2149 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2150
2151# Compile program code
2152program.o: program.c
2153 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2154
2155# Link program.
2156program: program.o VBoxCAPICGlue.o VirtualBox_i.o
2157 $(CC) -o $@ $^ -ldl -lpthread</screen></para>
2158 </sect3>
2159
2160 <sect3 id="capi_conversion">
2161 <title>Conversion of code using legacy C binding</title>
2162
2163 <para>This section aims to make the task of converting code using
2164 the legacy C binding to the new style a breeze, by pointing out some
2165 key steps.</para>
2166
2167 <para>One necessary change is adjusting your Makefile to reflect the
2168 different include paths. See above. There are now 3 relevant include
2169 directories, and most of it is pointing to the C binding directory.
2170 The XPCOM include directory is still relevant for platforms where
2171 the XPCOM middleware is used, but most of the include files live
2172 elsewhere now, so it's good to have it last. Additionally the
2173 <computeroutput>VirtualBox_i.c</computeroutput> file needs to be
2174 compiled and linked to the program, it contains the IIDs relevant
2175 for the VirtualBox API, making sure they are not replicated endlessly
2176 if the code refers to them frequently.</para>
2177
2178 <para>The C API client code should include <computeroutput>VBoxCAPIGlue.h</computeroutput>
2179 instead of <computeroutput>VBoxXPCOMCGlue.h</computeroutput> or
2180 <computeroutput>VBoxCAPI_v4_3.h</computeroutput>, as this makes sure
2181 the correct macros and internal translations are selected.</para>
2182
2183 <para>All API method calls (anything mentioning <code>vtbl</code>)
2184 should be rewritten using the convenience macros for calling methods,
2185 as these hide the internal details, are generally easier to use and
2186 shorter to type. You should remove as many as possible
2187 <code>(nsISupports **)</code> or similar typecasts, as the new style
2188 should use the correct type in most places, increasing the type
2189 safety in case of an error in the source code.</para>
2190
2191 <para>To gloss over the platform differences, API client code should
2192 no longer rely on XPCOM specific interface names such as
2193 <code>nsISupports</code>, <code>nsIException</code> and
2194 <code>nsIEventQueue</code>, and replace them by the platform
2195 independent interface names <code>IUnknown</code> and
2196 <code>IErrorInfo</code> for the first two respectively. Event queue
2197 handling should be replaced by using the platform independent way
2198 described in <xref linkend="c-eventhandling" />.</para>
2199
2200 <para>Finally adjust the string and array handling to use the new
2201 helpers, as these make sure the code works without changes with
2202 both COM and XPCOM, which are significantly different in this area.
2203 The code should be double checked if it uses the correct way to
2204 manage memory, and is freeing it only after the last use.</para>
2205 </sect3>
2206
2207 <sect3 id="xpcom_cbinding">
2208 <title>Legacy C binding to VirtualBox API for XPCOM</title>
2209
2210 <note>
2211 <para>This section applies to Linux, Mac OS X and Solaris
2212 hosts only and describes deprecated use of the API from C.</para>
2213 </note>
2214
2215 <para>Starting with version 2.2, VirtualBox offers a C binding for
2216 its API which works only on platforms using XPCOM. Refer to the
2217 old SDK documentation (included in the SDK packages for version 4.3.6
2218 or earlier), it still applies unchanged. The fundamental concepts are
2219 similar (but the syntactical details are quite different) to the
2220 newer cross-platform C binding which should be used for all new code,
2221 as the support for the old C binding will go away in a major release
2222 after version 4.3.</para>
2223 </sect3>
2224 </sect2>
2225 </sect1>
2226 </chapter>
2227
2228 <chapter id="concepts">
2229 <title>Basic VirtualBox concepts; some examples</title>
2230
2231 <para>The following explains some basic VirtualBox concepts such as the
2232 VirtualBox object, sessions and how virtual machines are manipulated and
2233 launched using the Main API. The coding examples use a pseudo-code style
2234 closely related to the object-oriented web service (OOWS) for JAX-WS.
2235 Depending on which environment you are using, you will need to adjust the
2236 examples.</para>
2237
2238 <sect1>
2239 <title>Obtaining basic machine information. Reading attributes</title>
2240
2241 <para>Any program using the Main API will first need access to the
2242 global VirtualBox object (see <xref linkend="IVirtualBox"
2243 xreflabel="IVirtualBox" />), from which all other functionality of the
2244 API is derived. With the OOWS for JAX-WS, this is returned from the
2245 <xref linkend="IWebsessionManager__logon"
2246 xreflabel="IWebsessionManager::logon()" /> call.</para>
2247
2248 <para>To enumerate virtual machines, one would look at the "machines"
2249 array attribute in the VirtualBox object (see <xref
2250 linkend="IVirtualBox__machines" xreflabel="IVirtualBox::machines" />).
2251 This array contains all virtual machines currently registered with the
2252 host, each of them being an instance of <xref linkend="IMachine"
2253 xreflabel="IMachine" />. From each such instance, one can query
2254 additional information, such as the UUID, the name, memory, operating
2255 system and more by looking at the attributes; see the attributes list in
2256 <xref linkend="IMachine" xreflabel="IMachine documentation" />.</para>
2257
2258 <para>As mentioned in the preceding chapters, depending on your
2259 programming environment, attributes are mapped to corresponding "get"
2260 and (if the attribute is not read-only) "set" methods. So when the
2261 documentation says that IMachine has a "<xref linkend="IMachine__name"
2262 xreflabel="name" />" attribute, this means you need to code something
2263 like the following to get the machine's name:<screen>IMachine machine = ...;
2264String name = machine.getName();</screen>Boolean attribute getters can
2265 sometimes be called <computeroutput>isAttribute()</computeroutput> due
2266 to JAX-WS naming conventions.</para>
2267 </sect1>
2268
2269 <sect1>
2270 <title>Changing machine settings: Sessions</title>
2271
2272 <para>As said in the previous section, to read a machine's attribute,
2273 one invokes the corresponding "get" method. One would think that to
2274 change settings of a machine, it would suffice to call the corresponding
2275 "set" method -- for example, to set a VM's memory to 1024 MB, one would
2276 call <computeroutput>setMemorySize(1024)</computeroutput>. Try that, and
2277 you will get an error: "The machine is not mutable."</para>
2278
2279 <para>So unfortunately, things are not that easy. VirtualBox is a
2280 complicated environment in which multiple processes compete for possibly
2281 the same resources, especially machine settings. As a result, machines
2282 must be "locked" before they can either be modified or started. This is
2283 to prevent multiple processes from making conflicting changes to a
2284 machine: it should, for example, not be allowed to change the memory
2285 size of a virtual machine while it is running. (You can't add more
2286 memory to a real computer while it is running either, at least not to an
2287 ordinary PC.) Also, two processes must not change settings at the same
2288 time, or start a machine at the same time.</para>
2289
2290 <para>These requirements are implemented in the Main API by way of
2291 "sessions", in particular, the <xref linkend="ISession"
2292 xreflabel="ISession" /> interface. Each process which talks to
2293 VirtualBox needs its own instance of ISession. In the web service, you
2294 cannot create such an object, but
2295 <computeroutput>vboxwebsrv</computeroutput> creates one for you when you
2296 log on, which you can obtain by calling <xref
2297 linkend="IWebsessionManager__getSessionObject"
2298 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
2299
2300 <para>This session object must then be used like a mutex semaphore in
2301 common programming environments. Before you can change machine settings,
2302 you must write-lock the machine by calling <xref
2303 linkend="IMachine__lockMachine" xreflabel="IMachine::lockMachine()" />
2304 with your process's session object.</para>
2305
2306 <para>After the machine has been locked, the <xref
2307 linkend="ISession__machine" xreflabel="ISession::machine" /> attribute
2308 contains a copy of the original IMachine object upon which the session
2309 was opened, but this copy is "mutable": you can invoke "set" methods on
2310 it.</para>
2311
2312 <para>When done making the changes to the machine, you must call <xref
2313 linkend="IMachine__saveSettings"
2314 xreflabel="IMachine::saveSettings()" />, which will copy the changes you
2315 have made from your "mutable" machine back to the real machine and write
2316 them out to the machine settings XML file. This will make your changes
2317 permanent.</para>
2318
2319 <para>Finally, it is important to always unlock the machine again, by
2320 calling <xref linkend="ISession__unlockMachine"
2321 xreflabel="ISession::unlockMachine()" />. Otherwise, when the calling
2322 process end, the machine will receive the "aborted" state, which can
2323 lead to loss of data.</para>
2324
2325 <para>So, as an example, the sequence to change a machine's memory to
2326 1024 MB is something like this:<screen>IWebsessionManager mgr ...;
2327IVirtualBox vbox = mgr.logon(user, pass);
2328...
2329IMachine machine = ...; // read-only machine
2330ISession session = mgr.getSessionObject();
2331machine.lockMachine(session, LockType.Write); // machine is now locked for writing
2332IMachine mutable = session.getMachine(); // obtain the mutable machine copy
2333mutable.setMemorySize(1024);
2334mutable.saveSettings(); // write settings to XML
2335session.unlockMachine();</screen></para>
2336 </sect1>
2337
2338 <sect1>
2339 <title>Launching virtual machines</title>
2340
2341 <para>To launch a virtual machine, you call <xref
2342 linkend="IMachine__launchVMProcess"
2343 xreflabel="IMachine::launchVMProcess()" />. In doing so, the caller
2344 instructs the VirtualBox engine to start a new process with the virtual
2345 machine in it, since to the host, each virtual machine looks like a
2346 single process, even if it has hundreds of its own processes inside.
2347 (This new VM process in turn obtains a write lock on the machine, as
2348 described above, to prevent conflicting changes from other processes;
2349 this is why opening another session will fail while the VM is
2350 running.)</para>
2351
2352 <para>Starting a machine looks something like this:<screen>IWebsessionManager mgr ...;
2353IVirtualBox vbox = mgr.logon(user, pass);
2354...
2355IMachine machine = ...; // read-only machine
2356ISession session = mgr.getSessionObject();
2357IProgress prog = machine.launchVMProcess(session,
2358 "gui", // session type
2359 ""); // possibly environment setting
2360prog.waitForCompletion(10000); // give the process 10 secs
2361if (prog.getResultCode() != 0) // check success
2362 System.out.println("Cannot launch VM!")</screen></para>
2363
2364 <para>The caller's session object can then be used as a sort of remote
2365 control to the VM process that was launched. It contains a "console"
2366 object (see <xref linkend="ISession__console"
2367 xreflabel="ISession::console" />) with which the VM can be paused,
2368 stopped, snapshotted or other things.</para>
2369 </sect1>
2370
2371 <sect1 id="events">
2372 <title>VirtualBox events</title>
2373
2374 <para>In VirtualBox, "events" provide a uniform mechanism to register
2375 for and consume specific events. A VirtualBox client can register an
2376 "event listener" (represented by the <xref linkend="IEventListener"
2377 xreflabel="IEventListener" /> interface), which will then get notified
2378 by the server when an event (represented by the <xref linkend="IEvent"
2379 xreflabel="IEvent" /> interface) happens.</para>
2380
2381 <para>The IEvent interface is an abstract parent interface for all
2382 events that can occur in VirtualBox. The actual events that the server
2383 sends out are then of one of the specific subclasses, for example <xref
2384 linkend="IMachineStateChangedEvent"
2385 xreflabel="IMachineStateChangedEvent" /> or <xref
2386 linkend="IMediumChangedEvent" xreflabel="IMediumChangedEvent" />.</para>
2387
2388 <para>As an example, the VirtualBox GUI waits for machine events and can
2389 thus update its display when the machine state changes or machine
2390 settings are modified, even if this happens in another client. This is
2391 how the GUI can automatically refresh its display even if you manipulate
2392 a machine from another client, for example, from VBoxManage.</para>
2393
2394 <para>To register an event listener to listen to events, use code like
2395 this:<screen>EventSource es = console.getEventSource();
2396IEventListener listener = es.createListener();
2397VBoxEventType aTypes[] = (VBoxEventType.OnMachineStateChanged);
2398 // list of event types to listen for
2399es.registerListener(listener, aTypes, false /* active */);
2400 // register passive listener
2401IEvent ev = es.getEvent(listener, 1000);
2402 // wait up to one second for event to happen
2403if (ev != null)
2404{
2405 // downcast to specific event interface (in this case we have only registered
2406 // for one type, otherwise IEvent::type would tell us)
2407 IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev);
2408 ... // inspect and do something
2409 es.eventProcessed(listener, ev);
2410}
2411...
2412es.unregisterListener(listener); </screen></para>
2413
2414 <para>A graphical user interface would probably best start its own
2415 thread to wait for events and then process these in a loop.</para>
2416
2417 <para>The events mechanism was introduced with VirtualBox 3.3 and
2418 replaces various callback interfaces which were called for each event in
2419 the interface. The callback mechanism was not compatible with scripting
2420 languages, local Java bindings and remote web services as they do not
2421 support callbacks. The new mechanism with events and event listeners
2422 works with all of these.</para>
2423
2424 <para>To simplify developement of application using events, concept of
2425 event aggregator was introduced. Essentially it's mechanism to aggregate
2426 multiple event sources into single one, and then work with this single
2427 aggregated event source instead of original sources. As an example, one
2428 can evaluate demo recorder in VirtualBox Python shell, shipped with SDK
2429 - it records mouse and keyboard events, represented as separate event
2430 sources. Code is essentially like this:<screen>
2431 listener = console.eventSource.createListener()
2432 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource])
2433 agg.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
2434 registered = True
2435 end = time.time() + dur
2436 while time.time() &lt; end:
2437 ev = agg.getEvent(listener, 1000)
2438 processEent(ev)
2439 agg.unregisterListener(listener)</screen> Without using aggregators
2440 consumer have to poll on both sources, or start multiple threads to
2441 block on those sources.</para>
2442 </sect1>
2443 </chapter>
2444
2445 <chapter id="vboxshell">
2446 <title>The VirtualBox shell</title>
2447
2448 <para>VirtualBox comes with an extensible shell, which allows you to
2449 control your virtual machines from the command line. It is also a
2450 nontrivial example of how to use the VirtualBox APIs from Python, for all
2451 three COM/XPCOM/WS styles of the API.</para>
2452
2453 <para>You can easily extend this shell with your own commands. Create a
2454 subdirectory named <computeroutput>.config/VirtualBox/shexts</computeroutput>
2455 below your home directory (respectively <computeroutput>.VirtualBox/shexts</computeroutput> on a Windows system and <computeroutput>Library/VirtualBox/shexts</computeroutput> on OS X) and put a Python file implementing your shell
2456 extension commands in this directory. This file must contain an array
2457 named <computeroutput>commands</computeroutput> containing your command
2458 definitions: <screen>
2459 commands = {
2460 'cmd1': ['Command cmd1 help', cmd1],
2461 'cmd2': ['Command cmd2 help', cmd2]
2462 }
2463 </screen> For example, to create a command for creating hard drive
2464 images, the following code can be used: <screen>
2465 def createHdd(ctx,args):
2466 # Show some meaningful error message on wrong input
2467 if (len(args) &lt; 3):
2468 print "usage: createHdd sizeM location type"
2469 return 0
2470
2471 # Get arguments
2472 size = int(args[1])
2473 loc = args[2]
2474 if len(args) &gt; 3:
2475 format = args[3]
2476 else:
2477 # And provide some meaningful defaults
2478 format = "vdi"
2479
2480 # Call VirtualBox API, using context's fields
2481 hdd = ctx['vb'].createHardDisk(format, loc)
2482 # Access constants using ctx['global'].constants
2483 progress = hdd.createBaseStorage(size, (ctx['global'].constants.MediumVariant_Standard, ))
2484 # use standard progress bar mechanism
2485 ctx['progressBar'](progress)
2486
2487
2488 # Report errors
2489 if not hdd.id:
2490 print "cannot create disk (file %s exist?)" %(loc)
2491 return 0
2492
2493 # Give user some feedback on success too
2494 print "created HDD with id: %s" %(hdd.id)
2495
2496 # 0 means continue execution, other values mean exit from the interpreter
2497 return 0
2498
2499 commands = {
2500 'myCreateHDD': ['Create virtual HDD, createHdd size location type', createHdd]
2501 }
2502 </screen> Just store the above text in the file
2503 <computeroutput>createHdd</computeroutput> (or any other meaningful name)
2504 in <computeroutput>.config/VirtualBox/shexts/</computeroutput>. Start the
2505 VirtualBox shell, or just issue the
2506 <computeroutput>reloadExts</computeroutput> command, if the shell is
2507 already running. Your new command will now be available.</para>
2508 </chapter>
2509
2510 <!--$VIRTUALBOX_MAIN_API_REFERENCE-->
2511
2512 <chapter id="hgcm">
2513 <title>Host-Guest Communication Manager</title>
2514
2515 <para>The VirtualBox Host-Guest Communication Manager (HGCM) allows a
2516 guest application or a guest driver to call a host shared library. The
2517 following features of VirtualBox are implemented using HGCM: <itemizedlist>
2518 <listitem>
2519 <para>Shared Folders</para>
2520 </listitem>
2521
2522 <listitem>
2523 <para>Shared Clipboard</para>
2524 </listitem>
2525
2526 <listitem>
2527 <para>Guest configuration interface</para>
2528 </listitem>
2529 </itemizedlist></para>
2530
2531 <para>The shared library contains a so called HGCM service. The guest HGCM
2532 clients establish connections to the service to call it. When calling a
2533 HGCM service the client supplies a function code and a number of
2534 parameters for the function.</para>
2535
2536 <sect1>
2537 <title>Virtual hardware implementation</title>
2538
2539 <para>HGCM uses the VMM virtual PCI device to exchange data between the
2540 guest and the host. The guest always acts as an initiator of requests. A
2541 request is constructed in the guest physical memory, which must be
2542 locked by the guest. The physical address is passed to the VMM device
2543 using a 32 bit <computeroutput>out edx, eax</computeroutput>
2544 instruction. The physical memory must be allocated below 4GB by 64 bit
2545 guests.</para>
2546
2547 <para>The host parses the request header and data and queues the request
2548 for a host HGCM service. The guest continues execution and usually waits
2549 on a HGCM event semaphore.</para>
2550
2551 <para>When the request has been processed by the HGCM service, the VMM
2552 device sets the completion flag in the request header, sets the HGCM
2553 event and raises an IRQ for the guest. The IRQ handler signals the HGCM
2554 event semaphore and all HGCM callers check the completion flag in the
2555 corresponding request header. If the flag is set, the request is
2556 considered completed.</para>
2557 </sect1>
2558
2559 <sect1>
2560 <title>Protocol specification</title>
2561
2562 <para>The HGCM protocol definitions are contained in the
2563 <computeroutput>VBox/VBoxGuest.h</computeroutput></para>
2564
2565 <sect2>
2566 <title>Request header</title>
2567
2568 <para>HGCM request structures contains a generic header
2569 (VMMDevHGCMRequestHeader): <table>
2570 <title>HGCM Request Generic Header</title>
2571
2572 <tgroup cols="2">
2573 <tbody>
2574 <row>
2575 <entry><emphasis role="bold">Name</emphasis></entry>
2576
2577 <entry><emphasis role="bold">Description</emphasis></entry>
2578 </row>
2579
2580 <row>
2581 <entry>size</entry>
2582
2583 <entry>Size of the entire request.</entry>
2584 </row>
2585
2586 <row>
2587 <entry>version</entry>
2588
2589 <entry>Version of the header, must be set to
2590 <computeroutput>0x10001</computeroutput>.</entry>
2591 </row>
2592
2593 <row>
2594 <entry>type</entry>
2595
2596 <entry>Type of the request.</entry>
2597 </row>
2598
2599 <row>
2600 <entry>rc</entry>
2601
2602 <entry>HGCM return code, which will be set by the VMM
2603 device.</entry>
2604 </row>
2605
2606 <row>
2607 <entry>reserved1</entry>
2608
2609 <entry>A reserved field 1.</entry>
2610 </row>
2611
2612 <row>
2613 <entry>reserved2</entry>
2614
2615 <entry>A reserved field 2.</entry>
2616 </row>
2617
2618 <row>
2619 <entry>flags</entry>
2620
2621 <entry>HGCM flags, set by the VMM device.</entry>
2622 </row>
2623
2624 <row>
2625 <entry>result</entry>
2626
2627 <entry>The HGCM result code, set by the VMM device.</entry>
2628 </row>
2629 </tbody>
2630 </tgroup>
2631 </table> <note>
2632 <itemizedlist>
2633 <listitem>
2634 <para>All fields are 32 bit.</para>
2635 </listitem>
2636
2637 <listitem>
2638 <para>Fields from <computeroutput>size</computeroutput> to
2639 <computeroutput>reserved2</computeroutput> are a standard VMM
2640 device request header, which is used for other interfaces as
2641 well.</para>
2642 </listitem>
2643 </itemizedlist>
2644 </note></para>
2645
2646 <para>The <emphasis role="bold">type</emphasis> field indicates the
2647 type of the HGCM request: <table>
2648 <title>Request Types</title>
2649
2650 <tgroup cols="2">
2651 <tbody>
2652 <row>
2653 <entry><emphasis role="bold">Name (decimal
2654 value)</emphasis></entry>
2655
2656 <entry><emphasis role="bold">Description</emphasis></entry>
2657 </row>
2658
2659 <row>
2660 <entry>VMMDevReq_HGCMConnect
2661 (<computeroutput>60</computeroutput>)</entry>
2662
2663 <entry>Connect to a HGCM service.</entry>
2664 </row>
2665
2666 <row>
2667 <entry>VMMDevReq_HGCMDisconnect
2668 (<computeroutput>61</computeroutput>)</entry>
2669
2670 <entry>Disconnect from the service.</entry>
2671 </row>
2672
2673 <row>
2674 <entry>VMMDevReq_HGCMCall32
2675 (<computeroutput>62</computeroutput>)</entry>
2676
2677 <entry>Call a HGCM function using the 32 bit
2678 interface.</entry>
2679 </row>
2680
2681 <row>
2682 <entry>VMMDevReq_HGCMCall64
2683 (<computeroutput>63</computeroutput>)</entry>
2684
2685 <entry>Call a HGCM function using the 64 bit
2686 interface.</entry>
2687 </row>
2688
2689 <row>
2690 <entry>VMMDevReq_HGCMCancel
2691 (<computeroutput>64</computeroutput>)</entry>
2692
2693 <entry>Cancel a HGCM request currently being processed by a
2694 host HGCM service.</entry>
2695 </row>
2696 </tbody>
2697 </tgroup>
2698 </table></para>
2699
2700 <para>The <emphasis role="bold">flags</emphasis> field may contain:
2701 <table>
2702 <title>Flags</title>
2703
2704 <tgroup cols="2">
2705 <tbody>
2706 <row>
2707 <entry><emphasis role="bold">Name (hexadecimal
2708 value)</emphasis></entry>
2709
2710 <entry><emphasis role="bold">Description</emphasis></entry>
2711 </row>
2712
2713 <row>
2714 <entry>VBOX_HGCM_REQ_DONE
2715 (<computeroutput>0x00000001</computeroutput>)</entry>
2716
2717 <entry>The request has been processed by the host
2718 service.</entry>
2719 </row>
2720
2721 <row>
2722 <entry>VBOX_HGCM_REQ_CANCELLED
2723 (<computeroutput>0x00000002</computeroutput>)</entry>
2724
2725 <entry>This request was cancelled.</entry>
2726 </row>
2727 </tbody>
2728 </tgroup>
2729 </table></para>
2730 </sect2>
2731
2732 <sect2>
2733 <title>Connect</title>
2734
2735 <para>The connection request must be issued by the guest HGCM client
2736 before it can call the HGCM service (VMMDevHGCMConnect): <table>
2737 <title>Connect request</title>
2738
2739 <tgroup cols="2">
2740 <tbody>
2741 <row>
2742 <entry><emphasis role="bold">Name</emphasis></entry>
2743
2744 <entry><emphasis role="bold">Description</emphasis></entry>
2745 </row>
2746
2747 <row>
2748 <entry>header</entry>
2749
2750 <entry>The generic HGCM request header with type equal to
2751 VMMDevReq_HGCMConnect
2752 (<computeroutput>60</computeroutput>).</entry>
2753 </row>
2754
2755 <row>
2756 <entry>type</entry>
2757
2758 <entry>The type of the service location information (32
2759 bit).</entry>
2760 </row>
2761
2762 <row>
2763 <entry>location</entry>
2764
2765 <entry>The service location information (128 bytes).</entry>
2766 </row>
2767
2768 <row>
2769 <entry>clientId</entry>
2770
2771 <entry>The client identifier assigned to the connecting
2772 client by the HGCM subsystem (32 bit).</entry>
2773 </row>
2774 </tbody>
2775 </tgroup>
2776 </table> The <emphasis role="bold">type</emphasis> field tells the
2777 HGCM how to look for the requested service: <table>
2778 <title>Location Information Types</title>
2779
2780 <tgroup cols="2">
2781 <tbody>
2782 <row>
2783 <entry><emphasis role="bold">Name (hexadecimal
2784 value)</emphasis></entry>
2785
2786 <entry><emphasis role="bold">Description</emphasis></entry>
2787 </row>
2788
2789 <row>
2790 <entry>VMMDevHGCMLoc_LocalHost
2791 (<computeroutput>0x1</computeroutput>)</entry>
2792
2793 <entry>The requested service is a shared library located on
2794 the host and the location information contains the library
2795 name.</entry>
2796 </row>
2797
2798 <row>
2799 <entry>VMMDevHGCMLoc_LocalHost_Existing
2800 (<computeroutput>0x2</computeroutput>)</entry>
2801
2802 <entry>The requested service is a preloaded one and the
2803 location information contains the service name.</entry>
2804 </row>
2805 </tbody>
2806 </tgroup>
2807 </table> <note>
2808 <para>Currently preloaded HGCM services are hard-coded in
2809 VirtualBox: <itemizedlist>
2810 <listitem>
2811 <para>VBoxSharedFolders</para>
2812 </listitem>
2813
2814 <listitem>
2815 <para>VBoxSharedClipboard</para>
2816 </listitem>
2817
2818 <listitem>
2819 <para>VBoxGuestPropSvc</para>
2820 </listitem>
2821
2822 <listitem>
2823 <para>VBoxSharedOpenGL</para>
2824 </listitem>
2825 </itemizedlist></para>
2826 </note> There is no difference between both types of HGCM services,
2827 only the location mechanism is different.</para>
2828
2829 <para>The client identifier is returned by the host and must be used
2830 in all subsequent requests by the client.</para>
2831 </sect2>
2832
2833 <sect2>
2834 <title>Disconnect</title>
2835
2836 <para>This request disconnects the client and makes the client
2837 identifier invalid (VMMDevHGCMDisconnect): <table>
2838 <title>Disconnect request</title>
2839
2840 <tgroup cols="2">
2841 <tbody>
2842 <row>
2843 <entry><emphasis role="bold">Name</emphasis></entry>
2844
2845 <entry><emphasis role="bold">Description</emphasis></entry>
2846 </row>
2847
2848 <row>
2849 <entry>header</entry>
2850
2851 <entry>The generic HGCM request header with type equal to
2852 VMMDevReq_HGCMDisconnect
2853 (<computeroutput>61</computeroutput>).</entry>
2854 </row>
2855
2856 <row>
2857 <entry>clientId</entry>
2858
2859 <entry>The client identifier previously returned by the
2860 connect request (32 bit).</entry>
2861 </row>
2862 </tbody>
2863 </tgroup>
2864 </table></para>
2865 </sect2>
2866
2867 <sect2>
2868 <title>Call32 and Call64</title>
2869
2870 <para>Calls the HGCM service entry point (VMMDevHGCMCall) using 32 bit
2871 or 64 bit addresses: <table>
2872 <title>Call request</title>
2873
2874 <tgroup cols="2">
2875 <tbody>
2876 <row>
2877 <entry><emphasis role="bold">Name</emphasis></entry>
2878
2879 <entry><emphasis role="bold">Description</emphasis></entry>
2880 </row>
2881
2882 <row>
2883 <entry>header</entry>
2884
2885 <entry>The generic HGCM request header with type equal to
2886 either VMMDevReq_HGCMCall32
2887 (<computeroutput>62</computeroutput>) or
2888 VMMDevReq_HGCMCall64
2889 (<computeroutput>63</computeroutput>).</entry>
2890 </row>
2891
2892 <row>
2893 <entry>clientId</entry>
2894
2895 <entry>The client identifier previously returned by the
2896 connect request (32 bit).</entry>
2897 </row>
2898
2899 <row>
2900 <entry>function</entry>
2901
2902 <entry>The function code to be processed by the service (32
2903 bit).</entry>
2904 </row>
2905
2906 <row>
2907 <entry>cParms</entry>
2908
2909 <entry>The number of following parameters (32 bit). This
2910 value is 0 if the function requires no parameters.</entry>
2911 </row>
2912
2913 <row>
2914 <entry>parms</entry>
2915
2916 <entry>An array of parameter description structures
2917 (HGCMFunctionParameter32 or
2918 HGCMFunctionParameter64).</entry>
2919 </row>
2920 </tbody>
2921 </tgroup>
2922 </table></para>
2923
2924 <para>The 32 bit parameter description (HGCMFunctionParameter32)
2925 consists of 32 bit type field and 8 bytes of an opaque value, so 12
2926 bytes in total. The 64 bit variant (HGCMFunctionParameter64) consists
2927 of the type and 12 bytes of a value, so 16 bytes in total.</para>
2928
2929 <para><table>
2930 <title>Parameter types</title>
2931
2932 <tgroup cols="2">
2933 <tbody>
2934 <row>
2935 <entry><emphasis role="bold">Type</emphasis></entry>
2936
2937 <entry><emphasis role="bold">Format of the
2938 value</emphasis></entry>
2939 </row>
2940
2941 <row>
2942 <entry>VMMDevHGCMParmType_32bit (1)</entry>
2943
2944 <entry>A 32 bit value.</entry>
2945 </row>
2946
2947 <row>
2948 <entry>VMMDevHGCMParmType_64bit (2)</entry>
2949
2950 <entry>A 64 bit value.</entry>
2951 </row>
2952
2953 <row>
2954 <entry>VMMDevHGCMParmType_PhysAddr (3)</entry>
2955
2956 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2957 physical address.</entry>
2958 </row>
2959
2960 <row>
2961 <entry>VMMDevHGCMParmType_LinAddr (4)</entry>
2962
2963 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2964 linear address. The buffer is used both for guest to host
2965 and for host to guest data.</entry>
2966 </row>
2967
2968 <row>
2969 <entry>VMMDevHGCMParmType_LinAddr_In (5)</entry>
2970
2971 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2972 used only for host to guest data.</entry>
2973 </row>
2974
2975 <row>
2976 <entry>VMMDevHGCMParmType_LinAddr_Out (6)</entry>
2977
2978 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2979 used only for guest to host data.</entry>
2980 </row>
2981
2982 <row>
2983 <entry>VMMDevHGCMParmType_LinAddr_Locked (7)</entry>
2984
2985 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2986 already locked by the guest.</entry>
2987 </row>
2988
2989 <row>
2990 <entry>VMMDevHGCMParmType_LinAddr_Locked_In (1)</entry>
2991
2992 <entry>Same as VMMDevHGCMParmType_LinAddr_In but the buffer
2993 is already locked by the guest.</entry>
2994 </row>
2995
2996 <row>
2997 <entry>VMMDevHGCMParmType_LinAddr_Locked_Out (1)</entry>
2998
2999 <entry>Same as VMMDevHGCMParmType_LinAddr_Out but the buffer
3000 is already locked by the guest.</entry>
3001 </row>
3002 </tbody>
3003 </tgroup>
3004 </table></para>
3005
3006 <para>The</para>
3007 </sect2>
3008
3009 <sect2>
3010 <title>Cancel</title>
3011
3012 <para>This request cancels a call request (VMMDevHGCMCancel): <table>
3013 <title>Cancel request</title>
3014
3015 <tgroup cols="2">
3016 <tbody>
3017 <row>
3018 <entry><emphasis role="bold">Name</emphasis></entry>
3019
3020 <entry><emphasis role="bold">Description</emphasis></entry>
3021 </row>
3022
3023 <row>
3024 <entry>header</entry>
3025
3026 <entry>The generic HGCM request header with type equal to
3027 VMMDevReq_HGCMCancel
3028 (<computeroutput>64</computeroutput>).</entry>
3029 </row>
3030 </tbody>
3031 </tgroup>
3032 </table></para>
3033 </sect2>
3034 </sect1>
3035
3036 <sect1>
3037 <title>Guest software interface</title>
3038
3039 <para>The guest HGCM clients can call HGCM services from both drivers
3040 and applications.</para>
3041
3042 <sect2>
3043 <title>The guest driver interface</title>
3044
3045 <para>The driver interface is implemented in the VirtualBox guest
3046 additions driver (VBoxGuest), which works with the VMM virtual device.
3047 Drivers must use the VBox Guest Library (VBGL), which provides an API
3048 for HGCM clients (<computeroutput>VBox/VBoxGuestLib.h</computeroutput>
3049 and <computeroutput>VBox/VBoxGuest.h</computeroutput>).</para>
3050
3051 <para><screen>
3052DECLVBGL(int) VbglHGCMConnect (VBGLHGCMHANDLE *pHandle, VBoxGuestHGCMConnectInfo *pData);
3053 </screen> Connects to the service: <screen>
3054 VBoxGuestHGCMConnectInfo data;
3055
3056 memset (&amp;data, sizeof (VBoxGuestHGCMConnectInfo));
3057
3058 data.result = VINF_SUCCESS;
3059 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
3060 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
3061
3062 rc = VbglHGCMConnect (&amp;handle, &amp;data);
3063
3064 if (RT_SUCCESS (rc))
3065 {
3066 rc = data.result;
3067 }
3068
3069 if (RT_SUCCESS (rc))
3070 {
3071 /* Get the assigned client identifier. */
3072 ulClientID = data.u32ClientID;
3073 }
3074 </screen></para>
3075
3076 <para><screen>
3077DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData);
3078 </screen> Disconnects from the service. <screen>
3079 VBoxGuestHGCMDisconnectInfo data;
3080
3081 RtlZeroMemory (&amp;data, sizeof (VBoxGuestHGCMDisconnectInfo));
3082
3083 data.result = VINF_SUCCESS;
3084 data.u32ClientID = ulClientID;
3085
3086 rc = VbglHGCMDisconnect (handle, &amp;data);
3087 </screen></para>
3088
3089 <para><screen>
3090DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
3091 </screen> Calls a function in the service. <screen>
3092typedef struct _VBoxSFRead
3093{
3094 VBoxGuestHGCMCallInfo callInfo;
3095
3096 /** pointer, in: SHFLROOT
3097 * Root handle of the mapping which name is queried.
3098 */
3099 HGCMFunctionParameter root;
3100
3101 /** value64, in:
3102 * SHFLHANDLE of object to read from.
3103 */
3104 HGCMFunctionParameter handle;
3105
3106 /** value64, in:
3107 * Offset to read from.
3108 */
3109 HGCMFunctionParameter offset;
3110
3111 /** value64, in/out:
3112 * Bytes to read/How many were read.
3113 */
3114 HGCMFunctionParameter cb;
3115
3116 /** pointer, out:
3117 * Buffer to place data to.
3118 */
3119 HGCMFunctionParameter buffer;
3120
3121} VBoxSFRead;
3122
3123/** Number of parameters */
3124#define SHFL_CPARMS_READ (5)
3125
3126...
3127
3128 VBoxSFRead data;
3129
3130 /* The call information. */
3131 data.callInfo.result = VINF_SUCCESS; /* Will be returned by HGCM. */
3132 data.callInfo.u32ClientID = ulClientID; /* Client identifier. */
3133 data.callInfo.u32Function = SHFL_FN_READ; /* The function code. */
3134 data.callInfo.cParms = SHFL_CPARMS_READ; /* Number of parameters. */
3135
3136 /* Initialize parameters. */
3137 data.root.type = VMMDevHGCMParmType_32bit;
3138 data.root.u.value32 = pMap-&gt;root;
3139
3140 data.handle.type = VMMDevHGCMParmType_64bit;
3141 data.handle.u.value64 = hFile;
3142
3143 data.offset.type = VMMDevHGCMParmType_64bit;
3144 data.offset.u.value64 = offset;
3145
3146 data.cb.type = VMMDevHGCMParmType_32bit;
3147 data.cb.u.value32 = *pcbBuffer;
3148
3149 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
3150 data.buffer.u.Pointer.size = *pcbBuffer;
3151 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
3152
3153 rc = VbglHGCMCall (handle, &amp;data.callInfo, sizeof (data));
3154
3155 if (RT_SUCCESS (rc))
3156 {
3157 rc = data.callInfo.result;
3158 *pcbBuffer = data.cb.u.value32; /* This is returned by the HGCM service. */
3159 }
3160 </screen></para>
3161 </sect2>
3162
3163 <sect2>
3164 <title>Guest application interface</title>
3165
3166 <para>Applications call the VirtualBox Guest Additions driver to
3167 utilize the HGCM interface. There are IOCTL's which correspond to the
3168 <computeroutput>Vbgl*</computeroutput> functions: <itemizedlist>
3169 <listitem>
3170 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CONNECT</computeroutput></para>
3171 </listitem>
3172
3173 <listitem>
3174 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_DISCONNECT</computeroutput></para>
3175 </listitem>
3176
3177 <listitem>
3178 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CALL</computeroutput></para>
3179 </listitem>
3180 </itemizedlist></para>
3181
3182 <para>These IOCTL's get the same input buffer as
3183 <computeroutput>VbglHGCM*</computeroutput> functions and the output
3184 buffer has the same format as the input buffer. The same address can
3185 be used as the input and output buffers.</para>
3186
3187 <para>For example see the guest part of shared clipboard, which runs
3188 as an application and uses the HGCM interface.</para>
3189 </sect2>
3190 </sect1>
3191
3192 <sect1>
3193 <title>HGCM Service Implementation</title>
3194
3195 <para>The HGCM service is a shared library with a specific set of entry
3196 points. The library must export the
3197 <computeroutput>VBoxHGCMSvcLoad</computeroutput> entry point: <screen>
3198extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable)
3199 </screen></para>
3200
3201 <para>The service must check the
3202 <computeroutput>ptable-&gt;cbSize</computeroutput> and
3203 <computeroutput>ptable-&gt;u32Version</computeroutput> fields of the
3204 input structure and fill the remaining fields with function pointers of
3205 entry points and the size of the required client buffer size.</para>
3206
3207 <para>The HGCM service gets a dedicated thread, which calls service
3208 entry points synchronously, that is the service will be called again
3209 only when a previous call has returned. However, the guest calls can be
3210 processed asynchronously. The service must call a completion callback
3211 when the operation is actually completed. The callback can be issued
3212 from another thread as well.</para>
3213
3214 <para>Service entry points are listed in the
3215 <computeroutput>VBox/hgcmsvc.h</computeroutput> in the
3216 <computeroutput>VBOXHGCMSVCFNTABLE</computeroutput> structure. <table>
3217 <title>Service entry points</title>
3218
3219 <tgroup cols="2">
3220 <tbody>
3221 <row>
3222 <entry><emphasis role="bold">Entry</emphasis></entry>
3223
3224 <entry><emphasis role="bold">Description</emphasis></entry>
3225 </row>
3226
3227 <row>
3228 <entry>pfnUnload</entry>
3229
3230 <entry>The service is being unloaded.</entry>
3231 </row>
3232
3233 <row>
3234 <entry>pfnConnect</entry>
3235
3236 <entry>A client <computeroutput>u32ClientID</computeroutput>
3237 is connected to the service. The
3238 <computeroutput>pvClient</computeroutput> parameter points to
3239 an allocated memory buffer which can be used by the service to
3240 store the client information.</entry>
3241 </row>
3242
3243 <row>
3244 <entry>pfnDisconnect</entry>
3245
3246 <entry>A client is being disconnected.</entry>
3247 </row>
3248
3249 <row>
3250 <entry>pfnCall</entry>
3251
3252 <entry>A guest client calls a service function. The
3253 <computeroutput>callHandle</computeroutput> must be used in
3254 the VBOXHGCMSVCHELPERS::pfnCallComplete callback when the call
3255 has been processed.</entry>
3256 </row>
3257
3258 <row>
3259 <entry>pfnHostCall</entry>
3260
3261 <entry>Called by the VirtualBox host components to perform
3262 functions which should be not accessible by the guest. Usually
3263 this entry point is used by VirtualBox to configure the
3264 service.</entry>
3265 </row>
3266
3267 <row>
3268 <entry>pfnSaveState</entry>
3269
3270 <entry>The VM state is being saved and the service must save
3271 relevant information using the SSM API
3272 (<computeroutput>VBox/ssm.h</computeroutput>).</entry>
3273 </row>
3274
3275 <row>
3276 <entry>pfnLoadState</entry>
3277
3278 <entry>The VM is being restored from the saved state and the
3279 service must load the saved information and be able to
3280 continue operations from the saved state.</entry>
3281 </row>
3282 </tbody>
3283 </tgroup>
3284 </table></para>
3285 </sect1>
3286 </chapter>
3287
3288 <chapter id="rdpweb">
3289 <title>RDP Web Control</title>
3290
3291 <para>The VirtualBox <emphasis>RDP Web Control</emphasis> (RDPWeb)
3292 provides remote access to a running VM. RDPWeb is a RDP (Remote Desktop
3293 Protocol) client based on Flash technology and can be used from a Web
3294 browser with a Flash plugin.</para>
3295
3296 <sect1>
3297 <title>RDPWeb features</title>
3298
3299 <para>RDPWeb is embedded into a Web page and can connect to VRDP server
3300 in order to displays the VM screen and pass keyboard and mouse events to
3301 the VM.</para>
3302 </sect1>
3303
3304 <sect1>
3305 <title>RDPWeb reference</title>
3306
3307 <para>RDPWeb consists of two required components:<itemizedlist>
3308 <listitem>
3309 <para>Flash movie
3310 <computeroutput>RDPClientUI.swf</computeroutput></para>
3311 </listitem>
3312
3313 <listitem>
3314 <para>JavaScript helpers
3315 <computeroutput>webclient.js</computeroutput></para>
3316 </listitem>
3317 </itemizedlist></para>
3318
3319 <para>The VirtualBox SDK contains sample HTML code
3320 including:<itemizedlist>
3321 <listitem>
3322 <para>JavaScript library for embedding Flash content
3323 <computeroutput>SWFObject.js</computeroutput></para>
3324 </listitem>
3325
3326 <listitem>
3327 <para>Sample HTML page
3328 <computeroutput>webclient3.html</computeroutput></para>
3329 </listitem>
3330 </itemizedlist></para>
3331
3332 <sect2>
3333 <title>RDPWeb functions</title>
3334
3335 <para><computeroutput>RDPClientUI.swf</computeroutput> and
3336 <computeroutput>webclient.js</computeroutput> work with each other.
3337 JavaScript code is responsible for a proper SWF initialization,
3338 delivering mouse events to the SWF and processing resize requests from
3339 the SWF. On the other hand, the SWF contains a few JavaScript callable
3340 methods, which are used both from
3341 <computeroutput>webclient.js</computeroutput> and the user HTML
3342 page.</para>
3343
3344 <sect3>
3345 <title>JavaScript functions</title>
3346
3347 <para><computeroutput>webclient.js</computeroutput> contains helper
3348 functions. In the following table ElementId refers to an HTML
3349 element name or attribute, and Element to the HTML element itself.
3350 HTML code<programlisting>
3351 &lt;div id="FlashRDP"&gt;
3352 &lt;/div&gt;
3353</programlisting> would have ElementId equal to FlashRDP and Element equal to
3354 the div element.</para>
3355
3356 <para><itemizedlist>
3357 <listitem>
3358 <programlisting>RDPWebClient.embedSWF(SWFFileName, ElementId)</programlisting>
3359
3360 <para>Uses SWFObject library to replace the HTML element with
3361 the Flash movie.</para>
3362 </listitem>
3363
3364 <listitem>
3365 <programlisting>RDPWebClient.isRDPWebControlById(ElementId)</programlisting>
3366
3367 <para>Returns true if the given id refers to a RDPWeb Flash
3368 element.</para>
3369 </listitem>
3370
3371 <listitem>
3372 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting>
3373
3374 <para>Returns true if the given element is a RDPWeb Flash
3375 element.</para>
3376 </listitem>
3377
3378 <listitem>
3379 <programlisting>RDPWebClient.getFlashById(ElementId)</programlisting>
3380
3381 <para>Returns an element, which is referenced by the given id.
3382 This function will try to resolve any element, event if it is
3383 not a Flash movie.</para>
3384 </listitem>
3385 </itemizedlist></para>
3386 </sect3>
3387
3388 <sect3>
3389 <title>Flash methods callable from JavaScript</title>
3390
3391 <para><computeroutput>RDPWebClienUI.swf</computeroutput> methods can
3392 be called directly from JavaScript code on a HTML page.</para>
3393
3394 <itemizedlist>
3395 <listitem>
3396 <para>getProperty(Name)</para>
3397 </listitem>
3398
3399 <listitem>
3400 <para>setProperty(Name)</para>
3401 </listitem>
3402
3403 <listitem>
3404 <para>connect()</para>
3405 </listitem>
3406
3407 <listitem>
3408 <para>disconnect()</para>
3409 </listitem>
3410
3411 <listitem>
3412 <para>keyboardSendCAD()</para>
3413 </listitem>
3414 </itemizedlist>
3415 </sect3>
3416
3417 <sect3>
3418 <title>Flash JavaScript callbacks</title>
3419
3420 <para><computeroutput>RDPWebClienUI.swf</computeroutput> calls
3421 JavaScript functions provided by the HTML page.</para>
3422 </sect3>
3423 </sect2>
3424
3425 <sect2>
3426 <title>Embedding RDPWeb in an HTML page</title>
3427
3428 <para>It is necessary to include
3429 <computeroutput>webclient.js</computeroutput> helper script. If
3430 SWFObject library is used, the
3431 <computeroutput>swfobject.js</computeroutput> must be also included
3432 and RDPWeb flash content can be embedded to a Web page using dynamic
3433 HTML. The HTML must include a "placeholder", which consists of 2
3434 <computeroutput>div</computeroutput> elements.</para>
3435 </sect2>
3436 </sect1>
3437
3438 <sect1>
3439 <title>RDPWeb change log</title>
3440
3441 <sect2>
3442 <title>Version 1.2.28</title>
3443
3444 <itemizedlist>
3445 <listitem>
3446 <para><computeroutput>keyboardLayout</computeroutput>,
3447 <computeroutput>keyboardLayouts</computeroutput>,
3448 <computeroutput>UUID</computeroutput> properties.</para>
3449 </listitem>
3450
3451 <listitem>
3452 <para>Support for German keyboard layout on the client.</para>
3453 </listitem>
3454
3455 <listitem>
3456 <para>Rebranding to Oracle.</para>
3457 </listitem>
3458 </itemizedlist>
3459 </sect2>
3460
3461 <sect2>
3462 <title>Version 1.1.26</title>
3463
3464 <itemizedlist>
3465 <listitem>
3466 <para><computeroutput>webclient.js</computeroutput> is a part of
3467 the distribution package.</para>
3468 </listitem>
3469
3470 <listitem>
3471 <para><computeroutput>lastError</computeroutput> property.</para>
3472 </listitem>
3473
3474 <listitem>
3475 <para><computeroutput>keyboardSendScancodes</computeroutput> and
3476 <computeroutput>keyboardSendCAD</computeroutput> methods.</para>
3477 </listitem>
3478 </itemizedlist>
3479 </sect2>
3480
3481 <sect2>
3482 <title>Version 1.0.24</title>
3483
3484 <itemizedlist>
3485 <listitem>
3486 <para>Initial release.</para>
3487 </listitem>
3488 </itemizedlist>
3489 </sect2>
3490 </sect1>
3491 </chapter>
3492
3493 <chapter id="dnd">
3494 <title>Drag'n Drop</title>
3495
3496 <para>Since VirtualBox 4.2 it's possible to transfer files from host to the
3497 Linux guests by dragging files, directories or text from the host into the
3498 guest's screen. This is called <emphasis>drag'n drop (DnD)</emphasis>.</para>
3499
3500 <para>In version 4.4 support for Windows guests has been added, as well as
3501 the ability to transfer data the other way around, that is, from the guest
3502 to the host.</para>
3503
3504 <note><para>Currently only the VirtualBox Manager frontend supports drag'n
3505 drop.</para></note>
3506
3507 <para>This chapter will show how to use the required interfaces provided
3508 by VirtualBox for adding drag'n drop functionality to third-party
3509 frontends.</para>
3510
3511 <sect1>
3512 <title>Basic concepts</title>
3513
3514 <para>In order to use the interfaces provided by VirtualBox, some basic
3515 concepts needs to be understood first: To successfully initiate a
3516 drag'n drop operation at least two sides needs to be involved, a
3517 <emphasis>source</emphasis> and a <emphasis>target</emphasis>:</para>
3518
3519 <para>The <emphasis>source</emphasis> is the side which provides the data,
3520 e.g. is the origin of data. This data can be stored within the source directly
3521 or can be retrieved on-demand by the source itself. Other interfaces don't
3522 care where the data from this source actually came from.</para>
3523
3524 <para>The <emphasis>target</emphasis> on the other hand is the side which
3525 provides the source a visual representation where the user can drop the
3526 data the source offers. This representation can be a window (or just a certain
3527 part of it), for example.</para>
3528
3529 <para>The source and the target have abstract interfaces called
3530 <xref linkend="IDnDSource" xreflabel="IDnDSource" /> and
3531 <xref linkend="IDnDTarget" xreflabel="IDnDTarget" />. VirtualBox also
3532 provides implementations of both interfaces, called
3533 <xref linkend="IGuestDnDSource" xreflabel="IGuestDnDSource" /> and
3534 <xref linkend="IGuestDnDTarget" xreflabel="IGuestDnDTarget" />. Both
3535 implementations are also used in the VirtualBox Manager frontend.</para>
3536 </sect1>
3537
3538 <sect1>
3539 <title>Supported formats</title>
3540
3541 <para>As the target needs to perform specific actions depending on the data
3542 the source provided, the target first needs to know what type of data it
3543 actually is going to retrieve. It might be that the source offers data the
3544 target cannot (or intentionally does not want to) support.</para>
3545
3546 <para>VirtualBox handles those data types by providing so-called
3547 <emphasis>MIME types</emphasis> -- these MIME types were originally defined
3548 in <ulink url="https://tools.ietf.org/html/rfc2046">RFC 2046</ulink> and
3549 are also called <emphasis>Content-types</emphasis>.
3550 <xref linkend="IGuestDnDSource" xreflabel="IGuestDnDSource" /> and
3551 <xref linkend="IGuestDnDTarget" xreflabel="IGuestDnDTarget" /> support
3552 the following MIME types by default:<itemizedlist>
3553 <listitem>
3554 <para><emphasis role="bold">text/uri-list</emphasis> - A list of URIs
3555 (Uniform Resource Identifier, see
3556 <ulink url="https://tools.ietf.org/html/rfc3986">RFC 3986</ulink>)
3557 pointing to the file and/or directory paths already transferred from
3558 the source to the target.</para>
3559 </listitem>
3560 <listitem>
3561 <para><emphasis role="bold">text/plain;charset=utf-8</emphasis> and
3562 <emphasis role="bold">UTF8_STRING</emphasis> - text in UTF8 format.</para>
3563 </listitem>
3564 <listitem>
3565 <para><emphasis role="bold">text/plain, TEXT</emphasis>
3566 and <emphasis role="bold">STRING</emphasis> - plain ASCII text, depending
3567 on the source's active ANSI page (if any).</para>
3568 </listitem>
3569 </itemizedlist>
3570 </para>
3571
3572 <para>If, for whatever reason, a certain default format should not be supported
3573 or a new format should be registered,
3574 <xref linkend="IDnDSource" xreflabel="IDnDSource" /> and
3575 <xref linkend="IDnDTarget" xreflabel="IDnDTarget" /> have methods derived from
3576 <xref linkend="IDnDBase" xreflabel="IDnDBase" /> which provide adding,
3577 removing and enumerating specific formats.
3578 <note><para>Registering new or removing default formats on the guest side
3579 currently is not implemented.</para></note></para>
3580 </sect1>
3581
3582 </chapter>
3583
3584 <chapter id="vbox-auth">
3585 <title>VirtualBox external authentication modules</title>
3586
3587 <para>VirtualBox supports arbitrary external modules to perform
3588 authentication. The module is used when the authentication method is set
3589 to "external" for a particular VM VRDE access and the library was
3590 specified with <computeroutput>VBoxManage setproperty
3591 vrdeauthlibrary</computeroutput>. Web service also use the authentication
3592 module which was specified with <computeroutput>VBoxManage setproperty
3593 websrvauthlibrary</computeroutput>.</para>
3594
3595 <para>This library will be loaded by the VM or web service process on
3596 demand, i.e. when the first remote desktop connection is made by a client
3597 or when a client that wants to use the web service logs on.</para>
3598
3599 <para>External authentication is the most flexible as the external handler
3600 can both choose to grant access to everyone (like the "null"
3601 authentication method would) and delegate the request to the guest
3602 authentication component. When delegating the request to the guest
3603 component, the handler will still be called afterwards with the option to
3604 override the result.</para>
3605
3606 <para>An authentication library is required to implement exactly one entry
3607 point:</para>
3608
3609 <screen>#include "VBoxAuth.h"
3610
3611/**
3612 * Authentication library entry point.
3613 *
3614 * Parameters:
3615 *
3616 * szCaller The name of the component which calls the library (UTF8).
3617 * pUuid Pointer to the UUID of the accessed virtual machine. Can be NULL.
3618 * guestJudgement Result of the guest authentication.
3619 * szUser User name passed in by the client (UTF8).
3620 * szPassword Password passed in by the client (UTF8).
3621 * szDomain Domain passed in by the client (UTF8).
3622 * fLogon Boolean flag. Indicates whether the entry point is called
3623 * for a client logon or the client disconnect.
3624 * clientId Server side unique identifier of the client.
3625 *
3626 * Return code:
3627 *
3628 * AuthResultAccessDenied Client access has been denied.
3629 * AuthResultAccessGranted Client has the right to use the
3630 * virtual machine.
3631 * AuthResultDelegateToGuest Guest operating system must
3632 * authenticate the client and the
3633 * library must be called again with
3634 * the result of the guest
3635 * authentication.
3636 *
3637 * Note: When 'fLogon' is 0, only pszCaller, pUuid and clientId are valid and the return
3638 * code is ignored.
3639 */
3640AuthResult AUTHCALL AuthEntry(
3641 const char *szCaller,
3642 PAUTHUUID pUuid,
3643 AuthGuestJudgement guestJudgement,
3644 const char *szUser,
3645 const char *szPassword
3646 const char *szDomain
3647 int fLogon,
3648 unsigned clientId)
3649{
3650 /* Process request against your authentication source of choice. */
3651 // if (authSucceeded(...))
3652 // return AuthResultAccessGranted;
3653 return AuthResultAccessDenied;
3654}</screen>
3655
3656 <para>A note regarding the UUID implementation of the
3657 <computeroutput>pUuid</computeroutput> argument: VirtualBox uses a
3658 consistent binary representation of UUIDs on all platforms. For this
3659 reason the integer fields comprising the UUID are stored as little endian
3660 values. If you want to pass such UUIDs to code which assumes that the
3661 integer fields are big endian (often also called network byte order), you
3662 need to adjust the contents of the UUID to e.g. achieve the same string
3663 representation. The required changes are:<itemizedlist>
3664 <listitem>
3665 <para>reverse the order of byte 0, 1, 2 and 3</para>
3666 </listitem>
3667
3668 <listitem>
3669 <para>reverse the order of byte 4 and 5</para>
3670 </listitem>
3671
3672 <listitem>
3673 <para>reverse the order of byte 6 and 7.</para>
3674 </listitem>
3675 </itemizedlist>Using this conversion you will get identical results when
3676 converting the binary UUID to the string representation.</para>
3677
3678 <para>The <computeroutput>guestJudgement</computeroutput> argument
3679 contains information about the guest authentication status. For the first
3680 call, it is always set to
3681 <computeroutput>AuthGuestNotAsked</computeroutput>. In case the
3682 <computeroutput>AuthEntry</computeroutput> function returns
3683 <computeroutput>AuthResultDelegateToGuest</computeroutput>, a guest
3684 authentication will be attempted and another call to the
3685 <computeroutput>AuthEntry</computeroutput> is made with its result. This
3686 can be either granted / denied or no judgement (the guest component chose
3687 for whatever reason to not make a decision). In case there is a problem
3688 with the guest authentication module (e.g. the Additions are not installed
3689 or not running or the guest did not respond within a timeout), the "not
3690 reacted" status will be returned.</para>
3691 </chapter>
3692
3693 <chapter id="javaapi">
3694 <title>Using Java API</title>
3695
3696 <sect1>
3697 <title>Introduction</title>
3698
3699 <para>VirtualBox can be controlled by a Java API, both locally
3700 (COM/XPCOM) and from remote (SOAP) clients. As with the Python bindings,
3701 a generic glue layer tries to hide all platform differences, allowing
3702 for source and binary compatibility on different platforms.</para>
3703 </sect1>
3704
3705 <sect1>
3706 <title>Requirements</title>
3707
3708 <para>To use the Java bindings, there are certain requirements depending
3709 on the platform. First of all, you need JDK 1.5 (Java 5) or later. Also
3710 please make sure that the version of the VirtualBox API .jar file
3711 exactly matches the version of VirtualBox you use. To avoid confusion,
3712 the VirtualBox API provides versioning in the Java package name, e.g.
3713 the package is named <computeroutput>org.virtualbox_3_2</computeroutput>
3714 for VirtualBox version 3.2. <itemizedlist>
3715 <listitem>
3716 <para><emphasis role="bold">XPCOM</emphasis> - for all platforms,
3717 but Microsoft Windows. A Java bridge based on JavaXPCOM is shipped
3718 with VirtualBox. The classpath must contain
3719 <computeroutput>vboxjxpcom.jar</computeroutput> and the
3720 <computeroutput>vbox.home</computeroutput> property must be set to
3721 location where the VirtualBox binaries are. Please make sure that
3722 the JVM bitness matches bitness of VirtualBox you use as the XPCOM
3723 bridge relies on native libraries.</para>
3724
3725 <para>Start your application like this: <programlisting>
3726 java -cp vboxjxpcom.jar -Dvbox.home=/opt/virtualbox MyProgram
3727 </programlisting></para>
3728 </listitem>
3729
3730 <listitem>
3731 <para><emphasis role="bold">COM</emphasis> - for Microsoft
3732 Windows. We rely on <computeroutput>Jacob</computeroutput> - a
3733 generic Java to COM bridge - which has to be installed seperately.
3734 See <ulink
3735 url="http://sourceforge.net/projects/jacob-project/">http://sourceforge.net/projects/jacob-project/</ulink>
3736 for installation instructions. Also, the VirtualBox provided
3737 <computeroutput>vboxjmscom.jar</computeroutput> must be in the
3738 class path.</para>
3739
3740 <para>Start your application like this: <programlisting>
3741 java -cp vboxjmscom.jar;c:\jacob\jacob.jar -Djava.library.path=c:\jacob MyProgram
3742 </programlisting></para>
3743 </listitem>
3744
3745 <listitem>
3746 <para><emphasis role="bold">SOAP</emphasis> - all platforms. Java
3747 6 is required, as it comes with builtin support for SOAP via the
3748 JAX-WS library. Also, the VirtualBox provided
3749 <computeroutput>vbojws.jar</computeroutput> must be in the class
3750 path. In the SOAP case it's possible to create several
3751 VirtualBoxManager instances to communicate with multiple
3752 VirtualBox hosts.</para>
3753
3754 <para>Start your application like this: <programlisting>
3755 java -cp vboxjws.jar MyProgram
3756 </programlisting></para>
3757 </listitem>
3758 </itemizedlist></para>
3759
3760 <para>Exception handling is also generalized by the generic glue layer,
3761 so that all methods could throw
3762 <computeroutput>VBoxException</computeroutput> containing human-readable
3763 text message (see <computeroutput>getMessage()</computeroutput> method)
3764 along with wrapped original exception (see
3765 <computeroutput>getWrapped()</computeroutput> method).</para>
3766 </sect1>
3767
3768 <sect1>
3769 <title>Example</title>
3770
3771 <para>This example shows a simple use case of the Java API. Differences
3772 for SOAP vs. local version are minimal, and limited to the connection
3773 setup phase (see <computeroutput>ws</computeroutput> variable). In the
3774 SOAP case it's possible to create several VirtualBoxManager instances to
3775 communicate with multiple VirtualBox hosts. <programlisting>
3776 import org.virtualbox_4_3.*;
3777 ....
3778 VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
3779 boolean ws = false; // or true, if we need the SOAP version
3780 if (ws)
3781 {
3782 String url = "http://myhost:18034";
3783 String user = "test";
3784 String passwd = "test";
3785 mgr.connect(url, user, passwd);
3786 }
3787 IVirtualBox vbox = mgr.getVBox();
3788 System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
3789 // get first VM name
3790 String m = vbox.getMachines().get(0).getName();
3791 System.out.println("\nAttempting to start VM '" + m + "'");
3792 // start it
3793 mgr.startVm(m, null, 7000);
3794
3795 if (ws)
3796 mgr.disconnect();
3797
3798 mgr.cleanup();
3799 </programlisting> For more a complete example, see
3800 <computeroutput>TestVBox.java</computeroutput>, shipped with the
3801 SDK. It contains exception handling and error printing code, which
3802 is important for reliable larger scale projects.</para>
3803 </sect1>
3804 </chapter>
3805
3806 <chapter>
3807 <title>License information</title>
3808
3809 <para>The sample code files shipped with the SDK are generally licensed
3810 liberally to make it easy for anyone to use this code for their own
3811 application code.</para>
3812
3813 <para>The Java files under
3814 <computeroutput>bindings/webservice/java/jax-ws/</computeroutput> (library
3815 files for the object-oriented web service) are, by contrast, licensed
3816 under the GNU Lesser General Public License (LGPL) V2.1.</para>
3817
3818 <para>See
3819 <computeroutput>sdk/bindings/webservice/java/jax-ws/src/COPYING.LIB</computeroutput>
3820 for the full text of the LGPL 2.1.</para>
3821
3822 <para>When in doubt, please refer to the individual source code files
3823 shipped with this SDK.</para>
3824 </chapter>
3825
3826 <chapter>
3827 <title>Main API change log</title>
3828
3829 <para>Generally, VirtualBox will maintain API compatibility within a major
3830 release; a major release occurs when the first or the second of the three
3831 version components of VirtualBox change (that is, in the x.y.z scheme, a
3832 major release is one where x or y change, but not when only z
3833 changes).</para>
3834
3835 <para>In other words, updates like those from 2.0.0 to 2.0.2 will not come
3836 with API breakages.</para>
3837
3838 <para>Migration between major releases most likely will lead to API
3839 breakage, so please make sure you updated code accordingly. The OOWS Java
3840 wrappers enforce that mechanism by putting VirtualBox classes into
3841 version-specific packages such as
3842 <computeroutput>org.virtualbox_2_2</computeroutput>. This approach allows
3843 for connecting to multiple VirtualBox versions simultaneously from the
3844 same Java application.</para>
3845
3846 <para>The following sections list incompatible changes that the Main API
3847 underwent since the original release of this SDK Reference with VirtualBox
3848 2.0. A change is deemed "incompatible" only if it breaks existing client
3849 code (e.g. changes in method parameter lists, renamed or removed
3850 interfaces and similar). In other words, the list does not contain new
3851 interfaces, methods or attributes or other changes that do not affect
3852 existing client code.</para>
3853
3854 <sect1>
3855 <title>Incompatible API changes with version 4.4</title>
3856
3857 <itemizedlist>
3858 <listitem><para>Drag'n drop APIs were changed as follows:<itemizedlist>
3859
3860 <listitem>
3861 <para>Methods for providing host to guest drag'n drop functionality,
3862 such as <computeroutput>IGuest::dragHGEnter</computeroutput>,
3863 <computeroutput>IGuest::dragHGMove()</computeroutput>,
3864 <computeroutput>IGuest::dragHGLeave()</computeroutput>,
3865 <computeroutput>IGuest::dragHGDrop()</computeroutput> and
3866 <computeroutput>IGuest::dragHGPutData()</computeroutput>,
3867 have been moved to an abstract base class called
3868 <xref linkend="IDnDTarget" xreflabel="IDnDTarget" />. VirtualBox implements
3869 this base class in the <xref linkend="IGuestDnDTarget" xreflabel="IGuestDnDTarget" />
3870 interface. The implementation can be used by using the
3871 <xref linkend="IGuest__dnDTarget" xreflabel="IGuest::dnDTarget()" /> method.</para>
3872 <para>Methods for providing guest to host drag'n drop functionality,
3873 such as <computeroutput>IGuest::dragGHPending()</computeroutput>,
3874 <computeroutput>IGuest::dragGHDropped()</computeroutput> and
3875 <computeroutput>IGuest::dragGHGetData()</computeroutput>,
3876 have been moved to an abstract base class called
3877 <xref linkend="IDnDSource" xreflabel="IDnDSource" />. VirtualBox implements
3878 this base class in the <xref linkend="IGuestDnDSource" xreflabel="IGuestDnDSource" />
3879 interface. The implementation can be used by using the
3880 <xref linkend="IGuest__dnDSource" xreflabel="IGuest::dnDSource()" /> method.</para>
3881 </listitem>
3882
3883 <listitem>
3884 <para>The <computeroutput>DragAndDropAction</computeroutput> enumeration has been
3885 renamed to <xref linkend="DnDAction" xreflabel="DnDAction" />.</para>
3886 </listitem>
3887
3888 <listitem>
3889 <para>The <computeroutput>DragAndDropMode</computeroutput> enumeration has been
3890 renamed to <xref linkend="DnDMode" xreflabel="DnDMode" />.</para>
3891 </listitem>
3892
3893 <listitem>
3894 <para>The attribute <computeroutput>IMachine::dragAndDropMode</computeroutput>
3895 has been renamed to <xref linkend="IMachine__dnDMode" xreflabel="IMachine::dnDMode()" />.</para>
3896 </listitem>
3897
3898 <listitem>
3899 <para>The event <computeroutput>IDragAndDropModeChangedEvent</computeroutput>
3900 has been renamed to <xref linkend="IDnDModeChangedEvent" xreflabel="IDnDModeChangedEvent" />.</para>
3901 </listitem>
3902
3903 <listitem>
3904 <para>The callback method <computeroutput>IInternalSessionControl::onDragAndDropModeChange</computeroutput>
3905 has been renamed to <xref linkend="IInternalSessionControl__onDnDModeChange" xreflabel="IInternalSessionControl::onDnDModeChange()" />.</para>
3906 </listitem>
3907
3908 </itemizedlist></para>
3909 </listitem>
3910 </itemizedlist>
3911 </sect1>
3912
3913 <sect1>
3914 <title>Incompatible API changes with version 4.3</title>
3915
3916 <itemizedlist>
3917 <listitem>
3918 <para>The explicit medium locking methods
3919 <xref linkend="IMedium__lockRead" xreflabel="IMedium::lockRead()" />
3920 and <xref linkend="IMedium__lockWrite" xreflabel="IMedium::lockWrite()" />
3921 have been redesigned. They return a lock token object reference
3922 now, and calling the <xref linkend="IToken__abandon"
3923 xreflabel="IToken::abandon()" /> method (or letting the reference
3924 count to this object drop to 0) will unlock it. This eliminates
3925 the rather common problem that an API client crash left behind
3926 locks, and also improves the safety (API clients can't release
3927 locks they didn't obtain).</para>
3928 </listitem>
3929
3930 <listitem>
3931 <para>The parameter list of <xref linkend="IAppliance__write"
3932 xreflabel="IAppliance::write()" /> has been changed slightly, to
3933 allow multiple flags to be passed.</para>
3934 </listitem>
3935
3936 <listitem>
3937 <para><computeroutput>IMachine::delete</computeroutput>
3938 has been renamed to <xref linkend="IMachine__deleteConfig"
3939 xreflabel="IMachine::deleteConfig()" />, to improve API client
3940 binding compatibility.</para>
3941 </listitem>
3942
3943 <listitem>
3944 <para><computeroutput>IMachine::export</computeroutput>
3945 has been renamed to <xref linkend="IMachine__exportTo"
3946 xreflabel="IMachine::exportTo()" />, to improve API client binding
3947 compatibility.</para>
3948 </listitem>
3949
3950 <listitem>
3951 <para>For <xref linkend="IMachine__launchVMProcess"
3952 xreflabel="IMachine::launchVMProcess()"/> the meaning of the
3953 <computeroutput>type</computeroutput> parameter has changed slightly.
3954 Empty string now means that the per-VM or global default frontend
3955 is launched. Most callers of this method should use the empty string
3956 now, unless they really want to override the default and launch a
3957 particular frontend.</para>
3958 </listitem>
3959
3960 <listitem>
3961 <para>Medium management APIs were changed as follows:<itemizedlist>
3962
3963 <listitem>
3964 <para>The type of attribute
3965 <xref linkend="IMedium__variant" xreflabel="IMedium::variant()"/>
3966 changed from <computeroutput>unsigned long</computeroutput>
3967 to <computeroutput>safe-array MediumVariant</computeroutput>.
3968 It is an array of flags instead of a set of flags which were stored inside one variable.
3969 </para>
3970 </listitem>
3971
3972 <listitem>
3973 <para>The parameter list for <xref
3974 linkend="IMedium__cloneTo"
3975 xreflabel="IMedium::cloneTo()" /> was modified.</para>
3976 The type of parameter variant was changed from unsigned long to safe-array MediumVariant.
3977 </listitem>
3978
3979 <listitem>
3980 <para>The parameter list for <xref
3981 linkend="IMedium__createBaseStorage"
3982 xreflabel="IMedium::createBaseStorage()" /> was modified.</para>
3983 The type of parameter variant was changed from unsigned long to safe-array MediumVariant.
3984 </listitem>
3985
3986 <listitem>
3987 <para>The parameter list for <xref
3988 linkend="IMedium__createDiffStorage"
3989 xreflabel="IMedium::createDiffStorage()" /> was modified.</para>
3990 The type of parameter variant was changed from unsigned long to safe-array MediumVariant.
3991 </listitem>
3992
3993 <listitem>
3994 <para>The parameter list for <xref
3995 linkend="IMedium__cloneToBase"
3996 xreflabel="IMedium::cloneToBase()" /> was modified.</para>
3997 The type of parameter variant was changed from unsigned long to safe-array MediumVariant.
3998 </listitem>
3999 </itemizedlist></para>
4000 </listitem>
4001
4002 <listitem>
4003 <para>The type of attribute
4004 <xref linkend="IMediumFormat__capabilities"
4005 xreflabel="IMediumFormat::capabilities()"/>
4006 changed from <computeroutput>unsigned long</computeroutput>
4007 to <computeroutput>safe-array MediumFormatCapabilities</computeroutput>.
4008 It is an array of flags instead of a set of flags which were stored inside one variable.
4009 </para>
4010 </listitem>
4011
4012 <listitem>
4013 <para>The attribute <xref linkend="IMedium__logicalSize"
4014 xreflabel="IMedium::logicalSize()" /> now returns the logical
4015 size of exactly this medium object (whether it is a base or diff
4016 image). The old behavior was no longer acceptable, as each image
4017 can have a different capacity.</para>
4018 </listitem>
4019
4020 <listitem>
4021 <para>Guest control APIs - such as <xref linkend="IGuest"
4022 xreflabel="IGuest" />, <xref linkend="IGuestSession"
4023 xreflabel="IGuestSession" />, <xref linkend="IGuestProcess"
4024 xreflabel="IGuestProcess" /> and so on - now emit own events to provide
4025 clients much finer control and the ability to write own frontends for
4026 guest operations. The event <xref linkend="IGuestSessionEvent"
4027 xreflabel="IGuestSessionEvent" /> acts as an abstract base class
4028 for all guest control events. Certain guest events contain a
4029 <xref linkend="IVirtualBoxErrorInfo" xreflabel="IVirtualBoxErrorInfo" /> member
4030 to provide more information in case of an error happened on the
4031 guest side.</para>
4032 </listitem>
4033
4034 <listitem>
4035 <para>Guest control sessions on the guest started by <xref
4036 linkend="IGuest__createSession" xreflabel="IGuest::createSession()" />
4037 now are dedicated guest processes to provide more safety and performance
4038 for certain operations. Also, the <xref linkend="IGuest__createSession"
4039 xreflabel="IGuest::createSession()" /> call does not wait for the
4040 guest session being created anymore due to the dedicated guest session
4041 processes just mentioned. This also will enable webservice clients to
4042 handle guest session creation more gracefully. To wait for a guest
4043 session being started, use the newly added attribute <xref
4044 linkend="IGuestSession__status" xreflabel="IGuestSession::status()" />
4045 to query the current guest session status.</para>
4046 </listitem>
4047
4048 <listitem>
4049 <para>The <xref linkend="IGuestFile" xreflabel="IGuestFile" />
4050 APIs are now implemented to provide native guest file access from
4051 the host.</para>
4052 </listitem>
4053
4054 <listitem>
4055 <para>The parameter list for <xref
4056 linkend="IGuest__updateGuestAdditions"
4057 xreflabel="IMedium::updateGuestAdditions()" /> was modified.</para>
4058 It now supports specifying optional command line arguments for the
4059 Guest Additions installer performing the actual update on the guest.
4060 </listitem>
4061
4062 <listitem>
4063 <para>A new event <xref linkend="IGuestUserStateChangedEvent"
4064 xreflabel="IGuestUserStateChangedEvent" /> was introduced to provide
4065 guest user status updates to the host via event listeners. To use this
4066 event there needs to be at least the 4.3 Guest Additions installed on
4067 the guest. At the moment only the states "Idle" and "InUse" of the
4068 <xref linkend="GuestUserState"
4069 xreflabel="GuestUserState" /> enumeration are supported on
4070 Windows guests, starting at Windows 2000 SP2.</para>
4071 </listitem>
4072
4073 <listitem>
4074 <para>
4075 The attribute <xref linkend="IGuestSession__protocolVersion"
4076 xreflabel="IGuestSession::protocolVersion"/> was added to provide a
4077 convenient way to lookup the guest session's protocol version it
4078 uses to communicate with the installed Guest Additions on the guest.
4079 Older Guest Additions will set the protocol version to 1, whereas
4080 Guest Additions 4.3 will set the protocol version to 2. This might
4081 change in the future as new features arise.</para>
4082 </listitem>
4083
4084 <listitem>
4085 <para><computeroutput>IDisplay::getScreenResolution</computeroutput>
4086 has been extended to return the display position in the guest.</para>
4087 </listitem>
4088
4089 <listitem>
4090 <para>
4091 The <xref linkend="IUSBController" xreflabel="IUSBController"/>
4092 class is not a singleton of <xref linkend="IMachine" xreflabel="IMachine"/>
4093 anymore but <xref linkend="IMachine" xreflabel="IMachine"/> contains
4094 a list of USB controllers present in the VM. The USB device filter
4095 handling was moved to <xref linkend="IUSBDeviceFilters" xreflabel="IUSBDeviceFilters"/>.
4096 </para>
4097 </listitem>
4098 </itemizedlist>
4099 </sect1>
4100
4101 <sect1>
4102 <title>Incompatible API changes with version 4.2</title>
4103
4104 <itemizedlist>
4105 <listitem>
4106 <para>Guest control APIs for executing guest processes, working with
4107 guest files or directories have been moved to the newly introduced
4108 <xref linkend="IGuestSession" xreflabel="IGuestSession" /> interface which
4109 can be created by calling <xref linkend="IGuest__createSession"
4110 xreflabel="IGuest::createSession()" />.</para>
4111
4112 <para>A guest session will act as a
4113 guest user's impersonation so that the guest credentials only have to
4114 be provided when creating a new guest session. There can be up to 32
4115 guest sessions at once per VM, each session serving up to 2048 guest
4116 processes running or files opened.</para>
4117
4118 <para>Instead of working with process or directory handles before
4119 version 4.2, there now are the dedicated interfaces
4120 <xref linkend="IGuestProcess" xreflabel="IGuestProcess" />,
4121 <xref linkend="IGuestDirectory" xreflabel="IGuestDirectory" /> and
4122 <xref linkend="IGuestFile" xreflabel="IGuestFile" />. To retrieve more
4123 information of a file system object the new interface
4124 <xref linkend="IGuestFsObjInfo" xreflabel="IGuestFsObjInfo" /> has been
4125 introduced.</para>
4126
4127 <para>Even though the guest control API was changed it is backwards
4128 compatible so that it can be used with older installed Guest
4129 Additions. However, to use upcoming features like process termination
4130 or waiting for input / output new Guest Additions must be installed when
4131 these features got implemented.</para>
4132
4133 <para>The following limitations apply:
4134 <itemizedlist>
4135 <listitem><para>The <xref linkend="IGuestFile" xreflabel="IGuestFile" />
4136 interface is not fully implemented yet.</para>
4137 </listitem>
4138 <listitem><para>The symbolic link APIs
4139 <xref linkend="IGuestSession__symlinkCreate"
4140 xreflabel="IGuestSession::symlinkCreate()" />,
4141 <xref linkend="IGuestSession__symlinkExists"
4142 xreflabel="IGuestSession::symlinkExists()" />,
4143 <xref linkend="IGuestSession__symlinkRead"
4144 xreflabel="IGuestSession::symlinkRead()" />,
4145 <xref linkend="IGuestSession__symlinkRemoveDirectory"
4146 xreflabel="IGuestSession::symlinkRemoveDirectory()" /> and
4147 <xref linkend="IGuestSession__symlinkRemoveFile"
4148 xreflabel="IGuestSession::symlinkRemoveFile()" /> are not
4149 implemented yet.</para>
4150 </listitem>
4151 <listitem><para>The directory APIs
4152 <xref linkend="IGuestSession__directoryRemove"
4153 xreflabel="IGuestSession::directoryRemove()" />,
4154 <xref linkend="IGuestSession__directoryRemoveRecursive"
4155 xreflabel="IGuestSession::directoryRemoveRecursive()" />,
4156 <xref linkend="IGuestSession__directoryRename"
4157 xreflabel="IGuestSession::directoryRename()" /> and
4158 <xref linkend="IGuestSession__directorySetACL"
4159 xreflabel="IGuestSession::directorySetACL()" /> are not
4160 implemented yet.</para>
4161 </listitem>
4162 <listitem><para>The temporary file creation API
4163 <xref linkend="IGuestSession__fileCreateTemp"
4164 xreflabel="IGuestSession::fileCreateTemp()" /> is not
4165 implemented yet.</para>
4166 </listitem>
4167 <listitem><para>Guest process termination via
4168 <xref linkend="IProcess__terminate"
4169 xreflabel="IProcess::terminate()" /> is not
4170 implemented yet.</para>
4171 </listitem>
4172 <listitem><para>Waiting for guest process output via
4173 <xref linkend="ProcessWaitForFlag__StdOut" xreflabel="ProcessWaitForFlag::StdOut" />
4174 and <xref linkend="ProcessWaitForFlag__StdErr" xreflabel="ProcessWaitForFlag::StdErr" />
4175 is not implemented yet.</para><para>To wait for process output, <xref linkend="IProcess__read"
4176 xreflabel="IProcess::read()" /> with appropriate flags still can be used to periodically
4177 check for new output data to arrive. Note that <xref linkend="ProcessCreateFlag__WaitForStdOut"
4178 xreflabel="ProcessCreateFlag::WaitForStdOut" /> and / or
4179 <xref linkend="ProcessCreateFlag__WaitForStdErr" xreflabel="ProcessCreateFlag::WaitForStdErr" />
4180 need to be specified when creating a guest process via <xref linkend="IGuestSession__processCreate"
4181 xreflabel="IGuestSession::processCreate()" /> or <xref linkend="IGuestSession__processCreateEx"
4182 xreflabel="IGuestSession::processCreateEx()" />.</para>
4183 </listitem>
4184 <listitem>
4185 <para>ACL (Access Control List) handling in general is not implemented yet.</para>
4186 </listitem>
4187 </itemizedlist>
4188 </para>
4189 </listitem>
4190
4191 <listitem>
4192 <para>The <xref linkend="LockType" xreflabel="LockType" />
4193 enumeration now has an additional value <computeroutput>VM</computeroutput>
4194 which tells <xref linkend="IMachine__lockMachine"
4195 xreflabel="IMachine::lockMachine()" /> to create a full-blown
4196 object structure for running a VM. This was the previous behavior
4197 with <computeroutput>Write</computeroutput>, which now only creates
4198 the minimal object structure to save time and resources (at the
4199 moment the Console object is still created, but all sub-objects
4200 such as Display, Keyboard, Mouse, Guest are not.</para>
4201 </listitem>
4202
4203 <listitem>
4204 <para>Machines can be put in groups (actually an array of groups).
4205 The primary group affects the default placement of files belonging
4206 to a VM. <xref linkend="IVirtualBox__createMachine"
4207 xreflabel="IVirtualBox::createMachine()"/> and
4208 <xref linkend="IVirtualBox__composeMachineFilename"
4209 xreflabel="IVirtualBox::composeMachineFilename()"/> have been
4210 adjusted accordingly, the former taking an array of groups as an
4211 additional parameter and the latter taking a group as an additional
4212 parameter. The create option handling has been changed for those two
4213 methods, too.</para>
4214 </listitem>
4215
4216 <listitem>
4217 <para>The method IVirtualBox::findMedium() has been removed, since
4218 it provides a subset of the functionality of <xref linkend="IVirtualBox__openMedium"
4219 xreflabel="IVirtualBox::openMedium()" />.</para>
4220 </listitem>
4221
4222 <listitem>
4223 <para>The use of acronyms in API enumeration, interface, attribute
4224 and method names has been made much more consistent, previously they
4225 sometimes were lowercase and sometimes mixed case. They are now
4226 consistently all caps:<table>
4227 <title>Renamed identifiers in VirtualBox 4.2</title>
4228
4229 <tgroup cols="2" style="verywide">
4230 <tbody>
4231 <row>
4232 <entry><emphasis role="bold">Old name</emphasis></entry>
4233
4234 <entry><emphasis role="bold">New name</emphasis></entry>
4235 </row>
4236 <row>
4237 <entry>PointingHidType</entry>
4238 <entry><xref linkend="PointingHIDType" xreflabel="PointingHIDType"/></entry>
4239 </row>
4240 <row>
4241 <entry>KeyboardHidType</entry>
4242 <entry><xref linkend="KeyboardHIDType" xreflabel="KeyboardHIDType"/></entry>
4243 </row>
4244 <row>
4245 <entry>IPciAddress</entry>
4246 <entry><xref linkend="IPCIAddress" xreflabel="IPCIAddress"/></entry>
4247 </row>
4248 <row>
4249 <entry>IPciDeviceAttachment</entry>
4250 <entry><xref linkend="IPCIDeviceAttachment" xreflabel="IPCIDeviceAttachment"/></entry>
4251 </row>
4252 <row>
4253 <entry>IMachine::pointingHidType</entry>
4254 <entry><xref linkend="IMachine__pointingHIDType" xreflabel="IMachine::pointingHIDType"/></entry>
4255 </row>
4256 <row>
4257 <entry>IMachine::keyboardHidType</entry>
4258 <entry><xref linkend="IMachine__keyboardHIDType" xreflabel="IMachine::keyboardHIDType"/></entry>
4259 </row>
4260 <row>
4261 <entry>IMachine::hpetEnabled</entry>
4262 <entry><xref linkend="IMachine__HPETEnabled" xreflabel="IMachine::HPETEnabled"/></entry>
4263 </row>
4264 <row>
4265 <entry>IMachine::sessionPid</entry>
4266 <entry><xref linkend="IMachine__sessionPID" xreflabel="IMachine::sessionPID"/></entry>
4267 </row>
4268 <row>
4269 <entry>IMachine::ioCacheEnabled</entry>
4270 <entry><xref linkend="IMachine__IOCacheEnabled" xreflabel="IMachine::IOCacheEnabled"/></entry>
4271 </row>
4272 <row>
4273 <entry>IMachine::ioCacheSize</entry>
4274 <entry><xref linkend="IMachine__IOCacheSize" xreflabel="IMachine::IOCacheSize"/></entry>
4275 </row>
4276 <row>
4277 <entry>IMachine::pciDeviceAssignments</entry>
4278 <entry><xref linkend="IMachine__PCIDeviceAssignments" xreflabel="IMachine::PCIDeviceAssignments"/></entry>
4279 </row>
4280 <row>
4281 <entry>IMachine::attachHostPciDevice()</entry>
4282 <entry><xref linkend="IMachine__attachHostPCIDevice" xreflabel="IMachine::attachHostPCIDevice"/></entry>
4283 </row>
4284 <row>
4285 <entry>IMachine::detachHostPciDevice()</entry>
4286 <entry><xref linkend="IMachine__detachHostPCIDevice" xreflabel="IMachine::detachHostPCIDevice()"/></entry>
4287 </row>
4288 <row>
4289 <entry>IConsole::attachedPciDevices</entry>
4290 <entry><xref linkend="IConsole__attachedPCIDevices" xreflabel="IConsole::attachedPCIDevices"/></entry>
4291 </row>
4292 <row>
4293 <entry>IHostNetworkInterface::dhcpEnabled</entry>
4294 <entry><xref linkend="IHostNetworkInterface__DHCPEnabled" xreflabel="IHostNetworkInterface::DHCPEnabled"/></entry>
4295 </row>
4296 <row>
4297 <entry>IHostNetworkInterface::enableStaticIpConfig()</entry>
4298 <entry><xref linkend="IHostNetworkInterface__enableStaticIPConfig" xreflabel="IHostNetworkInterface::enableStaticIPConfig()"/></entry>
4299 </row>
4300 <row>
4301 <entry>IHostNetworkInterface::enableStaticIpConfigV6()</entry>
4302 <entry><xref linkend="IHostNetworkInterface__enableStaticIPConfigV6" xreflabel="IHostNetworkInterface::enableStaticIPConfigV6()"/></entry>
4303 </row>
4304 <row>
4305 <entry>IHostNetworkInterface::enableDynamicIpConfig()</entry>
4306 <entry><xref linkend="IHostNetworkInterface__enableDynamicIPConfig" xreflabel="IHostNetworkInterface::enableDynamicIPConfig()"/></entry>
4307 </row>
4308 <row>
4309 <entry>IHostNetworkInterface::dhcpRediscover()</entry>
4310 <entry><xref linkend="IHostNetworkInterface__DHCPRediscover" xreflabel="IHostNetworkInterface::DHCPRediscover()"/></entry>
4311 </row>
4312 <row>
4313 <entry>IHost::Acceleration3DAvailable</entry>
4314 <entry><xref linkend="IHost__acceleration3DAvailable" xreflabel="IHost::acceleration3DAvailable"/></entry>
4315 </row>
4316 <row>
4317 <entry>IGuestOSType::recommendedPae</entry>
4318 <entry><xref linkend="IGuestOSType__recommendedPAE" xreflabel="IGuestOSType::recommendedPAE"/></entry>
4319 </row>
4320 <row>
4321 <entry>IGuestOSType::recommendedDvdStorageController</entry>
4322 <entry><xref linkend="IGuestOSType__recommendedDVDStorageController" xreflabel="IGuestOSType::recommendedDVDStorageController"/></entry>
4323 </row>
4324 <row>
4325 <entry>IGuestOSType::recommendedDvdStorageBus</entry>
4326 <entry><xref linkend="IGuestOSType__recommendedDVDStorageBus" xreflabel="IGuestOSType::recommendedDVDStorageBus"/></entry>
4327 </row>
4328 <row>
4329 <entry>IGuestOSType::recommendedHdStorageController</entry>
4330 <entry><xref linkend="IGuestOSType__recommendedHDStorageController" xreflabel="IGuestOSType::recommendedHDStorageController"/></entry>
4331 </row>
4332 <row>
4333 <entry>IGuestOSType::recommendedHdStorageBus</entry>
4334 <entry><xref linkend="IGuestOSType__recommendedHDStorageBus" xreflabel="IGuestOSType::recommendedHDStorageBus"/></entry>
4335 </row>
4336 <row>
4337 <entry>IGuestOSType::recommendedUsbHid</entry>
4338 <entry><xref linkend="IGuestOSType__recommendedUSBHID" xreflabel="IGuestOSType::recommendedUSBHID"/></entry>
4339 </row>
4340 <row>
4341 <entry>IGuestOSType::recommendedHpet</entry>
4342 <entry><xref linkend="IGuestOSType__recommendedHPET" xreflabel="IGuestOSType::recommendedHPET"/></entry>
4343 </row>
4344 <row>
4345 <entry>IGuestOSType::recommendedUsbTablet</entry>
4346 <entry><xref linkend="IGuestOSType__recommendedUSBTablet" xreflabel="IGuestOSType::recommendedUSBTablet"/></entry>
4347 </row>
4348 <row>
4349 <entry>IGuestOSType::recommendedRtcUseUtc</entry>
4350 <entry><xref linkend="IGuestOSType__recommendedRTCUseUTC" xreflabel="IGuestOSType::recommendedRTCUseUTC"/></entry>
4351 </row>
4352 <row>
4353 <entry>IGuestOSType::recommendedUsb</entry>
4354 <entry><xref linkend="IGuestOSType__recommendedUSB" xreflabel="IGuestOSType::recommendedUSB"/></entry>
4355 </row>
4356 <row>
4357 <entry>INetworkAdapter::natDriver</entry>
4358 <entry><xref linkend="INetworkAdapter__NATEngine" xreflabel="INetworkAdapter::NATEngine"/></entry>
4359 </row>
4360 <row>
4361 <entry>IUSBController::enabledEhci</entry>
4362 <entry>IUSBController::enabledEHCI"</entry>
4363 </row>
4364 <row>
4365 <entry>INATEngine::tftpPrefix</entry>
4366 <entry><xref linkend="INATEngine__TFTPPrefix" xreflabel="INATEngine::TFTPPrefix"/></entry>
4367 </row>
4368 <row>
4369 <entry>INATEngine::tftpBootFile</entry>
4370 <entry><xref linkend="INATEngine__TFTPBootFile" xreflabel="INATEngine::TFTPBootFile"/></entry>
4371 </row>
4372 <row>
4373 <entry>INATEngine::tftpNextServer</entry>
4374 <entry><xref linkend="INATEngine__TFTPNextServer" xreflabel="INATEngine::TFTPNextServer"/></entry>
4375 </row>
4376 <row>
4377 <entry>INATEngine::dnsPassDomain</entry>
4378 <entry><xref linkend="INATEngine__DNSPassDomain" xreflabel="INATEngine::DNSPassDomain"/></entry>
4379 </row>
4380 <row>
4381 <entry>INATEngine::dnsProxy</entry>
4382 <entry><xref linkend="INATEngine__DNSProxy" xreflabel="INATEngine::DNSProxy"/></entry>
4383 </row>
4384 <row>
4385 <entry>INATEngine::dnsUseHostResolver</entry>
4386 <entry><xref linkend="INATEngine__DNSUseHostResolver" xreflabel="INATEngine::DNSUseHostResolver"/></entry>
4387 </row>
4388 <row>
4389 <entry>VBoxEventType::OnHostPciDevicePlug</entry>
4390 <entry><xref linkend="VBoxEventType__OnHostPCIDevicePlug" xreflabel="VBoxEventType::OnHostPCIDevicePlug"/></entry>
4391 </row>
4392 <row>
4393 <entry>ICPUChangedEvent::cpu</entry>
4394 <entry><xref linkend="ICPUChangedEvent__CPU" xreflabel="ICPUChangedEvent::CPU"/></entry>
4395 </row>
4396 <row>
4397 <entry>INATRedirectEvent::hostIp</entry>
4398 <entry><xref linkend="INATRedirectEvent__hostIP" xreflabel="INATRedirectEvent::hostIP"/></entry>
4399 </row>
4400 <row>
4401 <entry>INATRedirectEvent::guestIp</entry>
4402 <entry><xref linkend="INATRedirectEvent__guestIP" xreflabel="INATRedirectEvent::guestIP"/></entry>
4403 </row>
4404 <row>
4405 <entry>IHostPciDevicePlugEvent</entry>
4406 <entry><xref linkend="IHostPCIDevicePlugEvent" xreflabel="IHostPCIDevicePlugEvent"/></entry>
4407 </row>
4408 </tbody>
4409 </tgroup></table></para>
4410 </listitem>
4411 </itemizedlist>
4412 </sect1>
4413
4414 <sect1>
4415 <title>Incompatible API changes with version 4.1</title>
4416
4417 <itemizedlist>
4418 <listitem>
4419 <para>The method <xref linkend="IAppliance__importMachines"
4420 xreflabel="IAppliance::importMachines()" /> has one more parameter
4421 now, which allows to configure the import process in more detail.
4422 </para>
4423 </listitem>
4424
4425 <listitem>
4426 <para>The method <xref linkend="IVirtualBox__openMedium"
4427 xreflabel="IVirtualBox::openMedium()" /> has one more parameter
4428 now, which allows resolving duplicate medium UUIDs without the need
4429 for external tools.</para>
4430 </listitem>
4431
4432 <listitem>
4433 <para>The <xref linkend="INetworkAdapter" xreflabel="INetworkAdapter"/>
4434 interface has been cleaned up. The various methods to activate an
4435 attachment type have been replaced by the
4436 <xref linkend="INetworkAdapter__attachmentType" xreflabel="INetworkAdapter::attachmentType"/> setter.</para>
4437 <para>Additionally each attachment mode now has its own attribute,
4438 which means that host only networks no longer share the settings with
4439 bridged interfaces.</para>
4440 <para>To allow introducing new network attachment implementations
4441 without making API changes, the concept of a generic network
4442 attachment driver has been introduced, which is configurable through
4443 key/value properties.</para>
4444 </listitem>
4445
4446 <listitem>
4447 <para>This version introduces the guest facilities concept. A guest
4448 facility either represents a module or feature the guest is running or
4449 offering, which is defined by <xref linkend="AdditionsFacilityType"
4450 xreflabel="AdditionsFacilityType"/>. Each facility is member of a
4451 <xref linkend="AdditionsFacilityClass" xreflabel="AdditionsFacilityClass"/>
4452 and has a current status indicated by <xref linkend="AdditionsFacilityStatus"
4453 xreflabel="AdditionsFacilityStatus"/>, together with a timestamp (in ms) of
4454 the last status update.</para>
4455 <para>To address the above concept, the following changes were made:
4456 <itemizedlist>
4457 <listitem>
4458 <para>
4459 In the <xref linkend="IGuest" xreflabel="IGuest"/> interface, the following were removed:
4460 <itemizedlist>
4461 <listitem>
4462 <para>the <computeroutput>supportsSeamless</computeroutput> attribute;</para>
4463 </listitem>
4464 <listitem>
4465 <para>the <computeroutput>supportsGraphics</computeroutput> attribute;</para>
4466 </listitem>
4467 </itemizedlist>
4468 </para>
4469 </listitem>
4470 <listitem>
4471 <para>
4472 The function <xref linkend="IGuest__getFacilityStatus" xreflabel="IGuest::getFacilityStatus()"/>
4473 was added. It quickly provides a facility's status without the need to get the facility
4474 collection with <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>.
4475 </para>
4476 </listitem>
4477 <listitem>
4478 <para>
4479 The attribute <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>
4480 was added to provide an easy to access collection of all currently known guest
4481 facilities, that is, it contains all facilies where at least one status update was
4482 made since the guest was started.
4483 </para>
4484 </listitem>
4485 <listitem>
4486 <para>
4487 The interface <xref linkend="IAdditionsFacility" xreflabel="IAdditionsFacility"/>
4488 was added to represent a single facility returned by
4489 <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>.
4490 </para>
4491 </listitem>
4492 <listitem>
4493 <para>
4494 <xref linkend="AdditionsFacilityStatus" xreflabel="AdditionsFacilityStatus"/>
4495 was added to represent a facility's overall status.
4496 </para>
4497 </listitem>
4498 <listitem>
4499 <para>
4500 <xref linkend="AdditionsFacilityType" xreflabel="AdditionsFacilityType"/> and
4501 <xref linkend="AdditionsFacilityClass" xreflabel="AdditionsFacilityClass"/> were
4502 added to represent the facility's type and class.
4503 </para>
4504 </listitem>
4505 </itemizedlist>
4506 </para>
4507 </listitem>
4508 </itemizedlist>
4509 </sect1>
4510
4511 <sect1>
4512 <title>Incompatible API changes with version 4.0</title>
4513
4514 <itemizedlist>
4515 <listitem>
4516 <para>A new Java glue layer replacing the previous OOWS JAX-WS
4517 bindings was introduced. The new library allows for uniform code
4518 targeting both local (COM/XPCOM) and remote (SOAP) transports. Now,
4519 instead of <computeroutput>IWebsessionManager</computeroutput>, the
4520 new class <computeroutput>VirtualBoxManager</computeroutput> must be
4521 used. See <xref linkend="javaapi" xreflabel="Java API chapter" />
4522 for details.</para>
4523 </listitem>
4524
4525 <listitem>
4526 <para>The confusingly named and impractical session APIs were
4527 changed. In existing client code, the following changes need to be
4528 made:<itemizedlist>
4529 <listitem>
4530 <para>Replace any
4531 <computeroutput>IVirtualBox::openSession(uuidMachine,
4532 ...)</computeroutput> API call with the machine's <xref
4533 linkend="IMachine__lockMachine"
4534 xreflabel="IMachine::lockMachine()" /> call and a
4535 <computeroutput>LockType.Write</computeroutput> argument. The
4536 functionality is unchanged, but instead of "opening a direct
4537 session on a machine" all documentation now refers to
4538 "obtaining a write lock on a machine for the client
4539 session".</para>
4540 </listitem>
4541
4542 <listitem>
4543 <para>Similarly, replace any
4544 <computeroutput>IVirtualBox::openExistingSession(uuidMachine,
4545 ...)</computeroutput> call with the machine's <xref
4546 linkend="IMachine__lockMachine"
4547 xreflabel="IMachine::lockMachine()" /> call and a
4548 <computeroutput>LockType.Shared</computeroutput> argument.
4549 Whereas it was previously impossible to connect a client
4550 session to a running VM process in a race-free manner, the new
4551 API will atomically either write-lock the machine for the
4552 current session or establish a remote link to an existing
4553 session. Existing client code which tried calling both
4554 <computeroutput>openSession()</computeroutput> and
4555 <computeroutput>openExistingSession()</computeroutput> can now
4556 use this one call instead.</para>
4557 </listitem>
4558
4559 <listitem>
4560 <para>Third, replace any
4561 <computeroutput>IVirtualBox::openRemoteSession(uuidMachine,
4562 ...)</computeroutput> call with the machine's <xref
4563 linkend="IMachine__launchVMProcess"
4564 xreflabel="IMachine::launchVMProcess()" /> call. The
4565 functionality is unchanged.</para>
4566 </listitem>
4567
4568 <listitem>
4569 <para>The <xref linkend="SessionState"
4570 xreflabel="SessionState" /> enum was adjusted accordingly:
4571 "Open" is now "Locked", "Closed" is now "Unlocked", "Closing"
4572 is now "Unlocking".</para>
4573 </listitem>
4574 </itemizedlist></para>
4575 </listitem>
4576
4577 <listitem>
4578 <para>Virtual machines created with VirtualBox 4.0 or later no
4579 longer register their media in the global media registry in the
4580 <computeroutput>VirtualBox.xml</computeroutput> file. Instead, such
4581 machines list all their media in their own machine XML files. As a
4582 result, a number of media-related APIs had to be modified again.
4583 <itemizedlist>
4584 <listitem>
4585 <para>Neither <xref linkend="IVirtualBox__createHardDisk"
4586 xreflabel="IVirtualBox::createHardDisk()" /> nor <xref
4587 linkend="IVirtualBox__openMedium"
4588 xreflabel="IVirtualBox::openMedium()" /> register media
4589 automatically any more.</para>
4590 </listitem>
4591
4592 <listitem>
4593 <para><xref linkend="IMachine__attachDevice"
4594 xreflabel="IMachine::attachDevice()" /> and <xref
4595 linkend="IMachine__mountMedium"
4596 xreflabel="IMachine::mountMedium()" /> now take an IMedium
4597 object instead of a UUID as an argument. It is these two calls
4598 which add media to a registry now (either a machine registry
4599 for machines created with VirtualBox 4.0 or later or the
4600 global registry otherwise). As a consequence, if a medium is
4601 opened but never attached to a machine, it is no longer added
4602 to any registry any more.</para>
4603 </listitem>
4604
4605 <listitem>
4606 <para>To reduce code duplication, the APIs
4607 IVirtualBox::findHardDisk(), getHardDisk(), findDVDImage(),
4608 getDVDImage(), findFloppyImage() and getFloppyImage() have all
4609 been merged into IVirtualBox::findMedium(), and
4610 IVirtualBox::openHardDisk(), openDVDImage() and
4611 openFloppyImage() have all been merged into <xref
4612 linkend="IVirtualBox__openMedium"
4613 xreflabel="IVirtualBox::openMedium()" />.</para>
4614 </listitem>
4615
4616 <listitem>
4617 <para>The rare use case of changing the UUID and parent UUID
4618 of a medium previously handled by
4619 <computeroutput>openHardDisk()</computeroutput> is now in a
4620 separate IMedium::setIDs method.</para>
4621 </listitem>
4622
4623 <listitem>
4624 <para><computeroutput>ISystemProperties::get/setDefaultHardDiskFolder()</computeroutput>
4625 have been removed since disk images are now by default placed
4626 in each machine's folder.</para>
4627 </listitem>
4628
4629 <listitem>
4630 <para>The <xref linkend="ISystemProperties__infoVDSize"
4631 xreflabel="ISystemProperties::infoVDSize" /> attribute
4632 replaces the <computeroutput>getMaxVDISize()</computeroutput>
4633 API call; this now uses bytes instead of megabytes.</para>
4634 </listitem>
4635 </itemizedlist></para>
4636 </listitem>
4637
4638 <listitem>
4639 <para>Machine management APIs were enhanced as follows:<itemizedlist>
4640 <listitem>
4641 <para><xref linkend="IVirtualBox__createMachine"
4642 xreflabel="IVirtualBox::createMachine()" /> is no longer
4643 restricted to creating machines in the default "Machines"
4644 folder, but can now create machines at arbitrary locations.
4645 For this to work, the parameter list had to be changed.</para>
4646 </listitem>
4647
4648 <listitem>
4649 <para>The long-deprecated
4650 <computeroutput>IVirtualBox::createLegacyMachine()</computeroutput>
4651 API has been removed.</para>
4652 </listitem>
4653
4654 <listitem>
4655 <para>To reduce code duplication and for consistency with the
4656 aforementioned media APIs,
4657 <computeroutput>IVirtualBox::getMachine()</computeroutput> has
4658 been merged with <xref linkend="IVirtualBox__findMachine"
4659 xreflabel="IVirtualBox::findMachine()" />, and
4660 <computeroutput>IMachine::getSnapshot()</computeroutput> has
4661 been merged with <xref linkend="IMachine__findSnapshot"
4662 xreflabel="IMachine::findSnapshot()" />.</para>
4663 </listitem>
4664
4665 <listitem>
4666 <para><computeroutput>IVirtualBox::unregisterMachine()</computeroutput>
4667 was replaced with <xref linkend="IMachine__unregister"
4668 xreflabel="IMachine::unregister()" /> with additional
4669 functionality for cleaning up machine files.</para>
4670 </listitem>
4671
4672 <listitem>
4673 <para><computeroutput>IConsole::forgetSavedState</computeroutput>
4674 has been renamed to <xref
4675 linkend="IConsole__discardSavedState"
4676 xreflabel="IConsole::discardSavedState()" />.</para>
4677 </listitem>
4678 </itemizedlist></para>
4679 </listitem>
4680
4681 <listitem>
4682 <para>All event callbacks APIs were replaced with a new, generic
4683 event mechanism that can be used both locally (COM, XPCOM) and
4684 remotely (web services). Also, the new mechanism is usable from
4685 scripting languages and a local Java. See <xref linkend="IEvent"
4686 xreflabel="events" /> for details. The new concept will require
4687 changes to all clients that used event callbacks.</para>
4688 </listitem>
4689
4690 <listitem>
4691 <para><computeroutput>additionsActive()</computeroutput> was
4692 replaced with <xref linkend="IGuest__additionsRunLevel"
4693 xreflabel="additionsRunLevel()" /> and <xref
4694 linkend="IGuest__getAdditionsStatus"
4695 xreflabel="getAdditionsStatus()" /> in order to support a more
4696 detailed status of the current Guest Additions loading/readiness
4697 state. <xref linkend="IGuest__additionsVersion"
4698 xreflabel="IGuest::additionsVersion()" /> no longer returns the
4699 Guest Additions interface version but the installed Guest Additions
4700 version and revision in form of
4701 <computeroutput>3.3.0r12345</computeroutput>.</para>
4702 </listitem>
4703
4704 <listitem>
4705 <para>To address shared folders auto-mounting support, the following
4706 APIs were extended to require an additional
4707 <computeroutput>automount</computeroutput> parameter: <itemizedlist>
4708 <listitem>
4709 <para><xref linkend="IVirtualBox__createSharedFolder"
4710 xreflabel="IVirtualBox::createSharedFolder()" /></para>
4711 </listitem>
4712
4713 <listitem>
4714 <para><xref linkend="IMachine__createSharedFolder"
4715 xreflabel="IMachine::createSharedFolder()" /></para>
4716 </listitem>
4717
4718 <listitem>
4719 <para><xref linkend="IConsole__createSharedFolder"
4720 xreflabel="IConsole::createSharedFolder()" /></para>
4721 </listitem>
4722 </itemizedlist> Also, a new property named
4723 <computeroutput>autoMount</computeroutput> was added to the <xref
4724 linkend="ISharedFolder" xreflabel="ISharedFolder" />
4725 interface.</para>
4726 </listitem>
4727
4728 <listitem>
4729 <para>The appliance (OVF) APIs were enhanced as
4730 follows:<itemizedlist>
4731 <listitem>
4732 <para><computeroutput>IMachine::export</computeroutput>
4733 received an extra parameter
4734 <computeroutput>location</computeroutput>, which is used to
4735 decide for the disk naming.</para>
4736 </listitem>
4737
4738 <listitem>
4739 <para><xref linkend="IAppliance__write"
4740 xreflabel="IAppliance::write()" /> received an extra parameter
4741 <computeroutput>manifest</computeroutput>, which can suppress
4742 creating the manifest file on export.</para>
4743 </listitem>
4744
4745 <listitem>
4746 <para><xref linkend="IVFSExplorer__entryList"
4747 xreflabel="IVFSExplorer::entryList()" /> received two extra
4748 parameters <computeroutput>sizes</computeroutput> and
4749 <computeroutput>modes</computeroutput>, which contains the
4750 sizes (in bytes) and the file access modes (in octal form) of
4751 the returned files.</para>
4752 </listitem>
4753 </itemizedlist></para>
4754 </listitem>
4755
4756 <listitem>
4757 <para>Support for remote desktop access to virtual machines has been
4758 cleaned up to allow third party implementations of the remote
4759 desktop server. This is called the VirtualBox Remote Desktop
4760 Extension (VRDE) and can be added to VirtualBox by installing the
4761 corresponding extension package; see the VirtualBox User Manual for
4762 details.</para>
4763
4764 <para>The following API changes were made to support the VRDE
4765 interface: <itemizedlist>
4766 <listitem>
4767 <para><computeroutput>IVRDPServer</computeroutput> has been
4768 renamed to <xref linkend="IVRDEServer"
4769 xreflabel="IVRDEServer" />.</para>
4770 </listitem>
4771
4772 <listitem>
4773 <para><computeroutput>IRemoteDisplayInfo</computeroutput> has
4774 been renamed to <xref linkend="IVRDEServerInfo"
4775 xreflabel="IVRDEServerInfo" />.</para>
4776 </listitem>
4777
4778 <listitem>
4779 <para><xref linkend="IMachine__VRDEServer"
4780 xreflabel="IMachine::VRDEServer" /> replaces
4781 <computeroutput>VRDPServer.</computeroutput></para>
4782 </listitem>
4783
4784 <listitem>
4785 <para><xref linkend="IConsole__VRDEServerInfo"
4786 xreflabel="IConsole::VRDEServerInfo" /> replaces
4787 <computeroutput>RemoteDisplayInfo</computeroutput>.</para>
4788 </listitem>
4789
4790 <listitem>
4791 <para><xref linkend="ISystemProperties__VRDEAuthLibrary"
4792 xreflabel="ISystemProperties::VRDEAuthLibrary" /> replaces
4793 <computeroutput>RemoteDisplayAuthLibrary</computeroutput>.</para>
4794 </listitem>
4795
4796 <listitem>
4797 <para>The following methods have been implemented in
4798 <computeroutput>IVRDEServer</computeroutput> to support
4799 generic VRDE properties: <itemizedlist>
4800 <listitem>
4801 <para><xref linkend="IVRDEServer__setVRDEProperty"
4802 xreflabel="IVRDEServer::setVRDEProperty" /></para>
4803 </listitem>
4804
4805 <listitem>
4806 <para><xref linkend="IVRDEServer__getVRDEProperty"
4807 xreflabel="IVRDEServer::getVRDEProperty" /></para>
4808 </listitem>
4809
4810 <listitem>
4811 <para><xref linkend="IVRDEServer__VRDEProperties"
4812 xreflabel="IVRDEServer::VRDEProperties" /></para>
4813 </listitem>
4814 </itemizedlist></para>
4815
4816 <para>A few implementation-specific attributes of the old
4817 <computeroutput>IVRDPServer</computeroutput> interface have
4818 been removed and replaced with properties: <itemizedlist>
4819 <listitem>
4820 <para><computeroutput>IVRDPServer::Ports</computeroutput>
4821 has been replaced with the
4822 <computeroutput>"TCP/Ports"</computeroutput> property.
4823 The property value is a string, which contains a
4824 comma-separated list of ports or ranges of ports. Use a
4825 dash between two port numbers to specify a range.
4826 Example:
4827 <computeroutput>"5000,5010-5012"</computeroutput></para>
4828 </listitem>
4829
4830 <listitem>
4831 <para><computeroutput>IVRDPServer::NetAddress</computeroutput>
4832 has been replaced with the
4833 <computeroutput>"TCP/Address"</computeroutput> property.
4834 The property value is an IP address string. Example:
4835 <computeroutput>"127.0.0.1"</computeroutput></para>
4836 </listitem>
4837
4838 <listitem>
4839 <para><computeroutput>IVRDPServer::VideoChannel</computeroutput>
4840 has been replaced with the
4841 <computeroutput>"VideoChannel/Enabled"</computeroutput>
4842 property. The property value is either
4843 <computeroutput>"true"</computeroutput> or
4844 <computeroutput>"false"</computeroutput></para>
4845 </listitem>
4846
4847 <listitem>
4848 <para><computeroutput>IVRDPServer::VideoChannelQuality</computeroutput>
4849 has been replaced with the
4850 <computeroutput>"VideoChannel/Quality"</computeroutput>
4851 property. The property value is a string which contain a
4852 decimal number in range 10..100. Invalid values are
4853 ignored and the quality is set to the default value 75.
4854 Example: <computeroutput>"50"</computeroutput></para>
4855 </listitem>
4856 </itemizedlist></para>
4857 </listitem>
4858 </itemizedlist></para>
4859 </listitem>
4860
4861 <listitem>
4862 <para>The VirtualBox external authentication module interface has
4863 been updated and made more generic. Because of that,
4864 <computeroutput>VRDPAuthType</computeroutput> enumeration has been
4865 renamed to <xref linkend="AuthType" xreflabel="AuthType" />.</para>
4866 </listitem>
4867 </itemizedlist>
4868 </sect1>
4869
4870 <sect1>
4871 <title>Incompatible API changes with version 3.2</title>
4872
4873 <itemizedlist>
4874 <listitem>
4875 <para>The following interfaces were renamed for consistency:
4876 <itemizedlist>
4877 <listitem>
4878 <para>IMachine::getCpuProperty() is now <xref
4879 linkend="IMachine__getCPUProperty"
4880 xreflabel="IMachine::getCPUProperty()" />;</para>
4881 </listitem>
4882
4883 <listitem>
4884 <para>IMachine::setCpuProperty() is now <xref
4885 linkend="IMachine__setCPUProperty"
4886 xreflabel="IMachine::setCPUProperty()" />;</para>
4887 </listitem>
4888
4889 <listitem>
4890 <para>IMachine::getCpuIdLeaf() is now <xref
4891 linkend="IMachine__getCPUIDLeaf"
4892 xreflabel="IMachine::getCPUIDLeaf()" />;</para>
4893 </listitem>
4894
4895 <listitem>
4896 <para>IMachine::setCpuIdLeaf() is now <xref
4897 linkend="IMachine__setCPUIDLeaf"
4898 xreflabel="IMachine::setCPUIDLeaf()" />;</para>
4899 </listitem>
4900
4901 <listitem>
4902 <para>IMachine::removeCpuIdLeaf() is now <xref
4903 linkend="IMachine__removeCPUIDLeaf"
4904 xreflabel="IMachine::removeCPUIDLeaf()" />;</para>
4905 </listitem>
4906
4907 <listitem>
4908 <para>IMachine::removeAllCpuIdLeafs() is now <xref
4909 linkend="IMachine__removeAllCPUIDLeaves"
4910 xreflabel="IMachine::removeAllCPUIDLeaves()" />;</para>
4911 </listitem>
4912
4913 <listitem>
4914 <para>the CpuPropertyType enum is now <xref
4915 linkend="CPUPropertyType"
4916 xreflabel="CPUPropertyType" />.</para>
4917 </listitem>
4918
4919 <listitem>
4920 <para>IVirtualBoxCallback::onSnapshotDiscarded() is now
4921 IVirtualBoxCallback::onSnapshotDeleted.</para>
4922 </listitem>
4923 </itemizedlist></para>
4924 </listitem>
4925
4926 <listitem>
4927 <para>When creating a VM configuration with <xref
4928 linkend="IVirtualBox__createMachine"
4929 xreflabel="IVirtualBox::createMachine" />) it is now possible to
4930 ignore existing configuration files which would previously have
4931 caused a failure. For this the
4932 <computeroutput>override</computeroutput> parameter was
4933 added.</para>
4934 </listitem>
4935
4936 <listitem>
4937 <para>Deleting snapshots via <xref
4938 linkend="IConsole__deleteSnapshot"
4939 xreflabel="IConsole::deleteSnapshot()" /> is now possible while the
4940 associated VM is running in almost all cases. The API is unchanged,
4941 but client code that verifies machine states to determine whether
4942 snapshots can be deleted may need to be adjusted.</para>
4943 </listitem>
4944
4945 <listitem>
4946 <para>The IoBackendType enumeration was replaced with a boolean flag
4947 (see <xref linkend="IStorageController__useHostIOCache"
4948 xreflabel="IStorageController::useHostIOCache" />).</para>
4949 </listitem>
4950
4951 <listitem>
4952 <para>To address multi-monitor support, the following APIs were
4953 extended to require an additional
4954 <computeroutput>screenId</computeroutput> parameter: <itemizedlist>
4955 <listitem>
4956 <para><xref linkend="IMachine__querySavedThumbnailSize"
4957 xreflabel="IMachine::querySavedThumbnailSize()" /></para>
4958 </listitem>
4959
4960 <listitem>
4961 <para><xref linkend="IMachine__readSavedThumbnailToArray"
4962 xreflabel="IMachine::readSavedThumbnailToArray()" /></para>
4963 </listitem>
4964
4965 <listitem>
4966 <para><xref linkend="IMachine__querySavedScreenshotPNGSize"
4967 xreflabel="IMachine::querySavedScreenshotPNGSize()" /></para>
4968 </listitem>
4969
4970 <listitem>
4971 <para><xref linkend="IMachine__readSavedScreenshotPNGToArray"
4972 xreflabel="IMachine::readSavedScreenshotPNGToArray()" /></para>
4973 </listitem>
4974 </itemizedlist></para>
4975 </listitem>
4976
4977 <listitem>
4978 <para>The <computeroutput>shape</computeroutput> parameter of
4979 IConsoleCallback::onMousePointerShapeChange was changed from a
4980 implementation-specific pointer to a safearray, enabling scripting
4981 languages to process pointer shapes.</para>
4982 </listitem>
4983 </itemizedlist>
4984 </sect1>
4985
4986 <sect1>
4987 <title>Incompatible API changes with version 3.1</title>
4988
4989 <itemizedlist>
4990 <listitem>
4991 <para>Due to the new flexibility in medium attachments that was
4992 introduced with version 3.1 (in particular, full flexibility with
4993 attaching CD/DVD drives to arbitrary controllers), we seized the
4994 opportunity to rework all interfaces dealing with storage media to
4995 make the API more flexible as well as logical. The <xref
4996 linkend="IStorageController" xreflabel="IStorageController" />,
4997 <xref linkend="IMedium" xreflabel="IMedium" />, <xref
4998 linkend="IMediumAttachment" xreflabel="IMediumAttachment" /> and,
4999 <xref linkend="IMachine" xreflabel="IMachine" /> interfaces were
5000 affected the most. Existing code using them to configure storage and
5001 media needs to be carefully checked.</para>
5002
5003 <para>All media (hard disks, floppies and CDs/DVDs) are now
5004 uniformly handled through the <xref linkend="IMedium"
5005 xreflabel="IMedium" /> interface. The device-specific interfaces
5006 (<code>IHardDisk</code>, <code>IDVDImage</code>,
5007 <code>IHostDVDDrive</code>, <code>IFloppyImage</code> and
5008 <code>IHostFloppyDrive</code>) have been merged into IMedium; CD/DVD
5009 and floppy media no longer need special treatment. The device type
5010 of a medium determines in which context it can be used. Some
5011 functionality was moved to the other storage-related
5012 interfaces.</para>
5013
5014 <para><code>IMachine::attachHardDisk</code> and similar methods have
5015 been renamed and generalized to deal with any type of drive and
5016 medium. <xref linkend="IMachine__attachDevice"
5017 xreflabel="IMachine::attachDevice()" /> is the API method for adding
5018 any drive to a storage controller. The floppy and DVD/CD drives are
5019 no longer handled specially, and that means you can have more than
5020 one of them. As before, drives can only be changed while the VM is
5021 powered off. Mounting (or unmounting) removable media at runtime is
5022 possible with <xref linkend="IMachine__mountMedium"
5023 xreflabel="IMachine::mountMedium()" />.</para>
5024
5025 <para>Newly created virtual machines have no storage controllers
5026 associated with them. Even the IDE Controller needs to be created
5027 explicitly. The floppy controller is now visible as a separate
5028 controller, with a new storage bus type. For each storage bus type
5029 you can query the device types which can be attached, so that it is
5030 not necessary to hardcode any attachment rules.</para>
5031
5032 <para>This required matching changes e.g. in the callback interfaces
5033 (the medium specific change notification was replaced by a generic
5034 medium change notification) and removing associated enums (e.g.
5035 <code>DriveState</code>). In many places the incorrect use of the
5036 plural form "media" was replaced by "medium", to improve
5037 consistency.</para>
5038 </listitem>
5039
5040 <listitem>
5041 <para>Reading the <xref linkend="IMedium__state"
5042 xreflabel="IMedium::state" /> attribute no longer
5043 automatically performs an accessibility check; a new method <xref
5044 linkend="IMedium__refreshState"
5045 xreflabel="IMedium::refreshState()" /> does this. The attribute only
5046 returns the state any more.</para>
5047 </listitem>
5048
5049 <listitem>
5050 <para>There were substantial changes related to snapshots, triggered
5051 by the "branched snapshots" functionality introduced with version
5052 3.1. IConsole::discardSnapshot was renamed to <xref
5053 linkend="IConsole__deleteSnapshot"
5054 xreflabel="IConsole::deleteSnapshot()" />.
5055 IConsole::discardCurrentState and
5056 IConsole::discardCurrentSnapshotAndState were removed; corresponding
5057 new functionality is in <xref linkend="IConsole__restoreSnapshot"
5058 xreflabel="IConsole::restoreSnapshot()" />. Also, when <xref
5059 linkend="IConsole__takeSnapshot"
5060 xreflabel="IConsole::takeSnapshot()" /> is called on a running
5061 virtual machine, a live snapshot will be created. The old behavior
5062 was to temporarily pause the virtual machine while creating an
5063 online snapshot.</para>
5064 </listitem>
5065
5066 <listitem>
5067 <para>The <computeroutput>IVRDPServer</computeroutput>,
5068 <computeroutput>IRemoteDisplayInfo"</computeroutput> and
5069 <computeroutput>IConsoleCallback</computeroutput> interfaces were
5070 changed to reflect VRDP server ability to bind to one of available
5071 ports from a list of ports.</para>
5072
5073 <para>The <computeroutput>IVRDPServer::port</computeroutput>
5074 attribute has been replaced with
5075 <computeroutput>IVRDPServer::ports</computeroutput>, which is a
5076 comma-separated list of ports or ranges of ports.</para>
5077
5078 <para>An <computeroutput>IRemoteDisplayInfo::port"</computeroutput>
5079 attribute has been added for querying the actual port VRDP server
5080 listens on.</para>
5081
5082 <para>An IConsoleCallback::onRemoteDisplayInfoChange() notification
5083 callback has been added.</para>
5084 </listitem>
5085
5086 <listitem>
5087 <para>The parameter lists for the following functions were
5088 modified:<itemizedlist>
5089 <listitem>
5090 <para><xref linkend="IHost__removeHostOnlyNetworkInterface"
5091 xreflabel="IHost::removeHostOnlyNetworkInterface()" /></para>
5092 </listitem>
5093
5094 <listitem>
5095 <para><xref linkend="IHost__removeUSBDeviceFilter"
5096 xreflabel="IHost::removeUSBDeviceFilter()" /></para>
5097 </listitem>
5098 </itemizedlist></para>
5099 </listitem>
5100
5101 <listitem>
5102 <para>In the OOWS bindings for JAX-WS, the behavior of structures
5103 changed: for one, we implemented natural structures field access so
5104 you can just call a "get" method to obtain a field. Secondly,
5105 setters in structures were disabled as they have no expected effect
5106 and were at best misleading.</para>
5107 </listitem>
5108 </itemizedlist>
5109 </sect1>
5110
5111 <sect1>
5112 <title>Incompatible API changes with version 3.0</title>
5113
5114 <itemizedlist>
5115 <listitem>
5116 <para>In the object-oriented web service bindings for JAX-WS, proper
5117 inheritance has been introduced for some classes, so explicit
5118 casting is no longer needed to call methods from a parent class. In
5119 particular, IHardDisk and other classes now properly derive from
5120 <xref linkend="IMedium" xreflabel="IMedium" />.</para>
5121 </listitem>
5122
5123 <listitem>
5124 <para>All object identifiers (machines, snapshots, disks, etc)
5125 switched from GUIDs to strings (now still having string
5126 representation of GUIDs inside). As a result, no particular internal
5127 structure can be assumed for object identifiers; instead, they
5128 should be treated as opaque unique handles. This change mostly
5129 affects Java and C++ programs; for other languages, GUIDs are
5130 transparently converted to strings.</para>
5131 </listitem>
5132
5133 <listitem>
5134 <para>The uses of NULL strings have been changed greatly. All out
5135 parameters now use empty strings to signal a null value. For in
5136 parameters both the old NULL and empty string is allowed. This
5137 change was necessary to support more client bindings, especially
5138 using the web service API. Many of them either have no special NULL
5139 value or have trouble dealing with it correctly in the respective
5140 library code.</para>
5141 </listitem>
5142
5143 <listitem>
5144 <para>Accidentally, the <code>TSBool</code> interface still appeared
5145 in 3.0.0, and was removed in 3.0.2. This is an SDK bug, do not use
5146 the SDK for VirtualBox 3.0.0 for developing clients.</para>
5147 </listitem>
5148
5149 <listitem>
5150 <para>The type of <xref linkend="IVirtualBoxErrorInfo__resultCode"
5151 xreflabel="IVirtualBoxErrorInfo::resultCode" /> changed from
5152 <computeroutput>result</computeroutput> to
5153 <computeroutput>long</computeroutput>.</para>
5154 </listitem>
5155
5156 <listitem>
5157 <para>The parameter list of IVirtualBox::openHardDisk was
5158 changed.</para>
5159 </listitem>
5160
5161 <listitem>
5162 <para>The method IConsole::discardSavedState was renamed to
5163 IConsole::forgetSavedState, and a parameter was added.</para>
5164 </listitem>
5165
5166 <listitem>
5167 <para>The method IConsole::powerDownAsync was renamed to <xref
5168 linkend="IConsole__powerDown" xreflabel="IConsole::powerDown" />,
5169 and the previous method with that name was deleted. So effectively a
5170 parameter was added.</para>
5171 </listitem>
5172
5173 <listitem>
5174 <para>In the <xref linkend="IFramebuffer"
5175 xreflabel="IFramebuffer" /> interface, the following were
5176 removed:<itemizedlist>
5177 <listitem>
5178 <para>the <computeroutput>operationSupported</computeroutput>
5179 attribute;</para>
5180
5181 <para>(as a result, the
5182 <computeroutput>FramebufferAccelerationOperation</computeroutput>
5183 enum was no longer needed and removed as well);</para>
5184 </listitem>
5185
5186 <listitem>
5187 <para>the <computeroutput>solidFill()</computeroutput>
5188 method;</para>
5189 </listitem>
5190
5191 <listitem>
5192 <para>the <computeroutput>copyScreenBits()</computeroutput>
5193 method.</para>
5194 </listitem>
5195 </itemizedlist></para>
5196 </listitem>
5197
5198 <listitem>
5199 <para>In the <xref linkend="IDisplay" xreflabel="IDisplay" />
5200 interface, the following were removed:<itemizedlist>
5201 <listitem>
5202 <para>the
5203 <computeroutput>setupInternalFramebuffer()</computeroutput>
5204 method;</para>
5205 </listitem>
5206
5207 <listitem>
5208 <para>the <computeroutput>lockFramebuffer()</computeroutput>
5209 method;</para>
5210 </listitem>
5211
5212 <listitem>
5213 <para>the <computeroutput>unlockFramebuffer()</computeroutput>
5214 method;</para>
5215 </listitem>
5216
5217 <listitem>
5218 <para>the
5219 <computeroutput>registerExternalFramebuffer()</computeroutput>
5220 method.</para>
5221 </listitem>
5222 </itemizedlist></para>
5223 </listitem>
5224 </itemizedlist>
5225 </sect1>
5226
5227 <sect1>
5228 <title>Incompatible API changes with version 2.2</title>
5229
5230 <itemizedlist>
5231 <listitem>
5232 <para>Added explicit version number into JAX-WS Java package names,
5233 such as <computeroutput>org.virtualbox_2_2</computeroutput>,
5234 allowing connect to multiple VirtualBox clients from single Java
5235 application.</para>
5236 </listitem>
5237
5238 <listitem>
5239 <para>The interfaces having a "2" suffix attached to them with
5240 version 2.1 were renamed again to have that suffix removed. This
5241 time around, this change involves only the name, there are no
5242 functional differences.</para>
5243
5244 <para>As a result, IDVDImage2 is now IDVDImage; IHardDisk2 is now
5245 IHardDisk; IHardDisk2Attachment is now IHardDiskAttachment.</para>
5246
5247 <para>Consequentially, all related methods and attributes that had a
5248 "2" suffix have been renamed; for example, IMachine::attachHardDisk2
5249 now becomes IMachine::attachHardDisk().</para>
5250 </listitem>
5251
5252 <listitem>
5253 <para>IVirtualBox::openHardDisk has an extra parameter for opening a
5254 disk read/write or read-only.</para>
5255 </listitem>
5256
5257 <listitem>
5258 <para>The remaining collections were replaced by more performant
5259 safe-arrays. This affects the following collections:</para>
5260
5261 <itemizedlist>
5262 <listitem>
5263 <para>IGuestOSTypeCollection</para>
5264 </listitem>
5265
5266 <listitem>
5267 <para>IHostDVDDriveCollection</para>
5268 </listitem>
5269
5270 <listitem>
5271 <para>IHostFloppyDriveCollection</para>
5272 </listitem>
5273
5274 <listitem>
5275 <para>IHostUSBDeviceCollection</para>
5276 </listitem>
5277
5278 <listitem>
5279 <para>IHostUSBDeviceFilterCollection</para>
5280 </listitem>
5281
5282 <listitem>
5283 <para>IProgressCollection</para>
5284 </listitem>
5285
5286 <listitem>
5287 <para>ISharedFolderCollection</para>
5288 </listitem>
5289
5290 <listitem>
5291 <para>ISnapshotCollection</para>
5292 </listitem>
5293
5294 <listitem>
5295 <para>IUSBDeviceCollection</para>
5296 </listitem>
5297
5298 <listitem>
5299 <para>IUSBDeviceFilterCollection</para>
5300 </listitem>
5301 </itemizedlist>
5302 </listitem>
5303
5304 <listitem>
5305 <para>Since "Host Interface Networking" was renamed to "bridged
5306 networking" and host-only networking was introduced, all associated
5307 interfaces needed renaming as well. In detail:</para>
5308
5309 <itemizedlist>
5310 <listitem>
5311 <para>The HostNetworkInterfaceType enum has been renamed to
5312 <xref linkend="HostNetworkInterfaceMediumType"
5313 xreflabel="HostNetworkInterfaceMediumType" /></para>
5314 </listitem>
5315
5316 <listitem>
5317 <para>The IHostNetworkInterface::type attribute has been renamed
5318 to <xref linkend="IHostNetworkInterface__mediumType"
5319 xreflabel="IHostNetworkInterface::mediumType" /></para>
5320 </listitem>
5321
5322 <listitem>
5323 <para>INetworkAdapter::attachToHostInterface() has been renamed
5324 to INetworkAdapter::attachToBridgedInterface</para>
5325 </listitem>
5326
5327 <listitem>
5328 <para>In the IHost interface, createHostNetworkInterface() has
5329 been renamed to <xref
5330 linkend="IHost__createHostOnlyNetworkInterface"
5331 xreflabel="createHostOnlyNetworkInterface()" /></para>
5332 </listitem>
5333
5334 <listitem>
5335 <para>Similarly, removeHostNetworkInterface() has been renamed
5336 to <xref linkend="IHost__removeHostOnlyNetworkInterface"
5337 xreflabel="removeHostOnlyNetworkInterface()" /></para>
5338 </listitem>
5339 </itemizedlist>
5340 </listitem>
5341 </itemizedlist>
5342 </sect1>
5343
5344 <sect1>
5345 <title>Incompatible API changes with version 2.1</title>
5346
5347 <itemizedlist>
5348 <listitem>
5349 <para>With VirtualBox 2.1, error codes were added to many error
5350 infos that give the caller a machine-readable (numeric) feedback in
5351 addition to the error string that has always been available. This is
5352 an ongoing process, and future versions of this SDK reference will
5353 document the error codes for each method call.</para>
5354 </listitem>
5355
5356 <listitem>
5357 <para>The hard disk and other media interfaces were completely
5358 redesigned. This was necessary to account for the support of VMDK,
5359 VHD and other image types; since backwards compatibility had to be
5360 broken anyway, we seized the moment to redesign the interfaces in a
5361 more logical way.</para>
5362
5363 <itemizedlist>
5364 <listitem>
5365 <para>Previously, the old IHardDisk interface had several
5366 derivatives called IVirtualDiskImage, IVMDKImage, IVHDImage,
5367 IISCSIHardDisk and ICustomHardDisk for the various disk formats
5368 supported by VirtualBox. The new IHardDisk2 interface that comes
5369 with version 2.1 now supports all hard disk image formats
5370 itself.</para>
5371 </listitem>
5372
5373 <listitem>
5374 <para>IHardDiskFormat is a new interface to describe the
5375 available back-ends for hard disk images (e.g. VDI, VMDK, VHD or
5376 iSCSI). The IHardDisk2::format attribute can be used to find out
5377 the back-end that is in use for a particular hard disk image.
5378 ISystemProperties::hardDiskFormats[] contains a list of all
5379 back-ends supported by the system. <xref
5380 linkend="ISystemProperties__defaultHardDiskFormat"
5381 xreflabel="ISystemProperties::defaultHardDiskFormat" /> contains
5382 the default system format.</para>
5383 </listitem>
5384
5385 <listitem>
5386 <para>In addition, the new <xref linkend="IMedium"
5387 xreflabel="IMedium" /> interface is a generic interface for hard
5388 disk, DVD and floppy images that contains the attributes and
5389 methods shared between them. It can be considered a parent class
5390 of the more specific interfaces for those images, which are now
5391 IHardDisk2, IDVDImage2 and IFloppyImage2.</para>
5392
5393 <para>In each case, the "2" versions of these interfaces replace
5394 the earlier versions that did not have the "2" suffix.
5395 Previously, the IDVDImage and IFloppyImage interfaces were
5396 entirely unrelated to IHardDisk.</para>
5397 </listitem>
5398
5399 <listitem>
5400 <para>As a result, all parts of the API that previously
5401 referenced IHardDisk, IDVDImage or IFloppyImage or any of the
5402 old subclasses are gone and will have replacements that use
5403 IHardDisk2, IDVDImage2 and IFloppyImage2; see, for example,
5404 IMachine::attachHardDisk2.</para>
5405 </listitem>
5406
5407 <listitem>
5408 <para>In particular, the IVirtualBox::hardDisks2 array replaces
5409 the earlier IVirtualBox::hardDisks collection.</para>
5410 </listitem>
5411 </itemizedlist>
5412 </listitem>
5413
5414 <listitem>
5415 <para><xref linkend="IGuestOSType" xreflabel="IGuestOSType" /> was
5416 extended to group operating systems into families and for 64-bit
5417 support.</para>
5418 </listitem>
5419
5420 <listitem>
5421 <para>The <xref linkend="IHostNetworkInterface"
5422 xreflabel="IHostNetworkInterface" /> interface was completely
5423 rewritten to account for the changes in how Host Interface
5424 Networking is now implemented in VirtualBox 2.1.</para>
5425 </listitem>
5426
5427 <listitem>
5428 <para>The IVirtualBox::machines2[] array replaces the former
5429 IVirtualBox::machines collection.</para>
5430 </listitem>
5431
5432 <listitem>
5433 <para>Added <xref linkend="IHost__getProcessorFeature"
5434 xreflabel="IHost::getProcessorFeature()" /> and <xref
5435 linkend="ProcessorFeature" xreflabel="ProcessorFeature" />
5436 enumeration.</para>
5437 </listitem>
5438
5439 <listitem>
5440 <para>The parameter list for <xref
5441 linkend="IVirtualBox__createMachine"
5442 xreflabel="IVirtualBox::createMachine()" /> was modified.</para>
5443 </listitem>
5444
5445 <listitem>
5446 <para>Added IMachine::pushGuestProperty.</para>
5447 </listitem>
5448
5449 <listitem>
5450 <para>New attributes in IMachine: <xref
5451 linkend="IMachine__accelerate3DEnabled"
5452 xreflabel="accelerate3DEnabled" />, HWVirtExVPIDEnabled, <xref
5453 linkend="IMachine__guestPropertyNotificationPatterns"
5454 xreflabel="guestPropertyNotificationPatterns" />, <xref
5455 linkend="IMachine__CPUCount" xreflabel="CPUCount" />.</para>
5456 </listitem>
5457
5458 <listitem>
5459 <para>Added <xref linkend="IConsole__powerUpPaused"
5460 xreflabel="IConsole::powerUpPaused()" /> and <xref
5461 linkend="IConsole__getGuestEnteredACPIMode"
5462 xreflabel="IConsole::getGuestEnteredACPIMode()" />.</para>
5463 </listitem>
5464
5465 <listitem>
5466 <para>Removed ResourceUsage enumeration.</para>
5467 </listitem>
5468 </itemizedlist>
5469 </sect1>
5470 </chapter>
5471</book>
5472<!-- vim: set shiftwidth=2 tabstop=2 expandtab: -->
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette