VirtualBox

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

Last change on this file since 100238 was 99783, checked in by vboxsync, 20 months ago

Guest Control/Main: Marked IGuestSession::waitFor() and IGuestProcess::waitFor() as being deprecated; we have the waitForArray() methods for that (don't use flags as parameters) [build fix]. bugref:9320

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