VirtualBox

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

Last change on this file since 81235 was 81093, checked in by vboxsync, 5 years ago

bugref:9555. Update SDK reference and user manual.

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

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