VirtualBox

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

最後變更 在這個檔案從96388是 96301,由 vboxsync 提交於 3 年 前

doc: comment fixes

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

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