VirtualBox

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

Last change on this file since 93707 was 92823, checked in by vboxsync, 3 years ago

Guest Control: Resolved a @todo: Implemented DirectoryCopyFlag_Recursive + DirectoryCopyFlag_FollowLinks and no longer do this implicitly internally [SDK ref build fix].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 283.4 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 installation.</para>
1500
1501 <para>See <xref linkend="glue-python-setup"/> for details on how to
1502 set up the glue layer if you want to use a different Python installation,
1503 or if the VirtualBox installer failed to detect and set it up accordingly.</para>
1504
1505 <para>The minimum supported Python version is 2.6.</para>
1506
1507 <para>In this layer, the class
1508 <computeroutput>VirtualBoxManager</computeroutput> hides most
1509 platform-specific details. It can be used to access both the local
1510 (COM) and the web service based API. The following code can be used by
1511 an application to use the glue layer.</para>
1512
1513 <screen># This code assumes vboxapi.py from VirtualBox distribution
1514# being in PYTHONPATH, or installed system-wide
1515from vboxapi import VirtualBoxManager
1516
1517# This code initializes VirtualBox manager with default style
1518# and parameters
1519virtualBoxManager = VirtualBoxManager(None, None)
1520
1521# Alternatively, one can be more verbose, and initialize
1522# glue with web service backend, and provide authentication
1523# information
1524virtualBoxManager = VirtualBoxManager("WEBSERVICE",
1525 {'url':'http://myhost.com::18083/',
1526 'user':'me',
1527 'password':'secret'}) </screen>
1528
1529 <para>We supply the <computeroutput>VirtualBoxManager</computeroutput>
1530 constructor with 2 arguments: style and parameters. Style defines
1531 which bindings style to use (could be "MSCOM", "XPCOM" or
1532 "WEBSERVICE"), and if set to <computeroutput>None</computeroutput>
1533 defaults to usable platform bindings (MS COM on Windows, XPCOM on
1534 other platforms). The second argument defines parameters, passed to
1535 the platform-specific module, as we do in the second example, where we
1536 pass username and password to be used to authenticate against the web
1537 service.</para>
1538
1539 <para>After obtaining the
1540 <computeroutput>VirtualBoxManager</computeroutput> instance, one can
1541 perform operations on the IVirtualBox class. For example, the
1542 following code will a start virtual machine by name or ID:</para>
1543
1544 <screen>from vboxapi import VirtualBoxManager
1545mgr = VirtualBoxManager(None, None)
1546vbox = mgr.getVirtualBox()
1547name = "Linux"
1548mach = vbox.findMachine(name)
1549session = mgr.getSessionObject(vbox)
1550progress = mach.launchVMProcess(session, "gui", "")
1551progress.waitForCompletion(-1)
1552mgr.closeMachineSession(session)
1553 </screen>
1554 <para>
1555 Following code will print all registered machines and their log
1556 folders
1557 </para>
1558 <screen>from vboxapi import VirtualBoxManager
1559mgr = VirtualBoxManager(None, None)
1560vbox = mgr.getVirtualBox()
1561
1562for m in mgr.getArray(vbox, 'machines'):
1563 print "Machine '%s' logs in '%s'" %(m.name, m.logFolder)
1564 </screen>
1565
1566 <para>Code above demonstrates cross-platform access to array properties
1567 (certain limitations prevent one from using
1568 <computeroutput>vbox.machines</computeroutput> to access a list of
1569 available virtual machines in case of XPCOM), and a mechanism of
1570 uniform session creation and closing
1571 (<computeroutput>mgr.getSessionObject()</computeroutput>).</para>
1572
1573 <sect3 id="glue-python-setup">
1574 <title>Manual or subsequent setup</title>
1575
1576 <para>In case you want to use the glue layer with a different Python
1577 installation or the installer failed to set it up, use these steps
1578 in a shell to install the necessary files:</para>
1579
1580 <screen> # cd VBOX_INSTALL_PATH/sdk/installer
1581 # PYTHON vboxapisetup.py install</screen>
1582
1583 <note> <para>On Windows hosts, a Python distribution along with the
1584 win32api bindings package need to be installed as a prerequisite. </para></note>
1585 </sect3>
1586
1587 </sect2>
1588
1589 <sect2 id="cppcom">
1590 <title>C++ COM API</title>
1591
1592 <para>C++ is the language that VirtualBox itself is written in, so C++
1593 is the most direct way to use the Main API -- but it is not
1594 necessarily the easiest, as using COM and XPCOM has its own set of
1595 complications.</para>
1596
1597 <para>VirtualBox ships with sample programs that demonstrate how to
1598 use the Main API to implement a number of tasks on your host platform.
1599 These samples can be found in the
1600 <computeroutput>/bindings/xpcom/samples</computeroutput> directory for
1601 Linux, Mac OS X and Solaris and
1602 <computeroutput>/bindings/mscom/samples</computeroutput> for Windows.
1603 The two samples are actually different, because the one for Windows
1604 uses native COM, whereas the other uses our XPCOM implementation, as
1605 described above.</para>
1606
1607 <para>Since COM and XPCOM are conceptually very similar but vary in
1608 the implementation details, we have created a "glue" layer that
1609 shields COM client code from these differences. All VirtualBox uses is
1610 this glue layer, so the same code written once works on both Windows
1611 hosts (with native COM) as well as on other hosts (with our XPCOM
1612 implementation). It is recommended to always use this glue code
1613 instead of using the COM and XPCOM APIs directly, as it is very easy
1614 to make your code completely independent from the platform it is
1615 running on.<!-- A third sample,
1616 <computeroutput>tstVBoxAPIGlue.cpp</computeroutput>, illustrates how to
1617 use the glue layer.
1618--></para>
1619
1620 <para>In order to encapsulate platform differences between Microsoft
1621 COM and XPCOM, the following items should be kept in mind when using
1622 the glue layer:</para>
1623
1624 <para><orderedlist>
1625 <listitem>
1626 <para><emphasis role="bold">Attribute getters and
1627 setters.</emphasis> COM has the notion of "attributes" in
1628 interfaces, which roughly compare to C++ member variables in
1629 classes. The difference is that for each attribute declared in
1630 an interface, COM automatically provides a "get" method to
1631 return the attribute's value. Unless the attribute has been
1632 marked as "readonly", a "set" attribute is also provided.</para>
1633
1634 <para>To illustrate, the IVirtualBox interface has a "version"
1635 attribute, which is read-only and of the "wstring" type (the
1636 standard string type in COM). As a result, you can call the
1637 "get" method for this attribute to retrieve the version number
1638 of VirtualBox.</para>
1639
1640 <para>Unfortunately, the implementation differs between COM and
1641 XPCOM. Microsoft COM names the "get" method like this:
1642 <computeroutput>get_Attribute()</computeroutput>, whereas XPCOM
1643 uses this syntax:
1644 <computeroutput>GetAttribute()</computeroutput> (and accordingly
1645 for "set" methods). To hide these differences, the VirtualBox
1646 glue code provides the
1647 <computeroutput>COMGETTER(attrib)</computeroutput> and
1648 <computeroutput>COMSETTER(attrib)</computeroutput> macros. So,
1649 <computeroutput>COMGETTER(version)()</computeroutput> (note, two
1650 pairs of brackets) expands to
1651 <computeroutput>get_Version()</computeroutput> on Windows and
1652 <computeroutput>GetVersion()</computeroutput> on other
1653 platforms.</para>
1654 </listitem>
1655
1656 <listitem>
1657 <para><emphasis role="bold">Unicode conversions.</emphasis>
1658 While the rest of the modern world has pretty much settled on
1659 encoding strings in UTF-8, COM, unfortunately, uses UCS-16
1660 encoding. This requires a lot of conversions, in particular
1661 between the VirtualBox Main API and the Qt GUI, which, like the
1662 rest of Qt, likes to use UTF-8.</para>
1663
1664 <para>To facilitate these conversions, VirtualBox provides the
1665 <computeroutput>com::Bstr</computeroutput> and
1666 <computeroutput>com::Utf8Str</computeroutput> classes, which
1667 support all kinds of conversions back and forth.</para>
1668 </listitem>
1669
1670 <listitem>
1671 <para><emphasis role="bold">COM autopointers.</emphasis>
1672 Possibly the greatest pain of using COM -- reference counting --
1673 is alleviated by the
1674 <computeroutput>ComPtr&lt;&gt;</computeroutput> template
1675 provided by the <computeroutput>ptr.h</computeroutput> file in
1676 the glue layer.</para>
1677 </listitem>
1678 </orderedlist></para>
1679 </sect2>
1680
1681 <sect2 id="event-queue">
1682 <title>Event queue processing</title>
1683
1684 <para>Both VirtualBox client programs and frontends should
1685 periodically perform processing of the main event queue, and do that
1686 on the application's main thread. In case of a typical GUI Windows/Mac
1687 OS application this happens automatically in the GUI's dispatch loop.
1688 However, for CLI only application, the appropriate actions have to be
1689 taken. For C++ applications, the VirtualBox SDK provided glue method
1690 <screen>
1691 int EventQueue::processEventQueue(uint32_t cMsTimeout)
1692 </screen> can be used for both blocking and non-blocking operations.
1693 For the Python bindings, a common layer provides the method <screen>
1694 VirtualBoxManager.waitForEvents(ms)
1695 </screen> with similar semantics.</para>
1696
1697 <para>Things get somewhat more complicated for situations where an
1698 application using VirtualBox cannot directly control the main event
1699 loop and the main event queue is separated from the event queue of the
1700 programming librarly (for example in case of Qt on Unix platforms). In
1701 such a case, the application developer is advised to use a
1702 platform/toolkit specific event injection mechanism to force event
1703 queue checks either based on periodical timer events delivered to the
1704 main thread, or by using custom platform messages to notify the main
1705 thread when events are available. See the VBoxSDL and Qt (VirtualBox)
1706 frontends as examples.</para>
1707 </sect2>
1708
1709 <sect2 id="vbcom">
1710 <title>Visual Basic and Visual Basic Script (VBS) on Windows
1711 hosts</title>
1712
1713 <para>On Windows hosts, one can control some of the VirtualBox Main
1714 API functionality from VBS scripts, and pretty much everything from
1715 Visual Basic programs.<footnote>
1716 <para>The difference results from the way VBS treats COM
1717 safearrays, which are used to keep lists in the Main API. VBS
1718 expects every array element to be a
1719 <computeroutput>VARIANT</computeroutput>, which is too strict a
1720 limitation for any high performance API. We may lift this
1721 restriction for interface APIs in a future version, or
1722 alternatively provide conversion APIs.</para>
1723 </footnote></para>
1724
1725 <para>VBS is scripting language available in any recent Windows
1726 environment. As an example, the following VBS code will print
1727 VirtualBox version: <screen>
1728 set vb = CreateObject("VirtualBox.VirtualBox")
1729 Wscript.Echo "VirtualBox version " &amp; vb.version
1730 </screen> See
1731 <computeroutput>bindings/mscom/vbs/sample/vboxinfo.vbs</computeroutput>
1732 for the complete sample.</para>
1733
1734 <para>Visual Basic is a popular high level language capable of
1735 accessing COM objects. The following VB code will iterate over all
1736 available virtual machines:<screen>
1737 Dim vb As VirtualBox.IVirtualBox
1738
1739 vb = CreateObject("VirtualBox.VirtualBox")
1740 machines = ""
1741 For Each m In vb.Machines
1742 m = m &amp; " " &amp; m.Name
1743 Next
1744 </screen> See
1745 <computeroutput>bindings/mscom/vb/sample/vboxinfo.vb</computeroutput>
1746 for the complete sample.</para>
1747 </sect2>
1748
1749 <sect2 id="cbinding">
1750 <title>C binding to VirtualBox API</title>
1751
1752 <para>The VirtualBox API originally is designed as object oriented,
1753 using XPCOM or COM as the middleware, which translates natively to C++.
1754 This means that in order to use it from C there needs to be some
1755 helper code to bridge the language differences and reduce the
1756 differences between platforms.</para>
1757
1758 <sect3 id="capi_glue">
1759 <title>Cross-platform C binding to VirtualBox API</title>
1760
1761 <para>Starting with version 4.3, VirtualBox offers a C binding
1762 which allows using the same C client sources for all platforms,
1763 covering Windows, Linux, Mac OS X and Solaris. It is the
1764 preferred way to write API clients, even though the old style
1765 is still available.</para>
1766
1767 </sect3>
1768
1769 <sect3 id="c-gettingstarted">
1770 <title>Getting started</title>
1771
1772 <para>The following sections describe how to use the VirtualBox API
1773 in a C program. The necessary files are included in the SDK, in the
1774 directories <computeroutput>sdk/bindings/c/include</computeroutput>
1775 and <computeroutput>sdk/bindings/c/glue</computeroutput>.</para>
1776
1777 <para>As part of the SDK, a sample program
1778 <computeroutput>tstCAPIGlue.c</computeroutput> is provided in the
1779 directory <computeroutput>sdk/bindings/c/samples</computeroutput>
1780 which demonstrates
1781 using the C binding to initialize the API, get handles for
1782 VirtualBox and Session objects, make calls to list and start virtual
1783 machines, monitor events, and uninitialize resources when done. The
1784 sample program is trying to illustrate all relevant concepts, so it
1785 is a great source of detail information. Among many other generally
1786 useful code sequences it contains a function which shows how to
1787 retrieve error details in C code if they are available from the API
1788 call.</para>
1789
1790 <para>The sample program <computeroutput>tstCAPIGlue</computeroutput>
1791 can be built using the provided
1792 <computeroutput>Makefile</computeroutput> and can be run without
1793 arguments.</para>
1794
1795 <para>It uses the VBoxCAPIGlue library (source code is in directory
1796 <computeroutput>sdk/bindings/c/glue</computeroutput>, to be used in
1797 your API client code) to open the C binding layer during runtime,
1798 which is preferred to other means as it isolates the code which
1799 locates the necessary dynamic library, using a known working way
1800 which works on all platforms. If you encounter problems with this
1801 glue code in <computeroutput>VBoxCAPIGlue.c</computeroutput>, let the
1802 VirtualBox developers know, rather than inventing incompatible
1803 solutions.</para>
1804
1805 <para>The following sections document the important concepts needed
1806 to correctly use the C binding, as it is vital for developing API
1807 client code which manages memory correctly, updates the reference
1808 counters correctly, avoiding crashes and memory leaks. Often API
1809 clients need to handle events, so the C API specifics are also
1810 described below.</para>
1811 </sect3>
1812
1813 <sect3 id="c-initialization">
1814 <title>VirtualBox C API initialization</title>
1815
1816 <para>Just like in C++, the API and the underlying middleware needs
1817 to be initialized before it can be used. The
1818 <computeroutput>VBoxCAPI_v4_3.h</computeroutput> header provides the
1819 interface to the C binding, but you can alternatively and more
1820 conveniently also include
1821 <computeroutput>VBoxCAPIGlue.h</computeroutput>,
1822 as this avoids the VirtualBox version dependent header file name and
1823 makes sure the global variable <code>g_pVBoxFuncs</code> contains a
1824 pointer to the structure which contains the helper function pointers.
1825 Here's how to initialize the C API:<screen>#include "VBoxCAPIGlue.h"
1826...
1827IVirtualBoxClient *vboxclient = NULL;
1828IVirtualBox *vbox = NULL;
1829ISession *session = NULL;
1830HRESULT rc;
1831ULONG revision;
1832
1833/*
1834 * VBoxCGlueInit() loads the necessary dynamic library, handles errors
1835 * (producing an error message hinting what went wrong) and gives you
1836 * the pointer to the function table (g_pVBoxFuncs).
1837 *
1838 * Once you get the function table, then how and which functions
1839 * to use is explained below.
1840 *
1841 * g_pVBoxFuncs-&gt;pfnClientInitialize does all the necessary startup
1842 * action and provides us with pointers to an IVirtualBoxClient instance.
1843 * It should be matched by a call to g_pVBoxFuncs-&gt;pfnClientUninitialize()
1844 * when done.
1845 */
1846
1847if (VBoxCGlueInit())
1848{
1849 fprintf(stderr, "s: FATAL: VBoxCGlueInit failed: %s\n",
1850 argv[0], g_szVBoxErrMsg);
1851 return EXIT_FAILURE;
1852}
1853
1854g_pVBoxFuncs-&gt;pfnClientInitialize(NULL, &amp;vboxclient);
1855if (!vboxclient)
1856{
1857 fprintf(stderr, "%s: FATAL: could not get VirtualBoxClient reference\n",
1858 argv[0]);
1859 return EXIT_FAILURE;
1860}</screen></para>
1861
1862 <para>If <computeroutput>vboxclient</computeroutput> is still
1863 <computeroutput>NULL</computeroutput> this means the initializationi
1864 failed and the VirtualBox C API cannot be used.</para>
1865
1866 <para>It is possible to write C applications using multiple threads
1867 which all use the VirtualBox API, as long as you're initializing
1868 the C API in each thread which your application creates. This is done
1869 with <code>g_pVBoxFuncs->pfnClientThreadInitialize()</code> and
1870 likewise before the thread is terminated the API must be
1871 uninitialized with
1872 <code>g_pVBoxFuncs->pfnClientThreadUninitialize()</code>. You don't
1873 have to use these functions in worker threads created by COM/XPCOM
1874 (which you might observe if your code uses active event handling),
1875 everything is initialized correctly already. On Windows the C
1876 bindings create a marshaller which supports a wide range of COM
1877 threading models, from STA to MTA, so you don't have to worry about
1878 these details unless you plan to use active event handlers. See
1879 the sample code how to get this to work reliably (in other words
1880 think twice if passive event handling isn't the better solution after
1881 you looked at the sample code).</para>
1882 </sect3>
1883
1884 <sect3 id="c-invocation">
1885 <title>C API attribute and method invocation</title>
1886
1887 <para>Method invocation is straightforward. It looks pretty much
1888 like the C++ way, by using a macro which internally accesses the
1889 vtable, and additionally needs to be passed a pointer to the objecti
1890 as the first argument to serve as the
1891 <computeroutput>this</computeroutput> pointer.</para>
1892
1893 <para>Using the C binding, all method invocations return a numeric
1894 result code of type <code>HRESULT</code> (with a few exceptions
1895 which normally are not relevant).</para>
1896
1897 <para>If an interface is specified as returning an object, a pointer
1898 to a pointer to the appropriate object must be passed as the last
1899 argument. The method will then store an object pointer in that
1900 location.</para>
1901
1902 <para>Likewise, attributes (properties) can be queried or set using
1903 method invocations, using specially named methods. For each
1904 attribute there exists a getter method, the name of which is composed
1905 of <computeroutput>get_</computeroutput> followed by the capitalized
1906 attribute name. Unless the attribute is read-only, an analogous
1907 <computeroutput>set_</computeroutput> method exists. Let's apply
1908 these rules to get the <computeroutput>IVirtualBox</computeroutput>
1909 reference, an <computeroutput>ISession</computeroutput> instance
1910 reference and read the
1911 <link linkend="IVirtualBox__revision">IVirtualBox::revision</link>
1912 attribute:
1913 <screen>rc = IVirtualBoxClient_get_VirtualBox(vboxclient, &amp;vbox);
1914if (FAILED(rc) || !vbox)
1915{
1916 PrintErrorInfo(argv[0], "FATAL: could not get VirtualBox reference", rc);
1917 return EXIT_FAILURE;
1918}
1919rc = IVirtualBoxClient_get_Session(vboxclient, &amp;session);
1920if (FAILED(rc) || !session)
1921{
1922 PrintErrorInfo(argv[0], "FATAL: could not get Session reference", rc);
1923 return EXIT_FAILURE;
1924}
1925
1926rc = IVirtualBox_get_Revision(vbox, &amp;revision);
1927if (SUCCEEDED(rc))
1928{
1929 printf("Revision: %u\n", revision);
1930}</screen></para>
1931
1932 <para>The convenience macros for calling a method are named by
1933 prepending the method name with the interface name (using
1934 <code>_</code>as the separator).</para>
1935
1936 <para>So far only attribute getters were illustrated, but generic
1937 method calls are straightforward, too:
1938 <screen>IMachine *machine = NULL;
1939BSTR vmname = ...;
1940...
1941/*
1942 * Calling IMachine::findMachine(...)
1943 */
1944rc = IVirtualBox_FindMachine(vbox, vmname, &amp;machine);</screen></para>
1945
1946 <para>As a more complicated example of a method invocation, let's
1947 call
1948 <link linkend="IMachine__launchVMProcess">IMachine::launchVMProcess</link>
1949 which returns an IProgress object. Note again that the method name is
1950 capitalized:
1951 <screen>IProgress *progress;
1952...
1953rc = IMachine_LaunchVMProcess(
1954 machine, /* this */
1955 session, /* arg 1 */
1956 sessionType, /* arg 2 */
1957 env, /* arg 3 */
1958 &amp;progress /* Out */
1959);</screen></para>
1960
1961 <para>All objects with their methods and attributes are documented
1962 in <xref linkend="sdkref_classes"/>.</para>
1963 </sect3>
1964
1965 <sect3 id="c-string-handling">
1966 <title>String handling</title>
1967
1968 <para>When dealing with strings you have to be aware of a string's
1969 encoding and ownership.</para>
1970
1971 <para>Internally, the API uses UTF-16 encoded strings. A set of
1972 conversion functions is provided to convert other encodings to and
1973 from UTF-16. The type of a UTF-16 character is
1974 <computeroutput>BSTR</computeroutput> (or its constant counterpart
1975 <computeroutput>CBSTR</computeroutput>), which is an array type,
1976 represented by a pointer to the start of the zero-terminated string.
1977 There are functions for converting between UTF-8 and UTF-16 strings
1978 available through <code>g_pVBoxFuncs</code>:
1979 <screen>int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString);
1980int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString);</screen></para>
1981
1982 <para>The ownership of a string determines who is responsible for
1983 releasing resources associated with the string. Whenever the API
1984 creates a string (essentially for output parameters), ownership is
1985 transferred to the caller. To avoid resource leaks, the caller
1986 should release resources once the string is no longer needed.
1987 There are plenty of examples in the sample code.</para>
1988 </sect3>
1989
1990 <sect3 id="c-safearray">
1991 <title>Array handling</title>
1992
1993 <para>Arrays are handled somewhat similarly to strings, with the
1994 additional information of the number of elements in the array. The
1995 exact details of string passing depends on the platform middleware
1996 (COM/XPCOM), and therefore the C binding offers helper functions to
1997 gloss over these differences.</para>
1998
1999 <para>Passing arrays as input parameters to API methods is usually
2000 done by the following sequence, calling a hypothetical
2001 <code>IArrayDemo_PassArray</code> API method:
2002 <screen>static const ULONG aElements[] = { 1, 2, 3, 4 };
2003ULONG cElements = sizeof(aElements) / sizeof(aElements[0]);
2004SAFEARRAY *psa = NULL;
2005psa = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_I4, 0, cElements);
2006g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(psa, aElements, sizeof(aElements));
2007IArrayDemo_PassArray(pThis, ComSafeArrayAsInParam(psa));
2008g_pVBoxFuncs->pfnSafeArrayDestroy(psa);</screen></para>
2009
2010 <para>Likewise, getting arrays results from output parameters is done
2011 using helper functions which manage memory allocations as part of
2012 their other functionality:
2013 <screen>SAFEARRAY *psa = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc();
2014ULONG *pData;
2015ULONG cElements;
2016IArrayDemo_ReturnArray(pThis, ComSafeArrayAsOutTypeParam(psa, ULONG));
2017g_pVBoxFuncs->pfnSafeArrayCopyOutParamHelper((void **)&amp;pData, &amp;cElements, VT_I4, psa);
2018g_pVBoxFuncs->pfnSafeArrayDestroy(psa);</screen></para>
2019
2020 <para>This covers the necessary functionality for all array element
2021 types except interface references. These need special helpers to
2022 manage the reference counting correctly. The following code snippet
2023 gets the list of VMs, and passes the first IMachine reference to
2024 another API function (assuming that there is at least one element
2025 in the array, to simplify the example):
2026 <screen>SAFEARRAY psa = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc();
2027IMachine **machines = NULL;
2028ULONG machineCnt = 0;
2029ULONG i;
2030IVirtualBox_get_Machines(virtualBox, ComSafeArrayAsOutIfaceParam(machinesSA, IMachine *));
2031g_pVBoxFuncs->pfnSafeArrayCopyOutIfaceParamHelper((IUnknown ***)&amp;machines, &amp;machineCnt, machinesSA);
2032g_pVBoxFuncs->pfnSafeArrayDestroy(machinesSA);
2033/* Now "machines" contains the IMachine references, and machineCnt the
2034 * number of elements in the array. */
2035...
2036SAFEARRAY *psa = g_pVBoxFuncs->pfnSafeArrayCreateVector(VT_IUNKNOWN, 0, 1);
2037g_pVBoxFuncs->pfnSafeArrayCopyInParamHelper(psa, (void *)&amp;machines[0], sizeof(machines[0]));
2038IVirtualBox_GetMachineStates(ComSafeArrayAsInParam(psa), ...);
2039...
2040g_pVBoxFuncs->pfnSafeArrayDestroy(psa);
2041for (i = 0; i &lt; machineCnt; ++i)
2042{
2043 IMachine *machine = machines[i];
2044 IMachine_Release(machine);
2045}
2046free(machines);</screen></para>
2047
2048 <para>Handling output parameters needs more special effort than
2049 input parameters, thus only for the former there are special helpers,
2050 and the latter is handled through the generic array support.</para>
2051 </sect3>
2052
2053 <sect3 id="c-eventhandling">
2054 <title>Event handling</title>
2055
2056 <para>The VirtualBox API offers two types of event handling, active
2057 and passive, and consequently there is support for both with the
2058 C API binding. Active event handling (based on asynchronous
2059 callback invocation for event delivery) is more difficult, as it
2060 requires the construction of valid C++ objects in C, which is
2061 inherently platform and compiler dependent. Passive event handling
2062 is much simpler, it relies on an event loop, fetching events and
2063 triggering the necessary handlers explicitly in the API client code.
2064 Both approaches depend on an event loop to make sure that events
2065 get delivered in a timely manner, with differences what exactly needs
2066 to be done.</para>
2067
2068 <para>The C API sample contains code for both event handling styles,
2069 and one has to modify the appropriate <code>#define</code> to select
2070 which style is actually used by the compiled program. It allows a
2071 good comparison between the two variants, and the code sequences are
2072 probably worth reusing without much change in other API clients
2073 with only minor adaptions.</para>
2074
2075 <para>Active event handling needs to ensure that the following helper
2076 function is called frequently enough in the primary thread:
2077 <screen>g_pVBoxFuncs->pfnProcessEventQueue(cTimeoutMS);</screen></para>
2078
2079 <para>The actual event handler implementation is quite tedious, as
2080 it has to implement a complete API interface. Especially on Windows
2081 it is a lot of work to implement the complicated
2082 <code>IDispatch</code> interface, requiring to load COM type
2083 information and using it in the <code>IDispatch</code> method
2084 implementation. Overall this is quite tedious compared to passive
2085 event handling.</para>
2086
2087 <para>Passive event handling uses a similar event loop structure,
2088 which requires calling the following function in a loop, and
2089 processing the returned event appropriately:
2090 <screen>rc = IEventSource_GetEvent(pEventSource, pListener, cTimeoutMS, &amp;pEvent);</screen></para>
2091
2092 <para>After processing the event it needs to be marked as processed
2093 with the following method call:
2094 <screen>rc = IEventSource_EventProcessed(pEventSource, pListener, pEvent);</screen></para>
2095
2096 <para>This is vital for vetoable events, as they would be stuck
2097 otherwise, waiting whether the veto comes or not. It does not do any
2098 harm for other event types, and in the end is cheaper than checking
2099 if the event at hand is vetoable or not.</para>
2100
2101 <para>The general event handling concepts are described in the API
2102 specification (see <xref linkend="events"/>), including how to
2103 aggregate multiple event sources for processing in one event loop.
2104 As mentioned, the sample illustrates the practical aspects of how to
2105 use both types of event handling, active and passive, from a C
2106 application. Additional hints are in the comments documenting
2107 the helper methods in
2108 <computeroutput>VBoxCAPI_v4_3.h</computeroutput>. The code complexity
2109 of active event handling (and its inherenly platform/compiler
2110 specific aspects) should be motivation to use passive event handling
2111 whereever possible.</para>
2112 </sect3>
2113
2114 <sect3 id="c-uninitialization">
2115 <title>C API uninitialization</title>
2116
2117 <para>Uninitialization is performed by
2118 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize().</computeroutput>
2119 If your program can exit from more than one place, it is a good idea
2120 to install this function as an exit handler with Standard C's
2121 <computeroutput>atexit()</computeroutput> just after calling
2122 <computeroutput>g_pVBoxFuncs-&gt;pfnClientInitialize()</computeroutput>
2123 , e.g. <screen>#include &lt;stdlib.h&gt;
2124#include &lt;stdio.h&gt;
2125
2126...
2127
2128/*
2129 * Make sure g_pVBoxFuncs-&gt;pfnClientUninitialize() is called at exit, no
2130 * matter if we return from the initial call to main or call exit()
2131 * somewhere else. Note that atexit registered functions are not
2132 * called upon abnormal termination, i.e. when calling abort() or
2133 * signal().
2134 */
2135
2136if (atexit(g_pVBoxFuncs-&gt;pfnClientUninitialize()) != 0) {
2137 fprintf(stderr, "failed to register g_pVBoxFuncs-&gt;pfnClientUninitialize()\n");
2138 exit(EXIT_FAILURE);
2139}</screen></para>
2140
2141 <para>Another idea would be to write your own <computeroutput>void
2142 myexit(int status)</computeroutput> function, calling
2143 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2144 followed by the real <computeroutput>exit()</computeroutput>, and
2145 use it instead of <computeroutput>exit()</computeroutput> throughout
2146 your program and at the end of
2147 <computeroutput>main.</computeroutput></para>
2148
2149 <para>If you expect the program to be terminated by a signal (e.g.
2150 user types CTRL-C sending SIGINT) you might want to install a signal
2151 handler setting a flag noting that a signal was sent and then
2152 calling
2153 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2154 later on, <emphasis>not</emphasis> from the handler itself.</para>
2155
2156 <para>That said, if a client program forgets to call
2157 <computeroutput>g_pVBoxFuncs-&gt;pfnClientUninitialize()</computeroutput>
2158 before it terminates, there is a mechanism in place which will
2159 eventually release references held by the client. On Windows it can
2160 take quite a while, in the order of 6-7 minutes.</para>
2161 </sect3>
2162
2163 <sect3 id="c-linking">
2164 <title>Compiling and linking</title>
2165
2166 <para>A program using the C binding has to open the library during
2167 runtime using the help of glue code provided and as shown in the
2168 example <computeroutput>tstCAPIGlue.c</computeroutput>.
2169 Compilation and linking can be achieved with a makefile fragment
2170 similar to:<screen># Where is the SDK directory?
2171PATH_SDK = ../../..
2172CAPI_INC = -I$(PATH_SDK)/bindings/c/include
2173ifdef ProgramFiles
2174PLATFORM_INC = -I$(PATH_SDK)/bindings/mscom/include
2175PLATFORM_LIB = $(PATH_SDK)/bindings/mscom/lib
2176else
2177PLATFORM_INC = -I$(PATH_SDK)/bindings/xpcom/include
2178PLATFORM_LIB = $(PATH_SDK)/bindings/xpcom/lib
2179endif
2180GLUE_DIR = $(PATH_SDK)/bindings/c/glue
2181GLUE_INC = -I$(GLUE_DIR)
2182
2183# Compile Glue Library
2184VBoxCAPIGlue.o: $(GLUE_DIR)/VBoxCAPIGlue.c
2185 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2186
2187# Compile interface ID list
2188VirtualBox_i.o: $(PLATFORM_LIB)/VirtualBox_i.c
2189 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2190
2191# Compile program code
2192program.o: program.c
2193 $(CC) $(CFLAGS) $(CAPI_INC) $(PLATFORM_INC) $(GLUE_INC) -o $@ -c $&lt;
2194
2195# Link program.
2196program: program.o VBoxCAPICGlue.o VirtualBox_i.o
2197 $(CC) -o $@ $^ -ldl -lpthread</screen></para>
2198 </sect3>
2199
2200 <sect3 id="capi_conversion">
2201 <title>Conversion of code using legacy C binding</title>
2202
2203 <para>This section aims to make the task of converting code using
2204 the legacy C binding to the new style a breeze, by pointing out some
2205 key steps.</para>
2206
2207 <para>One necessary change is adjusting your Makefile to reflect the
2208 different include paths. See above. There are now 3 relevant include
2209 directories, and most of it is pointing to the C binding directory.
2210 The XPCOM include directory is still relevant for platforms where
2211 the XPCOM middleware is used, but most of the include files live
2212 elsewhere now, so it's good to have it last. Additionally the
2213 <computeroutput>VirtualBox_i.c</computeroutput> file needs to be
2214 compiled and linked to the program, it contains the IIDs relevant
2215 for the VirtualBox API, making sure they are not replicated endlessly
2216 if the code refers to them frequently.</para>
2217
2218 <para>The C API client code should include
2219 <computeroutput>VBoxCAPIGlue.h</computeroutput> instead of
2220 <computeroutput>VBoxXPCOMCGlue.h</computeroutput> or
2221 <computeroutput>VBoxCAPI_v4_3.h</computeroutput>, as this makes sure
2222 the correct macros and internal translations are selected.</para>
2223
2224 <para>All API method calls (anything mentioning <code>vtbl</code>)
2225 should be rewritten using the convenience macros for calling methods,
2226 as these hide the internal details, are generally easier to use and
2227 shorter to type. You should remove as many as possible
2228 <code>(nsISupports **)</code> or similar typecasts, as the new style
2229 should use the correct type in most places, increasing the type
2230 safety in case of an error in the source code.</para>
2231
2232 <para>To gloss over the platform differences, API client code should
2233 no longer rely on XPCOM specific interface names such as
2234 <code>nsISupports</code>, <code>nsIException</code> and
2235 <code>nsIEventQueue</code>, and replace them by the platform
2236 independent interface names <code>IUnknown</code> and
2237 <code>IErrorInfo</code> for the first two respectively. Event queue
2238 handling should be replaced by using the platform independent way
2239 described in <xref linkend="c-eventhandling"/>.</para>
2240
2241 <para>Finally adjust the string and array handling to use the new
2242 helpers, as these make sure the code works without changes with
2243 both COM and XPCOM, which are significantly different in this area.
2244 The code should be double checked if it uses the correct way to
2245 manage memory, and is freeing it only after the last use.</para>
2246 </sect3>
2247
2248 <sect3 id="xpcom_cbinding">
2249 <title>Legacy C binding to VirtualBox API for XPCOM</title>
2250
2251 <note>
2252 <para>This section applies to Linux, Mac OS X and Solaris
2253 hosts only and describes deprecated use of the API from C.</para>
2254 </note>
2255
2256 <para>Starting with version 2.2, VirtualBox offers a C binding for
2257 its API which works only on platforms using XPCOM. Refer to the
2258 old SDK documentation (included in the SDK packages for version 4.3.6
2259 or earlier), it still applies unchanged. The fundamental concepts are
2260 similar (but the syntactical details are quite different) to the
2261 newer cross-platform C binding which should be used for all new code,
2262 as the support for the old C binding will go away in a major release
2263 after version 4.3.</para>
2264 </sect3>
2265 </sect2>
2266 </sect1>
2267 </chapter>
2268
2269 <chapter id="concepts">
2270 <title>Basic VirtualBox concepts; some examples</title>
2271
2272 <para>The following explains some basic VirtualBox concepts such as the
2273 VirtualBox object, sessions and how virtual machines are manipulated and
2274 launched using the Main API. The coding examples use a pseudo-code style
2275 closely related to the object-oriented web service (OOWS) for JAX-WS.
2276 Depending on which environment you are using, you will need to adjust the
2277 examples.</para>
2278
2279 <sect1>
2280 <title>Obtaining basic machine information. Reading attributes</title>
2281
2282 <para>Any program using the Main API will first need access to the
2283 global VirtualBox object (see
2284 <link linkend="IVirtualBox">IVirtualBox</link>), from which all other
2285 functionality of the API is derived. With the OOWS for JAX-WS, this is
2286 returned from the
2287 <link linkend="IWebsessionManager__logon">IWebsessionManager::logon()</link>
2288 call.</para>
2289
2290 <para>To enumerate virtual machines, one would look at the "machines"
2291 array attribute in the VirtualBox object (see
2292 <link linkend="IVirtualBox__machines">IVirtualBox::machines</link>).
2293 This array contains all virtual machines currently registered with the
2294 host, each of them being an instance of
2295 <link linkend="IMachine">IMachine</link>.
2296 From each such instance, one can query additional information, such as
2297 the UUID, the name, memory, operating system and more by looking at the
2298 attributes; see the attributes list in
2299 <link linkend="IMachine">IMachine</link> documentation.</para>
2300
2301 <para>As mentioned in the preceding chapters, depending on your
2302 programming environment, attributes are mapped to corresponding "get"
2303 and (if the attribute is not read-only) "set" methods. So when the
2304 documentation says that IMachine has a
2305 "<link linkend="IMachine__name">name</link>" attribute, this means you
2306 need to code something
2307 like the following to get the machine's name:
2308 <screen>IMachine machine = ...;
2309String name = machine.getName();</screen>
2310 Boolean attribute getters can sometimes be called
2311 <computeroutput>isAttribute()</computeroutput> due to JAX-WS naming
2312 conventions.</para>
2313 </sect1>
2314
2315 <sect1>
2316 <title>Changing machine settings: Sessions</title>
2317
2318 <para>As said in the previous section, to read a machine's attribute,
2319 one invokes the corresponding "get" method. One would think that to
2320 change settings of a machine, it would suffice to call the corresponding
2321 "set" method -- for example, to set a VM's memory to 1024 MB, one would
2322 call <computeroutput>setMemorySize(1024)</computeroutput>. Try that, and
2323 you will get an error: "The machine is not mutable."</para>
2324
2325 <para>So unfortunately, things are not that easy. VirtualBox is a
2326 complicated environment in which multiple processes compete for possibly
2327 the same resources, especially machine settings. As a result, machines
2328 must be "locked" before they can either be modified or started. This is
2329 to prevent multiple processes from making conflicting changes to a
2330 machine: it should, for example, not be allowed to change the memory
2331 size of a virtual machine while it is running. (You can't add more
2332 memory to a real computer while it is running either, at least not to an
2333 ordinary PC.) Also, two processes must not change settings at the same
2334 time, or start a machine at the same time.</para>
2335
2336 <para>These requirements are implemented in the Main API by way of
2337 "sessions", in particular, the <link linkend="ISession">ISession</link>
2338 interface. Each process which talks to
2339 VirtualBox needs its own instance of ISession. In the web service, you
2340 can request the creation of such an object by calling
2341 <link linkend="IWebsessionManager__getSessionObject">IWebsessionManager::getSessionObject()</link>.
2342 More complex management tasks might need multiple instances of ISession,
2343 and each call returns a new one.</para>
2344
2345 <para>This session object must then be used like a mutex semaphore in
2346 common programming environments. Before you can change machine settings,
2347 you must write-lock the machine by calling
2348 <link linkend="IMachine__lockMachine">IMachine::lockMachine()</link>
2349 with your process's session object.</para>
2350
2351 <para>After the machine has been locked, the
2352 <link linkend="ISession__machine">ISession::machine</link> attribute
2353 contains a copy of the original IMachine object upon which the session
2354 was opened, but this copy is "mutable": you can invoke "set" methods on
2355 it.</para>
2356
2357 <para>When done making the changes to the machine, you must call
2358 <link linkend="IMachine__saveSettings">IMachine::saveSettings()</link>,
2359 which will copy the changes you have made from your "mutable" machine
2360 back to the real machine and write them out to the machine settings XML
2361 file. This will make your changes permanent.</para>
2362
2363 <para>Finally, it is important to always unlock the machine again, by
2364 calling
2365 <link linkend="ISession__unlockMachine">ISession::unlockMachine()</link>.
2366 Otherwise, when the calling process end, the machine will receive the
2367 "aborted" state, which can lead to loss of data.</para>
2368
2369 <para>So, as an example, the sequence to change a machine's memory to
2370 1024 MB is something like this:<screen>IWebsessionManager mgr ...;
2371IVirtualBox vbox = mgr.logon(user, pass);
2372...
2373IMachine machine = ...; // read-only machine
2374ISession session = mgr.getSessionObject();
2375machine.lockMachine(session, LockType.Write); // machine is now locked for writing
2376IMachine mutable = session.getMachine(); // obtain the mutable machine copy
2377mutable.setMemorySize(1024);
2378mutable.saveSettings(); // write settings to XML
2379session.unlockMachine();</screen></para>
2380 </sect1>
2381
2382 <sect1>
2383 <title>Launching virtual machines</title>
2384
2385 <para>To launch a virtual machine, you call
2386 <link linkend="IMachine__launchVMProcess">IMachine::launchVMProcess()</link>.
2387 In doing so, the caller instructs the VirtualBox engine to start a new
2388 process with the virtual machine in it, since to the host, each virtual
2389 machine looks like single process, even if it has hundreds of its own
2390 processes inside. (This new VM process in turn obtains a write lock on
2391 the machine, as described above, to prevent conflicting changes from
2392 other processes; this is why opening another session will fail while the
2393 VM is running.)</para>
2394
2395 <para>Starting a machine looks something like this:
2396 <screen>IWebsessionManager mgr ...;
2397IVirtualBox vbox = mgr.logon(user, pass);
2398...
2399IMachine machine = ...; // read-only machine
2400ISession session = mgr.getSessionObject();
2401IProgress prog = machine.launchVMProcess(session,
2402 "gui", // session type
2403 ""); // possibly environment setting
2404prog.waitForCompletion(10000); // give the process 10 secs
2405if (prog.getResultCode() != 0) // check success
2406 System.out.println("Cannot launch VM!")</screen></para>
2407
2408 <para>The caller's session object can then be used as a sort of remote
2409 control to the VM process that was launched. It contains a "console"
2410 object (see <link linkend="ISession__console">ISession::console</link>)
2411 with which the VM can be paused,
2412 stopped, snapshotted or other things.</para>
2413 </sect1>
2414
2415 <sect1 id="events">
2416 <title>VirtualBox events</title>
2417
2418 <para>In VirtualBox, "events" provide a uniform mechanism to register
2419 for and consume specific events. A VirtualBox client can register an
2420 "event listener" (represented by the
2421 <link linkend="IEventListener">IEventListener</link> interface), which
2422 will then get notified by the server when an event (represented by the
2423 <link linkend="IEvent">IEvent</link> interface) happens.</para>
2424
2425 <para>The IEvent interface is an abstract parent interface for all
2426 events that can occur in VirtualBox. The actual events that the server
2427 sends out are then of one of the specific subclasses, for example
2428 <link linkend="IMachineStateChangedEvent">IMachineStateChangedEvent</link>
2429 or
2430 <link linkend="IMediumChangedEvent">IMediumChangedEvent</link>.</para>
2431
2432 <para>As an example, the VirtualBox GUI waits for machine events and can
2433 thus update its display when the machine state changes or machine
2434 settings are modified, even if this happens in another client. This is
2435 how the GUI can automatically refresh its display even if you manipulate
2436 a machine from another client, for example, from VBoxManage.</para>
2437
2438 <para>To register an event listener to listen to events, use code like
2439 this:<screen>EventSource es = console.getEventSource();
2440IEventListener listener = es.createListener();
2441VBoxEventType aTypes[] = (VBoxEventType.OnMachineStateChanged);
2442 // list of event types to listen for
2443es.registerListener(listener, aTypes, false /* active */);
2444 // register passive listener
2445IEvent ev = es.getEvent(listener, 1000);
2446 // wait up to one second for event to happen
2447if (ev != null)
2448{
2449 // downcast to specific event interface (in this case we have only registered
2450 // for one type, otherwise IEvent::type would tell us)
2451 IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev);
2452 ... // inspect and do something
2453 es.eventProcessed(listener, ev);
2454}
2455...
2456es.unregisterListener(listener); </screen></para>
2457
2458 <para>A graphical user interface would probably best start its own
2459 thread to wait for events and then process these in a loop.</para>
2460
2461 <para>The events mechanism was introduced with VirtualBox 3.3 and
2462 replaces various callback interfaces which were called for each event in
2463 the interface. The callback mechanism was not compatible with scripting
2464 languages, local Java bindings and remote web services as they do not
2465 support callbacks. The new mechanism with events and event listeners
2466 works with all of these.</para>
2467
2468 <para>To simplify developement of application using events, concept of
2469 event aggregator was introduced. Essentially it's mechanism to aggregate
2470 multiple event sources into single one, and then work with this single
2471 aggregated event source instead of original sources. As an example, one
2472 can evaluate demo recorder in VirtualBox Python shell, shipped with SDK
2473 - it records mouse and keyboard events, represented as separate event
2474 sources. Code is essentially like this:<screen>
2475 listener = console.eventSource.createListener()
2476 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource])
2477 agg.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
2478 registered = True
2479 end = time.time() + dur
2480 while time.time() &lt; end:
2481 ev = agg.getEvent(listener, 1000)
2482 processEent(ev)
2483 agg.unregisterListener(listener)</screen> Without using aggregators
2484 consumer have to poll on both sources, or start multiple threads to
2485 block on those sources.</para>
2486 </sect1>
2487 </chapter>
2488
2489 <chapter id="vboxshell">
2490 <title>The VirtualBox shell</title>
2491
2492 <para>VirtualBox comes with an extensible shell, which allows you to
2493 control your virtual machines from the command line. It is also a
2494 nontrivial example of how to use the VirtualBox APIs from Python, for all
2495 three COM/XPCOM/WS styles of the API.</para>
2496
2497 <para>You can easily extend this shell with your own commands. Create a
2498 subdirectory named
2499 <computeroutput>.config/VirtualBox/shexts</computeroutput> below your home
2500 directory (respectively <computeroutput>.VirtualBox/shexts</computeroutput>
2501 on a Windows system and
2502 <computeroutput>Library/VirtualBox/shexts</computeroutput> on OS X) and put
2503 a Python file implementing your shell extension commands in this directory.
2504 This file must contain an array named
2505 <computeroutput>commands</computeroutput> containing your command
2506 definitions: <screen>
2507 commands = {
2508 'cmd1': ['Command cmd1 help', cmd1],
2509 'cmd2': ['Command cmd2 help', cmd2]
2510 }
2511 </screen> For example, to create a command for creating hard drive
2512 images, the following code can be used: <screen>
2513 def createHdd(ctx,args):
2514 # Show some meaningful error message on wrong input
2515 if (len(args) &lt; 3):
2516 print "usage: createHdd sizeM location type"
2517 return 0
2518
2519 # Get arguments
2520 size = int(args[1])
2521 loc = args[2]
2522 if len(args) &gt; 3:
2523 format = args[3]
2524 else:
2525 # And provide some meaningful defaults
2526 format = "vdi"
2527
2528 # Call VirtualBox API, using context's fields
2529 hdd = ctx['vb'].createMedium(format, loc, ctx['global'].constants.AccessMode_ReadWrite, \
2530 ctx['global'].constants.DeviceType_HardDisk)
2531 # Access constants using ctx['global'].constants
2532 progress = hdd.createBaseStorage(size, (ctx['global'].constants.MediumVariant_Standard, ))
2533 # use standard progress bar mechanism
2534 ctx['progressBar'](progress)
2535
2536
2537 # Report errors
2538 if not hdd.id:
2539 print "cannot create disk (file %s exist?)" %(loc)
2540 return 0
2541
2542 # Give user some feedback on success too
2543 print "created HDD with id: %s" %(hdd.id)
2544
2545 # 0 means continue execution, other values mean exit from the interpreter
2546 return 0
2547
2548 commands = {
2549 'myCreateHDD': ['Create virtual HDD, createHdd size location type', createHdd]
2550 }
2551 </screen> Just store the above text in the file
2552 <computeroutput>createHdd</computeroutput> (or any other meaningful name)
2553 in <computeroutput>.config/VirtualBox/shexts/</computeroutput>. Start the
2554 VirtualBox shell, or just issue the
2555 <computeroutput>reloadExts</computeroutput> command, if the shell is
2556 already running. Your new command will now be available.</para>
2557 </chapter>
2558
2559 <xi:include href="SDKRef_apiref.xml" xpointer="xpointer(/book/*)"
2560 xmlns:xi="http://www.w3.org/2001/XInclude" />
2561
2562 <chapter id="cloud">
2563 <title>Working with the Cloud</title>
2564
2565 <para>VirtualBox supports and goes towards the Oracle tendencies like "move to the Cloud".</para>
2566
2567 <sect1>
2568 <title>OCI features</title>
2569 <para>VirtualBox supports the Oracle Cloud Infrastructure (OCI). See the interfaces:
2570 <link linkend="ICloudClient">ICloudClient</link>,
2571 <link linkend="ICloudProvider">ICloudProvider</link>,
2572 <link linkend="ICloudProfile">ICloudProfile</link>,
2573 <link linkend="ICloudProviderManager">ICloudProviderManager</link>.
2574 </para>
2575 <para>Each cloud interface has own implementation to support OCI features. There are everal functions in the implementation
2576 which should be explained in details because OCI requires some special data or settings.
2577 </para>
2578 <para>
2579 Also see the enumeration <link linkend="VirtualSystemDescriptionType">VirtualSystemDescriptionType</link> for the possible values.
2580 </para>
2581 </sect1>
2582
2583 <sect1>
2584 <title>Function ICloudClient::exportVM</title>
2585 <para>
2586 See the <link linkend="ICloudClient__exportVM">ICloudClient::exportVM</link>.
2587 The function exports an existing virtual machine into OCI. The final result of this operation is creation a custom image
2588 from the bootable image of VM. The Id of created image is returned in the parameter "description" (which is
2589 <link linkend="IVirtualSystemDescription">IVirtualSystemDescription</link>) as an entry with the type
2590 VirtualSystemDescriptionType::CloudImageId. The standard steps here are:
2591 <itemizedlist>
2592 <listitem>
2593 <para>Upload VBox image to OCI Object Storage.</para>
2594 </listitem>
2595 <listitem>
2596 <para>Create OCI custom image from the uploaded object.</para>
2597 </listitem>
2598 </itemizedlist>
2599 Parameter "description" must contain all information and settings needed for creation a custom image in OCI.
2600 At least next entries must be presented there before the call:
2601 <itemizedlist>
2602 <listitem>
2603 <para>VirtualSystemDescriptionType::Name - Name of new instance in OCI.</para>
2604 </listitem>
2605 <listitem>
2606 <para>VirtualSystemDescriptionType::HardDiskImage - The local path or id of bootable VM image.</para>
2607 </listitem>
2608 <listitem>
2609 <para>VirtualSystemDescriptionType::CloudBucket - A cloud bucket name where the exported image is uploaded.</para>
2610 </listitem>
2611 <listitem>
2612 <para>VirtualSystemDescriptionType::CloudImageDisplayName - A name which is assigned to a new custom image in the OCI.</para>
2613 </listitem>
2614 <listitem>
2615 <para>VirtualSystemDescriptionType::CloudKeepObject - Whether keep or delete an uploaded object after its usage.</para>
2616 </listitem>
2617 <listitem>
2618 <para>VirtualSystemDescriptionType::CloudLaunchInstance - Whether launch or not a new instance.</para>
2619 </listitem>
2620 </itemizedlist>
2621 </para>
2622 </sect1>
2623
2624 <sect1>
2625 <title>Function ICloudClient::launchVM</title>
2626 <para>
2627 See the <link linkend="ICloudClient__launchVM">ICloudClient::launchVM</link>.
2628 The function launches a new instance in OCI with a bootable volume previously created from a custom image in OCI or
2629 as the source may be used an existing bootable volume which shouldn't be attached to any instance.
2630 For launching instance from a custom image use the parameter VirtualSystemDescriptionType::CloudImageId.
2631 For launching instance from a bootable volume use the parameter VirtualSystemDescriptionType::CloudBootVolumeId.
2632 Only one of them must be presented otherwise the error will occur.
2633 The final result of this operation is a running instance. The id of created instance is returned
2634 in the parameter "description" (which is <link linkend="IVirtualSystemDescription">IVirtualSystemDescription</link>)
2635 as an entry with the type VirtualSystemDescriptionType::CloudInstanceId. Parameter "description" must contain all information
2636 and settings needed for creation a new instance in OCI. At least next entries must be presented there before the call:
2637 <itemizedlist>
2638 <listitem>
2639 <para>VirtualSystemDescriptionType::Name - Name of new instance in OCI.</para>
2640 </listitem>
2641 <listitem>
2642 <para>VirtualSystemDescriptionType::CloudOCISubnet - OCID of existing subnet in OCI which will be used by the instance.</para>
2643 </listitem>
2644 <listitem>
2645 <para>
2646 Use VirtualSystemDescriptionType::CloudImageId - OCID of custom image used as a bootable image for the instance
2647 or
2648 VirtualSystemDescriptionType::CloudBootVolumeId - OCID of existing and non-attached bootable volume used as a bootable volume for the instance.
2649 </para>
2650 </listitem>
2651 <listitem>
2652 <para>Add VirtualSystemDescriptionType::CloudBootDiskSize - The size of instance bootable volume in GB,
2653 If you use VirtualSystemDescriptionType::CloudImageId.</para>
2654 </listitem>
2655 <listitem>
2656 <para>VirtualSystemDescriptionType::CloudInstanceShape - The shape of instance according to OCI documentation,
2657 defines the number of CPUs and RAM memory.</para>
2658 </listitem>
2659 <listitem>
2660 <para>VirtualSystemDescriptionType::CloudLaunchInstance - Whether launch or not a new instance.</para>
2661 </listitem>
2662 <listitem>
2663 <para>VirtualSystemDescriptionType::CloudDomain - Availability domain in OCI where new instance is created.</para>
2664 </listitem>
2665 <listitem>
2666 <para>VirtualSystemDescriptionType::CloudPublicIP - Whether the instance will have a public IP or not.</para>
2667 </listitem>
2668 <listitem>
2669 <para>VirtualSystemDescriptionType::CloudPublicSSHKey - Public SSH key which is used to connect to an instance via SSH.
2670 It may be one or more records with the type VirtualSystemDescriptionType::CloudPublicSSHKey in the VirtualSystemDescription.
2671 But at least one should be presented otherwise user won't be able to connect to the instance via SSH.
2672 </para>
2673 </listitem>
2674 </itemizedlist>
2675 </para>
2676 </sect1>
2677
2678 <sect1>
2679 <title>Function ICloudClient::getInstanceInfo</title>
2680 <para>
2681 See the <link linkend="ICloudClient__getInstanceInfo">ICloudClient::getInstanceInfo</link>.
2682 The function takes an instance id (parameter "uid"), finds the requested instance in OCI and gets back information
2683 about the found instance in the parameter "description" (which is <link linkend="IVirtualSystemDescription">IVirtualSystemDescription</link>)
2684 The entries with next types will be presented in the object:
2685 <itemizedlist>
2686 <listitem>
2687 <para>VirtualSystemDescriptionType::Name - Displayed name of the instance.</para>
2688 </listitem>
2689 <listitem>
2690 <para>VirtualSystemDescriptionType::CloudDomain - Availability domain in OCI.</para>
2691 </listitem>
2692 <listitem>
2693 <para>VirtualSystemDescriptionType::CloudImageId - Name of custom image used for creation this instance.</para>
2694 </listitem>
2695 <listitem>
2696 <para>VirtualSystemDescriptionType::CloudInstanceId - The OCID of the instance.</para>
2697 </listitem>
2698 <listitem>
2699 <para>VirtualSystemDescriptionType::OS - Guest OS type of the instance.</para>
2700 </listitem>
2701 <listitem>
2702 <para>VirtualSystemDescriptionType::CloudBootDiskSize - Size of instance bootable image.</para>
2703 </listitem>
2704 <listitem>
2705 <para>VirtualSystemDescriptionType::CloudInstanceState - The instance state according to OCI documentation.</para>
2706 </listitem>
2707 <listitem>
2708 <para>VirtualSystemDescriptionType::CloudInstanceShape - The instance shape according to OCI documentation</para>
2709 </listitem>
2710 <listitem>
2711 <para>VirtualSystemDescriptionType::Memory - RAM memory in GB allocated for the instance.</para>
2712 </listitem>
2713 <listitem>
2714 <para>VirtualSystemDescriptionType::CPU - Number of virtual CPUs allocated for the instance.</para>
2715 </listitem>
2716 </itemizedlist>
2717 </para>
2718 </sect1>
2719
2720 <sect1>
2721 <title>Function ICloudClient::importInstance</title>
2722 <para>
2723 See the <link linkend="ICloudClient__importInstance">ICloudClient::importInstance</link>.
2724 The API function imports an existing instance from the OCI to the local host.
2725 The standard steps here are:
2726 <itemizedlist>
2727 <listitem>
2728 <para>Create a custom image from an existing OCI instance.</para>
2729 </listitem>
2730 <listitem>
2731 <para>Export the custom image to OCI object (the object is created in the OCI Object Storage).</para>
2732 </listitem>
2733 <listitem>
2734 <para>Download the OCI object to the local host.</para>
2735 </listitem>
2736 </itemizedlist>
2737 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
2738 contains a bootable instance image in QCOW2 format and a JSON file with some metadata related to
2739 the imported instance. The function takes the parameter "description"
2740 (which is <link linkend="IVirtualSystemDescription">IVirtualSystemDescription</link>)
2741 Parameter "description" must contain all information and settings needed for successful operation result.
2742 At least next entries must be presented there before the call:
2743 <itemizedlist>
2744 <listitem>
2745 <para>VirtualSystemDescriptionType::Name is used for the several purposes:
2746 <itemizedlist>
2747 <listitem>
2748 <para>As a custom image name. A custom image is created from an instance.</para>
2749 </listitem>
2750 <listitem>
2751 <para>As OCI object name. An object is a file in OCI Object Storage. The object is created from the custom image.</para>
2752 </listitem>
2753 <listitem>
2754 <para>Name of imported instance on the local host. Because the result of import is a file, the file will have this
2755 name and extension ".oci".</para>
2756 </listitem>
2757 </itemizedlist>
2758 </para>
2759 </listitem>
2760 <listitem>
2761 <para>VirtualSystemDescriptionType::CloudInstanceId - The OCID of the existing instance.</para>
2762 </listitem>
2763 <listitem>
2764 <para>VirtualSystemDescriptionType::CloudBucket - a cloud bucket name in OCI Object Storage where created an OCI object
2765 from a custom image.
2766 </para>
2767 </listitem>
2768 </itemizedlist>
2769 </para>
2770 </sect1>
2771
2772 </chapter>
2773
2774 <chapter id="hgcm">
2775 <title>Host-Guest Communication Manager</title>
2776
2777 <para>The VirtualBox Host-Guest Communication Manager (HGCM) allows a
2778 guest application or a guest driver to call a host shared library. The
2779 following features of VirtualBox are implemented using HGCM: <itemizedlist>
2780 <listitem>
2781 <para>Shared Folders</para>
2782 </listitem>
2783
2784 <listitem>
2785 <para>Shared Clipboard</para>
2786 </listitem>
2787
2788 <listitem>
2789 <para>Guest configuration interface</para>
2790 </listitem>
2791 </itemizedlist></para>
2792
2793 <para>The shared library contains a so called HGCM service. The guest HGCM
2794 clients establish connections to the service to call it. When calling a
2795 HGCM service the client supplies a function code and a number of
2796 parameters for the function.</para>
2797
2798 <sect1>
2799 <title>Virtual hardware implementation</title>
2800
2801 <para>HGCM uses the VMM virtual PCI device to exchange data between the
2802 guest and the host. The guest always acts as an initiator of requests. A
2803 request is constructed in the guest physical memory, which must be
2804 locked by the guest. The physical address is passed to the VMM device
2805 using a 32-bit <computeroutput>out edx, eax</computeroutput>
2806 instruction. The physical memory must be allocated below 4GB by 64-bit
2807 guests.</para>
2808
2809 <para>The host parses the request header and data and queues the request
2810 for a host HGCM service. The guest continues execution and usually waits
2811 on a HGCM event semaphore.</para>
2812
2813 <para>When the request has been processed by the HGCM service, the VMM
2814 device sets the completion flag in the request header, sets the HGCM
2815 event and raises an IRQ for the guest. The IRQ handler signals the HGCM
2816 event semaphore and all HGCM callers check the completion flag in the
2817 corresponding request header. If the flag is set, the request is
2818 considered completed.</para>
2819 </sect1>
2820
2821 <sect1>
2822 <title>Protocol specification</title>
2823
2824 <para>The HGCM protocol definitions are contained in the
2825 <computeroutput>VBox/VBoxGuest.h</computeroutput></para>
2826
2827 <sect2>
2828 <title>Request header</title>
2829
2830 <para>HGCM request structures contains a generic header
2831 (VMMDevHGCMRequestHeader): <table>
2832 <title>HGCM Request Generic Header</title>
2833
2834 <tgroup cols="2">
2835 <tbody>
2836 <row>
2837 <entry><emphasis role="bold">Name</emphasis></entry>
2838
2839 <entry><emphasis role="bold">Description</emphasis></entry>
2840 </row>
2841
2842 <row>
2843 <entry>size</entry>
2844
2845 <entry>Size of the entire request.</entry>
2846 </row>
2847
2848 <row>
2849 <entry>version</entry>
2850
2851 <entry>Version of the header, must be set to
2852 <computeroutput>0x10001</computeroutput>.</entry>
2853 </row>
2854
2855 <row>
2856 <entry>type</entry>
2857
2858 <entry>Type of the request.</entry>
2859 </row>
2860
2861 <row>
2862 <entry>rc</entry>
2863
2864 <entry>HGCM return code, which will be set by the VMM
2865 device.</entry>
2866 </row>
2867
2868 <row>
2869 <entry>reserved1</entry>
2870
2871 <entry>A reserved field 1.</entry>
2872 </row>
2873
2874 <row>
2875 <entry>reserved2</entry>
2876
2877 <entry>A reserved field 2.</entry>
2878 </row>
2879
2880 <row>
2881 <entry>flags</entry>
2882
2883 <entry>HGCM flags, set by the VMM device.</entry>
2884 </row>
2885
2886 <row>
2887 <entry>result</entry>
2888
2889 <entry>The HGCM result code, set by the VMM device.</entry>
2890 </row>
2891 </tbody>
2892 </tgroup>
2893 </table> <note>
2894 <itemizedlist>
2895 <listitem>
2896 <para>All fields are 32-bit.</para>
2897 </listitem>
2898
2899 <listitem>
2900 <para>Fields from <computeroutput>size</computeroutput> to
2901 <computeroutput>reserved2</computeroutput> are a standard VMM
2902 device request header, which is used for other interfaces as
2903 well.</para>
2904 </listitem>
2905 </itemizedlist>
2906 </note></para>
2907
2908 <para>The <emphasis role="bold">type</emphasis> field indicates the
2909 type of the HGCM request: <table>
2910 <title>Request Types</title>
2911
2912 <tgroup cols="2">
2913 <tbody>
2914 <row>
2915 <entry><emphasis role="bold">Name (decimal
2916 value)</emphasis></entry>
2917
2918 <entry><emphasis role="bold">Description</emphasis></entry>
2919 </row>
2920
2921 <row>
2922 <entry>VMMDevReq_HGCMConnect
2923 (<computeroutput>60</computeroutput>)</entry>
2924
2925 <entry>Connect to a HGCM service.</entry>
2926 </row>
2927
2928 <row>
2929 <entry>VMMDevReq_HGCMDisconnect
2930 (<computeroutput>61</computeroutput>)</entry>
2931
2932 <entry>Disconnect from the service.</entry>
2933 </row>
2934
2935 <row>
2936 <entry>VMMDevReq_HGCMCall32
2937 (<computeroutput>62</computeroutput>)</entry>
2938
2939 <entry>Call a HGCM function using the 32-bit
2940 interface.</entry>
2941 </row>
2942
2943 <row>
2944 <entry>VMMDevReq_HGCMCall64
2945 (<computeroutput>63</computeroutput>)</entry>
2946
2947 <entry>Call a HGCM function using the 64-bit
2948 interface.</entry>
2949 </row>
2950
2951 <row>
2952 <entry>VMMDevReq_HGCMCancel
2953 (<computeroutput>64</computeroutput>)</entry>
2954
2955 <entry>Cancel a HGCM request currently being processed by a
2956 host HGCM service.</entry>
2957 </row>
2958 </tbody>
2959 </tgroup>
2960 </table></para>
2961
2962 <para>The <emphasis role="bold">flags</emphasis> field may contain:
2963 <table>
2964 <title>Flags</title>
2965
2966 <tgroup cols="2">
2967 <tbody>
2968 <row>
2969 <entry><emphasis role="bold">Name (hexadecimal
2970 value)</emphasis></entry>
2971
2972 <entry><emphasis role="bold">Description</emphasis></entry>
2973 </row>
2974
2975 <row>
2976 <entry>VBOX_HGCM_REQ_DONE
2977 (<computeroutput>0x00000001</computeroutput>)</entry>
2978
2979 <entry>The request has been processed by the host
2980 service.</entry>
2981 </row>
2982
2983 <row>
2984 <entry>VBOX_HGCM_REQ_CANCELLED
2985 (<computeroutput>0x00000002</computeroutput>)</entry>
2986
2987 <entry>This request was cancelled.</entry>
2988 </row>
2989 </tbody>
2990 </tgroup>
2991 </table></para>
2992 </sect2>
2993
2994 <sect2>
2995 <title>Connect</title>
2996
2997 <para>The connection request must be issued by the guest HGCM client
2998 before it can call the HGCM service (VMMDevHGCMConnect): <table>
2999 <title>Connect request</title>
3000
3001 <tgroup cols="2">
3002 <tbody>
3003 <row>
3004 <entry><emphasis role="bold">Name</emphasis></entry>
3005
3006 <entry><emphasis role="bold">Description</emphasis></entry>
3007 </row>
3008
3009 <row>
3010 <entry>header</entry>
3011
3012 <entry>The generic HGCM request header with type equal to
3013 VMMDevReq_HGCMConnect
3014 (<computeroutput>60</computeroutput>).</entry>
3015 </row>
3016
3017 <row>
3018 <entry>type</entry>
3019
3020 <entry>The type of the service location information (32
3021 bit).</entry>
3022 </row>
3023
3024 <row>
3025 <entry>location</entry>
3026
3027 <entry>The service location information (128 bytes).</entry>
3028 </row>
3029
3030 <row>
3031 <entry>clientId</entry>
3032
3033 <entry>The client identifier assigned to the connecting
3034 client by the HGCM subsystem (32-bit).</entry>
3035 </row>
3036 </tbody>
3037 </tgroup>
3038 </table> The <emphasis role="bold">type</emphasis> field tells the
3039 HGCM how to look for the requested service: <table>
3040 <title>Location Information Types</title>
3041
3042 <tgroup cols="2">
3043 <tbody>
3044 <row>
3045 <entry><emphasis role="bold">Name (hexadecimal
3046 value)</emphasis></entry>
3047
3048 <entry><emphasis role="bold">Description</emphasis></entry>
3049 </row>
3050
3051 <row>
3052 <entry>VMMDevHGCMLoc_LocalHost
3053 (<computeroutput>0x1</computeroutput>)</entry>
3054
3055 <entry>The requested service is a shared library located on
3056 the host and the location information contains the library
3057 name.</entry>
3058 </row>
3059
3060 <row>
3061 <entry>VMMDevHGCMLoc_LocalHost_Existing
3062 (<computeroutput>0x2</computeroutput>)</entry>
3063
3064 <entry>The requested service is a preloaded one and the
3065 location information contains the service name.</entry>
3066 </row>
3067 </tbody>
3068 </tgroup>
3069 </table> <note>
3070 <para>Currently preloaded HGCM services are hard-coded in
3071 VirtualBox: <itemizedlist>
3072 <listitem>
3073 <para>VBoxSharedFolders</para>
3074 </listitem>
3075
3076 <listitem>
3077 <para>VBoxSharedClipboard</para>
3078 </listitem>
3079
3080 <listitem>
3081 <para>VBoxGuestPropSvc</para>
3082 </listitem>
3083
3084 <listitem>
3085 <para>VBoxSharedOpenGL</para>
3086 </listitem>
3087 </itemizedlist></para>
3088 </note> There is no difference between both types of HGCM services,
3089 only the location mechanism is different.</para>
3090
3091 <para>The client identifier is returned by the host and must be used
3092 in all subsequent requests by the client.</para>
3093 </sect2>
3094
3095 <sect2>
3096 <title>Disconnect</title>
3097
3098 <para>This request disconnects the client and makes the client
3099 identifier invalid (VMMDevHGCMDisconnect): <table>
3100 <title>Disconnect request</title>
3101
3102 <tgroup cols="2">
3103 <tbody>
3104 <row>
3105 <entry><emphasis role="bold">Name</emphasis></entry>
3106
3107 <entry><emphasis role="bold">Description</emphasis></entry>
3108 </row>
3109
3110 <row>
3111 <entry>header</entry>
3112
3113 <entry>The generic HGCM request header with type equal to
3114 VMMDevReq_HGCMDisconnect
3115 (<computeroutput>61</computeroutput>).</entry>
3116 </row>
3117
3118 <row>
3119 <entry>clientId</entry>
3120
3121 <entry>The client identifier previously returned by the
3122 connect request (32-bit).</entry>
3123 </row>
3124 </tbody>
3125 </tgroup>
3126 </table></para>
3127 </sect2>
3128
3129 <sect2>
3130 <title>Call32 and Call64</title>
3131
3132 <para>Calls the HGCM service entry point (VMMDevHGCMCall) using 32-bit
3133 or 64-bit addresses: <table>
3134 <title>Call request</title>
3135
3136 <tgroup cols="2">
3137 <tbody>
3138 <row>
3139 <entry><emphasis role="bold">Name</emphasis></entry>
3140
3141 <entry><emphasis role="bold">Description</emphasis></entry>
3142 </row>
3143
3144 <row>
3145 <entry>header</entry>
3146
3147 <entry>The generic HGCM request header with type equal to
3148 either VMMDevReq_HGCMCall32
3149 (<computeroutput>62</computeroutput>) or
3150 VMMDevReq_HGCMCall64
3151 (<computeroutput>63</computeroutput>).</entry>
3152 </row>
3153
3154 <row>
3155 <entry>clientId</entry>
3156
3157 <entry>The client identifier previously returned by the
3158 connect request (32-bit).</entry>
3159 </row>
3160
3161 <row>
3162 <entry>function</entry>
3163
3164 <entry>The function code to be processed by the service (32
3165 bit).</entry>
3166 </row>
3167
3168 <row>
3169 <entry>cParms</entry>
3170
3171 <entry>The number of following parameters (32-bit). This
3172 value is 0 if the function requires no parameters.</entry>
3173 </row>
3174
3175 <row>
3176 <entry>parms</entry>
3177
3178 <entry>An array of parameter description structures
3179 (HGCMFunctionParameter32 or
3180 HGCMFunctionParameter64).</entry>
3181 </row>
3182 </tbody>
3183 </tgroup>
3184 </table></para>
3185
3186 <para>The 32-bit parameter description (HGCMFunctionParameter32)
3187 consists of 32-bit type field and 8 bytes of an opaque value, so 12
3188 bytes in total. The 64-bit variant (HGCMFunctionParameter64) consists
3189 of the type and 12 bytes of a value, so 16 bytes in total.</para>
3190
3191 <para><table>
3192 <title>Parameter types</title>
3193
3194 <tgroup cols="2">
3195 <tbody>
3196 <row>
3197 <entry><emphasis role="bold">Type</emphasis></entry>
3198
3199 <entry><emphasis role="bold">Format of the
3200 value</emphasis></entry>
3201 </row>
3202
3203 <row>
3204 <entry>VMMDevHGCMParmType_32bit (1)</entry>
3205
3206 <entry>A 32-bit value.</entry>
3207 </row>
3208
3209 <row>
3210 <entry>VMMDevHGCMParmType_64bit (2)</entry>
3211
3212 <entry>A 64-bit value.</entry>
3213 </row>
3214
3215 <row>
3216 <entry>VMMDevHGCMParmType_PhysAddr (3)</entry>
3217
3218 <entry>A 32-bit size followed by a 32-bit or 64-bit guest
3219 physical address.</entry>
3220 </row>
3221
3222 <row>
3223 <entry>VMMDevHGCMParmType_LinAddr (4)</entry>
3224
3225 <entry>A 32-bit size followed by a 32-bit or 64-bit guest
3226 linear address. The buffer is used both for guest to host
3227 and for host to guest data.</entry>
3228 </row>
3229
3230 <row>
3231 <entry>VMMDevHGCMParmType_LinAddr_In (5)</entry>
3232
3233 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
3234 used only for host to guest data.</entry>
3235 </row>
3236
3237 <row>
3238 <entry>VMMDevHGCMParmType_LinAddr_Out (6)</entry>
3239
3240 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
3241 used only for guest to host data.</entry>
3242 </row>
3243
3244 <row>
3245 <entry>VMMDevHGCMParmType_LinAddr_Locked (7)</entry>
3246
3247 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
3248 already locked by the guest.</entry>
3249 </row>
3250
3251 <row>
3252 <entry>VMMDevHGCMParmType_LinAddr_Locked_In (1)</entry>
3253
3254 <entry>Same as VMMDevHGCMParmType_LinAddr_In but the buffer
3255 is already locked by the guest.</entry>
3256 </row>
3257
3258 <row>
3259 <entry>VMMDevHGCMParmType_LinAddr_Locked_Out (1)</entry>
3260
3261 <entry>Same as VMMDevHGCMParmType_LinAddr_Out but the buffer
3262 is already locked by the guest.</entry>
3263 </row>
3264 </tbody>
3265 </tgroup>
3266 </table></para>
3267
3268 <para>The</para>
3269 </sect2>
3270
3271 <sect2>
3272 <title>Cancel</title>
3273
3274 <para>This request cancels a call request (VMMDevHGCMCancel): <table>
3275 <title>Cancel request</title>
3276
3277 <tgroup cols="2">
3278 <tbody>
3279 <row>
3280 <entry><emphasis role="bold">Name</emphasis></entry>
3281
3282 <entry><emphasis role="bold">Description</emphasis></entry>
3283 </row>
3284
3285 <row>
3286 <entry>header</entry>
3287
3288 <entry>The generic HGCM request header with type equal to
3289 VMMDevReq_HGCMCancel
3290 (<computeroutput>64</computeroutput>).</entry>
3291 </row>
3292 </tbody>
3293 </tgroup>
3294 </table></para>
3295 </sect2>
3296 </sect1>
3297
3298 <sect1>
3299 <title>Guest software interface</title>
3300
3301 <para>The guest HGCM clients can call HGCM services from both drivers
3302 and applications.</para>
3303
3304 <sect2>
3305 <title>The guest driver interface</title>
3306
3307 <para>The driver interface is implemented in the VirtualBox guest
3308 additions driver (VBoxGuest), which works with the VMM virtual device.
3309 Drivers must use the VBox Guest Library (VBGL), which provides an API
3310 for HGCM clients (<computeroutput>VBox/VBoxGuestLib.h</computeroutput>
3311 and <computeroutput>VBox/VBoxGuest.h</computeroutput>).</para>
3312
3313 <para><screen>
3314DECLR0VBGL(int) VbglR0HGCMConnect(VBGLHGCMHANDLE *pHandle, const char *pszServiceName, HGCMCLIENTID *pidClient);
3315 </screen> Connects to the service: <screen>
3316 VBoxGuestHGCMConnectInfo data;
3317
3318 memset(&amp;data, sizeof(VBoxGuestHGCMConnectInfo));
3319
3320 data.result = VINF_SUCCESS;
3321 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
3322 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
3323
3324 rc = VbglHGCMConnect (&amp;handle, "VBoxSharedFolders"&amp;data);
3325
3326 if (RT_SUCCESS (rc))
3327 {
3328 rc = data.result;
3329 }
3330
3331 if (RT_SUCCESS (rc))
3332 {
3333 /* Get the assigned client identifier. */
3334 ulClientID = data.u32ClientID;
3335 }
3336 </screen></para>
3337
3338 <para><screen>
3339DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData);
3340 </screen> Disconnects from the service. <screen>
3341 VBoxGuestHGCMDisconnectInfo data;
3342
3343 RtlZeroMemory (&amp;data, sizeof (VBoxGuestHGCMDisconnectInfo));
3344
3345 data.result = VINF_SUCCESS;
3346 data.u32ClientID = ulClientID;
3347
3348 rc = VbglHGCMDisconnect (handle, &amp;data);
3349 </screen></para>
3350
3351 <para><screen>
3352DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
3353 </screen> Calls a function in the service. <screen>
3354typedef struct _VBoxSFRead
3355{
3356 VBoxGuestHGCMCallInfo callInfo;
3357
3358 /** pointer, in: SHFLROOT
3359 * Root handle of the mapping which name is queried.
3360 */
3361 HGCMFunctionParameter root;
3362
3363 /** value64, in:
3364 * SHFLHANDLE of object to read from.
3365 */
3366 HGCMFunctionParameter handle;
3367
3368 /** value64, in:
3369 * Offset to read from.
3370 */
3371 HGCMFunctionParameter offset;
3372
3373 /** value64, in/out:
3374 * Bytes to read/How many were read.
3375 */
3376 HGCMFunctionParameter cb;
3377
3378 /** pointer, out:
3379 * Buffer to place data to.
3380 */
3381 HGCMFunctionParameter buffer;
3382
3383} VBoxSFRead;
3384
3385/** Number of parameters */
3386#define SHFL_CPARMS_READ (5)
3387
3388...
3389
3390 VBoxSFRead data;
3391
3392 /* The call information. */
3393 data.callInfo.result = VINF_SUCCESS; /* Will be returned by HGCM. */
3394 data.callInfo.u32ClientID = ulClientID; /* Client identifier. */
3395 data.callInfo.u32Function = SHFL_FN_READ; /* The function code. */
3396 data.callInfo.cParms = SHFL_CPARMS_READ; /* Number of parameters. */
3397
3398 /* Initialize parameters. */
3399 data.root.type = VMMDevHGCMParmType_32bit;
3400 data.root.u.value32 = pMap-&gt;root;
3401
3402 data.handle.type = VMMDevHGCMParmType_64bit;
3403 data.handle.u.value64 = hFile;
3404
3405 data.offset.type = VMMDevHGCMParmType_64bit;
3406 data.offset.u.value64 = offset;
3407
3408 data.cb.type = VMMDevHGCMParmType_32bit;
3409 data.cb.u.value32 = *pcbBuffer;
3410
3411 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
3412 data.buffer.u.Pointer.size = *pcbBuffer;
3413 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
3414
3415 rc = VbglHGCMCall (handle, &amp;data.callInfo, sizeof (data));
3416
3417 if (RT_SUCCESS (rc))
3418 {
3419 rc = data.callInfo.result;
3420 *pcbBuffer = data.cb.u.value32; /* This is returned by the HGCM service. */
3421 }
3422 </screen></para>
3423 </sect2>
3424
3425 <sect2>
3426 <title>Guest application interface</title>
3427
3428 <para>Applications call the VirtualBox Guest Additions driver to
3429 utilize the HGCM interface. There are IOCTL's which correspond to the
3430 <computeroutput>Vbgl*</computeroutput> functions: <itemizedlist>
3431 <listitem>
3432 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CONNECT</computeroutput></para>
3433 </listitem>
3434
3435 <listitem>
3436 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_DISCONNECT</computeroutput></para>
3437 </listitem>
3438
3439 <listitem>
3440 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CALL</computeroutput></para>
3441 </listitem>
3442 </itemizedlist></para>
3443
3444 <para>These IOCTL's get the same input buffer as
3445 <computeroutput>VbglHGCM*</computeroutput> functions and the output
3446 buffer has the same format as the input buffer. The same address can
3447 be used as the input and output buffers.</para>
3448
3449 <para>For example see the guest part of shared clipboard, which runs
3450 as an application and uses the HGCM interface.</para>
3451 </sect2>
3452 </sect1>
3453
3454 <sect1>
3455 <title>HGCM Service Implementation</title>
3456
3457 <para>The HGCM service is a shared library with a specific set of entry
3458 points. The library must export the
3459 <computeroutput>VBoxHGCMSvcLoad</computeroutput> entry point: <screen>
3460extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable)
3461 </screen></para>
3462
3463 <para>The service must check the
3464 <computeroutput>ptable-&gt;cbSize</computeroutput> and
3465 <computeroutput>ptable-&gt;u32Version</computeroutput> fields of the
3466 input structure and fill the remaining fields with function pointers of
3467 entry points and the size of the required client buffer size.</para>
3468
3469 <para>The HGCM service gets a dedicated thread, which calls service
3470 entry points synchronously, that is the service will be called again
3471 only when a previous call has returned. However, the guest calls can be
3472 processed asynchronously. The service must call a completion callback
3473 when the operation is actually completed. The callback can be issued
3474 from another thread as well.</para>
3475
3476 <para>Service entry points are listed in the
3477 <computeroutput>VBox/hgcmsvc.h</computeroutput> in the
3478 <computeroutput>VBOXHGCMSVCFNTABLE</computeroutput> structure. <table>
3479 <title>Service entry points</title>
3480
3481 <tgroup cols="2">
3482 <tbody>
3483 <row>
3484 <entry><emphasis role="bold">Entry</emphasis></entry>
3485
3486 <entry><emphasis role="bold">Description</emphasis></entry>
3487 </row>
3488
3489 <row>
3490 <entry>pfnUnload</entry>
3491
3492 <entry>The service is being unloaded.</entry>
3493 </row>
3494
3495 <row>
3496 <entry>pfnConnect</entry>
3497
3498 <entry>A client <computeroutput>u32ClientID</computeroutput>
3499 is connected to the service. The
3500 <computeroutput>pvClient</computeroutput> parameter points to
3501 an allocated memory buffer which can be used by the service to
3502 store the client information.</entry>
3503 </row>
3504
3505 <row>
3506 <entry>pfnDisconnect</entry>
3507
3508 <entry>A client is being disconnected.</entry>
3509 </row>
3510
3511 <row>
3512 <entry>pfnCall</entry>
3513
3514 <entry>A guest client calls a service function. The
3515 <computeroutput>callHandle</computeroutput> must be used in
3516 the VBOXHGCMSVCHELPERS::pfnCallComplete callback when the call
3517 has been processed.</entry>
3518 </row>
3519
3520 <row>
3521 <entry>pfnHostCall</entry>
3522
3523 <entry>Called by the VirtualBox host components to perform
3524 functions which should be not accessible by the guest. Usually
3525 this entry point is used by VirtualBox to configure the
3526 service.</entry>
3527 </row>
3528
3529 <row>
3530 <entry>pfnSaveState</entry>
3531
3532 <entry>The VM state is being saved and the service must save
3533 relevant information using the SSM API
3534 (<computeroutput>VBox/ssm.h</computeroutput>).</entry>
3535 </row>
3536
3537 <row>
3538 <entry>pfnLoadState</entry>
3539
3540 <entry>The VM is being restored from the saved state and the
3541 service must load the saved information and be able to
3542 continue operations from the saved state.</entry>
3543 </row>
3544 </tbody>
3545 </tgroup>
3546 </table></para>
3547 </sect1>
3548 </chapter>
3549
3550 <chapter id="rdpweb">
3551 <title>RDP Web Control</title>
3552
3553 <para>The VirtualBox <emphasis>RDP Web Control</emphasis> (RDPWeb)
3554 provides remote access to a running VM. RDPWeb is a RDP (Remote Desktop
3555 Protocol) client based on Flash technology and can be used from a Web
3556 browser with a Flash plugin.</para>
3557
3558 <sect1>
3559 <title>RDPWeb features</title>
3560
3561 <para>RDPWeb is embedded into a Web page and can connect to VRDP server
3562 in order to displays the VM screen and pass keyboard and mouse events to
3563 the VM.</para>
3564 </sect1>
3565
3566 <sect1>
3567 <title>RDPWeb reference</title>
3568
3569 <para>RDPWeb consists of two required components:<itemizedlist>
3570 <listitem>
3571 <para>Flash movie
3572 <computeroutput>RDPClientUI.swf</computeroutput></para>
3573 </listitem>
3574
3575 <listitem>
3576 <para>JavaScript helpers
3577 <computeroutput>webclient.js</computeroutput></para>
3578 </listitem>
3579 </itemizedlist></para>
3580
3581 <para>The VirtualBox SDK contains sample HTML code
3582 including:<itemizedlist>
3583 <listitem>
3584 <para>JavaScript library for embedding Flash content
3585 <computeroutput>SWFObject.js</computeroutput></para>
3586 </listitem>
3587
3588 <listitem>
3589 <para>Sample HTML page
3590 <computeroutput>webclient3.html</computeroutput></para>
3591 </listitem>
3592 </itemizedlist></para>
3593
3594 <sect2>
3595 <title>RDPWeb functions</title>
3596
3597 <para><computeroutput>RDPClientUI.swf</computeroutput> and
3598 <computeroutput>webclient.js</computeroutput> work with each other.
3599 JavaScript code is responsible for a proper SWF initialization,
3600 delivering mouse events to the SWF and processing resize requests from
3601 the SWF. On the other hand, the SWF contains a few JavaScript callable
3602 methods, which are used both from
3603 <computeroutput>webclient.js</computeroutput> and the user HTML
3604 page.</para>
3605
3606 <sect3>
3607 <title>JavaScript functions</title>
3608
3609 <para><computeroutput>webclient.js</computeroutput> contains helper
3610 functions. In the following table ElementId refers to an HTML
3611 element name or attribute, and Element to the HTML element itself.
3612 HTML code<programlisting>
3613 &lt;div id="FlashRDP"&gt;
3614 &lt;/div&gt;
3615</programlisting> would have ElementId equal to FlashRDP and Element equal to
3616 the div element.</para>
3617
3618 <para><itemizedlist>
3619 <listitem>
3620 <programlisting>RDPWebClient.embedSWF(SWFFileName, ElementId)</programlisting>
3621
3622 <para>Uses SWFObject library to replace the HTML element with
3623 the Flash movie.</para>
3624 </listitem>
3625
3626 <listitem>
3627 <programlisting>RDPWebClient.isRDPWebControlById(ElementId)</programlisting>
3628
3629 <para>Returns true if the given id refers to a RDPWeb Flash
3630 element.</para>
3631 </listitem>
3632
3633 <listitem>
3634 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting>
3635
3636 <para>Returns true if the given element is a RDPWeb Flash
3637 element.</para>
3638 </listitem>
3639
3640 <listitem>
3641 <programlisting>RDPWebClient.getFlashById(ElementId)</programlisting>
3642
3643 <para>Returns an element, which is referenced by the given id.
3644 This function will try to resolve any element, event if it is
3645 not a Flash movie.</para>
3646 </listitem>
3647 </itemizedlist></para>
3648 </sect3>
3649
3650 <sect3>
3651 <title>Flash methods callable from JavaScript</title>
3652
3653 <para><computeroutput>RDPWebClienUI.swf</computeroutput> methods can
3654 be called directly from JavaScript code on a HTML page.</para>
3655
3656 <itemizedlist>
3657 <listitem>
3658 <para>getProperty(Name)</para>
3659 </listitem>
3660
3661 <listitem>
3662 <para>setProperty(Name)</para>
3663 </listitem>
3664
3665 <listitem>
3666 <para>connect()</para>
3667 </listitem>
3668
3669 <listitem>
3670 <para>disconnect()</para>
3671 </listitem>
3672
3673 <listitem>
3674 <para>keyboardSendCAD()</para>
3675 </listitem>
3676 </itemizedlist>
3677 </sect3>
3678
3679 <sect3>
3680 <title>Flash JavaScript callbacks</title>
3681
3682 <para><computeroutput>RDPWebClienUI.swf</computeroutput> calls
3683 JavaScript functions provided by the HTML page.</para>
3684 </sect3>
3685 </sect2>
3686
3687 <sect2>
3688 <title>Embedding RDPWeb in an HTML page</title>
3689
3690 <para>It is necessary to include
3691 <computeroutput>webclient.js</computeroutput> helper script. If
3692 SWFObject library is used, the
3693 <computeroutput>swfobject.js</computeroutput> must be also included
3694 and RDPWeb flash content can be embedded to a Web page using dynamic
3695 HTML. The HTML must include a "placeholder", which consists of 2
3696 <computeroutput>div</computeroutput> elements.</para>
3697 </sect2>
3698 </sect1>
3699
3700 <sect1>
3701 <title>RDPWeb change log</title>
3702
3703 <sect2>
3704 <title>Version 1.2.28</title>
3705
3706 <itemizedlist>
3707 <listitem>
3708 <para><computeroutput>keyboardLayout</computeroutput>,
3709 <computeroutput>keyboardLayouts</computeroutput>,
3710 <computeroutput>UUID</computeroutput> properties.</para>
3711 </listitem>
3712
3713 <listitem>
3714 <para>Support for German keyboard layout on the client.</para>
3715 </listitem>
3716
3717 <listitem>
3718 <para>Rebranding to Oracle.</para>
3719 </listitem>
3720 </itemizedlist>
3721 </sect2>
3722
3723 <sect2>
3724 <title>Version 1.1.26</title>
3725
3726 <itemizedlist>
3727 <listitem>
3728 <para><computeroutput>webclient.js</computeroutput> is a part of
3729 the distribution package.</para>
3730 </listitem>
3731
3732 <listitem>
3733 <para><computeroutput>lastError</computeroutput> property.</para>
3734 </listitem>
3735
3736 <listitem>
3737 <para><computeroutput>keyboardSendScancodes</computeroutput> and
3738 <computeroutput>keyboardSendCAD</computeroutput> methods.</para>
3739 </listitem>
3740 </itemizedlist>
3741 </sect2>
3742
3743 <sect2>
3744 <title>Version 1.0.24</title>
3745
3746 <itemizedlist>
3747 <listitem>
3748 <para>Initial release.</para>
3749 </listitem>
3750 </itemizedlist>
3751 </sect2>
3752 </sect1>
3753 </chapter>
3754
3755 <chapter id="dnd">
3756 <title>Drag and Drop</title>
3757
3758 <para>Since VirtualBox 4.2 it's possible to transfer files from host to the
3759 Linux guests by dragging files, directories or text from the host into the
3760 guest's screen. This is called <emphasis>drag and drop
3761 (DnD)</emphasis>.</para>
3762
3763 <para>In version 5.0 support for Windows guests has been added, as well as
3764 the ability to transfer data the other way around, that is, from the guest
3765 to the host.</para>
3766
3767 <note><para>Currently only the VirtualBox Manager frontend supports drag and
3768 drop.</para></note>
3769
3770 <para>This chapter will show how to use the required interfaces provided
3771 by VirtualBox for adding drag and drop functionality to third-party
3772 frontends.</para>
3773
3774 <sect1>
3775 <title>Basic concepts</title>
3776
3777 <para>In order to use the interfaces provided by VirtualBox, some basic
3778 concepts needs to be understood first: To successfully initiate a
3779 drag and drop operation at least two sides needs to be involved, a
3780 <emphasis>source</emphasis> and a <emphasis>target</emphasis>:</para>
3781
3782 <para>The <emphasis>source</emphasis> is the side which provides the
3783 data, e.g. is the origin of data. This data can be stored within the
3784 source directly or can be retrieved on-demand by the source itself. Other
3785 interfaces don't care where the data from this source actually came
3786 from.</para>
3787
3788 <para>The <emphasis>target</emphasis> on the other hand is the side which
3789 provides the source a visual representation where the user can drop the
3790 data the source offers. This representation can be a window (or just a
3791 certain part of it), for example.</para>
3792
3793 <para>The source and the target have abstract interfaces called
3794 <link linkend="IDnDSource">IDnDSource</link> and
3795 <link linkend="IDnDTarget">IDnDTarget</link>. VirtualBox also
3796 provides implementations of both interfaces, called
3797 <link linkend="IGuestDnDSource">IGuestDnDSource</link> and
3798 <link linkend="IGuestDnDTarget">IGuestDnDTarget</link>. Both
3799 implementations are also used in the VirtualBox Manager frontend.</para>
3800 </sect1>
3801
3802 <sect1>
3803 <title>Supported formats</title>
3804
3805 <para>As the target needs to perform specific actions depending on the
3806 data the source provided, the target first needs to know what type of
3807 data it actually is going to retrieve. It might be that the source offers
3808 data the target cannot (or intentionally does not want to)
3809 support.</para>
3810
3811 <para>VirtualBox handles those data types by providing so-called
3812 <emphasis>MIME types</emphasis> -- these MIME types were originally
3813 defined in
3814 <ulink url="https://tools.ietf.org/html/rfc2046">RFC 2046</ulink> and
3815 are also called <emphasis>Content-types</emphasis>.
3816 <link linkend="IGuestDnDSource">IGuestDnDSource</link> and
3817 <link linkend="IGuestDnDTarget">IGuestDnDTarget</link> support
3818 the following MIME types by default:<itemizedlist>
3819 <listitem>
3820 <para><emphasis role="bold">text/uri-list</emphasis> - A list of
3821 URIs (Uniform Resource Identifier, see
3822 <ulink url="https://tools.ietf.org/html/rfc3986">RFC 3986</ulink>)
3823 pointing to the file and/or directory paths already transferred
3824 from the source to the target.</para>
3825 </listitem>
3826 <listitem>
3827 <para><emphasis role="bold">text/plain;charset=utf-8</emphasis> and
3828 <emphasis role="bold">UTF8_STRING</emphasis> - text in UTF-8
3829 format.</para>
3830 </listitem>
3831 <listitem>
3832 <para><emphasis role="bold">text/plain, TEXT</emphasis>
3833 and <emphasis role="bold">STRING</emphasis> - plain ASCII text,
3834 depending on the source's active ANSI page (if any).</para>
3835 </listitem>
3836 </itemizedlist>
3837 </para>
3838
3839 <para>If, for whatever reason, a certain default format should not be
3840 supported or a new format should be registered,
3841 <link linkend="IDnDSource">IDnDSource</link> and
3842 <link linkend="IDnDTarget">IDnDTarget</link> have methods derived from
3843 <link linkend="IDnDBase">IDnDBase</link> which provide adding,
3844 removing and enumerating specific formats.
3845 <note><para>Registering new or removing default formats on the guest side
3846 currently is not implemented.</para></note></para>
3847 </sect1>
3848
3849 </chapter>
3850
3851 <chapter id="vbox-auth">
3852 <title>VirtualBox external authentication modules</title>
3853
3854 <para>VirtualBox supports arbitrary external modules to perform
3855 authentication. The module is used when the authentication method is set
3856 to "external" for a particular VM VRDE access and the library was
3857 specified with <computeroutput>VBoxManage setproperty
3858 vrdeauthlibrary</computeroutput>. Web service also use the authentication
3859 module which was specified with <computeroutput>VBoxManage setproperty
3860 websrvauthlibrary</computeroutput>.</para>
3861
3862 <para>This library will be loaded by the VM or web service process on
3863 demand, i.e. when the first remote desktop connection is made by a client
3864 or when a client that wants to use the web service logs on.</para>
3865
3866 <para>External authentication is the most flexible as the external handler
3867 can both choose to grant access to everyone (like the "null"
3868 authentication method would) and delegate the request to the guest
3869 authentication component. When delegating the request to the guest
3870 component, the handler will still be called afterwards with the option to
3871 override the result.</para>
3872
3873 <para>An authentication library is required to implement exactly one entry
3874 point:</para>
3875
3876 <screen>#include "VBoxAuth.h"
3877
3878/**
3879 * Authentication library entry point.
3880 *
3881 * Parameters:
3882 *
3883 * szCaller The name of the component which calls the library (UTF8).
3884 * pUuid Pointer to the UUID of the accessed virtual machine. Can be NULL.
3885 * guestJudgement Result of the guest authentication.
3886 * szUser User name passed in by the client (UTF8).
3887 * szPassword Password passed in by the client (UTF8).
3888 * szDomain Domain passed in by the client (UTF8).
3889 * fLogon Boolean flag. Indicates whether the entry point is called
3890 * for a client logon or the client disconnect.
3891 * clientId Server side unique identifier of the client.
3892 *
3893 * Return code:
3894 *
3895 * AuthResultAccessDenied Client access has been denied.
3896 * AuthResultAccessGranted Client has the right to use the
3897 * virtual machine.
3898 * AuthResultDelegateToGuest Guest operating system must
3899 * authenticate the client and the
3900 * library must be called again with
3901 * the result of the guest
3902 * authentication.
3903 *
3904 * Note: When 'fLogon' is 0, only pszCaller, pUuid and clientId are valid and the return
3905 * code is ignored.
3906 */
3907AuthResult AUTHCALL AuthEntry(
3908 const char *szCaller,
3909 PAUTHUUID pUuid,
3910 AuthGuestJudgement guestJudgement,
3911 const char *szUser,
3912 const char *szPassword
3913 const char *szDomain
3914 int fLogon,
3915 unsigned clientId)
3916{
3917 /* Process request against your authentication source of choice. */
3918 // if (authSucceeded(...))
3919 // return AuthResultAccessGranted;
3920 return AuthResultAccessDenied;
3921}</screen>
3922
3923 <para>A note regarding the UUID implementation of the
3924 <computeroutput>pUuid</computeroutput> argument: VirtualBox uses a
3925 consistent binary representation of UUIDs on all platforms. For this
3926 reason the integer fields comprising the UUID are stored as little endian
3927 values. If you want to pass such UUIDs to code which assumes that the
3928 integer fields are big endian (often also called network byte order), you
3929 need to adjust the contents of the UUID to e.g. achieve the same string
3930 representation. The required changes are:<itemizedlist>
3931 <listitem>
3932 <para>reverse the order of byte 0, 1, 2 and 3</para>
3933 </listitem>
3934
3935 <listitem>
3936 <para>reverse the order of byte 4 and 5</para>
3937 </listitem>
3938
3939 <listitem>
3940 <para>reverse the order of byte 6 and 7.</para>
3941 </listitem>
3942 </itemizedlist>Using this conversion you will get identical results when
3943 converting the binary UUID to the string representation.</para>
3944
3945 <para>The <computeroutput>guestJudgement</computeroutput> argument
3946 contains information about the guest authentication status. For the first
3947 call, it is always set to
3948 <computeroutput>AuthGuestNotAsked</computeroutput>. In case the
3949 <computeroutput>AuthEntry</computeroutput> function returns
3950 <computeroutput>AuthResultDelegateToGuest</computeroutput>, a guest
3951 authentication will be attempted and another call to the
3952 <computeroutput>AuthEntry</computeroutput> is made with its result. This
3953 can be either granted / denied or no judgement (the guest component chose
3954 for whatever reason to not make a decision). In case there is a problem
3955 with the guest authentication module (e.g. the Additions are not installed
3956 or not running or the guest did not respond within a timeout), the "not
3957 reacted" status will be returned.</para>
3958 </chapter>
3959
3960 <chapter id="javaapi">
3961 <title>Using Java API</title>
3962
3963 <sect1>
3964 <title>Introduction</title>
3965
3966 <para>VirtualBox can be controlled by a Java API, both locally
3967 (COM/XPCOM) and from remote (SOAP) clients. As with the Python bindings,
3968 a generic glue layer tries to hide all platform differences, allowing
3969 for source and binary compatibility on different platforms.</para>
3970 </sect1>
3971
3972 <sect1>
3973 <title>Requirements</title>
3974
3975 <para>To use the Java bindings, there are certain requirements depending
3976 on the platform. First of all, you need JDK 1.5 (Java 5) or later. Also
3977 please make sure that the version of the VirtualBox API .jar file
3978 exactly matches the version of VirtualBox you use. To avoid confusion,
3979 the VirtualBox API provides versioning in the Java package name, e.g.
3980 the package is named <computeroutput>org.virtualbox_3_2</computeroutput>
3981 for VirtualBox version 3.2. <itemizedlist>
3982 <listitem>
3983 <para><emphasis role="bold">XPCOM</emphasis> - for all platforms,
3984 but Microsoft Windows. A Java bridge based on JavaXPCOM is shipped
3985 with VirtualBox. The classpath must contain
3986 <computeroutput>vboxjxpcom.jar</computeroutput> and the
3987 <computeroutput>vbox.home</computeroutput> property must be set to
3988 location where the VirtualBox binaries are. Please make sure that
3989 the JVM bitness matches bitness of VirtualBox you use as the XPCOM
3990 bridge relies on native libraries.</para>
3991
3992 <para>Start your application like this: <programlisting>
3993 java -cp vboxjxpcom.jar -Dvbox.home=/opt/virtualbox MyProgram
3994 </programlisting></para>
3995 </listitem>
3996
3997 <listitem>
3998 <para><emphasis role="bold">COM</emphasis> - for Microsoft
3999 Windows. We rely on <computeroutput>Jacob</computeroutput> - a
4000 generic Java to COM bridge - which has to be installed seperately.
4001 See <ulink
4002 url="http://sourceforge.net/projects/jacob-project/">http://sourceforge.net/projects/jacob-project/</ulink>
4003 for installation instructions. Also, the VirtualBox provided
4004 <computeroutput>vboxjmscom.jar</computeroutput> must be in the
4005 class path.</para>
4006
4007 <para>Start your application like this:
4008 <programlisting>java -cp vboxjmscom.jar;c:\jacob\jacob.jar -Djava.library.path=c:\jacob MyProgram</programlisting></para>
4009 </listitem>
4010
4011 <listitem>
4012 <para><emphasis role="bold">SOAP</emphasis> - all platforms. Java
4013 6 is required, as it comes with builtin support for SOAP via the
4014 JAX-WS library. Also, the VirtualBox provided
4015 <computeroutput>vbojws.jar</computeroutput> must be in the class
4016 path. In the SOAP case it's possible to create several
4017 VirtualBoxManager instances to communicate with multiple
4018 VirtualBox hosts.</para>
4019
4020 <para>Start your application like this: <programlisting>
4021 java -cp vboxjws.jar MyProgram
4022 </programlisting></para>
4023 </listitem>
4024 </itemizedlist></para>
4025
4026 <para>Exception handling is also generalized by the generic glue layer,
4027 so that all methods could throw
4028 <computeroutput>VBoxException</computeroutput> containing human-readable
4029 text message (see <computeroutput>getMessage()</computeroutput> method)
4030 along with wrapped original exception (see
4031 <computeroutput>getWrapped()</computeroutput> method).</para>
4032 </sect1>
4033
4034 <sect1>
4035 <title>Example</title>
4036
4037 <para>This example shows a simple use case of the Java API. Differences
4038 for SOAP vs. local version are minimal, and limited to the connection
4039 setup phase (see <computeroutput>ws</computeroutput> variable). In the
4040 SOAP case it's possible to create several VirtualBoxManager instances to
4041 communicate with multiple VirtualBox hosts. <programlisting>
4042 import org.virtualbox_4_3.*;
4043 ....
4044 VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
4045 boolean ws = false; // or true, if we need the SOAP version
4046 if (ws)
4047 {
4048 String url = "http://myhost:18034";
4049 String user = "test";
4050 String passwd = "test";
4051 mgr.connect(url, user, passwd);
4052 }
4053 IVirtualBox vbox = mgr.getVBox();
4054 System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
4055 // get first VM name
4056 String m = vbox.getMachines().get(0).getName();
4057 System.out.println("\nAttempting to start VM '" + m + "'");
4058 // start it
4059 mgr.startVm(m, null, 7000);
4060
4061 if (ws)
4062 mgr.disconnect();
4063
4064 mgr.cleanup();
4065 </programlisting> For more a complete example, see
4066 <computeroutput>TestVBox.java</computeroutput>, shipped with the
4067 SDK. It contains exception handling and error printing code, which
4068 is important for reliable larger scale projects.</para>
4069
4070 <para>It is good practice in long-running API clients to process the
4071 system events every now and then in the main thread (does not work
4072 in other threads). As a rule of thumb it makes sense to process them
4073 every few 100msec to every few seconds). This is done by
4074 calling<programlisting>
4075 mgr.waitForEvents(0);
4076 </programlisting>
4077 This avoids that a large number of system events accumulate, which can
4078 need a significant amount of memory, and as they also play a role in
4079 object cleanup it helps freeing additional memory in a timely manner
4080 which is used by the API implementation itself. Java's garbage collection
4081 approach already needs more memory due to the delayed freeing of memory
4082 used by no longer accessible objects, and not processing the system
4083 events exacerbates the memory usage. The
4084 <computeroutput>TestVBox.java</computeroutput> example code sprinkles
4085 such lines over the code to achieve the desired effect. In multi-threaded
4086 applications it can be called from the main thread periodically.
4087 Sometimes it's possible to use the non-zero timeout variant of the
4088 method, which then waits the specified number of milliseconds for
4089 events, processing them immediately as they arrive. It achieves better
4090 runtime behavior than separate sleeping/processing.</para>
4091 </sect1>
4092 </chapter>
4093
4094 <chapter>
4095 <title>License information</title>
4096
4097 <para>The sample code files shipped with the SDK are generally licensed
4098 liberally to make it easy for anyone to use this code for their own
4099 application code.</para>
4100
4101 <para>The Java files under
4102 <computeroutput>bindings/webservice/java/jax-ws/</computeroutput> (library
4103 files for the object-oriented web service) are, by contrast, licensed
4104 under the GNU Lesser General Public License (LGPL) V2.1.</para>
4105
4106 <para>See
4107 <computeroutput>sdk/bindings/webservice/java/jax-ws/src/COPYING.LIB</computeroutput>
4108 for the full text of the LGPL 2.1.</para>
4109
4110 <para>When in doubt, please refer to the individual source code files
4111 shipped with this SDK.</para>
4112 </chapter>
4113
4114 <chapter>
4115 <title>Main API change log</title>
4116
4117 <para>Generally, VirtualBox will maintain API compatibility within a major
4118 release; a major release occurs when the first or the second of the three
4119 version components of VirtualBox change (that is, in the x.y.z scheme, a
4120 major release is one where x or y change, but not when only z
4121 changes).</para>
4122
4123 <para>In other words, updates like those from 2.0.0 to 2.0.2 will not come
4124 with API breakages.</para>
4125
4126 <para>Migration between major releases most likely will lead to API
4127 breakage, so please make sure you updated code accordingly. The OOWS Java
4128 wrappers enforce that mechanism by putting VirtualBox classes into
4129 version-specific packages such as
4130 <computeroutput>org.virtualbox_2_2</computeroutput>. This approach allows
4131 for connecting to multiple VirtualBox versions simultaneously from the
4132 same Java application.</para>
4133
4134 <para>The following sections list incompatible changes that the Main API
4135 underwent since the original release of this SDK Reference with VirtualBox
4136 2.0. A change is deemed "incompatible" only if it breaks existing client
4137 code (e.g. changes in method parameter lists, renamed or removed
4138 interfaces and similar). In other words, the list does not contain new
4139 interfaces, methods or attributes or other changes that do not affect
4140 existing client code.</para>
4141
4142 <sect1>
4143 <title>Incompatible API changes with version 7.0</title>
4144
4145 <itemizedlist>
4146
4147 <listitem><para><link linkend="IGuestSession__directoryCopyFromGuest">IGuestSession::directoryCopyFromGuest()</link> and
4148 <link linkend="IGuestSession__directoryCopyToGuest">IGuestSession::directoryCopyToGuest()</link> no longer implicitly
4149 copy recursively and follow symbolic links -- for this to continue working, the newly introduced flags
4150 <link linkend="DirectoryCopyFlag__Recursive">DirectoryCopyFlag::Recursive</link> and/or
4151 <link linkend="DirectoryCopyFlag__FollowLinks">DirectoryCopyFlag::FollowLinks</link> have to be used.</para>
4152 </listitem>
4153
4154 </itemizedlist>
4155
4156 </sect1>
4157
4158 <sect1>
4159 <title>Incompatible API changes with version 6.1</title>
4160
4161 <itemizedlist>
4162
4163 <listitem><para>Split off the graphics adapter part of
4164 <link linkend="IMachine">IMachine</link> into
4165 <link linkend="IGraphicsAdapter">IGraphicsAdapter</link>.
4166 This moved 5 attributes.</para>
4167 </listitem>
4168
4169 </itemizedlist>
4170
4171 </sect1>
4172
4173 <sect1>
4174 <title>Incompatible API changes with version 6.0</title>
4175
4176 <itemizedlist>
4177
4178 <listitem><para>Video recording APIs were changed as follows:
4179 <itemizedlist>
4180 <listitem><para>All attributes which were living in <link linkend="IMachine">IMachine</link> before
4181 have been moved to an own, dedicated interface named <link linkend="IRecordingSettings">IRecordingSettings</link>.
4182 This new interface can be accessed via the new <link linkend="IMachine__recordingSettings">IMachine::recordingSettings</link>
4183 attribute. This should emphasize that recording is not limited to video capturing as such.</para>
4184 </listitem>
4185
4186 <listitem><para>For further flexibility all specific per-VM-screen settings have been moved to a new interface
4187 called <link linkend="IRecordingScreenSettings">IRecordingScreenSettings</link>. Such settings now exist per configured
4188 VM display and can be retrieved via the <link linkend="IRecordingSettings__screens">IRecordingSettings::screens</link>
4189 attribute or the <link linkend="IRecordingSettings__getScreenSettings">IRecordingSettings::getScreenSettings</link>
4190 method.
4191 <note><para>For now all screen settings will share the same settings, e.g. different settings on a per-screen basis
4192 is not implemented yet.</para></note>
4193 </para>
4194 </listitem>
4195
4196 <listitem><para>The event <computeroutput>IVideoCaptureChangedEvent</computeroutput> was renamed into
4197 <link linkend="IRecordingChangedEvent">IRecordingChangedEvent</link>.</para>
4198 </listitem>
4199
4200 </itemizedlist>
4201 </para></listitem>
4202
4203 <listitem><para>Guest Control APIs were changed as follows:
4204 <itemizedlist>
4205 <listitem><para><link linkend="IGuest__createSession">IGuest::createSession()</link>,
4206 <link linkend="IGuestSession__processCreate">IGuestSession::processCreate()</link>,
4207 <link linkend="IGuestSession__processCreateEx">IGuestSession::processCreateEx()</link>,
4208 <link linkend="IGuestSession__directoryOpen">IGuestSession::directoryOpen()</link> and
4209 <link linkend="IGuestSession__fileOpen">IGuestSession::fileOpen()</link> now will
4210 return the new error code VBOX_E_MAXIMUM_REACHED if the limit for the according object
4211 group has been reached.</para>
4212 </listitem>
4213
4214 <listitem><para>The enumerations FileOpenExFlags, FsObjMoveFlags and DirectoryCopyFlags have
4215 been renamed to <link linkend="FileOpenExFlag">FileOpenExFlag</link>,
4216 <link linkend="FsObjMoveFlag">FsObjMoveFlag</link> and <link linkend="DirectoryCopyFlag">DirectoryCopyFlag</link>
4217 accordingly to match the rest of the API.</para>
4218 </listitem>
4219
4220 <listitem>
4221 <para>The following methods have been implemented:
4222 <computeroutput>IGuestSession::directoryCopyFromGuest()</computeroutput> and
4223 <computeroutput>IGuestSession::directoryCopyToGuest()</computeroutput>.
4224 </para>
4225
4226 <para>The following attributes have been implemented:
4227 <computeroutput>IGuestFsObjInfo::accessTime</computeroutput>,
4228 <computeroutput>IGuestFsObjInfo::birthTime</computeroutput>,
4229 <computeroutput>IGuestFsObjInfo::changeTime</computeroutput> and
4230 <computeroutput>IGuestFsObjInfo::modificationTime</computeroutput>.
4231 </para>
4232
4233 </listitem>
4234 </itemizedlist>
4235 </para></listitem>
4236
4237 <listitem><para>The webservice version of the <link linkend="ISharedFolder">ISharedFolder</link>
4238 interface was changed from a struct to a managed object. This causes incompatiblities on the
4239 protocol level as the shared folder attributes are not returned in the responses of
4240 <link linkend="IVirtualBox__sharedFolders">IVirtualBox::getSharedFolders</link> and
4241 <link linkend="IMachine__sharedFolders">IMachine::getSharedFolders</link> anymore. They
4242 return object UUIDs instead which need be wrapped by stub objects. The change is not visible when
4243 using the appropriate client bindings from the most recent VirtualBox SDK.
4244 </para></listitem>
4245
4246 </itemizedlist>
4247
4248 </sect1>
4249
4250 <sect1>
4251 <title>Incompatible API changes with version 5.x</title>
4252
4253 <itemizedlist>
4254 <listitem><para>ProcessCreateFlag::NoProfile has been renamed to
4255 <link linkend="ProcessCreateFlag__Profile">ProcessCreateFlag::Profile</link>,
4256 whereas the semantics also has been changed: ProcessCreateFlag::NoProfile
4257 explicitly <emphasis role="bold">did not</emphasis> utilize the guest user's profile data,
4258 which in turn <link linkend="ProcessCreateFlag__Profile">ProcessCreateFlag::Profile</link>
4259 explicitly <emphasis role="bold">does now</emphasis>.</para>
4260 </listitem>
4261 </itemizedlist>
4262
4263 </sect1>
4264
4265 <sect1>
4266 <title>Incompatible API changes with version 5.0</title>
4267
4268 <itemizedlist>
4269 <listitem>
4270 <para>The methods for saving state, adopting a saved state file,
4271 discarding a saved state, taking a snapshot, restoring
4272 a snapshot and deleting a snapshot have been moved from
4273 <computeroutput>IConsole</computeroutput> to
4274 <computeroutput>IMachine</computeroutput>. This straightens out the
4275 logical placement of methods and was necessary to resolve a
4276 long-standing issue, preventing 32-bit API clients from invoking
4277 those operations in the case where no VM is running.
4278 <itemizedlist>
4279 <listitem><para><link linkend="IMachine__saveState">IMachine::saveState()</link>
4280 replaces
4281 <computeroutput>IConsole::saveState()</computeroutput></para>
4282 </listitem>
4283 <listitem>
4284 <para><link linkend="IMachine__adoptSavedState">IMachine::adoptSavedState()</link>
4285 replaces
4286 <computeroutput>IConsole::adoptSavedState()</computeroutput></para>
4287 </listitem>
4288 <listitem>
4289 <para><link linkend="IMachine__discardSavedState">IMachine::discardSavedState()</link>
4290 replaces
4291 <computeroutput>IConsole::discardSavedState()</computeroutput></para>
4292 </listitem>
4293 <listitem>
4294 <para><link linkend="IMachine__takeSnapshot">IMachine::takeSnapshot()</link>
4295 replaces
4296 <computeroutput>IConsole::takeSnapshot()</computeroutput></para>
4297 </listitem>
4298 <listitem>
4299 <para><link linkend="IMachine__deleteSnapshot">IMachine::deleteSnapshot()</link>
4300 replaces
4301 <computeroutput>IConsole::deleteSnapshot()</computeroutput></para>
4302 </listitem>
4303 <listitem>
4304 <para><link linkend="IMachine__deleteSnapshotAndAllChildren">IMachine::deleteSnapshotAndAllChildren()</link>
4305 replaces
4306 <computeroutput>IConsole::deleteSnapshotAndAllChildren()</computeroutput></para>
4307 </listitem>
4308 <listitem>
4309 <para><link linkend="IMachine__deleteSnapshotRange">IMachine::deleteSnapshotRange()</link>
4310 replaces
4311 <computeroutput>IConsole::deleteSnapshotRange()</computeroutput></para>
4312 </listitem>
4313 <listitem>
4314 <para><link linkend="IMachine__restoreSnapshot">IMachine::restoreSnapshot()</link>
4315 replaces
4316 <computeroutput>IConsole::restoreSnapshot()</computeroutput></para>
4317 </listitem>
4318 </itemizedlist>
4319 Small adjustments to the parameter lists have been made to reduce
4320 the number of API calls when taking online snapshots (no longer
4321 needs explicit pausing), and taking a snapshot also returns now
4322 the snapshot id (useful for finding the right snapshot if there
4323 are non-unique snapshot names).</para>
4324 </listitem>
4325
4326 <listitem>
4327 <para>Two new machine states have been introduced to allow proper
4328 distinction between saving state and taking a snapshot.
4329 <link linkend="MachineState__Saving">MachineState::Saving</link>
4330 now is used exclusively while the VM's state is being saved, without
4331 any overlaps with snapshot functionality. The new state
4332 <link linkend="MachineState__Snapshotting">MachineState::Snapshotting</link>
4333 is used when an offline snapshot is taken and likewise the new state
4334 <link linkend="MachineState__OnlineSnapshotting">MachineState::OnlineSnapshotting</link>
4335 is used when an online snapshot is taken.</para>
4336 </listitem>
4337
4338 <listitem>
4339 <para>A new event has been introduced, which signals when a snapshot
4340 has been restored:
4341 <link linkend="ISnapshotRestoredEvent">ISnapshotRestoredEvent</link>.
4342 Previously the event
4343 <link linkend="ISnapshotDeletedEvent">ISnapshotDeletedEvent</link>
4344 was signalled, which isn't logical (but could be distinguished from
4345 actual deletion by the fact that the snapshot was still
4346 there).</para>
4347 </listitem>
4348
4349 <listitem>
4350 <para>The method
4351 <link linkend="IVirtualBox__createMedium">IVirtualBox::createMedium()</link>
4352 replaces
4353 <computeroutput>VirtualBox::createHardDisk()</computeroutput>.
4354 Adjusting existing code needs adding two parameters with
4355 value <computeroutput>AccessMode_ReadWrite</computeroutput>
4356 and <computeroutput>DeviceType_HardDisk</computeroutput>
4357 respectively. The new method supports creating floppy and
4358 DVD images, and (less obviously) further API functionality
4359 such as cloning floppy images.</para>
4360 </listitem>
4361
4362 <listitem>
4363 <para>The method
4364 <link linkend="IMachine__getStorageControllerByInstance">IMachine::getStorageControllerByInstance()</link>
4365 now has an additional parameter (first parameter), for specifying the
4366 storage bus which the storage controller must be using. The method
4367 was not useful before, as the instance numbers are only unique for a
4368 specfic storage bus.</para>
4369 </listitem>
4370
4371 <listitem>
4372 <para>The attribute
4373 <computeroutput>IMachine::sessionType</computeroutput> has been
4374 renamed to
4375 <link linkend="IMachine__sessionName">IMachine::sessionName()</link>.
4376 This cleans up the confusing terminology (as the session type is
4377 something different).</para>
4378 </listitem>
4379
4380 <listitem>
4381 <para>The attribute
4382 <computeroutput>IMachine::guestPropertyNotificationPatterns</computeroutput>
4383 has been removed. In practice it was not usable because it is too
4384 global and didn't distinguish between API clients.</para>
4385 </listitem>
4386
4387 <listitem><para>Drag and drop APIs were changed as follows:<itemizedlist>
4388
4389 <listitem>
4390 <para>Methods for providing host to guest drag and drop
4391 functionality, such as
4392 <computeroutput>IGuest::dragHGEnter</computeroutput>,
4393 <computeroutput>IGuest::dragHGMove()</computeroutput>,
4394 <computeroutput>IGuest::dragHGLeave()</computeroutput>,
4395 <computeroutput>IGuest::dragHGDrop()</computeroutput> and
4396 <computeroutput>IGuest::dragHGPutData()</computeroutput>,
4397 have been moved to an abstract base class called
4398 <link linkend="IDnDTarget">IDnDTarget</link>.
4399 VirtualBox implements this base class in the
4400 <link linkend="IGuestDnDTarget">IGuestDnDTarget</link>
4401 interface. The implementation can be used by using the
4402 <link linkend="IGuest__dnDTarget">IGuest::dnDTarget()</link>
4403 method.</para>
4404 <para>Methods for providing guest to host drag and drop
4405 functionality, such as
4406 <computeroutput>IGuest::dragGHPending()</computeroutput>,
4407 <computeroutput>IGuest::dragGHDropped()</computeroutput> and
4408 <computeroutput>IGuest::dragGHGetData()</computeroutput>,
4409 have been moved to an abstract base class called
4410 <link linkend="IDnDSource">IDnDSource</link>.
4411 VirtualBox implements this base class in the
4412 <link linkend="IGuestDnDSource">IGuestDnDSource</link>
4413 interface. The implementation can be used by using the
4414 <link linkend="IGuest__dnDSource">IGuest::dnDSource()</link>
4415 method.</para>
4416 </listitem>
4417
4418 <listitem>
4419 <para>The <computeroutput>DragAndDropAction</computeroutput>
4420 enumeration has been renamed to
4421 <link linkend="DnDAction">DnDAction</link>.</para>
4422 </listitem>
4423
4424 <listitem>
4425 <para>The <computeroutput>DragAndDropMode</computeroutput>
4426 enumeration has been renamed to
4427 <link linkend="DnDMode">DnDMode</link>.</para>
4428 </listitem>
4429
4430 <listitem>
4431 <para>The attribute
4432 <computeroutput>IMachine::dragAndDropMode</computeroutput>
4433 has been renamed to
4434 <link linkend="IMachine__dnDMode">IMachine::dnDMode()</link>.</para>
4435 </listitem>
4436
4437 <listitem>
4438 <para>The event
4439 <computeroutput>IDragAndDropModeChangedEvent</computeroutput>
4440 has been renamed to
4441 <link linkend="IDnDModeChangedEvent">IDnDModeChangedEvent</link>.</para>
4442 </listitem>
4443
4444 </itemizedlist></para>
4445 </listitem>
4446
4447 <listitem><para>IDisplay and IFramebuffer interfaces were changed to
4448 allow IFramebuffer object to reside in a separate frontend
4449 process:<itemizedlist>
4450
4451 <listitem><para>
4452 IDisplay::ResizeCompleted() has been removed, because the
4453 IFramebuffer object does not provide the screen memory anymore.
4454 </para></listitem>
4455
4456 <listitem><para>
4457 IDisplay::SetFramebuffer() has been replaced with
4458 IDisplay::AttachFramebuffer() and IDisplay::DetachFramebuffer().
4459 </para></listitem>
4460
4461 <listitem><para>
4462 IDisplay::GetFramebuffer() has been replaced with
4463 IDisplay::QueryFramebuffer().
4464 </para></listitem>
4465
4466 <listitem><para>
4467 IDisplay::GetScreenResolution() has a new output parameter
4468 <computeroutput>guestMonitorStatus</computeroutput>
4469 which tells whether the monitor is enabled in the guest.
4470 </para></listitem>
4471
4472 <listitem><para>
4473 IDisplay::TakeScreenShot() and IDisplay::TakeScreenShotToArray()
4474 have a new parameter
4475 <computeroutput>bitmapFormat</computeroutput>. As a consequence of
4476 this, IDisplay::TakeScreenShotPNGToArray() has been removed.
4477 </para></listitem>
4478
4479 <listitem><para>
4480 IFramebuffer::RequestResize() has been replaced with
4481 IFramebuffer::NotifyChange().
4482 </para></listitem>
4483
4484 <listitem><para>
4485 IFramebuffer::NotifyUpdateImage() added to support IFramebuffer
4486 objects in a different process.
4487 </para></listitem>
4488
4489 <listitem><para>
4490 IFramebuffer::Lock(), IFramebuffer::Unlock(),
4491 IFramebuffer::Address(), IFramebuffer::UsesGuestVRAM() have been
4492 removed because the IFramebuffer object does not provide the screen
4493 memory anymore.
4494 </para></listitem>
4495
4496 </itemizedlist></para>
4497 </listitem>
4498
4499 <listitem><para>IGuestSession, IGuestFile and IGuestProcess interfaces
4500 were changed as follows:
4501 <itemizedlist>
4502 <listitem>
4503 <para>Replaced IGuestSession::directoryQueryInfo and
4504 IGuestSession::fileQueryInfo with a new
4505 <link linkend="IGuestSession__fsObjQueryInfo">IGuestSession::fsObjQueryInfo</link>
4506 method that works on any type of file system object.</para>
4507 </listitem>
4508 <listitem>
4509 <para>Replaced IGuestSession::fileRemove,
4510 IGuestSession::symlinkRemoveDirectory and
4511 IGuestSession::symlinkRemoveFile with a new
4512 <link linkend="IGuestSession__fsObjRemove">IGuestSession::fsObjRemove</link>
4513 method that works on any type of file system object except
4514 directories. (fileRemove also worked on any type of object
4515 too, though that was not the intent of the method.)</para>
4516 </listitem>
4517 <listitem>
4518 <para>Replaced IGuestSession::directoryRename and
4519 IGuestSession::directoryRename with a new
4520 <link linkend="IGuestSession__fsObjRename">IGuestSession::fsObjRename</link>
4521 method that works on any type of file system object.
4522 (directoryRename and fileRename may already have worked for
4523 any kind of object, but that was never the intent of the
4524 methods.)</para>
4525 </listitem>
4526 <listitem>
4527 <para>Replaced the unimplemented IGuestSession::directorySetACL
4528 and IGuestSession::fileSetACL with a new
4529 <link linkend="IGuestSession__fsObjSetACL">IGuestSession::fsObjSetACL</link>
4530 method that works on all type of file system object. Also
4531 added a UNIX-style mode parameter as an alternative to the
4532 ACL.</para>
4533 </listitem>
4534 <listitem>
4535 <para>Replaced IGuestSession::fileRemove,
4536 IGuestSession::symlinkRemoveDirectory and
4537 IGuestSession::symlinkRemoveFile with a new
4538 <link linkend="IGuestSession__fsObjRemove">IGuestSession::fsObjRemove</link>
4539 method that works on any type of file system object except
4540 directories (fileRemove also worked on any type of object,
4541 though that was not the intent of the method.)</para>
4542 </listitem>
4543 <listitem>
4544 <para>Renamed IGuestSession::copyTo to
4545 <link linkend="IGuestSession__fileCopyToGuest">IGuestSession::fileCopyToGuest</link>.</para>
4546 </listitem>
4547 <listitem>
4548 <para>Renamed IGuestSession::copyFrom to
4549 <link linkend="IGuestSession__fileCopyFromGuest">IGuestSession::fileCopyFromGuest</link>.</para>
4550 </listitem>
4551 <listitem>
4552 <para>Renamed the CopyFileFlag enum to
4553 <link linkend="FileCopyFlag">FileCopyFlag</link>.</para>
4554 </listitem>
4555 <listitem>
4556 <para>Renamed the IGuestSession::environment attribute to
4557 <link linkend="IGuestSession__environmentChanges">IGuestSession::environmentChanges</link>
4558 to better reflect what it does.</para>
4559 </listitem>
4560 <listitem>
4561 <para>Changed the
4562 <link linkend="IProcess__environment">IGuestProcess::environment</link>
4563 to a stub returning E_NOTIMPL since it wasn't doing what was
4564 advertised (returned changes, not the actual environment).</para>
4565 </listitem>
4566 <listitem>
4567 <para>Renamed IGuestSession::environmentSet to
4568 <link linkend="IGuestSession__environmentScheduleSet">IGuestSession::environmentScheduleSet</link>
4569 to better reflect what it does.</para>
4570 </listitem>
4571 <listitem>
4572 <para>Renamed IGuestSession::environmentUnset to
4573 <link linkend="IGuestSession__environmentScheduleUnset">IGuestSession::environmentScheduleUnset</link>
4574 to better reflect what it does.</para>
4575 </listitem>
4576 <listitem>
4577 <para>Removed IGuestSession::environmentGet it was only getting
4578 changes while giving the impression it was actual environment
4579 variables, and it did not represent scheduled unset
4580 operations.</para>
4581 </listitem>
4582 <listitem>
4583 <para>Removed IGuestSession::environmentClear as it duplicates
4584 assigning an empty array to the
4585 <link linkend="IGuestSession__environmentChanges">IGuestSession::environmentChanges</link>
4586 (formerly known as IGuestSession::environment).</para>
4587 </listitem>
4588 <listitem>
4589 <para>Changed the
4590 <link linkend="IGuestSession__processCreate">IGuestSession::processCreate</link>
4591 and
4592 <link linkend="IGuestSession__processCreateEx">IGuestSession::processCreateEx</link>
4593 methods to accept arguments starting with argument zero (argv[0])
4594 instead of argument one (argv[1]). (Not yet implemented on the
4595 guest additions side, so argv[0] will probably be ignored for a
4596 short while.)</para>
4597 </listitem>
4598
4599 <listitem>
4600 <para>Added a followSymlink parameter to the following methods:
4601 <itemizedlist>
4602 <listitem><para><link linkend="IGuestSession__directoryExists">IGuestSession::directoryExists</link></para></listitem>
4603 <listitem><para><link linkend="IGuestSession__fileExists">IGuestSession::fileExists</link></para></listitem>
4604 <listitem><para><link linkend="IGuestSession__fileQuerySize">IGuestSession::fileQuerySize</link></para></listitem>
4605 </itemizedlist></para>
4606 </listitem>
4607 <listitem>
4608 <para>The parameters to the
4609 <link linkend="IGuestSession__fileOpen">IGuestSession::fileOpen</link>
4610 and
4611 <link linkend="IGuestSession__fileOpenEx">IGuestSession::fileOpenEx</link>
4612 methods were altered:<itemizedlist>
4613 <listitem><para>The openMode string parameter was replaced by
4614 the enum
4615 <link linkend="FileAccessMode">FileAccessMode</link>
4616 and renamed to accessMode.</para></listitem>
4617 <listitem><para>The disposition string parameter was replaced
4618 by the enum
4619 <link linkend="FileOpenAction">FileOpenAction</link>
4620 and renamed to openAction.</para></listitem>
4621 <listitem><para>The unimplemented sharingMode string parameter
4622 was replaced by the enum
4623 <link linkend="FileSharingMode">FileSharingMode</link>
4624 (fileOpenEx only).</para></listitem>
4625 <listitem><para>Added a flags parameter taking a list of
4626 <link linkend="FileOpenExFlag">FileOpenExFlag</link> values
4627 (fileOpenEx only).</para></listitem>
4628 <listitem><para>Removed the offset parameter (fileOpenEx
4629 only).</para></listitem>
4630 </itemizedlist></para>
4631 </listitem>
4632
4633 <listitem>
4634 <para><link linkend="IFile__seek">IGuestFile::seek</link> now
4635 returns the new offset.</para>
4636 </listitem>
4637 <listitem>
4638 <para>Renamed the FileSeekType enum used by
4639 <link linkend="IFile__seek">IGuestFile::seek</link>
4640 to <link linkend="FileSeekOrigin">FileSeekOrigin</link> and
4641 added the missing End value and renaming the Set to
4642 Begin.</para>
4643 </listitem>
4644 <listitem>
4645 <para>Extended the unimplemented
4646 <link linkend="IFile__setACL">IGuestFile::setACL</link>
4647 method with a UNIX-style mode parameter as an alternative to
4648 the ACL.</para>
4649 </listitem>
4650 <listitem>
4651 <para>Renamed the IFile::openMode attribute to
4652 <link linkend="IFile__accessMode">IFile::accessMode</link>
4653 and change the type from string to
4654 <link linkend="FileAccessMode">FileAccessMode</link> to reflect
4655 the changes to the fileOpen methods.</para>
4656 </listitem>
4657 <listitem>
4658 <para>Renamed the IGuestFile::disposition attribute to
4659 <link linkend="IFile__openAction">IFile::openAction</link> and
4660 change the type from string to
4661 <link linkend="FileOpenAction">FileOpenAction</link> to reflect
4662 the changes to the fileOpen methods.</para>
4663 </listitem>
4664
4665 <!-- Non-incompatible things worth mentioning (stubbed methods/attrs aren't worth it). -->
4666 <listitem>
4667 <para>Added
4668 <link linkend="IGuestSession__pathStyle">IGuestSession::pathStyle</link>
4669 attribute.</para>
4670 </listitem>
4671 <listitem>
4672 <para>Added
4673 <link linkend="IGuestSession__fsObjExists">IGuestSession::fsObjExists</link>
4674 attribute.</para>
4675 </listitem>
4676
4677 </itemizedlist>
4678 </para>
4679 </listitem>
4680
4681 <listitem><para>
4682 IConsole::GetDeviceActivity() returns information about multiple
4683 devices.
4684 </para></listitem>
4685
4686 <listitem><para>
4687 IMachine::ReadSavedThumbnailToArray() has a new parameter
4688 <computeroutput>bitmapFormat</computeroutput>. As a consequence of
4689 this, IMachine::ReadSavedThumbnailPNGToArray() has been removed.
4690 </para></listitem>
4691
4692 <listitem><para>
4693 IMachine::QuerySavedScreenshotPNGSize() has been renamed to
4694 IMachine::QuerySavedScreenshotInfo() which also returns
4695 an array of available screenshot formats.
4696 </para></listitem>
4697
4698 <listitem><para>
4699 IMachine::ReadSavedScreenshotPNGToArray() has been renamed to
4700 IMachine::ReadSavedScreenshotToArray() which has a new parameter
4701 <computeroutput>bitmapFormat</computeroutput>.
4702 </para></listitem>
4703
4704 <listitem><para>
4705 IMachine::QuerySavedThumbnailSize() has been removed.
4706 </para></listitem>
4707
4708 <listitem>
4709 <para>The method
4710 <link linkend="IWebsessionManager__getSessionObject">IWebsessionManager::getSessionObject()</link>
4711 now returns a new <link linkend="ISession">ISession</link> instance
4712 for every invocation. This puts the behavior in line with other
4713 binding styles, which never forced the equivalent of establishing
4714 another connection and logging in again to get another
4715 instance.</para>
4716 </listitem>
4717 </itemizedlist>
4718 </sect1>
4719
4720 <sect1>
4721 <title>Incompatible API changes with version 4.3</title>
4722
4723 <itemizedlist>
4724 <listitem>
4725 <para>The explicit medium locking methods
4726 <link linkend="IMedium__lockRead">IMedium::lockRead()</link>
4727 and <link linkend="IMedium__lockWrite">IMedium::lockWrite()</link>
4728 have been redesigned. They return a lock token object reference
4729 now, and calling the
4730 <link linkend="IToken__abandon">IToken::abandon()</link> method (or
4731 letting the reference count to this object drop to 0) will unlock
4732 it. This eliminates the rather common problem that an API client
4733 crash left behind locks, and also improves the safety (API clients
4734 can't release locks they didn't obtain).</para>
4735 </listitem>
4736
4737 <listitem>
4738 <para>The parameter list of
4739 <link linkend="IAppliance__write">IAppliance::write()</link>
4740 has been changed slightly, to allow multiple flags to be
4741 passed.</para>
4742 </listitem>
4743
4744 <listitem>
4745 <para><computeroutput>IMachine::delete</computeroutput>
4746 has been renamed to
4747 <link linkend="IMachine__deleteConfig">IMachine::deleteConfig()</link>,
4748 to improve API client binding compatibility.</para>
4749 </listitem>
4750
4751 <listitem>
4752 <para><computeroutput>IMachine::export</computeroutput>
4753 has been renamed to
4754 <link linkend="IMachine__exportTo">IMachine::exportTo()</link>,
4755 to improve API client binding compatibility.</para>
4756 </listitem>
4757
4758 <listitem>
4759 <para>For
4760 <link linkend="IMachine__launchVMProcess">IMachine::launchVMProcess()</link>
4761 the meaning of the <computeroutput>type</computeroutput> parameter
4762 has changed slightly. Empty string now means that the per-VM or
4763 global default frontend is launched. Most callers of this method
4764 should use the empty string now, unless they really want to override
4765 the default and launch a particular frontend.</para>
4766 </listitem>
4767
4768 <listitem>
4769 <para>Medium management APIs were changed as follows:<itemizedlist>
4770
4771 <listitem>
4772 <para>The type of attribute
4773 <link linkend="IMedium__variant">IMedium::variant()</link>
4774 changed from <computeroutput>unsigned long</computeroutput>
4775 to <computeroutput>safe-array MediumVariant</computeroutput>.
4776 It is an array of flags instead of a set of flags which were
4777 stored inside one variable.
4778 </para>
4779 </listitem>
4780
4781 <listitem>
4782 <para>The parameter list for
4783 <link linkend="IMedium__cloneTo">IMedium::cloneTo()</link>
4784 was modified. The type of parameter variant was changed from
4785 unsigned long to safe-array MediumVariant.
4786 </para>
4787 </listitem>
4788
4789 <listitem>
4790 <para>The parameter list for
4791 <link linkend="IMedium__createBaseStorage">IMedium::createBaseStorage()</link>
4792 was modified. The type of parameter variant was changed from
4793 unsigned long to safe-array MediumVariant.
4794 </para>
4795 </listitem>
4796
4797 <listitem>
4798 <para>The parameter list for
4799 <link linkend="IMedium__createDiffStorage">IMedium::createDiffStorage()</link>
4800 was modified. The type of parameter variant was changed from
4801 unsigned long to safe-array MediumVariant.
4802 </para>
4803 </listitem>
4804
4805 <listitem>
4806 <para>The parameter list for
4807 <link linkend="IMedium__cloneToBase">IMedium::cloneToBase()</link>
4808 was modified. The type of parameter variant was changed from
4809 unsigned long to safe-array MediumVariant.
4810 </para>
4811 </listitem>
4812 </itemizedlist></para>
4813 </listitem>
4814
4815 <listitem>
4816 <para>The type of attribute
4817 <link linkend="IMediumFormat__capabilities">IMediumFormat::capabilities()</link>
4818 changed from <computeroutput>unsigned long</computeroutput> to
4819 <computeroutput>safe-array MediumFormatCapabilities</computeroutput>.
4820 It is an array of flags instead of a set of flags which were stored
4821 inside one variable.
4822 </para>
4823 </listitem>
4824
4825 <listitem>
4826 <para>The attribute
4827 <link linkend="IMedium__logicalSize">IMedium::logicalSize()</link>
4828 now returns the logical size of exactly this medium object (whether
4829 it is a base or diff image). The old behavior was no longer
4830 acceptable, as each image can have a different capacity.</para>
4831 </listitem>
4832
4833 <listitem>
4834 <para>Guest control APIs - such as
4835 <link linkend="IGuest">IGuest</link>,
4836 <link linkend="IGuestSession">IGuestSession</link>,
4837 <link linkend="IGuestProcess">IGuestProcess</link> and so on - now
4838 emit own events to provide clients much finer control and the ability
4839 to write own frontends for guest operations. The event
4840 <link linkend="IGuestSessionEvent">IGuestSessionEvent</link> acts as
4841 an abstract base class for all guest control events. Certain guest
4842 events contain a
4843 <link linkend="IVirtualBoxErrorInfo">IVirtualBoxErrorInfo</link>
4844 member to provide more information in case of an error happened on
4845 the guest side.</para>
4846 </listitem>
4847
4848 <listitem>
4849 <para>Guest control sessions on the guest started by
4850 <link linkend="IGuest__createSession">IGuest::createSession()</link>
4851 now are dedicated guest processes to provide more safety and
4852 performance for certain operations. Also, the
4853 <link linkend="IGuest__createSession">IGuest::createSession()</link>
4854 call does not wait for the guest session being created anymore due
4855 to the dedicated guest session processes just mentioned. This also
4856 will enable webservice clients to handle guest session creation
4857 more gracefully. To wait for a guest session being started, use the
4858 newly added attribute
4859 <link linkend="IGuestSession__status">IGuestSession::status()</link>
4860 to query the current guest session status.</para>
4861 </listitem>
4862
4863 <listitem>
4864 <para>The <link linkend="IGuestFile">IGuestFile</link>
4865 APIs are now implemented to provide native guest file access from
4866 the host.</para>
4867 </listitem>
4868
4869 <listitem>
4870 <para>The parameter list for
4871 <link linkend="IGuest__updateGuestAdditions">IMedium::updateGuestAdditions()</link>
4872 was modified. It now supports specifying optional command line
4873 arguments for the Guest Additions installer performing the actual
4874 update on the guest.
4875 </para>
4876 </listitem>
4877
4878 <listitem>
4879 <para>A new event
4880 <link linkend="IGuestUserStateChangedEvent">IGuestUserStateChangedEvent</link>
4881 was introduced to provide guest user status updates to the host via
4882 event listeners. To use this event there needs to be at least the 4.3
4883 Guest Additions installed on the guest. At the moment only the states
4884 "Idle" and "InUse" of the
4885 <link linkend="GuestUserState">GuestUserState</link> enumeration arei
4886 supported on Windows guests, starting at Windows 2000 SP2.</para>
4887 </listitem>
4888
4889 <listitem>
4890 <para>
4891 The attribute
4892 <link linkend="IGuestSession__protocolVersion">IGuestSession::protocolVersion</link>
4893 was added to provide a convenient way to lookup the guest session's
4894 protocol version it uses to communicate with the installed Guest
4895 Additions on the guest. Older Guest Additions will set the protocol
4896 version to 1, whereas Guest Additions 4.3 will set the protocol
4897 version to 2. This might change in the future as new features
4898 arise.</para>
4899 </listitem>
4900
4901 <listitem>
4902 <para><computeroutput>IDisplay::getScreenResolution</computeroutput>
4903 has been extended to return the display position in the guest.</para>
4904 </listitem>
4905
4906 <listitem>
4907 <para>
4908 The <link linkend="IUSBController">IUSBController</link>
4909 class is not a singleton of
4910 <link linkend="IMachine">IMachine</link> anymore but
4911 <link linkend="IMachine">IMachine</link> contains a list of USB
4912 controllers present in the VM. The USB device filter handling was
4913 moved to
4914 <link linkend="IUSBDeviceFilters">IUSBDeviceFilters</link>.
4915 </para>
4916 </listitem>
4917 </itemizedlist>
4918 </sect1>
4919
4920 <sect1>
4921 <title>Incompatible API changes with version 4.2</title>
4922
4923 <itemizedlist>
4924 <listitem>
4925 <para>Guest control APIs for executing guest processes, working with
4926 guest files or directories have been moved to the newly introduced
4927 <link linkend="IGuestSession">IGuestSession</link> interface which
4928 can be created by calling
4929 <link linkend="IGuest__createSession">IGuest::createSession()</link>.</para>
4930
4931 <para>A guest session will act as a
4932 guest user's impersonation so that the guest credentials only have to
4933 be provided when creating a new guest session. There can be up to 32
4934 guest sessions at once per VM, each session serving up to 2048 guest
4935 processes running or files opened.</para>
4936
4937 <para>Instead of working with process or directory handles before
4938 version 4.2, there now are the dedicated interfaces
4939 <link linkend="IGuestProcess">IGuestProcess</link>,
4940 <link linkend="IGuestDirectory">IGuestDirectory</link> and
4941 <link linkend="IGuestFile">IGuestFile</link>. To retrieve more
4942 information of a file system object the new interface
4943 <link linkend="IGuestFsObjInfo">IGuestFsObjInfo</link> has been
4944 introduced.</para>
4945
4946 <para>Even though the guest control API was changed it is backwards
4947 compatible so that it can be used with older installed Guest
4948 Additions. However, to use upcoming features like process termination
4949 or waiting for input / output new Guest Additions must be installed
4950 when these features got implemented.</para>
4951
4952 <para>The following limitations apply:
4953 <itemizedlist>
4954 <listitem><para>The <link linkend="IGuestFile">IGuestFile</link>
4955 interface is not fully implemented yet.</para>
4956 </listitem>
4957 <listitem><para>The symbolic link APIs
4958 <link linkend="IGuestSession__symlinkCreate">IGuestSession::symlinkCreate()</link>,
4959 <link linkend="IGuestSession__symlinkExists">IGuestSession::symlinkExists()</link>,
4960 <link linkend="IGuestSession__symlinkRead">IGuestSession::symlinkRead()</link>,
4961 IGuestSession::symlinkRemoveDirectory() and
4962 IGuestSession::symlinkRemoveFile() are not
4963 implemented yet.</para>
4964 </listitem>
4965 <listitem><para>The directory APIs
4966 <link linkend="IGuestSession__directoryRemove">IGuestSession::directoryRemove()</link>,
4967 <link linkend="IGuestSession__directoryRemoveRecursive">IGuestSession::directoryRemoveRecursive()</link>,
4968 IGuestSession::directoryRename() and
4969 IGuestSession::directorySetACL() are not
4970 implemented yet.</para>
4971 </listitem>
4972 <listitem><para>The temporary file creation API
4973 <link linkend="IGuestSession__fileCreateTemp">IGuestSession::fileCreateTemp()</link>
4974 is not implemented yet.</para>
4975 </listitem>
4976 <listitem><para>Guest process termination via
4977 <link linkend="IProcess__terminate">IProcess::terminate()</link>
4978 is not implemented yet.</para>
4979 </listitem>
4980 <listitem><para>Waiting for guest process output via
4981 <link linkend="ProcessWaitForFlag__StdOut">ProcessWaitForFlag::StdOut</link>
4982 and
4983 <link linkend="ProcessWaitForFlag__StdErr">ProcessWaitForFlag::StdErr</link>
4984 is not implemented yet.</para>
4985 <para>To wait for process output,
4986 <link linkend="IProcess__read">IProcess::read()</link> with
4987 appropriate flags still can be used to periodically check for
4988 new output data to arrive. Note that
4989 <link linkend="ProcessCreateFlag__WaitForStdOut">ProcessCreateFlag::WaitForStdOut</link>
4990 and / or
4991 <link linkend="ProcessCreateFlag__WaitForStdErr">ProcessCreateFlag::WaitForStdErr</link>
4992 need to be specified when creating a guest process via
4993 <link linkend="IGuestSession__processCreate">IGuestSession::processCreate()</link>
4994 or
4995 <link linkend="IGuestSession__processCreateEx">IGuestSession::processCreateEx()</link>.</para>
4996 </listitem>
4997 <listitem>
4998 <para>ACL (Access Control List) handling in general is not
4999 implemented yet.</para>
5000 </listitem>
5001 </itemizedlist>
5002 </para>
5003 </listitem>
5004
5005 <listitem>
5006 <para>The <link linkend="LockType">LockType</link>
5007 enumeration now has an additional value
5008 <computeroutput>VM</computeroutput> which tells
5009 <link linkend="IMachine__lockMachine">IMachine::lockMachine()</link>
5010 to create a full-blown object structure for running a VM. This was
5011 the previous behavior with <computeroutput>Write</computeroutput>,
5012 which now only creates the minimal object structure to save time and
5013 resources (at the moment the Console object is still created, but all
5014 sub-objects such as Display, Keyboard, Mouse, Guest are not.</para>
5015 </listitem>
5016
5017 <listitem>
5018 <para>Machines can be put in groups (actually an array of groups).
5019 The primary group affects the default placement of files belonging
5020 to a VM.
5021 <link linkend="IVirtualBox__createMachine">IVirtualBox::createMachine()</link>
5022 and
5023 <link linkend="IVirtualBox__composeMachineFilename">IVirtualBox::composeMachineFilename()</link>
5024 have been adjusted accordingly, the former taking an array of groups
5025 as an additional parameter and the latter taking a group as an
5026 additional parameter. The create option handling has been changed for
5027 those two methods, too.</para>
5028 </listitem>
5029
5030 <listitem>
5031 <para>The method IVirtualBox::findMedium() has been removed, since
5032 it provides a subset of the functionality of
5033 <link linkend="IVirtualBox__openMedium">IVirtualBox::openMedium()</link>.</para>
5034 </listitem>
5035
5036 <listitem>
5037 <para>The use of acronyms in API enumeration, interface, attribute
5038 and method names has been made much more consistent, previously they
5039 sometimes were lowercase and sometimes mixed case. They are now
5040 consistently all caps:<table>
5041 <title>Renamed identifiers in VirtualBox 4.2</title>
5042
5043 <tgroup cols="2" style="verywide">
5044 <tbody>
5045 <row>
5046 <entry><emphasis role="bold">Old name</emphasis></entry>
5047
5048 <entry><emphasis role="bold">New name</emphasis></entry>
5049 </row>
5050 <row>
5051 <entry>PointingHidType</entry>
5052 <entry><link linkend="PointingHIDType">PointingHIDType</link></entry>
5053 </row>
5054 <row>
5055 <entry>KeyboardHidType</entry>
5056 <entry><link linkend="KeyboardHIDType">KeyboardHIDType</link></entry>
5057 </row>
5058 <row>
5059 <entry>IPciAddress</entry>
5060 <entry><link linkend="IPCIAddress">IPCIAddress</link></entry>
5061 </row>
5062 <row>
5063 <entry>IPciDeviceAttachment</entry>
5064 <entry><link linkend="IPCIDeviceAttachment">IPCIDeviceAttachment</link></entry>
5065 </row>
5066 <row>
5067 <entry>IMachine::pointingHidType</entry>
5068 <entry><link linkend="IMachine__pointingHIDType">IMachine::pointingHIDType</link></entry>
5069 </row>
5070 <row>
5071 <entry>IMachine::keyboardHidType</entry>
5072 <entry><link linkend="IMachine__keyboardHIDType">IMachine::keyboardHIDType</link></entry>
5073 </row>
5074 <row>
5075 <entry>IMachine::hpetEnabled</entry>
5076 <entry><link linkend="IMachine__HPETEnabled">IMachine::HPETEnabled</link></entry>
5077 </row>
5078 <row>
5079 <entry>IMachine::sessionPid</entry>
5080 <entry><link linkend="IMachine__sessionPID">IMachine::sessionPID</link></entry>
5081 </row>
5082 <row>
5083 <entry>IMachine::ioCacheEnabled</entry>
5084 <entry><link linkend="IMachine__IOCacheEnabled">IMachine::IOCacheEnabled</link></entry>
5085 </row>
5086 <row>
5087 <entry>IMachine::ioCacheSize</entry>
5088 <entry><link linkend="IMachine__IOCacheSize">IMachine::IOCacheSize</link></entry>
5089 </row>
5090 <row>
5091 <entry>IMachine::pciDeviceAssignments</entry>
5092 <entry><link linkend="IMachine__PCIDeviceAssignments">IMachine::PCIDeviceAssignments</link></entry>
5093 </row>
5094 <row>
5095 <entry>IMachine::attachHostPciDevice()</entry>
5096 <entry><link linkend="IMachine__attachHostPCIDevice">IMachine::attachHostPCIDevice</link></entry>
5097 </row>
5098 <row>
5099 <entry>IMachine::detachHostPciDevice()</entry>
5100 <entry><link linkend="IMachine__detachHostPCIDevice">IMachine::detachHostPCIDevice()</link></entry>
5101 </row>
5102 <row>
5103 <entry>IConsole::attachedPciDevices</entry>
5104 <entry><link linkend="IConsole__attachedPCIDevices">IConsole::attachedPCIDevices</link></entry>
5105 </row>
5106 <row>
5107 <entry>IHostNetworkInterface::dhcpEnabled</entry>
5108 <entry><link linkend="IHostNetworkInterface__DHCPEnabled">IHostNetworkInterface::DHCPEnabled</link></entry>
5109 </row>
5110 <row>
5111 <entry>IHostNetworkInterface::enableStaticIpConfig()</entry>
5112 <entry><link linkend="IHostNetworkInterface__enableStaticIPConfig">IHostNetworkInterface::enableStaticIPConfig()</link></entry>
5113 </row>
5114 <row>
5115 <entry>IHostNetworkInterface::enableStaticIpConfigV6()</entry>
5116 <entry><link linkend="IHostNetworkInterface__enableStaticIPConfigV6">IHostNetworkInterface::enableStaticIPConfigV6()</link></entry>
5117 </row>
5118 <row>
5119 <entry>IHostNetworkInterface::enableDynamicIpConfig()</entry>
5120 <entry><link linkend="IHostNetworkInterface__enableDynamicIPConfig">IHostNetworkInterface::enableDynamicIPConfig()</link></entry>
5121 </row>
5122 <row>
5123 <entry>IHostNetworkInterface::dhcpRediscover()</entry>
5124 <entry><link linkend="IHostNetworkInterface__DHCPRediscover">IHostNetworkInterface::DHCPRediscover()</link></entry>
5125 </row>
5126 <row>
5127 <entry>IHost::Acceleration3DAvailable</entry>
5128 <entry><link linkend="IHost__acceleration3DAvailable">IHost::acceleration3DAvailable</link></entry>
5129 </row>
5130 <row>
5131 <entry>IGuestOSType::recommendedPae</entry>
5132 <entry><link linkend="IGuestOSType__recommendedPAE">IGuestOSType::recommendedPAE</link></entry>
5133 </row>
5134 <row>
5135 <entry>IGuestOSType::recommendedDvdStorageController</entry>
5136 <entry><link linkend="IGuestOSType__recommendedDVDStorageController">IGuestOSType::recommendedDVDStorageController</link></entry>
5137 </row>
5138 <row>
5139 <entry>IGuestOSType::recommendedDvdStorageBus</entry>
5140 <entry><link linkend="IGuestOSType__recommendedDVDStorageBus">IGuestOSType::recommendedDVDStorageBus</link></entry>
5141 </row>
5142 <row>
5143 <entry>IGuestOSType::recommendedHdStorageController</entry>
5144 <entry><link linkend="IGuestOSType__recommendedHDStorageController">IGuestOSType::recommendedHDStorageController</link></entry>
5145 </row>
5146 <row>
5147 <entry>IGuestOSType::recommendedHdStorageBus</entry>
5148 <entry><link linkend="IGuestOSType__recommendedHDStorageBus">IGuestOSType::recommendedHDStorageBus</link></entry>
5149 </row>
5150 <row>
5151 <entry>IGuestOSType::recommendedUsbHid</entry>
5152 <entry><link linkend="IGuestOSType__recommendedUSBHID">IGuestOSType::recommendedUSBHID</link></entry>
5153 </row>
5154 <row>
5155 <entry>IGuestOSType::recommendedHpet</entry>
5156 <entry><link linkend="IGuestOSType__recommendedHPET">IGuestOSType::recommendedHPET</link></entry>
5157 </row>
5158 <row>
5159 <entry>IGuestOSType::recommendedUsbTablet</entry>
5160 <entry><link linkend="IGuestOSType__recommendedUSBTablet">IGuestOSType::recommendedUSBTablet</link></entry>
5161 </row>
5162 <row>
5163 <entry>IGuestOSType::recommendedRtcUseUtc</entry>
5164 <entry><link linkend="IGuestOSType__recommendedRTCUseUTC">IGuestOSType::recommendedRTCUseUTC</link></entry>
5165 </row>
5166 <row>
5167 <entry>IGuestOSType::recommendedUsb</entry>
5168 <entry><link linkend="IGuestOSType__recommendedUSB">IGuestOSType::recommendedUSB</link></entry>
5169 </row>
5170 <row>
5171 <entry>INetworkAdapter::natDriver</entry>
5172 <entry><link linkend="INetworkAdapter__NATEngine">INetworkAdapter::NATEngine</link></entry>
5173 </row>
5174 <row>
5175 <entry>IUSBController::enabledEhci</entry>
5176 <entry>IUSBController::enabledEHCI"</entry>
5177 </row>
5178 <row>
5179 <entry>INATEngine::tftpPrefix</entry>
5180 <entry><link linkend="INATEngine__TFTPPrefix">INATEngine::TFTPPrefix</link></entry>
5181 </row>
5182 <row>
5183 <entry>INATEngine::tftpBootFile</entry>
5184 <entry><link linkend="INATEngine__TFTPBootFile">INATEngine::TFTPBootFile</link></entry>
5185 </row>
5186 <row>
5187 <entry>INATEngine::tftpNextServer</entry>
5188 <entry><link linkend="INATEngine__TFTPNextServer">INATEngine::TFTPNextServer</link></entry>
5189 </row>
5190 <row>
5191 <entry>INATEngine::dnsPassDomain</entry>
5192 <entry><link linkend="INATEngine__DNSPassDomain">INATEngine::DNSPassDomain</link></entry>
5193 </row>
5194 <row>
5195 <entry>INATEngine::dnsProxy</entry>
5196 <entry><link linkend="INATEngine__DNSProxy">INATEngine::DNSProxy</link></entry>
5197 </row>
5198 <row>
5199 <entry>INATEngine::dnsUseHostResolver</entry>
5200 <entry><link linkend="INATEngine__DNSUseHostResolver">INATEngine::DNSUseHostResolver</link></entry>
5201 </row>
5202 <row>
5203 <entry>VBoxEventType::OnHostPciDevicePlug</entry>
5204 <entry><link linkend="VBoxEventType__OnHostPCIDevicePlug">VBoxEventType::OnHostPCIDevicePlug</link></entry>
5205 </row>
5206 <row>
5207 <entry>ICPUChangedEvent::cpu</entry>
5208 <entry><link linkend="ICPUChangedEvent__CPU">ICPUChangedEvent::CPU</link></entry>
5209 </row>
5210 <row>
5211 <entry>INATRedirectEvent::hostIp</entry>
5212 <entry><link linkend="INATRedirectEvent__hostIP">INATRedirectEvent::hostIP</link></entry>
5213 </row>
5214 <row>
5215 <entry>INATRedirectEvent::guestIp</entry>
5216 <entry><link linkend="INATRedirectEvent__guestIP">INATRedirectEvent::guestIP</link></entry>
5217 </row>
5218 <row>
5219 <entry>IHostPciDevicePlugEvent</entry>
5220 <entry><link linkend="IHostPCIDevicePlugEvent">IHostPCIDevicePlugEvent</link></entry>
5221 </row>
5222 </tbody>
5223 </tgroup></table></para>
5224 </listitem>
5225 </itemizedlist>
5226 </sect1>
5227
5228 <sect1>
5229 <title>Incompatible API changes with version 4.1</title>
5230
5231 <itemizedlist>
5232 <listitem>
5233 <para>The method
5234 <link linkend="IAppliance__importMachines">IAppliance::importMachines()</link>
5235 has one more parameter now, which allows to configure the import
5236 process in more detail.
5237 </para>
5238 </listitem>
5239
5240 <listitem>
5241 <para>The method
5242 <link linkend="IVirtualBox__openMedium">IVirtualBox::openMedium()</link>
5243 has one more parameter now, which allows resolving duplicate medium
5244 UUIDs without the need for external tools.</para>
5245 </listitem>
5246
5247 <listitem>
5248 <para>The <link linkend="INetworkAdapter">INetworkAdapter</link>
5249 interface has been cleaned up. The various methods to activate an
5250 attachment type have been replaced by the
5251 <link linkend="INetworkAdapter__attachmentType">INetworkAdapter::attachmentType</link>
5252 setter.</para>
5253 <para>Additionally each attachment mode now has its own attribute,
5254 which means that host only networks no longer share the settings with
5255 bridged interfaces.</para>
5256 <para>To allow introducing new network attachment implementations
5257 without making API changes, the concept of a generic network
5258 attachment driver has been introduced, which is configurable through
5259 key/value properties.</para>
5260 </listitem>
5261
5262 <listitem>
5263 <para>This version introduces the guest facilities concept. A guest
5264 facility either represents a module or feature the guest is running
5265 or offering, which is defined by
5266 <link linkend="AdditionsFacilityType">AdditionsFacilityType</link>.
5267 Each facility is member of a
5268 <link linkend="AdditionsFacilityClass">AdditionsFacilityClass</link>
5269 and has a current status indicated by
5270 <link linkend="AdditionsFacilityStatus">AdditionsFacilityStatus</link>,
5271 together with a timestamp (in ms) of the last status update.</para>
5272 <para>To address the above concept, the following changes were made:
5273 <itemizedlist>
5274 <listitem>
5275 <para>
5276 In the <link linkend="IGuest">IGuest</link> interface, the
5277 following were removed:
5278 <itemizedlist>
5279 <listitem>
5280 <para>the
5281 <computeroutput>supportsSeamless</computeroutput>
5282 attribute;</para>
5283 </listitem>
5284 <listitem>
5285 <para>the
5286 <computeroutput>supportsGraphics</computeroutput>
5287 attribute;</para>
5288 </listitem>
5289 </itemizedlist>
5290 </para>
5291 </listitem>
5292 <listitem>
5293 <para>
5294 The function
5295 <link linkend="IGuest__getFacilityStatus">IGuest::getFacilityStatus()</link>
5296 was added. It quickly provides a facility's status without
5297 the need to get the facility collection with
5298 <link linkend="IGuest__facilities">IGuest::facilities</link>.
5299 </para>
5300 </listitem>
5301 <listitem>
5302 <para>
5303 The attribute
5304 <link linkend="IGuest__facilities">IGuest::facilities</link>
5305 was added to provide an easy to access collection of all
5306 currently known guest facilities, that is, it contains all
5307 facilies where at least one status update was made since the
5308 guest was started.
5309 </para>
5310 </listitem>
5311 <listitem>
5312 <para>
5313 The interface
5314 <link linkend="IAdditionsFacility">IAdditionsFacility</link>
5315 was added to represent a single facility returned by
5316 <link linkend="IGuest__facilities">IGuest::facilities</link>.
5317 </para>
5318 </listitem>
5319 <listitem>
5320 <para>
5321 <link linkend="AdditionsFacilityStatus">AdditionsFacilityStatus</link>
5322 was added to represent a facility's overall status.
5323 </para>
5324 </listitem>
5325 <listitem>
5326 <para>
5327 <link linkend="AdditionsFacilityType">AdditionsFacilityType</link> and
5328 <link linkend="AdditionsFacilityClass">AdditionsFacilityClass</link> were
5329 added to represent the facility's type and class.
5330 </para>
5331 </listitem>
5332 </itemizedlist>
5333 </para>
5334 </listitem>
5335 </itemizedlist>
5336 </sect1>
5337
5338 <sect1>
5339 <title>Incompatible API changes with version 4.0</title>
5340
5341 <itemizedlist>
5342 <listitem>
5343 <para>A new Java glue layer replacing the previous OOWS JAX-WS
5344 bindings was introduced. The new library allows for uniform code
5345 targeting both local (COM/XPCOM) and remote (SOAP) transports. Now,
5346 instead of <computeroutput>IWebsessionManager</computeroutput>, the
5347 new class <computeroutput>VirtualBoxManager</computeroutput> must be
5348 used. See <xref linkend="javaapi"/> for details.</para>
5349 </listitem>
5350
5351 <listitem>
5352 <para>The confusingly named and impractical session APIs were
5353 changed. In existing client code, the following changes need to be
5354 made:<itemizedlist>
5355 <listitem>
5356 <para>Replace any
5357 <computeroutput>IVirtualBox::openSession(uuidMachine,
5358 ...)</computeroutput> API call with the machine's
5359 <link linkend="IMachine__lockMachine">IMachine::lockMachine()</link>
5360 call and a
5361 <computeroutput>LockType.Write</computeroutput> argument. The
5362 functionality is unchanged, but instead of "opening a direct
5363 session on a machine" all documentation now refers to
5364 "obtaining a write lock on a machine for the client
5365 session".</para>
5366 </listitem>
5367
5368 <listitem>
5369 <para>Similarly, replace any
5370 <computeroutput>IVirtualBox::openExistingSession(uuidMachine,
5371 ...)</computeroutput> call with the machine's
5372 <link linkend="IMachine__lockMachine">IMachine::lockMachine()</link>
5373 call and a <computeroutput>LockType.Shared</computeroutput>
5374 argument. Whereas it was previously impossible to connect a
5375 client session to a running VM process in a race-free manner,
5376 the new API will atomically either write-lock the machine for
5377 the current session or establish a remote link to an existing
5378 session. Existing client code which tried calling both
5379 <computeroutput>openSession()</computeroutput> and
5380 <computeroutput>openExistingSession()</computeroutput> can now
5381 use this one call instead.</para>
5382 </listitem>
5383
5384 <listitem>
5385 <para>Third, replace any
5386 <computeroutput>IVirtualBox::openRemoteSession(uuidMachine,
5387 ...)</computeroutput> call with the machine's
5388 <link linkend="IMachine__launchVMProcess">IMachine::launchVMProcess()</link>
5389 call. The functionality is unchanged.</para>
5390 </listitem>
5391
5392 <listitem>
5393 <para>The <link linkend="SessionState">SessionState</link> enum
5394 was adjusted accordingly: "Open" is now "Locked", "Closed" is
5395 now "Unlocked", "Closing" is now "Unlocking".</para>
5396 </listitem>
5397 </itemizedlist></para>
5398 </listitem>
5399
5400 <listitem>
5401 <para>Virtual machines created with VirtualBox 4.0 or later no
5402 longer register their media in the global media registry in the
5403 <computeroutput>VirtualBox.xml</computeroutput> file. Instead, such
5404 machines list all their media in their own machine XML files. As a
5405 result, a number of media-related APIs had to be modified again.
5406 <itemizedlist>
5407 <listitem>
5408 <para>Neither
5409 <computeroutput>IVirtualBox::createHardDisk()</computeroutput>
5410 nor
5411 <link linkend="IVirtualBox__openMedium">IVirtualBox::openMedium()</link>
5412 register media automatically any more.</para>
5413 </listitem>
5414
5415 <listitem>
5416 <para><link linkend="IMachine__attachDevice">IMachine::attachDevice()</link>
5417 and
5418 <link linkend="IMachine__mountMedium">IMachine::mountMedium()</link>
5419 now take an IMedium object instead of a UUID as an argument. It
5420 is these two calls which add media to a registry now (either a
5421 machine registry for machines created with VirtualBox 4.0 or
5422 later or the global registry otherwise). As a consequence, if a
5423 medium is opened but never attached to a machine, it is no
5424 longer added to any registry any more.</para>
5425 </listitem>
5426
5427 <listitem>
5428 <para>To reduce code duplication, the APIs
5429 IVirtualBox::findHardDisk(), getHardDisk(), findDVDImage(),
5430 getDVDImage(), findFloppyImage() and getFloppyImage() have all
5431 been merged into IVirtualBox::findMedium(), and
5432 IVirtualBox::openHardDisk(), openDVDImage() and
5433 openFloppyImage() have all been merged into
5434 <link linkend="IVirtualBox__openMedium">IVirtualBox::openMedium()</link>.</para>
5435 </listitem>
5436
5437 <listitem>
5438 <para>The rare use case of changing the UUID and parent UUID
5439 of a medium previously handled by
5440 <computeroutput>openHardDisk()</computeroutput> is now in a
5441 separate IMedium::setIDs method.</para>
5442 </listitem>
5443
5444 <listitem>
5445 <para><computeroutput>ISystemProperties::get/setDefaultHardDiskFolder()</computeroutput>
5446 have been removed since disk images are now by default placed
5447 in each machine's folder.</para>
5448 </listitem>
5449
5450 <listitem>
5451 <para>The
5452 <link linkend="ISystemProperties__infoVDSize">ISystemProperties::infoVDSize</link>
5453 attribute replaces the
5454 <computeroutput>getMaxVDISize()</computeroutput>
5455 API call; this now uses bytes instead of megabytes.</para>
5456 </listitem>
5457 </itemizedlist></para>
5458 </listitem>
5459
5460 <listitem>
5461 <para>Machine management APIs were enhanced as follows:<itemizedlist>
5462 <listitem>
5463 <para><link linkend="IVirtualBox__createMachine">IVirtualBox::createMachine()</link>
5464 is no longer restricted to creating machines in the default
5465 "Machines" folder, but can now create machines at arbitrary
5466 locations. For this to work, the parameter list had to be
5467 changed.</para>
5468 </listitem>
5469
5470 <listitem>
5471 <para>The long-deprecated
5472 <computeroutput>IVirtualBox::createLegacyMachine()</computeroutput>
5473 API has been removed.</para>
5474 </listitem>
5475
5476 <listitem>
5477 <para>To reduce code duplication and for consistency with the
5478 aforementioned media APIs,
5479 <computeroutput>IVirtualBox::getMachine()</computeroutput> has
5480 been merged with
5481 <link linkend="IVirtualBox__findMachine">IVirtualBox::findMachine()</link>,
5482 and
5483 <computeroutput>IMachine::getSnapshot()</computeroutput> has
5484 been merged with
5485 <link linkend="IMachine__findSnapshot">IMachine::findSnapshot()</link>.</para>
5486 </listitem>
5487
5488 <listitem>
5489 <para><computeroutput>IVirtualBox::unregisterMachine()</computeroutput>
5490 was replaced with
5491 <link linkend="IMachine__unregister">IMachine::unregister()</link>
5492 with additional functionality for cleaning up machine
5493 files.</para>
5494 </listitem>
5495
5496 <listitem>
5497 <para><computeroutput>IMachine::deleteSettings</computeroutput>
5498 has been replaced by IMachine::delete, which allows specifying
5499 which disk images are to be deleted as part of the deletion,
5500 and because it can take a while it also returns a
5501 <computeroutput>IProgress</computeroutput> object reference,
5502 so that the completion of the asynchronous activities can be
5503 monitored.</para>
5504 </listitem>
5505
5506 <listitem>
5507 <para><computeroutput>IConsole::forgetSavedState</computeroutput>
5508 has been renamed to
5509 <computeroutput>IConsole::discardSavedState()</computeroutput>.</para>
5510 </listitem>
5511 </itemizedlist></para>
5512 </listitem>
5513
5514 <listitem>
5515 <para>All event callbacks APIs were replaced with a new, generic
5516 event mechanism that can be used both locally (COM, XPCOM) and
5517 remotely (web services). Also, the new mechanism is usable from
5518 scripting languages and a local Java. See
5519 <link linkend="IEvent">events</link> for details. The new concept
5520 will require changes to all clients that used event callbacks.</para>
5521 </listitem>
5522
5523 <listitem>
5524 <para><computeroutput>additionsActive()</computeroutput> was replaced
5525 with
5526 <link linkend="IGuest__additionsRunLevel">additionsRunLevel()</link>
5527 and
5528 <link linkend="IGuest__getAdditionsStatus">getAdditionsStatus()</link>
5529 in order to support a more detailed status of the current Guest
5530 Additions loading/readiness state.
5531 <link linkend="IGuest__additionsVersion">IGuest::additionsVersion()</link>
5532 no longer returns the Guest Additions interface version but the
5533 installed Guest Additions version and revision in form of
5534 <computeroutput>3.3.0r12345</computeroutput>.</para>
5535 </listitem>
5536
5537 <listitem>
5538 <para>To address shared folders auto-mounting support, the following
5539 APIs were extended to require an additional
5540 <computeroutput>automount</computeroutput> parameter: <itemizedlist>
5541 <listitem>
5542 <para><link linkend="IVirtualBox__createSharedFolder">IVirtualBox::createSharedFolder()</link></para>
5543 </listitem>
5544
5545 <listitem>
5546 <para><link linkend="IMachine__createSharedFolder">IMachine::createSharedFolder()</link></para>
5547 </listitem>
5548
5549 <listitem>
5550 <para><link linkend="IConsole__createSharedFolder">IConsole::createSharedFolder()</link></para>
5551 </listitem>
5552 </itemizedlist> Also, a new property named
5553 <computeroutput>autoMount</computeroutput> was added to the
5554 <link linkend="ISharedFolder">ISharedFolder</link>
5555 interface.</para>
5556 </listitem>
5557
5558 <listitem>
5559 <para>The appliance (OVF) APIs were enhanced as
5560 follows:<itemizedlist>
5561 <listitem>
5562 <para><computeroutput>IMachine::export</computeroutput>
5563 received an extra parameter
5564 <computeroutput>location</computeroutput>, which is used to
5565 decide for the disk naming.</para>
5566 </listitem>
5567
5568 <listitem>
5569 <para><link linkend="IAppliance__write">IAppliance::write()</link>
5570 received an extra parameter
5571 <computeroutput>manifest</computeroutput>, which can suppress
5572 creating the manifest file on export.</para>
5573 </listitem>
5574
5575 <listitem>
5576 <para><link linkend="IVFSExplorer__entryList">IVFSExplorer::entryList()</link>
5577 received two extra parameters
5578 <computeroutput>sizes</computeroutput> and
5579 <computeroutput>modes</computeroutput>, which contains the
5580 sizes (in bytes) and the file access modes (in octal form) of
5581 the returned files.</para>
5582 </listitem>
5583 </itemizedlist></para>
5584 </listitem>
5585
5586 <listitem>
5587 <para>Support for remote desktop access to virtual machines has been
5588 cleaned up to allow third party implementations of the remote
5589 desktop server. This is called the VirtualBox Remote Desktop
5590 Extension (VRDE) and can be added to VirtualBox by installing the
5591 corresponding extension package; see the VirtualBox User Manual for
5592 details.</para>
5593
5594 <para>The following API changes were made to support the VRDE
5595 interface: <itemizedlist>
5596 <listitem>
5597 <para><computeroutput>IVRDPServer</computeroutput> has been
5598 renamed to
5599 <link linkend="IVRDEServer">IVRDEServer</link>.</para>
5600 </listitem>
5601
5602 <listitem>
5603 <para><computeroutput>IRemoteDisplayInfo</computeroutput> has
5604 been renamed to
5605 <link linkend="IVRDEServerInfo">IVRDEServerInfo</link>.</para>
5606 </listitem>
5607
5608 <listitem>
5609 <para><link linkend="IMachine__VRDEServer">IMachine::VRDEServer</link>
5610 replaces
5611 <computeroutput>VRDPServer.</computeroutput></para>
5612 </listitem>
5613
5614 <listitem>
5615 <para><link linkend="IConsole__VRDEServerInfo">IConsole::VRDEServerInfo</link>
5616 replaces
5617 <computeroutput>RemoteDisplayInfo</computeroutput>.</para>
5618 </listitem>
5619
5620 <listitem>
5621 <para><link linkend="ISystemProperties__VRDEAuthLibrary">ISystemProperties::VRDEAuthLibrary</link>
5622 replaces
5623 <computeroutput>RemoteDisplayAuthLibrary</computeroutput>.</para>
5624 </listitem>
5625
5626 <listitem>
5627 <para>The following methods have been implemented in
5628 <computeroutput>IVRDEServer</computeroutput> to support
5629 generic VRDE properties: <itemizedlist>
5630 <listitem>
5631 <para><link linkend="IVRDEServer__setVRDEProperty">IVRDEServer::setVRDEProperty</link></para>
5632 </listitem>
5633
5634 <listitem>
5635 <para><link linkend="IVRDEServer__getVRDEProperty">IVRDEServer::getVRDEProperty</link></para>
5636 </listitem>
5637
5638 <listitem>
5639 <para><link linkend="IVRDEServer__VRDEProperties">IVRDEServer::VRDEProperties</link></para>
5640 </listitem>
5641 </itemizedlist></para>
5642
5643 <para>A few implementation-specific attributes of the old
5644 <computeroutput>IVRDPServer</computeroutput> interface have
5645 been removed and replaced with properties: <itemizedlist>
5646 <listitem>
5647 <para><computeroutput>IVRDPServer::Ports</computeroutput>
5648 has been replaced with the
5649 <computeroutput>"TCP/Ports"</computeroutput> property.
5650 The property value is a string, which contains a
5651 comma-separated list of ports or ranges of ports. Use a
5652 dash between two port numbers to specify a range.
5653 Example:
5654 <computeroutput>"5000,5010-5012"</computeroutput></para>
5655 </listitem>
5656
5657 <listitem>
5658 <para><computeroutput>IVRDPServer::NetAddress</computeroutput>
5659 has been replaced with the
5660 <computeroutput>"TCP/Address"</computeroutput> property.
5661 The property value is an IP address string. Example:
5662 <computeroutput>"127.0.0.1"</computeroutput></para>
5663 </listitem>
5664
5665 <listitem>
5666 <para><computeroutput>IVRDPServer::VideoChannel</computeroutput>
5667 has been replaced with the
5668 <computeroutput>"VideoChannel/Enabled"</computeroutput>
5669 property. The property value is either
5670 <computeroutput>"true"</computeroutput> or
5671 <computeroutput>"false"</computeroutput></para>
5672 </listitem>
5673
5674 <listitem>
5675 <para><computeroutput>IVRDPServer::VideoChannelQuality</computeroutput>
5676 has been replaced with the
5677 <computeroutput>"VideoChannel/Quality"</computeroutput>
5678 property. The property value is a string which contain a
5679 decimal number in range 10..100. Invalid values are
5680 ignored and the quality is set to the default value 75.
5681 Example: <computeroutput>"50"</computeroutput></para>
5682 </listitem>
5683 </itemizedlist></para>
5684 </listitem>
5685 </itemizedlist></para>
5686 </listitem>
5687
5688 <listitem>
5689 <para>The VirtualBox external authentication module interface has
5690 been updated and made more generic. Because of that,
5691 <computeroutput>VRDPAuthType</computeroutput> enumeration has been
5692 renamed to <link linkend="AuthType">AuthType</link>.</para>
5693 </listitem>
5694 </itemizedlist>
5695 </sect1>
5696
5697 <sect1>
5698 <title>Incompatible API changes with version 3.2</title>
5699
5700 <itemizedlist>
5701 <listitem>
5702 <para>The following interfaces were renamed for consistency:
5703 <itemizedlist>
5704 <listitem>
5705 <para>IMachine::getCpuProperty() is now
5706 <link linkend="IMachine__getCPUProperty">IMachine::getCPUProperty()</link>;</para>
5707 </listitem>
5708
5709 <listitem>
5710 <para>IMachine::setCpuProperty() is now
5711 <link linkend="IMachine__setCPUProperty">IMachine::setCPUProperty()</link>;</para>
5712 </listitem>
5713
5714 <listitem>
5715 <para>IMachine::getCpuIdLeaf() is now
5716 <link linkend="IMachine__getCPUIDLeaf">IMachine::getCPUIDLeaf()</link>;</para>
5717 </listitem>
5718
5719 <listitem>
5720 <para>IMachine::setCpuIdLeaf() is now
5721 <link linkend="IMachine__setCPUIDLeaf">IMachine::setCPUIDLeaf()</link>;</para>
5722 </listitem>
5723
5724 <listitem>
5725 <para>IMachine::removeCpuIdLeaf() is now
5726 <link linkend="IMachine__removeCPUIDLeaf">IMachine::removeCPUIDLeaf()</link>;</para>
5727 </listitem>
5728
5729 <listitem>
5730 <para>IMachine::removeAllCpuIdLeafs() is now
5731 <link linkend="IMachine__removeAllCPUIDLeaves">IMachine::removeAllCPUIDLeaves()</link>;</para>
5732 </listitem>
5733
5734 <listitem>
5735 <para>the CpuPropertyType enum is now
5736 <link linkend="CPUPropertyType">CPUPropertyType</link>.</para>
5737 </listitem>
5738
5739 <listitem>
5740 <para>IVirtualBoxCallback::onSnapshotDiscarded() is now
5741 IVirtualBoxCallback::onSnapshotDeleted.</para>
5742 </listitem>
5743 </itemizedlist></para>
5744 </listitem>
5745
5746 <listitem>
5747 <para>When creating a VM configuration with
5748 <link linkend="IVirtualBox__createMachine">IVirtualBox::createMachine()</link>
5749 it is now possible to ignore existing configuration files which would
5750 previously have caused a failure. For this the
5751 <computeroutput>override</computeroutput> parameter was added.</para>
5752 </listitem>
5753
5754 <listitem>
5755 <para>Deleting snapshots via
5756 <computeroutput>IConsole::deleteSnapshot()</computeroutput> is now
5757 possible while the associated VM is running in almost all cases.
5758 The API is unchanged, but client code that verifies machine states
5759 to determine whether snapshots can be deleted may need to be
5760 adjusted.</para>
5761 </listitem>
5762
5763 <listitem>
5764 <para>The IoBackendType enumeration was replaced with a boolean flag
5765 (see
5766 <link linkend="IStorageController__useHostIOCache">IStorageController::useHostIOCache</link>).</para>
5767 </listitem>
5768
5769 <listitem>
5770 <para>To address multi-monitor support, the following APIs were
5771 extended to require an additional
5772 <computeroutput>screenId</computeroutput> parameter: <itemizedlist>
5773 <listitem>
5774 <para>IMachine::querySavedThumbnailSize()</para>
5775 </listitem>
5776
5777 <listitem>
5778 <para><link linkend="IMachine__readSavedThumbnailToArray">IMachine::readSavedThumbnailToArray()</link></para>
5779 </listitem>
5780
5781 <listitem>
5782 <para><link linkend="IMachine__querySavedScreenshotInfo">IMachine::querySavedScreenshotPNGSize()</link></para>
5783 </listitem>
5784
5785 <listitem>
5786 <para><link linkend="IMachine__readSavedScreenshotToArray">IMachine::readSavedScreenshotPNGToArray()</link></para>
5787 </listitem>
5788 </itemizedlist></para>
5789 </listitem>
5790
5791 <listitem>
5792 <para>The <computeroutput>shape</computeroutput> parameter of
5793 IConsoleCallback::onMousePointerShapeChange was changed from a
5794 implementation-specific pointer to a safearray, enabling scripting
5795 languages to process pointer shapes.</para>
5796 </listitem>
5797 </itemizedlist>
5798 </sect1>
5799
5800 <sect1>
5801 <title>Incompatible API changes with version 3.1</title>
5802
5803 <itemizedlist>
5804 <listitem>
5805 <para>Due to the new flexibility in medium attachments that was
5806 introduced with version 3.1 (in particular, full flexibility with
5807 attaching CD/DVD drives to arbitrary controllers), we seized the
5808 opportunity to rework all interfaces dealing with storage media to
5809 make the API more flexible as well as logical. The
5810 <link linkend="IStorageController">IStorageController</link>,
5811 <link linkend="IMedium">IMedium</link>,
5812 <link linkend="IMediumAttachment">IMediumAttachment</link> and
5813 <link linkend="IMachine">IMachine</link> interfaces were
5814 affected the most. Existing code using them to configure storage and
5815 media needs to be carefully checked.</para>
5816
5817 <para>All media (hard disks, floppies and CDs/DVDs) are now
5818 uniformly handled through the <link linkend="IMedium">IMedium</link>
5819 interface. The device-specific interfaces
5820 (<code>IHardDisk</code>, <code>IDVDImage</code>,
5821 <code>IHostDVDDrive</code>, <code>IFloppyImage</code> and
5822 <code>IHostFloppyDrive</code>) have been merged into IMedium; CD/DVD
5823 and floppy media no longer need special treatment. The device type
5824 of a medium determines in which context it can be used. Some
5825 functionality was moved to the other storage-related
5826 interfaces.</para>
5827
5828 <para><code>IMachine::attachHardDisk</code> and similar methods have
5829 been renamed and generalized to deal with any type of drive and
5830 medium.
5831 <link linkend="IMachine__attachDevice">IMachine::attachDevice()</link>
5832 is the API method for adding any drive to a storage controller. The
5833 floppy and DVD/CD drives are no longer handled specially, and that
5834 means you can have more than one of them. As before, drives can only
5835 be changed while the VM is powered off. Mounting (or unmounting)
5836 removable media at runtime is possible with
5837 <link linkend="IMachine__mountMedium">IMachine::mountMedium()</link>.</para>
5838
5839 <para>Newly created virtual machines have no storage controllers
5840 associated with them. Even the IDE Controller needs to be created
5841 explicitly. The floppy controller is now visible as a separate
5842 controller, with a new storage bus type. For each storage bus type
5843 you can query the device types which can be attached, so that it is
5844 not necessary to hardcode any attachment rules.</para>
5845
5846 <para>This required matching changes e.g. in the callback interfaces
5847 (the medium specific change notification was replaced by a generic
5848 medium change notification) and removing associated enums (e.g.
5849 <code>DriveState</code>). In many places the incorrect use of the
5850 plural form "media" was replaced by "medium", to improve
5851 consistency.</para>
5852 </listitem>
5853
5854 <listitem>
5855 <para>Reading the
5856 <link linkend="IMedium__state">IMedium::state</link> attribute no
5857 longer automatically performs an accessibility check; a new method
5858 <link linkend="IMedium__refreshState">IMedium::refreshState()</link>
5859 does this. The attribute only returns the state now.</para>
5860 </listitem>
5861
5862 <listitem>
5863 <para>There were substantial changes related to snapshots, triggered
5864 by the "branched snapshots" functionality introduced with version
5865 3.1. IConsole::discardSnapshot was renamed to
5866 <computeroutput>IConsole::deleteSnapshot()</computeroutput>.
5867 IConsole::discardCurrentState and
5868 IConsole::discardCurrentSnapshotAndState were removed; corresponding
5869 new functionality is in
5870 <computeroutput>IConsole::restoreSnapshot()</computeroutput>.
5871 Also, when <computeroutput>IConsole::takeSnapshot()</computeroutput>
5872 is called on a running virtual machine, a live snapshot will be
5873 created. The old behavior was to temporarily pause the virtual
5874 machine while creating an online snapshot.</para>
5875 </listitem>
5876
5877 <listitem>
5878 <para>The <computeroutput>IVRDPServer</computeroutput>,
5879 <computeroutput>IRemoteDisplayInfo"</computeroutput> and
5880 <computeroutput>IConsoleCallback</computeroutput> interfaces were
5881 changed to reflect VRDP server ability to bind to one of available
5882 ports from a list of ports.</para>
5883
5884 <para>The <computeroutput>IVRDPServer::port</computeroutput>
5885 attribute has been replaced with
5886 <computeroutput>IVRDPServer::ports</computeroutput>, which is a
5887 comma-separated list of ports or ranges of ports.</para>
5888
5889 <para>An <computeroutput>IRemoteDisplayInfo::port"</computeroutput>
5890 attribute has been added for querying the actual port VRDP server
5891 listens on.</para>
5892
5893 <para>An IConsoleCallback::onRemoteDisplayInfoChange() notification
5894 callback has been added.</para>
5895 </listitem>
5896
5897 <listitem>
5898 <para>The parameter lists for the following functions were
5899 modified:<itemizedlist>
5900 <listitem>
5901 <para><link linkend="IHost__removeHostOnlyNetworkInterface">IHost::removeHostOnlyNetworkInterface()</link></para>
5902 </listitem>
5903
5904 <listitem>
5905 <para><link linkend="IHost__removeUSBDeviceFilter">IHost::removeUSBDeviceFilter()</link></para>
5906 </listitem>
5907 </itemizedlist></para>
5908 </listitem>
5909
5910 <listitem>
5911 <para>In the OOWS bindings for JAX-WS, the behavior of structures
5912 changed: for one, we implemented natural structures field access so
5913 you can just call a "get" method to obtain a field. Secondly,
5914 setters in structures were disabled as they have no expected effect
5915 and were at best misleading.</para>
5916 </listitem>
5917 </itemizedlist>
5918 </sect1>
5919
5920 <sect1>
5921 <title>Incompatible API changes with version 3.0</title>
5922
5923 <itemizedlist>
5924 <listitem>
5925 <para>In the object-oriented web service bindings for JAX-WS, proper
5926 inheritance has been introduced for some classes, so explicit
5927 casting is no longer needed to call methods from a parent class. In
5928 particular, IHardDisk and other classes now properly derive from
5929 <link linkend="IMedium">IMedium</link>.</para>
5930 </listitem>
5931
5932 <listitem>
5933 <para>All object identifiers (machines, snapshots, disks, etc)
5934 switched from GUIDs to strings (now still having string
5935 representation of GUIDs inside). As a result, no particular internal
5936 structure can be assumed for object identifiers; instead, they
5937 should be treated as opaque unique handles. This change mostly
5938 affects Java and C++ programs; for other languages, GUIDs are
5939 transparently converted to strings.</para>
5940 </listitem>
5941
5942 <listitem>
5943 <para>The uses of NULL strings have been changed greatly. All out
5944 parameters now use empty strings to signal a null value. For in
5945 parameters both the old NULL and empty string is allowed. This
5946 change was necessary to support more client bindings, especially
5947 using the web service API. Many of them either have no special NULL
5948 value or have trouble dealing with it correctly in the respective
5949 library code.</para>
5950 </listitem>
5951
5952 <listitem>
5953 <para>Accidentally, the <code>TSBool</code> interface still appeared
5954 in 3.0.0, and was removed in 3.0.2. This is an SDK bug, do not use
5955 the SDK for VirtualBox 3.0.0 for developing clients.</para>
5956 </listitem>
5957
5958 <listitem>
5959 <para>The type of
5960 <link linkend="IVirtualBoxErrorInfo__resultCode">IVirtualBoxErrorInfo::resultCode</link>
5961 changed from
5962 <computeroutput>result</computeroutput> to
5963 <computeroutput>long</computeroutput>.</para>
5964 </listitem>
5965
5966 <listitem>
5967 <para>The parameter list of IVirtualBox::openHardDisk was
5968 changed.</para>
5969 </listitem>
5970
5971 <listitem>
5972 <para>The method IConsole::discardSavedState was renamed to
5973 IConsole::forgetSavedState, and a parameter was added.</para>
5974 </listitem>
5975
5976 <listitem>
5977 <para>The method IConsole::powerDownAsync was renamed to
5978 <link linkend="IConsole__powerDown">IConsole::powerDown</link>,
5979 and the previous method with that name was deleted. So effectively a
5980 parameter was added.</para>
5981 </listitem>
5982
5983 <listitem>
5984 <para>In the
5985 <link linkend="IFramebuffer">IFramebuffer</link> interface, the
5986 following were removed:<itemizedlist>
5987 <listitem>
5988 <para>the <computeroutput>operationSupported</computeroutput>
5989 attribute;</para>
5990
5991 <para>(as a result, the
5992 <computeroutput>FramebufferAccelerationOperation</computeroutput>
5993 enum was no longer needed and removed as well);</para>
5994 </listitem>
5995
5996 <listitem>
5997 <para>the <computeroutput>solidFill()</computeroutput>
5998 method;</para>
5999 </listitem>
6000
6001 <listitem>
6002 <para>the <computeroutput>copyScreenBits()</computeroutput>
6003 method.</para>
6004 </listitem>
6005 </itemizedlist></para>
6006 </listitem>
6007
6008 <listitem>
6009 <para>In the <link linkend="IDisplay">IDisplay</link>
6010 interface, the following were removed:<itemizedlist>
6011 <listitem>
6012 <para>the
6013 <computeroutput>setupInternalFramebuffer()</computeroutput>
6014 method;</para>
6015 </listitem>
6016
6017 <listitem>
6018 <para>the <computeroutput>lockFramebuffer()</computeroutput>
6019 method;</para>
6020 </listitem>
6021
6022 <listitem>
6023 <para>the <computeroutput>unlockFramebuffer()</computeroutput>
6024 method;</para>
6025 </listitem>
6026
6027 <listitem>
6028 <para>the
6029 <computeroutput>registerExternalFramebuffer()</computeroutput>
6030 method.</para>
6031 </listitem>
6032 </itemizedlist></para>
6033 </listitem>
6034 </itemizedlist>
6035 </sect1>
6036
6037 <sect1>
6038 <title>Incompatible API changes with version 2.2</title>
6039
6040 <itemizedlist>
6041 <listitem>
6042 <para>Added explicit version number into JAX-WS Java package names,
6043 such as <computeroutput>org.virtualbox_2_2</computeroutput>,
6044 allowing connect to multiple VirtualBox clients from single Java
6045 application.</para>
6046 </listitem>
6047
6048 <listitem>
6049 <para>The interfaces having a "2" suffix attached to them with
6050 version 2.1 were renamed again to have that suffix removed. This
6051 time around, this change involves only the name, there are no
6052 functional differences.</para>
6053
6054 <para>As a result, IDVDImage2 is now IDVDImage; IHardDisk2 is now
6055 IHardDisk; IHardDisk2Attachment is now IHardDiskAttachment.</para>
6056
6057 <para>Consequentially, all related methods and attributes that had a
6058 "2" suffix have been renamed; for example, IMachine::attachHardDisk2
6059 now becomes IMachine::attachHardDisk().</para>
6060 </listitem>
6061
6062 <listitem>
6063 <para>IVirtualBox::openHardDisk has an extra parameter for opening a
6064 disk read/write or read-only.</para>
6065 </listitem>
6066
6067 <listitem>
6068 <para>The remaining collections were replaced by more performant
6069 safe-arrays. This affects the following collections:</para>
6070
6071 <itemizedlist>
6072 <listitem>
6073 <para>IGuestOSTypeCollection</para>
6074 </listitem>
6075
6076 <listitem>
6077 <para>IHostDVDDriveCollection</para>
6078 </listitem>
6079
6080 <listitem>
6081 <para>IHostFloppyDriveCollection</para>
6082 </listitem>
6083
6084 <listitem>
6085 <para>IHostUSBDeviceCollection</para>
6086 </listitem>
6087
6088 <listitem>
6089 <para>IHostUSBDeviceFilterCollection</para>
6090 </listitem>
6091
6092 <listitem>
6093 <para>IProgressCollection</para>
6094 </listitem>
6095
6096 <listitem>
6097 <para>ISharedFolderCollection</para>
6098 </listitem>
6099
6100 <listitem>
6101 <para>ISnapshotCollection</para>
6102 </listitem>
6103
6104 <listitem>
6105 <para>IUSBDeviceCollection</para>
6106 </listitem>
6107
6108 <listitem>
6109 <para>IUSBDeviceFilterCollection</para>
6110 </listitem>
6111 </itemizedlist>
6112 </listitem>
6113
6114 <listitem>
6115 <para>Since "Host Interface Networking" was renamed to "bridged
6116 networking" and host-only networking was introduced, all associated
6117 interfaces needed renaming as well. In detail:</para>
6118
6119 <itemizedlist>
6120 <listitem>
6121 <para>The HostNetworkInterfaceType enum has been renamed to
6122 <link linkend="HostNetworkInterfaceMediumType">HostNetworkInterfaceMediumType</link></para>
6123 </listitem>
6124
6125 <listitem>
6126 <para>The IHostNetworkInterface::type attribute has been renamed
6127 to
6128 <link linkend="IHostNetworkInterface__mediumType">IHostNetworkInterface::mediumType</link></para>
6129 </listitem>
6130
6131 <listitem>
6132 <para>INetworkAdapter::attachToHostInterface() has been renamed
6133 to INetworkAdapter::attachToBridgedInterface</para>
6134 </listitem>
6135
6136 <listitem>
6137 <para>In the IHost interface, createHostNetworkInterface() has
6138 been renamed to
6139 <link linkend="IHost__createHostOnlyNetworkInterface">createHostOnlyNetworkInterface()</link></para>
6140 </listitem>
6141
6142 <listitem>
6143 <para>Similarly, removeHostNetworkInterface() has been renamed
6144 to
6145 <link linkend="IHost__removeHostOnlyNetworkInterface">removeHostOnlyNetworkInterface()</link></para>
6146 </listitem>
6147 </itemizedlist>
6148 </listitem>
6149 </itemizedlist>
6150 </sect1>
6151
6152 <sect1>
6153 <title>Incompatible API changes with version 2.1</title>
6154
6155 <itemizedlist>
6156 <listitem>
6157 <para>With VirtualBox 2.1, error codes were added to many error
6158 infos that give the caller a machine-readable (numeric) feedback in
6159 addition to the error string that has always been available. This is
6160 an ongoing process, and future versions of this SDK reference will
6161 document the error codes for each method call.</para>
6162 </listitem>
6163
6164 <listitem>
6165 <para>The hard disk and other media interfaces were completely
6166 redesigned. This was necessary to account for the support of VMDK,
6167 VHD and other image types; since backwards compatibility had to be
6168 broken anyway, we seized the moment to redesign the interfaces in a
6169 more logical way.</para>
6170
6171 <itemizedlist>
6172 <listitem>
6173 <para>Previously, the old IHardDisk interface had several
6174 derivatives called IVirtualDiskImage, IVMDKImage, IVHDImage,
6175 IISCSIHardDisk and ICustomHardDisk for the various disk formats
6176 supported by VirtualBox. The new IHardDisk2 interface that comes
6177 with version 2.1 now supports all hard disk image formats
6178 itself.</para>
6179 </listitem>
6180
6181 <listitem>
6182 <para>IHardDiskFormat is a new interface to describe the
6183 available back-ends for hard disk images (e.g. VDI, VMDK, VHD or
6184 iSCSI). The IHardDisk2::format attribute can be used to find out
6185 the back-end that is in use for a particular hard disk image.
6186 ISystemProperties::hardDiskFormats[] contains a list of all
6187 back-ends supported by the system.
6188 <link linkend="ISystemProperties__defaultHardDiskFormat">ISystemProperties::defaultHardDiskFormat</link>
6189 contains the default system format.</para>
6190 </listitem>
6191
6192 <listitem>
6193 <para>In addition, the new
6194 <link linkend="IMedium">IMedium</link> interface is a generic
6195 interface for hard disk, DVD and floppy images that contains the
6196 attributes and methods shared between them. It can be considered
6197 a parent class of the more specific interfaces for those images,
6198 which are now IHardDisk2, IDVDImage2 and IFloppyImage2.</para>
6199
6200 <para>In each case, the "2" versions of these interfaces replace
6201 the earlier versions that did not have the "2" suffix.
6202 Previously, the IDVDImage and IFloppyImage interfaces were
6203 entirely unrelated to IHardDisk.</para>
6204 </listitem>
6205
6206 <listitem>
6207 <para>As a result, all parts of the API that previously
6208 referenced IHardDisk, IDVDImage or IFloppyImage or any of the
6209 old subclasses are gone and will have replacements that use
6210 IHardDisk2, IDVDImage2 and IFloppyImage2; see, for example,
6211 IMachine::attachHardDisk2.</para>
6212 </listitem>
6213
6214 <listitem>
6215 <para>In particular, the IVirtualBox::hardDisks2 array replaces
6216 the earlier IVirtualBox::hardDisks collection.</para>
6217 </listitem>
6218 </itemizedlist>
6219 </listitem>
6220
6221 <listitem>
6222 <para><link linkend="IGuestOSType">IGuestOSType</link> was
6223 extended to group operating systems into families and for 64-bit
6224 support.</para>
6225 </listitem>
6226
6227 <listitem>
6228 <para>The
6229 <link linkend="IHostNetworkInterface">IHostNetworkInterface</link>
6230 interface was completely rewritten to account for the changes in how
6231 Host Interface Networking is now implemented in VirtualBox
6232 2.1.</para>
6233 </listitem>
6234
6235 <listitem>
6236 <para>The IVirtualBox::machines2[] array replaces the former
6237 IVirtualBox::machines collection.</para>
6238 </listitem>
6239
6240 <listitem>
6241 <para>Added
6242 <link linkend="IHost__getProcessorFeature">IHost::getProcessorFeature()</link>
6243 and <link linkend="ProcessorFeature">ProcessorFeature</link>
6244 enumeration.</para>
6245 </listitem>
6246
6247 <listitem>
6248 <para>The parameter list for
6249 <link linkend="IVirtualBox__createMachine">IVirtualBox::createMachine()</link>
6250 was modified.</para>
6251 </listitem>
6252
6253 <listitem>
6254 <para>Added IMachine::pushGuestProperty.</para>
6255 </listitem>
6256
6257 <listitem>
6258 <para>New attributes in IMachine: accelerate3DEnabled,
6259 HWVirtExVPIDEnabled,
6260 <computeroutput>IMachine::guestPropertyNotificationPatterns</computeroutput>,
6261 <link linkend="IMachine__CPUCount">CPUCount</link>.</para>
6262 </listitem>
6263
6264 <listitem>
6265 <para>Added
6266 <link linkend="IConsole__powerUpPaused">IConsole::powerUpPaused()</link>
6267 and
6268 <link linkend="IConsole__getGuestEnteredACPIMode">IConsole::getGuestEnteredACPIMode()</link>.</para>
6269 </listitem>
6270
6271 <listitem>
6272 <para>Removed ResourceUsage enumeration.</para>
6273 </listitem>
6274 </itemizedlist>
6275 </sect1>
6276 </chapter>
6277</book>
6278<!-- 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