VirtualBox

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

Last change on this file since 80954 was 80893, checked in by vboxsync, 5 years ago

doc/SDKRef: Use vbox = mgr.getVirtualBox() in Python examples.
The old vbox = mgr.vbox shortcut no longer works.

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