VirtualBox

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

Last change on this file since 37929 was 37865, checked in by vboxsync, 13 years ago

SDK-Doc: document API change of r72759

File size: 196.4 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
3"http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
4<book>
5 <bookinfo>
6 <title>$VBOX_PRODUCT<superscript>®</superscript></title>
7
8 <subtitle>Programming Guide and Reference</subtitle>
9
10 <edition>Version $VBOX_VERSION_STRING</edition>
11
12 <corpauthor>$VBOX_VENDOR</corpauthor>
13
14 <address>http://www.virtualbox.org</address>
15
16 <copyright>
17 <year>2004-$VBOX_C_YEAR</year>
18
19 <holder>$VBOX_VENDOR</holder>
20 </copyright>
21 </bookinfo>
22
23 <chapter>
24 <title>Introduction</title>
25
26 <para>VirtualBox comes with comprehensive support for third-party
27 developers. This Software Development Kit (SDK) contains all the
28 documentation and interface files that are needed to write code that
29 interacts with VirtualBox.</para>
30
31 <sect1>
32 <title>Modularity: the building blocks of VirtualBox</title>
33
34 <para>VirtualBox is cleanly separated into several layers, which can be
35 visualized like in the picture below:</para>
36
37 <mediaobject>
38 <imageobject>
39 <imagedata align="center" fileref="images/vbox-components.png"
40 width="12cm" />
41 </imageobject>
42 </mediaobject>
43
44 <para>The orange area represents code that runs in kernel mode, the blue
45 area represents userspace code.</para>
46
47 <para>At the bottom of the stack resides the hypervisor -- the core of
48 the virtualization engine, controlling execution of the virtual machines
49 and making sure they do not conflict with each other or whatever the
50 host computer is doing otherwise.</para>
51
52 <para>On top of the hypervisor, additional internal modules provide
53 extra functionality. For example, the RDP server, which can deliver the
54 graphical output of a VM remotely to an RDP client, is a separate module
55 that is only loosely tacked into the virtual graphics device. Live
56 Migration and Resource Monitor are additional modules currently in the
57 process of being added to VirtualBox.</para>
58
59 <para>What is primarily of interest for purposes of the SDK is the API
60 layer block that sits on top of all the previously mentioned blocks.
61 This API, which we call the <emphasis role="bold">"Main API"</emphasis>,
62 exposes the entire feature set of the virtualization engine below. It is
63 completely documented in this SDK Reference -- see <xref
64 linkend="sdkref_classes" /> and <xref linkend="sdkref_enums" /> -- and
65 available to anyone who wishes to control VirtualBox programmatically.
66 We chose the name "Main API" to differentiate it from other programming
67 interfaces of VirtualBox that may be publicly accessible.</para>
68
69 <para>With the Main API, you can create, configure, start, stop and
70 delete virtual machines, retrieve performance statistics about running
71 VMs, configure the VirtualBox installation in general, and more. In
72 fact, internally, the front-end programs
73 <computeroutput>VirtualBox</computeroutput> and
74 <computeroutput>VBoxManage</computeroutput> use nothing but this API as
75 well -- there are no hidden backdoors into the virtualization engine for
76 our own front-ends. This ensures the entire Main API is both
77 well-documented and well-tested. (The same applies to
78 <computeroutput>VBoxHeadless</computeroutput>, which is not shown in the
79 image.)</para>
80 </sect1>
81
82 <sect1 id="webservice-or-com">
83 <title>Two guises of the same "Main API": the web service or
84 COM/XPCOM</title>
85
86 <para>There are several ways in which the Main API can be called by
87 other code:<orderedlist>
88 <listitem>
89 <para>VirtualBox comes with a <emphasis role="bold">web
90 service</emphasis> that maps nearly the entire Main API. The web
91 service ships in a stand-alone executable
92 (<computeroutput>vboxwebsrv</computeroutput>) that, when running,
93 acts as an HTTP server, accepts SOAP connections and processes
94 them.</para>
95
96 <para>Since the entire web service API is publicly described in a
97 web service description file (in WSDL format), you can write
98 client programs that call the web service in any language with a
99 toolkit that understands WSDL. These days, that includes most
100 programming languages that are available: Java, C++, .NET, PHP,
101 Python, Perl and probably many more.</para>
102
103 <para>All of this is explained in detail in subsequent chapters of
104 this book.</para>
105
106 <para>There are two ways in which you can write client code that
107 uses the web service:<orderedlist>
108 <listitem>
109 <para>For Java as well as Python, the SDK contains
110 easy-to-use classes that allow you to use the web service in
111 an object-oriented, straightforward manner. We shall refer
112 to this as the <emphasis role="bold">"object-oriented web
113 service (OOWS)"</emphasis>.</para>
114
115 <para>The OO bindings for Java are described in <xref
116 linkend="javaapi" />, those for Python in <xref lang=""
117 linkend="glue-python-ws" />.</para>
118 </listitem>
119
120 <listitem>
121 <para>Alternatively, you can use the web service directly,
122 without the object-oriented client layer. We shall refer to
123 this as the <emphasis role="bold">"raw web
124 service"</emphasis>.</para>
125
126 <para>You will then have neither native object orientation
127 nor full type safety, since web services are neither
128 object-oriented nor stateful. However, in this way, you can
129 write client code even in languages for which we do not ship
130 object-oriented client code; all you need is a programming
131 language with a toolkit that can parse WSDL and generate
132 client wrapper code from it.</para>
133
134 <para>We describe this further in <xref
135 linkend="raw-webservice" />, with samples for Java and
136 Perl.</para>
137 </listitem>
138 </orderedlist></para>
139 </listitem>
140
141 <listitem>
142 <para>Internally, for portability and easier maintenance, the Main
143 API is implemented using the <emphasis role="bold">Component
144 Object Model (COM),</emphasis> an interprocess mechanism for
145 software components originally introduced by Microsoft for
146 Microsoft Windows. On a Windows host, VirtualBox will use
147 Microsoft COM; on other hosts where COM is not present, it ships
148 with XPCOM, a free software implementation of COM originally
149 created by the Mozilla project for their browsers.</para>
150
151 <para>So, if you are familiar with COM and the C++ programming
152 language (or with any other programming language that can handle
153 COM/XPCOM objects, such as Java, Visual Basic or C#), then you can
154 use the COM/XPCOM API directly. VirtualBox comes with all
155 necessary files and documentation to build fully functional COM
156 applications. For an introduction, please see <xref
157 linkend="api_com" /> below.</para>
158
159 <para>The VirtualBox front-ends (the graphical user interfaces as
160 well as the command line), which are all written in C++, use
161 COM/XPCOM to call the Main API. Technically, the web service is
162 another front-end to this COM API, mapping almost all of it to
163 SOAP clients.</para>
164 </listitem>
165 </orderedlist></para>
166
167 <para>If you wonder which way to choose, here are a few
168 comparisons:<table>
169 <title>Comparison web service vs. COM/XPCOM</title>
170
171 <tgroup cols="2">
172 <tbody>
173 <row>
174 <entry><emphasis role="bold">Web service</emphasis></entry>
175
176 <entry><emphasis role="bold">COM/XPCOM</emphasis></entry>
177 </row>
178
179 <row>
180 <entry><emphasis role="bold">Pro:</emphasis> Easy to use with
181 Java and Python with the object-oriented web service;
182 extensive support even with other languages (C++, .NET, PHP,
183 Perl and others)</entry>
184
185 <entry><emphasis role="bold">Con:</emphasis> Usable from
186 languages where COM bridge available (most languages on
187 Windows platform, Python and C++ on other hosts)</entry>
188 </row>
189
190 <row>
191 <entry><emphasis role="bold">Pro:</emphasis> Client can be on
192 remote machine</entry>
193
194 <entry><emphasis role="bold">Con: </emphasis>Client must be on
195 the same host where virtual machine is executed</entry>
196 </row>
197
198 <row>
199 <entry><emphasis role="bold">Con: </emphasis>Significant
200 overhead due to XML marshalling over the wire for each method
201 call</entry>
202
203 <entry><emphasis role="bold">Pro: </emphasis>Relatively low
204 invocation overhead</entry>
205 </row>
206 </tbody>
207 </tgroup>
208 </table></para>
209
210 <para>In the following chapters, we will describe the different ways in
211 which to program VirtualBox, starting with the method that is easiest to
212 use and then increase complexity as we go along.</para>
213 </sect1>
214
215 <sect1 id="api_soap_intro">
216 <title>About web services in general</title>
217
218 <para>Web services are a particular type of programming interface.
219 Whereas, with "normal" programming, a program calls an application
220 programming interface (API) defined by another program or the operating
221 system and both sides of the interface have to agree on the calling
222 convention and, in most cases, use the same programming language, web
223 services use Internet standards such as HTTP and XML to
224 communicate.<footnote>
225 <para>In some ways, web services promise to deliver the same thing
226 as CORBA and DCOM did years ago. However, while these previous
227 technologies relied on specific binary protocols and thus proved to
228 be difficult to use between diverging platforms, web services
229 circumvent these incompatibilities by using text-only standards like
230 HTTP and XML. On the downside (and, one could say, typical of things
231 related to XML), a lot of standards are involved before a web
232 service can be implemented. Many of the standards invented around
233 XML are used one way or another. As a result, web services are slow
234 and verbose, and the details can be incredibly messy. The relevant
235 standards here are called SOAP and WSDL, where SOAP describes the
236 format of the messages that are exchanged (an XML document wrapped
237 in an HTTP header), and WSDL is an XML format that describes a
238 complete API provided by a web service. WSDL in turn uses XML Schema
239 to describe types, which is not exactly terse either. However, as
240 you will see from the samples provided in this chapter, the
241 VirtualBox web service shields you from these details and is easy to
242 use.</para>
243 </footnote></para>
244
245 <para>In order to successfully use a web service, a number of things are
246 required -- primarily, a web service accepting connections; service
247 descriptions; and then a client that connects to that web service. The
248 connections are governed by the SOAP standard, which describes how
249 messages are to be exchanged between a service and its clients; the
250 service descriptions are governed by WSDL.</para>
251
252 <para>In the case of VirtualBox, this translates into the following
253 three components:<orderedlist>
254 <listitem>
255 <para>The VirtualBox web service (the "server"): this is the
256 <computeroutput>vboxwebsrv</computeroutput> executable shipped
257 with VirtualBox. Once you start this executable (which acts as a
258 HTTP server on a specific TCP/IP port), clients can connect to the
259 web service and thus control a VirtualBox installation.</para>
260 </listitem>
261
262 <listitem>
263 <para>VirtualBox also comes with WSDL files that describe the
264 services provided by the web service. You can find these files in
265 the <computeroutput>sdk/bindings/webservice/</computeroutput>
266 directory. These files are understood by the web service toolkits
267 that are shipped with most programming languages and enable you to
268 easily access a web service even if you don't use our
269 object-oriented client layers. VirtualBox is shipped with
270 pregenerated web service glue code for several languages (Python,
271 Perl, Java).</para>
272 </listitem>
273
274 <listitem>
275 <para>A client that connects to the web service in order to
276 control the VirtualBox installation.</para>
277
278 <para>Unless you play with some of the samples shipped with
279 VirtualBox, this needs to be written by you.</para>
280 </listitem>
281 </orderedlist></para>
282 </sect1>
283
284 <sect1 id="runvboxwebsrv">
285 <title>Running the web service</title>
286
287 <para>The web service ships in an stand-alone executable,
288 <computeroutput>vboxwebsrv</computeroutput>, that, when running, acts as
289 a HTTP server, accepts SOAP connections and processes them -- remotely
290 or from the same machine.<note>
291 <para>The web service executable is not contained with the
292 VirtualBox SDK, but instead ships with the standard VirtualBox
293 binary package for your specific platform. Since the SDK contains
294 only platform-independent text files and documentation, the binaries
295 are instead shipped with the platform-specific packages.</para>
296 </note></para>
297
298 <para>The <computeroutput>vboxwebsrv</computeroutput> program, which
299 implements the web service, is a text-mode (console) program which,
300 after being started, simply runs until it is interrupted with Ctrl-C or
301 a kill command.</para>
302
303 <para>Once the web service is started, it acts as a front-end to the
304 VirtualBox installation of the user account that it is running under. In
305 other words, if the web service is run under the user account of
306 <computeroutput>user1</computeroutput>, it will see and manipulate the
307 virtual machines and other data represented by the VirtualBox data of
308 that user (e.g., on a Linux machine, under
309 <computeroutput>/home/user1/.VirtualBox</computeroutput>; see the
310 VirtualBox User Manual for details on where this data is stored).</para>
311
312 <sect2 id="vboxwebsrv-ref">
313 <title>Command line options of vboxwebsrv</title>
314
315 <para>The web service supports the following command line
316 options:</para>
317
318 <itemizedlist>
319 <listitem>
320 <para><computeroutput>--help</computeroutput> (or
321 <computeroutput>-h</computeroutput>): print a brief summary of
322 command line options.</para>
323 </listitem>
324
325 <listitem>
326 <para><computeroutput>--background</computeroutput> (or
327 <computeroutput>-b</computeroutput>): run the web service as a
328 background daemon. This option is not supported on Windows
329 hosts.</para>
330 </listitem>
331
332 <listitem>
333 <para><computeroutput>--host</computeroutput> (or
334 <computeroutput>-H</computeroutput>): This specifies the host to
335 bind to and defaults to "localhost".</para>
336 </listitem>
337
338 <listitem>
339 <para><computeroutput>--port</computeroutput> (or
340 <computeroutput>-p</computeroutput>): This specifies which port to
341 bind to on the host and defaults to 18083.</para>
342 </listitem>
343
344 <listitem>
345 <para><computeroutput>--timeout</computeroutput> (or
346 <computeroutput>-t</computeroutput>): This specifies the session
347 timeout, in seconds, and defaults to 300 (five minutes). A web
348 service client that has logged on but makes no calls to the web
349 service will automatically be disconnected after the number of
350 seconds specified here, as if it had called the
351 <computeroutput>IWebSessionManager::logoff()</computeroutput>
352 method provided by the web service itself.</para>
353
354 <para>It is normally vital that each web service client call this
355 method, as the web service can accumulate large amounts of memory
356 when running, especially if a web service client does not properly
357 release managed object references. As a result, this timeout value
358 should not be set too high, especially on machines with a high
359 load on the web service, or the web service may eventually deny
360 service.</para>
361 </listitem>
362
363 <listitem>
364 <para><computeroutput>--check-interval</computeroutput> (or
365 <computeroutput>-i</computeroutput>): This specifies the interval
366 in which the web service checks for timed-out clients, in seconds,
367 and defaults to 5. This normally does not need to be
368 changed.</para>
369 </listitem>
370
371 <listitem>
372 <para><computeroutput>--verbose</computeroutput> (or
373 <computeroutput>-v</computeroutput>): Normally, the webservice
374 outputs only brief messages to the console each time a request is
375 served. With this option, the webservice prints much more detailed
376 data about every request and the COM methods that those requests
377 are mapped to internally, which can be useful for debugging client
378 programs.</para>
379 </listitem>
380
381 <listitem>
382 <para><computeroutput>--logfile</computeroutput> (or
383 <computeroutput>-F</computeroutput>)
384 <computeroutput>&lt;file&gt;</computeroutput>: If this is
385 specified, the webservice not only prints its output to the
386 console, but also writes it to the specified file. The file is
387 created if it does not exist; if it does exist, new output is
388 appended to it. This is useful if you run the webservice
389 unattended and need to debug problems after they have
390 occurred.</para>
391 </listitem>
392 </itemizedlist>
393 </sect2>
394
395 <sect2 id="websrv_authenticate">
396 <title>Authenticating at web service logon</title>
397
398 <para>As opposed to the COM/XPCOM variant of the Main API, a client
399 that wants to use the web service must first log on by calling the
400 <computeroutput>IWebsessionManager::logon()</computeroutput> API (see
401 <xref linkend="IWebsessionManager__logon" />) that is specific to the
402 web service. Logon is necessary for the web service to be stateful;
403 internally, it maintains a session for each client that connects to
404 it.</para>
405
406 <para>The <computeroutput>IWebsessionManager::logon()</computeroutput>
407 API takes a user name and a password as arguments, which the web
408 service then passes to a customizable authentication plugin that
409 performs the actual authentication.</para>
410
411 <para>For testing purposes, it is recommended that you first disable
412 authentication with this command:<screen>VBoxManage setproperty websrvauthlibrary null</screen></para>
413
414 <para><warning>
415 <para>This will cause all logons to succeed, regardless of user
416 name or password. This should of course not be used in a
417 production environment.</para>
418 </warning>Generally, the mechanism by which clients are
419 authenticated is configurable by way of the
420 <computeroutput>VBoxManage</computeroutput> command:</para>
421
422 <para><screen>VBoxManage setproperty websrvauthlibrary default|null|&lt;library&gt;</screen></para>
423
424 <para>This way you can specify any shared object/dynamic link module
425 that conforms with the specifications for VirtualBox external
426 authentication modules as laid out in section <emphasis
427 role="bold">VRDE authentication</emphasis> of the VirtualBox User
428 Manual; the web service uses the same kind of modules as the
429 VirtualBox VRDE server. For technical details on VirtualBox external
430 authentication modules see <xref linkend="vbox-auth" /></para>
431
432 <para>By default, after installation, the web service uses the
433 VBoxAuth module that ships with VirtualBox. This module uses PAM on
434 Linux hosts to authenticate users. Any valid username/password
435 combination is accepted, it does not have to be the username and
436 password of the user running the webservice daemon. Unless
437 <computeroutput>vboxwebsrv</computeroutput> runs as root, PAM
438 authentication can fail, because sometimes the file
439 <computeroutput>/etc/shadow</computeroutput>, which is used by PAM, is
440 not readable. On most Linux distribution PAM uses a suid root helper
441 internally, so make sure you test this before deploying it. One can
442 override this behavior by setting the environment variable
443 <computeroutput>VBOX_PAM_ALLOW_INACTIVE</computeroutput> which will
444 suppress failures when unable to read the shadow password file. Please
445 use this variable carefully, and only if you fully understand what
446 you're doing.</para>
447 </sect2>
448
449 <sect2>
450 <title>Solaris host: starting the web service via SMF</title>
451
452 <para>On Solaris hosts, the VirtualBox web service daemon is
453 integrated into the SMF framework. You can change the parameters, but
454 don't have to if the defaults below already match your needs:<screen>svccfg -s svc:/application/virtualbox/webservice:default setprop config/host=localhost
455svccfg -s svc:/application/virtualbox/webservice:default setprop config/port=18083
456svccfg -s svc:/application/virtualbox/webservice:default setprop config/user=root</screen></para>
457
458 <para>If you made any change, don't forget to run the following
459 command to put the changes into effect immediately:<screen>svcadm refresh svc:/application/virtualbox/webservice:default</screen></para>
460
461 <para>If you forget the above command then the previous settings will
462 be used when enabling the service. Check the current property settings
463 with:<screen>svcprop -p config svc:/application/virtualbox/webservice:default</screen></para>
464
465 <para>When everything is configured correctly you can start the
466 VirtualBox webservice with the following command:<screen>svcadm enable svc:/application/virtualbox/webservice:default</screen></para>
467
468 <para>For more information about SMF, please refer to the Solaris
469 documentation.</para>
470 </sect2>
471 </sect1>
472 </chapter>
473
474 <chapter>
475 <title>Environment-specific notes</title>
476
477 <para>The Main API described in <xref linkend="sdkref_classes" /> and
478 <xref linkend="sdkref_enums" /> is mostly identical in all the supported
479 programming environments which have been briefly mentioned in the
480 introduction of this book. As a result, the Main API's general concepts
481 described in <xref linkend="concepts" /> are the same whether you use the
482 object-oriented web service (OOWS) for JAX-WS or a raw web service
483 connection via, say, Perl, or whether you use C++ COM bindings.</para>
484
485 <para>Some things are different depending on your environment, however.
486 These differences are explained in this chapter.</para>
487
488 <sect1 id="glue">
489 <title>Using the object-oriented web service (OOWS)</title>
490
491 <para>As explained in <xref linkend="webservice-or-com" />, VirtualBox
492 ships with client-side libraries for Java, Python and PHP that allow you
493 to use the VirtualBox web service in an intuitive, object-oriented way.
494 These libraries shield you from the client-side complications of managed
495 object references and other implementation details that come with the
496 VirtualBox web service. (If you are interested in these complications,
497 have a look at <xref linkend="raw-webservice" />).</para>
498
499 <para>We recommend that you start your experiments with the VirtualBox
500 web service by using our object-oriented client libraries for JAX-WS, a
501 web service toolkit for Java, which enables you to write code to
502 interact with VirtualBox in the simplest manner possible.</para>
503
504 <para>As "interfaces", "attributes" and "methods" are COM concepts,
505 please read the documentation in <xref linkend="sdkref_classes" /> and
506 <xref linkend="sdkref_enums" /> with the following notes in mind.</para>
507
508 <para>The OOWS bindings attempt to map the Main API as closely as
509 possible to the Java, Python and PHP languages. In other words, objects
510 are objects, interfaces become classes, and you can call methods on
511 objects as you would on local objects.</para>
512
513 <para>The main difference remains with attributes: to read an attribute,
514 call a "getXXX" method, with "XXX" being the attribute name with a
515 capitalized first letter. So when the Main API Reference says that
516 <computeroutput>IMachine</computeroutput> has a "name" attribute (see
517 <xref linkend="IMachine__name" xreflabel="IMachine::name" />), call
518 <computeroutput>getName()</computeroutput> on an IMachine object to
519 obtain a machine's name. Unless the attribute is marked as read-only in
520 the documentation, there will also be a corresponding "set"
521 method.</para>
522
523 <sect2 id="glue-jax-ws">
524 <title>The object-oriented web service for JAX-WS</title>
525
526 <para>JAX-WS is a powerful toolkit by Sun Microsystems to build both
527 server and client code with Java. It is part of Java 6 (JDK 1.6), but
528 can also be obtained separately for Java 5 (JDK 1.5). The VirtualBox
529 SDK comes with precompiled OOWS bindings working with both Java 5 and
530 6.</para>
531
532 <para>The following sections explain how to get the JAX-WS sample code
533 running and explain a few common practices when using the JAX-WS
534 object-oriented web service.</para>
535
536 <sect3>
537 <title>Preparations</title>
538
539 <para>Since JAX-WS is already integrated into Java 6, no additional
540 preparations are needed for Java 6.</para>
541
542 <para>If you are using Java 5 (JDK 1.5.x), you will first need to
543 download and install an external JAX-WS implementation, as Java 5
544 does not support JAX-WS out of the box; for example, you can
545 download one from here: <ulink
546 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>.
547 Then perform the installation (<computeroutput>java -jar
548 JAXWS2.1.4-20080502.jar</computeroutput>).</para>
549 </sect3>
550
551 <sect3>
552 <title>Getting started: running the sample code</title>
553
554 <para>To run the OOWS for JAX-WS samples that we ship with the SDK,
555 perform the following steps: <orderedlist>
556 <listitem>
557 <para>Open a terminal and change to the directory where the
558 JAX-WS samples reside.<footnote>
559 <para>In
560 <computeroutput>sdk/bindings/glue/java/</computeroutput>.</para>
561 </footnote> Examine the header of
562 <computeroutput>Makefile</computeroutput> to see if the
563 supplied variables (Java compiler, Java executable) and a few
564 other details match your system settings.</para>
565 </listitem>
566
567 <listitem>
568 <para>To start the VirtualBox web service, open a second
569 terminal and change to the directory where the VirtualBox
570 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
571
572 <para>The web service now waits for connections and will run
573 until you press Ctrl+C in this second terminal. The -v
574 argument causes it to log all connections to the terminal.
575 (See <xref linkend="runvboxwebsrv" os="" /> for details on how
576 to run the web service.)</para>
577 </listitem>
578
579 <listitem>
580 <para>Back in the first terminal and still in the samples
581 directory, to start a simple client example just type:<screen>make run16</screen></para>
582
583 <para>if you're on a Java 6 system; on a Java 5 system, run
584 <computeroutput>make run15</computeroutput> instead.</para>
585
586 <para>This should work on all Unix-like systems such as Linux
587 and Solaris. For Windows systems, use commands similar to what
588 is used in the Makefile.</para>
589
590 <para>This will compile the
591 <computeroutput>clienttest.java</computeroutput> code on the
592 first call and then execute the resulting
593 <computeroutput>clienttest</computeroutput> class to show the
594 locally installed VMs (see below).</para>
595 </listitem>
596 </orderedlist></para>
597
598 <para>The <computeroutput>clienttest</computeroutput> sample
599 imitates a few typical command line tasks that
600 <computeroutput>VBoxManage</computeroutput>, VirtualBox's regular
601 command-line front-end, would provide (see the VirtualBox User
602 Manual for details). In particular, you can run:<itemizedlist>
603 <listitem>
604 <para><computeroutput>java clienttest show
605 vms</computeroutput>: show the virtual machines that are
606 registered locally.</para>
607 </listitem>
608
609 <listitem>
610 <para><computeroutput>java clienttest list
611 hostinfo</computeroutput>: show various information about the
612 host this VirtualBox installation runs on.</para>
613 </listitem>
614
615 <listitem>
616 <para><computeroutput>java clienttest startvm
617 &lt;vmname|uuid&gt;</computeroutput>: start the given virtual
618 machine.</para>
619 </listitem>
620 </itemizedlist></para>
621
622 <para>The <computeroutput>clienttest.java</computeroutput> sample
623 code illustrates common basic practices how to use the VirtualBox
624 OOWS for JAX-WS, which we will explain in more detail in the
625 following chapters.</para>
626 </sect3>
627
628 <sect3>
629 <title>Logging on to the web service</title>
630
631 <para>Before a web service client can do anything useful, two
632 objects need to be created, as can be seen in the
633 <computeroutput>clienttest</computeroutput> constructor:<orderedlist>
634 <listitem>
635 <para>An instance of <xref linkend="IWebsessionManager"
636 xreflabel="IWebsessionManager" />, which is an interface
637 provided by the web service to manage "web sessions" -- that
638 is, stateful connections to the web service with persistent
639 objects upon which methods can be invoked.</para>
640
641 <para>In the OOWS for JAX-WS, the IWebsessionManager class
642 must be constructed explicitly, and a URL must be provided in
643 the constructor that specifies where the web service (the
644 server) awaits connections. The code in
645 <computeroutput>clienttest.java</computeroutput> connects to
646 "http://localhost:18083/", which is the default.</para>
647
648 <para>The port number, by default 18083, must match the port
649 number given to the
650 <computeroutput>vboxwebsrv</computeroutput> command line; see
651 <xref linkend="vboxwebsrv-ref" />.</para>
652 </listitem>
653
654 <listitem>
655 <para>After that, the code calls <xref
656 linkend="IWebsessionManager__logon"
657 xreflabel="IWebsessionManager::logon()" />, which is the first
658 call that actually communicates with the server. This
659 authenticates the client with the web service and returns an
660 instance of <xref linkend="IVirtualBox"
661 xreflabel="IVirtualBox" />, the most fundamental interface of
662 the VirtualBox web service, from which all other functionality
663 can be derived.</para>
664
665 <para>If logon doesn't work, please take another look at <xref
666 linkend="websrv_authenticate" />.</para>
667 </listitem>
668 </orderedlist></para>
669 </sect3>
670
671 <sect3>
672 <title>Object management</title>
673
674 <para>The current OOWS for JAX-WS has certain memory management
675 related limitations. When you no longer need an object, call its
676 <xref linkend="IManagedObjectRef__release"
677 xreflabel="IManagedObjectRef::release()" /> method explicitly, which
678 frees appropriate managed reference, as is required by the raw
679 webservice; see <xref linkend="managed-object-references" /> for
680 details. This limitation may be reconsidered in a future version of
681 the VirtualBox SDK.</para>
682 </sect3>
683 </sect2>
684
685 <sect2 id="glue-python-ws">
686 <title>The object-oriented web service for Python</title>
687
688 <para>VirtualBox comes with two flavors of a Python API: one for web
689 service, discussed here, and one for the COM/XPCOM API discussed in
690 <xref linkend="pycom" />. The client code is mostly similar, except
691 for the initialization part, so it is up to the application developer
692 to choose the appropriate technology. Moreover, a common Python glue
693 layer exists, abstracting out concrete platform access details, see
694 <xref linkend="glue-python" />.</para>
695
696 <para>As indicated in <xref linkend="webservice-or-com" />, the
697 COM/XPCOM API gives better performance without the SOAP overhead, and
698 does not require a web server to be running. On the other hand, the
699 COM/XPCOM Python API requires a suitable Python bridge for your Python
700 installation (VirtualBox ships the most important ones for each
701 platform<footnote>
702 <para>On On Mac OS X only the Python versions bundled with the OS
703 are officially supported. This means Python 2.3 for 10.4, Python
704 2.5 for 10.5 and Python 2.5 and 2.6 for 10.6.</para>
705 </footnote>). On Windows, you can use the Main API from Python if the Win32 extensions
706 package for Python<footnote>
707 <para>See <ulink
708 url="http://sourceforge.net/project/showfiles.php?group_id=78018">http://sourceforge.net/project/showfiles.php?group_id=78018</ulink>.</para>
709 </footnote> is installed. Version of Python Win32 extensions earlier than 2.16 are known to have bugs,
710 leading to issues with VirtualBox Python bindings, and also some early builds of Python 2.5 for Windows have issues with
711 reporting platform name on some Windows versions, so please make sure to use latest available Python
712 and Win32 extensions.</para>
713
714 <para>The VirtualBox OOWS for Python relies on the Python ZSI SOAP
715 implementation (see <ulink
716 url="http://pywebsvcs.sourceforge.net/zsi.html">http://pywebsvcs.sourceforge.net/zsi.html</ulink>),
717 which you will need to install locally before trying the examples.
718 Most Linux distributions come with package for ZSI, such as
719 <computeroutput>python-zsi</computeroutput> in Ubuntu.</para>
720
721 <para>To get started, open a terminal and change to the
722 <computeroutput>bindings/glue/python/sample</computeroutput>
723 directory, which contains an example of a simple interactive shell
724 able to control a VirtualBox instance. The shell is written using the
725 API layer, thereby hiding different implementation details, so it is
726 actually an example of code share among XPCOM, MSCOM and web services.
727 If you are interested in how to interact with the webservices layer
728 directly, have a look at
729 <computeroutput>install/vboxapi/__init__.py</computeroutput> which
730 contains the glue layer for all target platforms (i.e. XPCOM, MSCOM
731 and web services).</para>
732
733 <para>To start the shell, perform the following commands: <screen>/opt/VirtualBox/vboxwebsrv -t 0
734 # start webservice with object autocollection disabled
735export VBOX_PROGRAM_PATH=/opt/VirtualBox
736 # your VirtualBox installation directory
737export VBOX_SDK_PATH=/home/youruser/vbox-sdk
738 # where you've extracted the SDK
739./vboxshell.py -w </screen>See <xref linkend="vboxshell" /> for more
740 details on the shell's functionality. For you, as a VirtualBox
741 application developer, the vboxshell sample could be interesting as an
742 example of how to write code targeting both local and remote cases
743 (COM/XPCOM and SOAP). The common part of the shell is the same -- the
744 only difference is how it interacts with the invocation layer. You can
745 use the <computeroutput>connect</computeroutput> shell command to
746 connect to remote VirtualBox servers; in this case you can skip
747 starting the local webserver.</para>
748 </sect2>
749
750 <sect2>
751 <title>The object-oriented web service for PHP</title>
752
753 <para>VirtualBox also comes with object-oriented web service (OOWS)
754 wrappers for PHP5. These wrappers rely on the PHP SOAP
755 Extension<footnote>
756 <para>See <ulink url="???">http://www.php.net/soap</ulink>.</para>
757 </footnote>, which can be installed by configuring PHP with
758 <computeroutput>--enable-soap</computeroutput>.</para>
759 </sect2>
760 </sect1>
761
762 <sect1 id="raw-webservice">
763 <title>Using the raw web service with any language</title>
764
765 <para>The following examples show you how to use the raw web service,
766 without the object-oriented client-side code that was described in the
767 previous chapter.</para>
768
769 <para>Generally, when reading the documentation in <xref
770 linkend="sdkref_classes" /> and <xref linkend="sdkref_enums" />, due to
771 the limitations of SOAP and WSDL lined out in <xref
772 linkend="rawws-conventions" />, please have the following notes in
773 mind:</para>
774
775 <para><orderedlist>
776 <listitem>
777 <para>Any COM method call becomes a <emphasis role="bold">plain
778 function call</emphasis> in the raw web service, with the object
779 as an additional first parameter (before the "real" parameters
780 listed in the documentation). So when the documentation says that
781 the <computeroutput>IVirtualBox</computeroutput> interface
782 supports the <computeroutput>createMachine()</computeroutput>
783 method (see <xref linkend="IVirtualBox__createMachine"
784 xreflabel="IVirtualBox::createMachine()" />), the web service
785 operation is
786 <computeroutput>IVirtualBox_createMachine(...)</computeroutput>,
787 and a managed object reference to an
788 <computeroutput>IVirtualBox</computeroutput> object must be passed
789 as the first argument.</para>
790 </listitem>
791
792 <listitem>
793 <para>For <emphasis role="bold">attributes</emphasis> in
794 interfaces, there will be at least one "get" function; there will
795 also be a "set" function, unless the attribute is "readonly". The
796 attribute name will be appended to the "get" or "set" prefix, with
797 a capitalized first letter. So, the "version" readonly attribute
798 of the <computeroutput>IVirtualBox</computeroutput> interface can
799 be retrieved by calling
800 <computeroutput>IVirtualBox_getVersion(vbox)</computeroutput>,
801 with <computeroutput>vbox</computeroutput> being the VirtualBox
802 object.</para>
803 </listitem>
804
805 <listitem>
806 <para>Whenever the API documentation says that a method (or an
807 attribute getter) returns an <emphasis
808 role="bold">object</emphasis>, it will returned a managed object
809 reference in the web service instead. As said above, managed
810 object references should be released if the web service client
811 does not log off again immediately!</para>
812 </listitem>
813 </orderedlist></para>
814
815 <para></para>
816
817 <sect2 id="webservice-java-sample">
818 <title>Raw web service example for Java with Axis</title>
819
820 <para>Axis is an older web service toolkit created by the Apache
821 foundation. If your distribution does not have it installed, you can
822 get a binary from <ulink
823 url="http://www.apache.org">http://www.apache.org</ulink>. The
824 following examples assume that you have Axis 1.4 installed.</para>
825
826 <para>The VirtualBox SDK ships with an example for Axis that, again,
827 is called <computeroutput>clienttest.java</computeroutput> and that
828 imitates a few of the commands of
829 <computeroutput>VBoxManage</computeroutput> over the wire.</para>
830
831 <para>Then perform the following steps:<orderedlist>
832 <listitem>
833 <para>Create a working directory somewhere. Under your
834 VirtualBox installation directory, find the
835 <computeroutput>sdk/webservice/samples/java/axis/</computeroutput>
836 directory and copy the file
837 <computeroutput>clienttest.java</computeroutput> to your working
838 directory.</para>
839 </listitem>
840
841 <listitem>
842 <para>Open a terminal in your working directory. Execute the
843 following command:<screen> java org.apache.axis.wsdl.WSDL2Java /path/to/vboxwebService.wsdl</screen></para>
844
845 <para>The <computeroutput>vboxwebService.wsdl</computeroutput>
846 file should be located in the
847 <computeroutput>sdk/webservice/</computeroutput>
848 directory.</para>
849
850 <para>If this fails, your Apache Axis may not be located on your
851 system classpath, and you may have to adjust the CLASSPATH
852 environment variable. Something like this:<screen>export CLASSPATH="/path-to-axis-1_4/lib/*":$CLASSPATH</screen></para>
853
854 <para>Use the directory where the Axis JAR files are located.
855 Mind the quotes so that your shell passes the "*" character to
856 the java executable without expanding. Alternatively, add a
857 corresponding <computeroutput>-classpath</computeroutput>
858 argument to the "java" call above.</para>
859
860 <para>If the command executes successfully, you should see an
861 "org" directory with subdirectories containing Java source files
862 in your working directory. These classes represent the
863 interfaces that the VirtualBox web service offers, as described
864 by the WSDL file.</para>
865
866 <para>This is the bit that makes using web services so
867 attractive to client developers: if a language's toolkit
868 understands WSDL, it can generate large amounts of support code
869 automatically. Clients can then easily use this support code and
870 can be done with just a few lines of code.</para>
871 </listitem>
872
873 <listitem>
874 <para>Next, compile the
875 <computeroutput>clienttest.java</computeroutput> source:<screen>javac clienttest.java </screen></para>
876
877 <para>This should yield a "clienttest.class" file.</para>
878 </listitem>
879
880 <listitem>
881 <para>To start the VirtualBox web service, open a second
882 terminal and change to the directory where the VirtualBox
883 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
884
885 <para>The web service now waits for connections and will run
886 until you press Ctrl+C in this second terminal. The -v argument
887 causes it to log all connections to the terminal. (See <xref
888 linkend="runvboxwebsrv" os="" /> for details on how to run the
889 web service.)</para>
890 </listitem>
891
892 <listitem>
893 <para>Back in the original terminal where you compiled the Java
894 source, run the resulting binary, which will then connect to the
895 web service:<screen>java clienttest</screen></para>
896
897 <para>The client sample will connect to the web service (on
898 localhost, but the code could be changed to connect remotely if
899 the web service was running on a different machine) and make a
900 number of method calls. It will output the version number of
901 your VirtualBox installation and a list of all virtual machines
902 that are currently registered (with a bit of seemingly random
903 data, which will be explained later).</para>
904 </listitem>
905 </orderedlist></para>
906 </sect2>
907
908 <sect2 id="raw-webservice-perl">
909 <title>Raw web service example for Perl</title>
910
911 <para>We also ship a small sample for Perl. It uses the SOAP::Lite
912 perl module to communicate with the VirtualBox web service.</para>
913
914 <para>The
915 <computeroutput>sdk/bindings/webservice/perl/lib/</computeroutput>
916 directory contains a pre-generated Perl module that allows for
917 communicating with the web service from Perl. You can generate such a
918 module yourself using the "stubmaker" tool that comes with SOAP::Lite,
919 but since that tool is slow as well as sometimes unreliable, we are
920 shipping a working module with the SDK for your convenience.</para>
921
922 <para>Perform the following steps:<orderedlist>
923 <listitem>
924 <para>If SOAP::Lite is not yet installed on your system, you
925 will need to install the package first. On Debian-based systems,
926 the package is called
927 <computeroutput>libsoap-lite-perl</computeroutput>; on Gentoo,
928 it's <computeroutput>dev-perl/SOAP-Lite</computeroutput>.</para>
929 </listitem>
930
931 <listitem>
932 <para>Open a terminal in the
933 <computeroutput>sdk/bindings/webservice/perl/samples/</computeroutput>
934 directory.</para>
935 </listitem>
936
937 <listitem>
938 <para>To start the VirtualBox web service, open a second
939 terminal and change to the directory where the VirtualBox
940 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
941
942 <para>The web service now waits for connections and will run
943 until you press Ctrl+C in this second terminal. The -v argument
944 causes it to log all connections to the terminal. (See <xref
945 linkend="runvboxwebsrv" os="" /> for details on how to run the
946 web service.)</para>
947 </listitem>
948
949 <listitem>
950 <para>In the first terminal with the Perl sample, run the
951 clienttest.pl script:<screen>perl -I ../lib clienttest.pl</screen></para>
952 </listitem>
953 </orderedlist></para>
954 </sect2>
955
956 <sect2>
957 <title>Programming considerations for the raw web service</title>
958
959 <para>If you use the raw web service, you need to keep a number of
960 things in mind, or you will sooner or later run into issues that are
961 not immediately obvious. By contrast, the object-oriented client-side
962 libraries described in <xref linkend="glue" /> take care of these
963 things automatically and thus greatly simplify using the web
964 service.</para>
965
966 <sect3 id="rawws-conventions">
967 <title>Fundamental conventions</title>
968
969 <para>If you are familiar with other web services, you may find the
970 VirtualBox web service to behave a bit differently to accommodate
971 for the fact that VirtualBox web service more or less maps the
972 VirtualBox Main COM API. The following main differences had to be
973 taken care of:<itemizedlist>
974 <listitem>
975 <para>Web services, as expressed by WSDL, are not
976 object-oriented. Even worse, they are normally stateless (or,
977 in web services terminology, "loosely coupled"). Web service
978 operations are entirely procedural, and one cannot normally
979 make assumptions about the state of a web service between
980 function calls.</para>
981
982 <para>In particular, this normally means that you cannot work
983 on objects in one method call that were created by another
984 call.</para>
985 </listitem>
986
987 <listitem>
988 <para>By contrast, the VirtualBox Main API, being expressed in
989 COM, is object-oriented and works entirely on objects, which
990 are grouped into public interfaces, which in turn have
991 attributes and methods associated with them.</para>
992 </listitem>
993 </itemizedlist> For the VirtualBox web service, this results in
994 three fundamental conventions:<orderedlist>
995 <listitem>
996 <para>All <emphasis role="bold">function names</emphasis> in
997 the VirtualBox web service consist of an interface name and a
998 method name, joined together by an underscore. This is because
999 there are only functions ("operations") in WSDL, but no
1000 classes, interfaces, or methods.</para>
1001
1002 <para>In addition, all calls to the VirtualBox web service
1003 (except for logon, see below) take a <emphasis
1004 role="bold">managed object reference</emphasis> as the first
1005 argument, representing the object upon which the underlying
1006 method is invoked. (Managed object references are explained in
1007 detail below; see <xref
1008 linkend="managed-object-references" />.)</para>
1009
1010 <para>So, when one would normally code, in the pseudo-code of
1011 an object-oriented language, to invoke a method upon an
1012 object:<screen>IMachine machine;
1013result = machine.getName();</screen></para>
1014
1015 <para>In the VirtualBox web service, this looks something like
1016 this (again, pseudo-code):<screen>IMachineRef machine;
1017result = IMachine_getName(machine);</screen></para>
1018 </listitem>
1019
1020 <listitem>
1021 <para>To make the web service stateful, and objects persistent
1022 between method calls, the VirtualBox web service introduces a
1023 <emphasis role="bold">session manager</emphasis> (by way of
1024 the <xref linkend="IWebsessionManager"
1025 xreflabel="IWebsessionManager" /> interface), which manages
1026 object references. Any client wishing to interact with the web
1027 service must first log on to the session manager and in turn
1028 receives a managed object reference to an object that supports
1029 the <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />
1030 interface (the basic interface in the Main API).</para>
1031 </listitem>
1032 </orderedlist></para>
1033
1034 <para>In other words, as opposed to other web services, <emphasis
1035 role="bold">the VirtualBox web service is both object-oriented and
1036 stateful.</emphasis></para>
1037 </sect3>
1038
1039 <sect3>
1040 <title>Example: A typical web service client session</title>
1041
1042 <para>A typical short web service session to retrieve the version
1043 number of the VirtualBox web service (to be precise, the underlying
1044 Main API version number) looks like this:<orderedlist>
1045 <listitem>
1046 <para>A client logs on to the web service by calling <xref
1047 linkend="IWebsessionManager__logon"
1048 xreflabel="IWebsessionManager::logon()" /> with a valid user
1049 name and password. See <xref linkend="websrv_authenticate" />
1050 for details about how authentication works.</para>
1051 </listitem>
1052
1053 <listitem>
1054 <para>On the server side,
1055 <computeroutput>vboxwebsrv</computeroutput> creates a session,
1056 which persists until the client calls <xref
1057 linkend="IWebsessionManager__logoff"
1058 xreflabel="IWebsessionManager::logoff()" /> or the session
1059 times out after a configurable period of inactivity (see <xref
1060 linkend="vboxwebsrv-ref" />).</para>
1061
1062 <para>For the new session, the web service creates an instance
1063 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />.
1064 This interface is the most central one in the Main API and
1065 allows access to all other interfaces, either through
1066 attributes or method calls. For example, IVirtualBox contains
1067 a list of all virtual machines that are currently registered
1068 (as they would be listed on the left side of the VirtualBox
1069 main program).</para>
1070
1071 <para>The web service then creates a managed object reference
1072 for this instance of IVirtualBox and returns it to the calling
1073 client, which receives it as the return value of the logon
1074 call. Something like this:</para>
1075
1076 <screen>string oVirtualBox;
1077oVirtualBox = webservice.IWebsessionManager_logon("user", "pass");</screen>
1078
1079 <para>(The managed object reference "oVirtualBox" is just a
1080 string consisting of digits and dashes. However, it is a
1081 string with a meaning and will be checked by the web service.
1082 For details, see below. As hinted above, <xref
1083 linkend="IWebsessionManager__logon"
1084 xreflabel="IWebsessionManager::logon()" /> is the
1085 <emphasis>only</emphasis> operation provided by the web
1086 service which does not take a managed object reference as the
1087 first argument!)</para>
1088 </listitem>
1089
1090 <listitem>
1091 <para>The VirtualBox Main API documentation says that the
1092 <computeroutput>IVirtualBox</computeroutput> interface has a
1093 <xref linkend="IVirtualBox__version" xreflabel="version" />
1094 attribute, which is a string. For each attribute, there is a
1095 "get" and a "set" method in COM, which maps to according
1096 operations in the web service. So, to retrieve the "version"
1097 attribute of this <computeroutput>IVirtualBox</computeroutput>
1098 object, the web service client does this:<screen>string version;
1099version = webservice.IVirtualBox_getVersion(oVirtualBox);
1100
1101print version;</screen></para>
1102
1103 <para>And it will print
1104 "$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD".</para>
1105 </listitem>
1106
1107 <listitem>
1108 <para>The web service client calls <xref
1109 linkend="IWebsessionManager__logoff"
1110 xreflabel="IWebsessionManager::logoff()" /> with the
1111 VirtualBox managed object reference. This will clean up all
1112 allocated resources.</para>
1113 </listitem>
1114 </orderedlist></para>
1115 </sect3>
1116
1117 <sect3 id="managed-object-references">
1118 <title>Managed object references</title>
1119
1120 <para>To a web service client, a managed object reference looks like
1121 a string: two 64-bit hex numbers separated by a dash. This string,
1122 however, represents a COM object that "lives" in the web service
1123 process. The two 64-bit numbers encoded in the managed object
1124 reference represent a session ID (which is the same for all objects
1125 in the same web service session, i.e. for all objects after one
1126 logon) and a unique object ID within that session.</para>
1127
1128 <para>Managed object references are created in two
1129 situations:<orderedlist>
1130 <listitem>
1131 <para>When a client logs on, by calling <xref
1132 linkend="IWebsessionManager__logon"
1133 xreflabel="IWebsessionManager::logon()" />.</para>
1134
1135 <para>Upon logon, the websession manager creates one instance
1136 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" /> and
1137 another object of <xref linkend="ISession"
1138 xreflabel="ISession" /> representing the web service session.
1139 This can be retrieved using <xref
1140 linkend="IWebsessionManager__getSessionObject"
1141 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
1142
1143 <para>(Technically, there is always only one <xref
1144 linkend="IVirtualBox" xreflabel="IVirtualBox" /> object, which
1145 is shared between all sessions and clients, as it is a COM
1146 singleton. However, each session receives its own managed
1147 object reference to it. The <xref linkend="ISession"
1148 xreflabel="ISession" /> object, however, is created and
1149 destroyed for each session.)</para>
1150 </listitem>
1151
1152 <listitem>
1153 <para>Whenever a web service clients invokes an operation
1154 whose COM implementation creates COM objects.</para>
1155
1156 <para>For example, <xref linkend="IVirtualBox__createMachine"
1157 xreflabel="IVirtualBox::createMachine()" /> creates a new
1158 instance of <xref linkend="IMachine" xreflabel="IMachine" />;
1159 the COM object returned by the COM method call is then wrapped
1160 into a managed object reference by the web server, and this
1161 reference is returned to the web service client.</para>
1162 </listitem>
1163 </orderedlist></para>
1164
1165 <para>Internally, in the web service process, each managed object
1166 reference is simply a small data structure, containing a COM pointer
1167 to the "real" COM object, the web session ID and the object ID. This
1168 structure is allocated on creation and stored efficiently in hashes,
1169 so that the web service can look up the COM object quickly whenever
1170 a web service client wishes to make a method call. The random
1171 session ID also ensures that one web service client cannot intercept
1172 the objects of another.</para>
1173
1174 <para>Managed object references are not destroyed automatically and
1175 must be released by explicitly calling <xref
1176 linkend="IManagedObjectRef__release"
1177 xreflabel="IManagedObjectRef::release()" />. This is important, as
1178 otherwise hundreds or thousands of managed object references (and
1179 corresponding COM objects, which can consume much more memory!) can
1180 pile up in the web service process and eventually cause it to deny
1181 service.</para>
1182
1183 <para>To reiterate: The underlying COM object, which the reference
1184 points to, is only freed if the managed object reference is
1185 released. It is therefore vital that web service clients properly
1186 clean up after the managed object references that are returned to
1187 them.</para>
1188
1189 <para>When a web service client calls <xref
1190 linkend="IWebsessionManager__logoff"
1191 xreflabel="IWebsessionManager::logoff()" />, all managed object
1192 references created during the session are automatically freed. For
1193 short-lived sessions that do not create a lot of objects, logging
1194 off may therefore be sufficient, although it is certainly not "best
1195 practice".</para>
1196 </sect3>
1197
1198 <sect3>
1199 <title>Some more detail about web service operation</title>
1200
1201 <sect4 id="soap">
1202 <title>SOAP messages</title>
1203
1204 <para>Whenever a client makes a call to a web service, this
1205 involves a complicated procedure internally. These calls are
1206 remote procedure calls. Each such procedure call typically
1207 consists of two "message" being passed, where each message is a
1208 plain-text HTTP request with a standard HTTP header and a special
1209 XML document following. This XML document encodes the name of the
1210 procedure to call and the argument names and values passed to
1211 it.</para>
1212
1213 <para>To give you an idea of what such a message looks like,
1214 assuming that a web service provides a procedure called
1215 "SayHello", which takes a string "name" as an argument and returns
1216 "Hello" with a space and that name appended, the request message
1217 could look like this:</para>
1218
1219 <para><screen>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
1220&lt;SOAP-ENV:Envelope
1221 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
1222 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
1223 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1224 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1225 xmlns:test="http://test/"&gt;
1226&lt;SOAP-ENV:Body&gt;
1227 &lt;test:SayHello&gt;
1228 &lt;name&gt;Peter&lt;/name&gt;
1229 &lt;/test:SayHello&gt;
1230 &lt;/SOAP-ENV:Body&gt;
1231&lt;/SOAP-ENV:Envelope&gt;</screen>A similar message -- the "response" message
1232 -- would be sent back from the web service to the client,
1233 containing the return value "Hello Peter".</para>
1234
1235 <para>Most programming languages provide automatic support to
1236 generate such messages whenever code in that programming language
1237 makes such a request. In other words, these programming languages
1238 allow for writing something like this (in pseudo-C++ code):</para>
1239
1240 <para><screen>webServiceClass service("localhost", 18083); // server and port
1241string result = service.SayHello("Peter"); // invoke remote procedure</screen>and
1242 would, for these two pseudo-lines, automatically perform these
1243 steps:</para>
1244
1245 <para><orderedlist>
1246 <listitem>
1247 <para>prepare a connection to a web service running on port
1248 18083 of "localhost";</para>
1249 </listitem>
1250
1251 <listitem>
1252 <para>for the <computeroutput>SayHello()</computeroutput>
1253 function of the web service, generate a SOAP message like in
1254 the above example by encoding all arguments of the remote
1255 procedure call (which could involve all kinds of type
1256 conversions and complex marshalling for arrays and
1257 structures);</para>
1258 </listitem>
1259
1260 <listitem>
1261 <para>connect to the web service via HTTP and send that
1262 message;</para>
1263 </listitem>
1264
1265 <listitem>
1266 <para>wait for the web service to send a response
1267 message;</para>
1268 </listitem>
1269
1270 <listitem>
1271 <para>decode that response message and put the return value
1272 of the remote procedure into the "result" variable.</para>
1273 </listitem>
1274 </orderedlist></para>
1275 </sect4>
1276
1277 <sect4 id="wsdl">
1278 <title>Service descriptions in WSDL</title>
1279
1280 <para>In the above explanations about SOAP, it was left open how
1281 the programming language learns about how to translate function
1282 calls in its own syntax into proper SOAP messages. In other words,
1283 the programming language needs to know what operations the web
1284 service supports and what types of arguments are required for the
1285 operation's data in order to be able to properly serialize and
1286 deserialize the data to and from the web service. For example, if
1287 a web service operation expects a number in "double" floating
1288 point format for a particular parameter, the programming language
1289 cannot send to it a string instead.</para>
1290
1291 <para>For this, the Web Service Definition Language (WSDL) was
1292 invented, another XML substandard that describes exactly what
1293 operations the web service supports and, for each operation, which
1294 parameters and types are needed with each request and response
1295 message. WSDL descriptions can be incredibly verbose, and one of
1296 the few good things that can be said about this standard is that
1297 it is indeed supported by most programming languages.</para>
1298
1299 <para>So, if it is said that a programming language "supports" web
1300 services, this typically means that a programming language has
1301 support for parsing WSDL files and somehow integrating the remote
1302 procedure calls into the native language syntax -- for example,
1303 like in the Java sample shown in <xref
1304 linkend="webservice-java-sample" />.</para>
1305
1306 <para>For details about how programming languages support web
1307 services, please refer to the documentation that comes with the
1308 individual languages. Here are a few pointers:</para>
1309
1310 <orderedlist>
1311 <listitem>
1312 <para>For <emphasis role="bold">C++,</emphasis> among many
1313 others, the gSOAP toolkit is a good option. Parts of gSOAP are
1314 also used in VirtualBox to implement the VirtualBox web
1315 service.</para>
1316 </listitem>
1317
1318 <listitem>
1319 <para>For <emphasis role="bold">Java,</emphasis> there are
1320 several implementations already described in this document
1321 (see <xref linkend="glue-jax-ws" /> and <xref
1322 linkend="webservice-java-sample" />).</para>
1323 </listitem>
1324
1325 <listitem>
1326 <para><emphasis role="bold">Perl</emphasis> supports WSDL via
1327 the SOAP::Lite package. This in turn comes with a tool called
1328 <computeroutput>stubmaker.pl</computeroutput> that allows you
1329 to turn any WSDL file into a Perl package that you can import.
1330 (You can also import any WSDL file "live" by having it parsed
1331 every time the script runs, but that can take a while.) You
1332 can then code (again, assuming the above example):<screen>my $result = servicename-&gt;sayHello("Peter");</screen></para>
1333
1334 <para>A sample that uses SOAP::Lite was described in <xref
1335 linkend="raw-webservice-perl" />.</para>
1336 </listitem>
1337 </orderedlist>
1338 </sect4>
1339 </sect3>
1340 </sect2>
1341 </sect1>
1342
1343 <sect1 id="api_com">
1344 <title>Using COM/XPCOM directly</title>
1345
1346 <para>If you do not require <emphasis>remote</emphasis> procedure calls
1347 such as those offered by the VirtualBox web service, and if you know
1348 Python or C++ as well as COM, you might find it preferable to program
1349 VirtualBox's Main API directly via COM.</para>
1350
1351 <para>COM stands for "Component Object Model" and is a standard
1352 originally introduced by Microsoft in the 1990s for Microsoft Windows.
1353 It allows for organizing software in an object-oriented way and across
1354 processes; code in one process may access objects that live in another
1355 process.</para>
1356
1357 <para>COM has several advantages: it is language-neutral, meaning that
1358 even though all of VirtualBox is internally written in C++, programs
1359 written in other languages could communicate with it. COM also cleanly
1360 separates interface from implementation, so that external programs need
1361 not know anything about the messy and complicated details of VirtualBox
1362 internals.</para>
1363
1364 <para>On a Windows host, all parts of VirtualBox will use the COM
1365 functionality that is native to Windows. On other hosts (including
1366 Linux), VirtualBox comes with a built-in implementation of XPCOM, as
1367 originally created by the Mozilla project, which we have enhanced to
1368 support interprocess communication on a level comparable to Microsoft
1369 COM. Internally, VirtualBox has an abstraction layer that allows the
1370 same VirtualBox code to work both with native COM as well as our XPCOM
1371 implementation.</para>
1372
1373 <sect2 id="pycom">
1374 <title>Python COM API</title>
1375
1376 <para>On Windows, Python scripts can use COM and VirtualBox interfaces
1377 to control almost all aspects of virtual machine execution. As an
1378 example, use the following commands to instantiate the VirtualBox
1379 object and start a VM: <screen>
1380 vbox = win32com.client.Dispatch("VirtualBox.VirtualBox")
1381 session = win32com.client.Dispatch("VirtualBox.Session")
1382 mach = vbox.findMachine("uuid or name of machine to start")
1383 progress = mach.launchVMProcess(session, "gui", "")
1384 progress.waitForCompletion(-1)
1385 </screen> Also, see
1386 <computeroutput>/bindings/glue/python/samples/vboxshell.py</computeroutput>
1387 for more advanced usage scenarious. However, unless you have specific
1388 requirements, we strongly recommend to use the generic glue layer
1389 described in the next section to access MS COM objects.</para>
1390 </sect2>
1391
1392 <sect2 id="glue-python">
1393 <title>Common Python bindings layer</title>
1394
1395 <para>As different wrappers ultimately provide access to the same
1396 underlying API, and to simplify porting and development of Python
1397 application using the VirtualBox Main API, we developed a common glue
1398 layer that abstracts out most platform-specific details from the
1399 application and allows the developer to focus on application logic.
1400 The VirtualBox installer automatically sets up this glue layer for the
1401 system default Python install. See below for details on how to set up
1402 the glue layer if you want to use a different Python
1403 installation.</para>
1404
1405 <para>In this layer, the class
1406 <computeroutput>VirtualBoxManager</computeroutput> hides most
1407 platform-specific details. It can be used to access both the local
1408 (COM) and the webservice-based API. The following code can be used by
1409 an application to use the glue layer.</para>
1410
1411 <screen># This code assumes vboxapi.py from VirtualBox distribution
1412# being in PYTHONPATH, or installed system-wide
1413from vboxapi import VirtualBoxManager
1414
1415# This code initializes VirtualBox manager with default style
1416# and parameters
1417virtualBoxManager = VirtualBoxManager(None, None)
1418
1419# Alternatively, one can be more verbose, and initialize
1420# glue with webservice backend, and provide authentication
1421# information
1422virtualBoxManager = VirtualBoxManager("WEBSERVICE",
1423 {'url':'http://myhost.com::18083/',
1424 'user':'me',
1425 'password':'secret'}) </screen>
1426
1427 <para>We supply the <computeroutput>VirtualBoxManager</computeroutput>
1428 constructor with 2 arguments: style and parameters. Style defines
1429 which bindings style to use (could be "MSCOM", "XPCOM" or
1430 "WEBSERVICE"), and if set to <computeroutput>None</computeroutput>
1431 defaults to usable platform bindings (MS COM on Windows, XPCOM on
1432 other platforms). The second argument defines parameters, passed to
1433 the platform-specific module, as we do in the second example, where we
1434 pass username and password to be used to authenticate against the web
1435 service.</para>
1436
1437 <para>After obtaining the
1438 <computeroutput>VirtualBoxManager</computeroutput> instance, one can
1439 perform operations on the IVirtualBox class. For example, the
1440 following code will a start virtual machine by name or ID:</para>
1441
1442 <screen>from vboxapi import VirtualBoxManager
1443mgr = VirtualBoxManager(None, None)
1444vbox = mgr.vbox
1445name = "Linux"
1446mach = vbox.findMachine(name)
1447session = mgr.mgr.getSessionObject(vbox)
1448progress = mach.launchVMProcess(session, "gui", "")
1449progress.waitForCompletion(-1)
1450mgr.closeMachineSession(session)
1451 </screen>
1452 <para>
1453 Following code will print all registered machines and their log folders
1454 </para>
1455 <screen>from vboxapi import VirtualBoxManager
1456mgr = VirtualBoxManager(None, None)
1457vbox = mgr.vbox
1458
1459for m in mgr.getArray(vbox, 'machines'):
1460print "Machine '%s' logs in '%s'" %(m.name, m.logFolder)
1461 </screen>
1462
1463 <para>Code above demonstartes cross-platform access to array properties
1464 (certain limitations prevent one from using
1465 <computeroutput>vbox.machines</computeroutput> to access a list of
1466 available virtual machines in case of XPCOM), and a mechanism of
1467 uniform session creation and closing
1468 (<computeroutput>mgr.mgr.getSessionObject()</computeroutput>).</para>
1469
1470 <para>In case you want to use the glue layer with a different Python
1471 installation, use these steps in a shell to add the necessary
1472 files:</para>
1473
1474 <screen> # cd VBOX_INSTALL_PATH/sdk/installer
1475 # PYTHON vboxapisetup.py install</screen>
1476 </sect2>
1477
1478 <sect2 id="cppcom">
1479 <title>C++ COM API</title>
1480
1481 <para>C++ is the language that VirtualBox itself is written in, so C++
1482 is the most direct way to use the Main API -- but it is not
1483 necessarily the easiest, as using COM and XPCOM has its own set of
1484 complications.</para>
1485
1486 <para>VirtualBox ships with sample programs that demonstrate how to
1487 use the Main API to implement a number of tasks on your host platform.
1488 These samples can be found in the
1489 <computeroutput>/bindings/xpcom/samples</computeroutput> directory for
1490 Linux, Mac OS X and Solaris and
1491 <computeroutput>/bindings/mscom/samples</computeroutput> for Windows.
1492 The two samples are actually different, because the one for Windows
1493 uses native COM, whereas the other uses our XPCOM implementation, as
1494 described above.</para>
1495
1496 <para>Since COM and XPCOM are conceptually very similar but vary in
1497 the implementation details, we have created a "glue" layer that
1498 shields COM client code from these differences. All VirtualBox uses is
1499 this glue layer, so the same code written once works on both Windows
1500 hosts (with native COM) as well as on other hosts (with our XPCOM
1501 implementation). It is recommended to always use this glue code
1502 instead of using the COM and XPCOM APIs directly, as it is very easy
1503 to make your code completely independent from the platform it is
1504 running on.<!-- A third sample,
1505 <computeroutput>tstVBoxAPIGlue.cpp</computeroutput>, illustrates how to
1506 use the glue layer.
1507--></para>
1508
1509 <para>In order to encapsulate platform differences between Microsoft
1510 COM and XPCOM, the following items should be kept in mind when using
1511 the glue layer:</para>
1512
1513 <para><orderedlist>
1514 <listitem>
1515 <para><emphasis role="bold">Attribute getters and
1516 setters.</emphasis> COM has the notion of "attributes" in
1517 interfaces, which roughly compare to C++ member variables in
1518 classes. The difference is that for each attribute declared in
1519 an interface, COM automatically provides a "get" method to
1520 return the attribute's value. Unless the attribute has been
1521 marked as "readonly", a "set" attribute is also provided.</para>
1522
1523 <para>To illustrate, the IVirtualBox interface has a "version"
1524 attribute, which is read-only and of the "wstring" type (the
1525 standard string type in COM). As a result, you can call the
1526 "get" method for this attribute to retrieve the version number
1527 of VirtualBox.</para>
1528
1529 <para>Unfortunately, the implementation differs between COM and
1530 XPCOM. Microsoft COM names the "get" method like this:
1531 <computeroutput>get_Attribute()</computeroutput>, whereas XPCOM
1532 uses this syntax:
1533 <computeroutput>GetAttribute()</computeroutput> (and accordingly
1534 for "set" methods). To hide these differences, the VirtualBox
1535 glue code provides the
1536 <computeroutput>COMGETTER(attrib)</computeroutput> and
1537 <computeroutput>COMSETTER(attrib)</computeroutput> macros. So,
1538 <computeroutput>COMGETTER(version)()</computeroutput> (note, two
1539 pairs of brackets) expands to
1540 <computeroutput>get_Version()</computeroutput> on Windows and
1541 <computeroutput>GetVersion()</computeroutput> on other
1542 platforms.</para>
1543 </listitem>
1544
1545 <listitem>
1546 <para><emphasis role="bold">Unicode conversions.</emphasis>
1547 While the rest of the modern world has pretty much settled on
1548 encoding strings in UTF-8, COM, unfortunately, uses UCS-16
1549 encoding. This requires a lot of conversions, in particular
1550 between the VirtualBox Main API and the Qt GUI, which, like the
1551 rest of Qt, likes to use UTF-8.</para>
1552
1553 <para>To facilitate these conversions, VirtualBox provides the
1554 <computeroutput>com::Bstr</computeroutput> and
1555 <computeroutput>com::Utf8Str</computeroutput> classes, which
1556 support all kinds of conversions back and forth.</para>
1557 </listitem>
1558
1559 <listitem>
1560 <para><emphasis role="bold">COM autopointers.</emphasis>
1561 Possibly the greatest pain of using COM -- reference counting --
1562 is alleviated by the
1563 <computeroutput>ComPtr&lt;&gt;</computeroutput> template
1564 provided by the <computeroutput>ptr.h</computeroutput> file in
1565 the glue layer.</para>
1566 </listitem>
1567 </orderedlist></para>
1568 </sect2>
1569
1570 <sect2 id="event-queue">
1571 <title>Event queue processing</title>
1572
1573 <para>Both VirtualBox client programs and frontends should
1574 periodically perform processing of the main event queue, and do that
1575 on the application's main thread. In case of a typical GUI Windows/Mac
1576 OS application this happens automatically in the GUI's dispatch loop.
1577 However, for CLI only application, the appropriate actions have to be
1578 taken. For C++ applications, the VirtualBox SDK provided glue method
1579 <screen>
1580 int EventQueue::processEventQueue(uint32_t cMsTimeout)
1581 </screen> can be used for both blocking and non-blocking operations.
1582 For the Python bindings, a common layer provides the method <screen>
1583 VirtualBoxManager.waitForEvents(ms)
1584 </screen> with similar semantics.</para>
1585
1586 <para>Things get somewhat more complicated for situations where an
1587 application using VirtualBox cannot directly control the main event
1588 loop and the main event queue is separated from the event queue of the
1589 programming librarly (for example in case of Qt on Unix platforms). In
1590 such a case, the application developer is advised to use a
1591 platform/toolkit specific event injection mechanism to force event
1592 queue checks either based on periodical timer events delivered to the
1593 main thread, or by using custom platform messages to notify the main
1594 thread when events are available. See the VBoxSDL and Qt (VirtualBox)
1595 frontends as examples.</para>
1596 </sect2>
1597
1598 <sect2 id="vbcom">
1599 <title>Visual Basic and Visual Basic Script (VBS) on Windows
1600 hosts</title>
1601
1602 <para>On Windows hosts, one can control some of the VirtualBox Main
1603 API functionality from VBS scripts, and pretty much everything from
1604 Visual Basic programs.<footnote>
1605 <para>The difference results from the way VBS treats COM
1606 safearrays, which are used to keep lists in the Main API. VBS
1607 expects every array element to be a
1608 <computeroutput>VARIANT</computeroutput>, which is too strict a
1609 limitation for any high performance API. We may lift this
1610 restriction for interface APIs in a future version, or
1611 alternatively provide conversion APIs.</para>
1612 </footnote></para>
1613
1614 <para>VBS is scripting language available in any recent Windows
1615 environment. As an example, the following VBS code will print
1616 VirtualBox version: <screen>
1617 set vb = CreateObject("VirtualBox.VirtualBox")
1618 Wscript.Echo "VirtualBox version " &amp; vb.version
1619 </screen> See
1620 <computeroutput>bindings/mscom/vbs/sample/vboxinfo.vbs</computeroutput>
1621 for the complete sample.</para>
1622
1623 <para>Visual Basic is a popular high level language capable of
1624 accessing COM objects. The following VB code will iterate over all
1625 available virtual machines:<screen>
1626 Dim vb As VirtualBox.IVirtualBox
1627
1628 vb = CreateObject("VirtualBox.VirtualBox")
1629 machines = ""
1630 For Each m In vb.Machines
1631 m = m &amp; " " &amp; m.Name
1632 Next
1633 </screen> See
1634 <computeroutput>bindings/mscom/vb/sample/vboxinfo.vb</computeroutput>
1635 for the complete sample.</para>
1636 </sect2>
1637
1638 <sect2 id="cbinding">
1639 <title>C binding to XPCOM API</title>
1640
1641 <note>
1642 <para>This section currently applies to Linux hosts only.</para>
1643 </note>
1644
1645 <para>Starting with version 2.2, VirtualBox offers a C binding for the
1646 XPCOM API.</para>
1647
1648 <para>The C binding provides a layer enabling object creation, method
1649 invocation and attribute access from C.</para>
1650
1651 <sect3 id="c-gettingstarted">
1652 <title>Getting started</title>
1653
1654 <para>The following sections describe how to use the C binding in a
1655 C program.</para>
1656
1657 <para>For Linux, a sample program is provided which demonstrates use
1658 of the C binding to initialize XPCOM, get handles for VirtualBox and
1659 Session objects, make calls to list and start virtual machines, and
1660 uninitialize resources when done. The program uses the VBoxGlue
1661 library to open the C binding layer during runtime.</para>
1662
1663 <para>The sample program
1664 <computeroutput>tstXPCOMCGlue</computeroutput> is located in the bin
1665 directory and can be run without arguments. It lists registered
1666 machines on the host along with some additional information and ask
1667 for a machine to start. The source for this program is available in
1668 <computeroutput>sdk/bindings/xpcom/cbinding/samples/</computeroutput>
1669 directory. The source for the VBoxGlue library is available in the
1670 <computeroutput>sdk/bindings/xpcom/cbinding/</computeroutput>
1671 directory.</para>
1672 </sect3>
1673
1674 <sect3 id="c-initialization">
1675 <title>XPCOM initialization</title>
1676
1677 <para>Just like in C++, XPCOM needs to be initialized before it can
1678 be used. The <computeroutput>VBoxCAPI_v2_5.h</computeroutput> header
1679 provides the interface to the C binding. Here's how to initialize
1680 XPCOM:</para>
1681
1682 <screen>#include "VBoxCAPI_v2_5.h"
1683...
1684PCVBOXXPCOM g_pVBoxFuncs = NULL;
1685IVirtualBox *vbox = NULL;
1686ISession *session = NULL;
1687
1688/*
1689 * VBoxGetXPCOMCFunctions() is the only function exported by
1690 * VBoxXPCOMC.so and the only one needed to make virtualbox
1691 * work with C. This functions gives you the pointer to the
1692 * function table (g_pVBoxFuncs).
1693 *
1694 * Once you get the function table, then how and which functions
1695 * to use is explained below.
1696 *
1697 * g_pVBoxFuncs-&gt;pfnComInitialize does all the necessary startup
1698 * action and provides us with pointers to vbox and session handles.
1699 * It should be matched by a call to g_pVBoxFuncs-&gt;pfnComUninitialize()
1700 * when done.
1701 */
1702
1703g_pVBoxFuncs = VBoxGetXPCOMCFunctions(VBOX_XPCOMC_VERSION);
1704g_pVBoxFuncs-&gt;pfnComInitialize(&amp;vbox, &amp;session);</screen>
1705
1706 <para>If either <computeroutput>vbox</computeroutput> or
1707 <computeroutput>session</computeroutput> is still
1708 <computeroutput>NULL</computeroutput>, initialization failed and the
1709 XPCOM API cannot be used.</para>
1710 </sect3>
1711
1712 <sect3 id="c-invocation">
1713 <title>XPCOM method invocation</title>
1714
1715 <para>Method invocation is straightforward. It looks pretty much
1716 like the C++ way, augmented with an extra indirection due to
1717 accessing the vtable and passing a pointer to the object as the
1718 first argument to serve as the <computeroutput>this</computeroutput>
1719 pointer.</para>
1720
1721 <para>Using the C binding, all method invocations return a numeric
1722 result code.</para>
1723
1724 <para>If an interface is specified as returning an object, a pointer
1725 to a pointer to the appropriate object must be passed as the last
1726 argument. The method will then store an object pointer in that
1727 location.</para>
1728
1729 <para>In other words, to call an object's method what you need
1730 is</para>
1731
1732 <screen>IObject *object;
1733nsresult rc;
1734...
1735/*
1736 * Calling void IObject::method(arg, ...)
1737 */
1738rc = object-&gt;vtbl-&gt;Method(object, arg, ...);
1739
1740...
1741IFoo *foo;
1742/*
1743 * Calling IFoo IObject::method(arg, ...)
1744 */
1745rc = object-&gt;vtbl-&gt;Method(object, args, ..., &amp;foo);</screen>
1746
1747 <para>As a real-world example of a method invocation, let's call
1748 <xref linkend="IMachine__launchVMProcess"
1749 xreflabel="IMachine::launchVMProcess" /> which returns an
1750 IProgress object. Note again that the method name is
1751 capitalized.</para>
1752
1753 <screen>IProgress *progress;
1754...
1755rc = vbox-&gt;vtbl-&gt;LaunchVMProcess(
1756 machine, /* this */
1757 session, /* arg 1 */
1758 sessionType, /* arg 2 */
1759 env, /* arg 3 */
1760 &amp;progress /* Out */
1761);
1762</screen>
1763 </sect3>
1764
1765 <sect3 id="c-attributes">
1766 <title>XPCOM attribute access</title>
1767
1768 <para>A construct similar to calling non-void methods is used to
1769 access object attributes. For each attribute there exists a getter
1770 method, the name of which is composed of
1771 <computeroutput>Get</computeroutput> followed by the capitalized
1772 attribute name. Unless the attribute is read-only, an analogous
1773 <computeroutput>Set</computeroutput> method exists. Let's apply
1774 these rules to read the <xref linkend="IVirtualBox__revision"
1775 xreflabel="IVirtualBox::revision" /> attribute.</para>
1776
1777 <para>Using the <computeroutput>IVirtualBox</computeroutput> handle
1778 <computeroutput>vbox</computeroutput> obtained above, calling its
1779 <computeroutput>GetRevision</computeroutput> method looks like
1780 this:</para>
1781
1782 <screen>PRUint32 rev;
1783
1784rc = vbox-&gt;vtbl-&gt;GetRevision(vbox, &amp;rev);
1785if (NS_SUCCEEDED(rc))
1786{
1787 printf("Revision: %u\n", (unsigned)rev);
1788}
1789</screen>
1790
1791 <para>All objects with their methods and attributes are documented
1792 in <xref linkend="sdkref_classes" />.</para>
1793 </sect3>
1794
1795 <sect3 id="c-string-handling">
1796 <title>String handling</title>
1797
1798 <para>When dealing with strings you have to be aware of a string's
1799 encoding and ownership.</para>
1800
1801 <para>Internally, XPCOM uses UTF-16 encoded strings. A set of
1802 conversion functions is provided to convert other encodings to and
1803 from UTF-16. The type of a UTF-16 character is
1804 <computeroutput>PRUnichar</computeroutput>. Strings of UTF-16
1805 characters are arrays of that type. Most string handling functions
1806 take pointers to that type. Prototypes for the following conversion
1807 functions are declared in
1808 <computeroutput>VBoxCAPI_v2_5.h</computeroutput>.</para>
1809
1810 <sect4>
1811 <title>Conversion of UTF-16 to and from UTF-8</title>
1812
1813 <screen>int (*pfnUtf16ToUtf8)(const PRUnichar *pwszString, char **ppszString);
1814int (*pfnUtf8ToUtf16)(const char *pszString, PRUnichar **ppwszString);
1815</screen>
1816 </sect4>
1817
1818 <sect4>
1819 <title>Ownership</title>
1820
1821 <para>The ownership of a string determines who is responsible for
1822 releasing resources associated with the string. Whenever XPCOM
1823 creates a string, ownership is transferred to the caller. To avoid
1824 resource leaks, the caller should release resources once the
1825 string is no longer needed.</para>
1826 </sect4>
1827 </sect3>
1828
1829 <sect3 id="c-uninitialization">
1830 <title>XPCOM uninitialization</title>
1831
1832 <para>Uninitialization is performed by
1833 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize().</computeroutput>
1834 If your program can exit from more than one place, it is a good idea
1835 to install this function as an exit handler with Standard C's
1836 <computeroutput>atexit()</computeroutput> just after calling
1837 <computeroutput>g_pVBoxFuncs-&gt;pfnComInitialize()</computeroutput>
1838 , e.g. <screen>#include &lt;stdlib.h&gt;
1839#include &lt;stdio.h&gt;
1840
1841...
1842
1843/*
1844 * Make sure g_pVBoxFuncs-&gt;pfnComUninitialize() is called at exit, no
1845 * matter if we return from the initial call to main or call exit()
1846 * somewhere else. Note that atexit registered functions are not
1847 * called upon abnormal termination, i.e. when calling abort() or
1848 * signal(). Separate provisions must be taken for these cases.
1849 */
1850
1851if (atexit(g_pVBoxFuncs-&gt;pfnComUninitialize()) != 0) {
1852 fprintf(stderr, "failed to register g_pVBoxFuncs-&gt;pfnComUninitialize()\n");
1853 exit(EXIT_FAILURE);
1854}
1855</screen></para>
1856
1857 <para>Another idea would be to write your own <computeroutput>void
1858 myexit(int status)</computeroutput> function, calling
1859 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1860 followed by the real <computeroutput>exit()</computeroutput>, and
1861 use it instead of <computeroutput>exit()</computeroutput> throughout
1862 your program and at the end of
1863 <computeroutput>main.</computeroutput></para>
1864
1865 <para>If you expect the program to be terminated by a signal (e.g.
1866 user types CTRL-C sending SIGINT) you might want to install a signal
1867 handler setting a flag noting that a signal was sent and then
1868 calling
1869 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1870 later on (usually <emphasis>not</emphasis> from the handler itself
1871 .)</para>
1872
1873 <para>That said, if a client program forgets to call
1874 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1875 before it terminates, there is a mechanism in place which will
1876 eventually release references held by the client. You should not
1877 rely on this, however.</para>
1878 </sect3>
1879
1880 <sect3 id="c-linking">
1881 <title>Compiling and linking</title>
1882
1883 <para>A program using the C binding has to open the library during
1884 runtime using the help of glue code provided and as shown in the
1885 example <computeroutput>tstXPCOMCGlue.c</computeroutput>.
1886 Compilation and linking can be achieved, e.g., with a makefile
1887 fragment similar to</para>
1888
1889 <screen># Where is the XPCOM include directory?
1890INCS_XPCOM = -I../../include
1891# Where is the glue code directory?
1892GLUE_DIR = ..
1893GLUE_INC = -I..
1894
1895#Compile Glue Library
1896VBoxXPCOMCGlue.o: $(GLUE_DIR)/VBoxXPCOMCGlue.c
1897 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $&lt;
1898
1899# Compile.
1900program.o: program.c VBoxCAPI_v2_5.h
1901 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $&lt;
1902
1903# Link.
1904program: program.o VBoxXPCOMCGlue.o
1905 $(CC) -o $@ $^ -ldl</screen>
1906 </sect3>
1907 </sect2>
1908 </sect1>
1909 </chapter>
1910
1911 <chapter id="concepts">
1912 <title>Basic VirtualBox concepts; some examples</title>
1913
1914 <para>The following explains some basic VirtualBox concepts such as the
1915 VirtualBox object, sessions and how virtual machines are manipulated and
1916 launched using the Main API. The coding examples use a pseudo-code style
1917 closely related to the object-oriented web service (OOWS) for JAX-WS.
1918 Depending on which environment you are using, you will need to adjust the
1919 examples.</para>
1920
1921 <sect1>
1922 <title>Obtaining basic machine information. Reading attributes</title>
1923
1924 <para>Any program using the Main API will first need access to the
1925 global VirtualBox object (see <xref linkend="IVirtualBox"
1926 xreflabel="IVirtualBox" />), from which all other functionality of the
1927 API is derived. With the OOWS for JAX-WS, this is returned from the
1928 <xref linkend="IWebsessionManager__logon"
1929 xreflabel="IWebsessionManager::logon()" /> call.</para>
1930
1931 <para>To enumerate virtual machines, one would look at the "machines"
1932 array attribute in the VirtualBox object (see <xref
1933 linkend="IVirtualBox__machines" xreflabel="IVirtualBox::machines" />).
1934 This array contains all virtual machines currently registered with the
1935 host, each of them being an instance of <xref linkend="IMachine"
1936 xreflabel="IMachine" />. From each such instance, one can query
1937 additional information, such as the UUID, the name, memory, operating
1938 system and more by looking at the attributes; see the attributes list in
1939 <xref linkend="IMachine" xreflabel="IMachine documentation" />.</para>
1940
1941 <para>As mentioned in the preceding chapters, depending on your
1942 programming environment, attributes are mapped to corresponding "get"
1943 and (if the attribute is not read-only) "set" methods. So when the
1944 documentation says that IMachine has a "<xref linkend="IMachine__name"
1945 xreflabel="name" />" attribute, this means you need to code something
1946 like the following to get the machine's name:<screen>IMachine machine = ...;
1947String name = machine.getName();</screen>Boolean attribute getters can
1948 sometimes be called <computeroutput>isAttribute()</computeroutput> due
1949 to JAX-WS naming conventions.</para>
1950 </sect1>
1951
1952 <sect1>
1953 <title>Changing machine settings. Sessions</title>
1954
1955 <para>As said in the previous section, to read a machine's attribute,
1956 one invokes the corresponding "get" method. One would think that to
1957 change settings of a machine, it would suffice to call the corresponding
1958 "set" method -- for example, to set a VM's memory to 1024 MB, one would
1959 call <computeroutput>setMemorySize(1024)</computeroutput>. Try that, and
1960 you will get an error: "The machine is not mutable."</para>
1961
1962 <para>So unfortunately, things are not that easy. VirtualBox is a
1963 complicated environment in which multiple processes compete for possibly
1964 the same resources, especially machine settings. As a result, machines
1965 must be "locked" before they can either be modified or started. This is
1966 to prevent multiple processes from making conflicting changes to a
1967 machine: it should, for example, not be allowed to change the memory
1968 size of a virtual machine while it is running. (You can't add more
1969 memory to a real computer while it is running either, at least not to an
1970 ordinary PC.) Also, two processes must not change settings at the same
1971 time, or start a machine at the same time.</para>
1972
1973 <para>These requirements are implemented in the Main API by way of
1974 "sessions", in particular, the <xref linkend="ISession"
1975 xreflabel="ISession" /> interface. Each process which talks to
1976 VirtualBox needs its own instance of ISession. In the web service, you
1977 cannot create such an object, but
1978 <computeroutput>vboxwebsrv</computeroutput> creates one for you when you
1979 log on, which you can obtain by calling <xref
1980 linkend="IWebsessionManager__getSessionObject"
1981 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
1982
1983 <para>This session object must then be used like a mutex semaphore in
1984 common programming environments. Before you can change machine settings,
1985 you must write-lock the machine by calling <xref
1986 linkend="IMachine__lockMachine" xreflabel="IMachine::lockMachine()" />
1987 with your process's session object.</para>
1988
1989 <para>After the machine has been locked, the <xref
1990 linkend="ISession__machine" xreflabel="ISession::machine" /> attribute
1991 contains a copy of the original IMachine object upon which the session
1992 was opened, but this copy is "mutable": you can invoke "set" methods on
1993 it.</para>
1994
1995 <para>When done making the changes to the machine, you must call <xref
1996 linkend="IMachine__saveSettings"
1997 xreflabel="IMachine::saveSettings()" />, which will copy the changes you
1998 have made from your "mutable" machine back to the real machine and write
1999 them out to the machine settings XML file. This will make your changes
2000 permanent.</para>
2001
2002 <para>Finally, it is important to always unlock the machine again, by
2003 calling <xref linkend="ISession__unlockMachine"
2004 xreflabel="ISession::unlockMachine()" />. Otherwise, when the calling
2005 process end, the machine will receive the "aborted" state, which can
2006 lead to loss of data.</para>
2007
2008 <para>So, as an example, the sequence to change a machine's memory to
2009 1024 MB is something like this:<screen>IWebsessionManager mgr ...;
2010IVirtualBox vbox = mgr.logon(user, pass);
2011...
2012IMachine machine = ...; // read-only machine
2013ISession session = mgr.getSessionObject();
2014machine.lockMachine(session, LockType.Write); // machine is now locked for writing
2015IMachine mutable = session.getMachine(); // obtain the mutable machine copy
2016mutable.setMemorySize(1024);
2017mutable.saveSettings(); // write settings to XML
2018session.unlockMachine();</screen></para>
2019 </sect1>
2020
2021 <sect1>
2022 <title>Launching virtual machines</title>
2023
2024 <para>To launch a virtual machine, you call <xref
2025 linkend="IMachine__launchVMProcess"
2026 xreflabel="IMachine::launchVMProcess()" />. In doing so, the caller
2027 instructs the VirtualBox engine to start a new process with the virtual
2028 machine in it, since to the host, each virtual machine looks like a
2029 single process, even if it has hundreds of its own processes inside.
2030 (This new VM process in turn obtains a write lock on the machine, as
2031 described above, to prevent conflicting changes from other processes;
2032 this is why opening another session will fail while the VM is
2033 running.)</para>
2034
2035 <para>Starting a machine looks something like this:<screen>IWebsessionManager mgr ...;
2036IVirtualBox vbox = mgr.logon(user, pass);
2037...
2038IMachine machine = ...; // read-only machine
2039ISession session = mgr.getSessionObject();
2040IProgress prog = machine.launchVMProcess(session,
2041 "gui", // session type
2042 ""); // possibly environment setting
2043prog.waitForCompletion(10000); // give the process 10 secs
2044if (prog.getResultCode() != 0) // check success
2045 System.out.println("Cannot launch VM!")</screen></para>
2046
2047 <para>The caller's session object can then be used as a sort of remote
2048 control to the VM process that was launched. It contains a "console"
2049 object (see <xref linkend="ISession__console"
2050 xreflabel="ISession::console" />) with which the VM can be paused,
2051 stopped, snapshotted or other things.</para>
2052 </sect1>
2053
2054 <sect1>
2055 <title>VirtualBox events</title>
2056
2057 <para>In VirtualBox, "events" provide a uniform mechanism to register
2058 for and consume specific events. A VirtualBox client can register an
2059 "event listener" (represented by the <xref linkend="IEventListener"
2060 xreflabel="IEventListener" /> interface), which will then get notified
2061 by the server when an event (represented by the <xref linkend="IEvent"
2062 xreflabel="IEvent" /> interface) happens.</para>
2063
2064 <para>The IEvent interface is an abstract parent interface for all
2065 events that can occur in VirtualBox. The actual events that the server
2066 sends out are then of one of the specific subclasses, for example <xref
2067 linkend="IMachineStateChangedEvent"
2068 xreflabel="IMachineStateChangedEvent" /> or <xref
2069 linkend="IMediumChangedEvent" xreflabel="IMediumChangedEvent" />.</para>
2070
2071 <para>As an example, the VirtualBox GUI waits for machine events and can
2072 thus update its display when the machine state changes or machine
2073 settings are modified, even if this happens in another client. This is
2074 how the GUI can automatically refresh its display even if you manipulate
2075 a machine from another client, for example, from VBoxManage.</para>
2076
2077 <para>To register an event listener to listen to events, use code like
2078 this:<screen>EventSource es = console.getEventSource();
2079IEventListener listener = es.createListener();
2080VBoxEventType aTypes[] = (VBoxEventType.OnMachineStateChanged);
2081 // list of event types to listen for
2082es.registerListener(listener, aTypes, false /* active */);
2083 // register passive listener
2084IEvent ev = es.getEvent(listener, 1000);
2085 // wait up to one second for event to happen
2086if (ev != null)
2087{
2088 // downcast to specific event interface (in this case we have only registered
2089 // for one type, otherwise IEvent::type would tell us)
2090 IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev);
2091 ... // inspect and do something
2092 es.eventProcessed(listener, ev);
2093}
2094...
2095es.unregisterListener(listener); </screen></para>
2096
2097 <para>A graphical user interface would probably best start its own
2098 thread to wait for events and then process these in a loop.</para>
2099
2100 <para>The events mechanism was introduced with VirtualBox 3.3 and
2101 replaces various callback interfaces which were called for each event in
2102 the interface. The callback mechanism was not compatible with scripting
2103 languages, local Java bindings and remote web services as they do not
2104 support callbacks. The new mechanism with events and event listeners
2105 works with all of these.</para>
2106
2107 <para>To simplify developement of application using events, concept of
2108 event aggregator was introduced. Essentially it's mechanism to aggregate
2109 multiple event sources into single one, and then work with this single
2110 aggregated event source instead of original sources. As an example, one
2111 can evaluate demo recorder in VirtualBox Python shell, shipped with SDK
2112 - it records mouse and keyboard events, represented as separate event
2113 sources. Code is essentially like this:<screen>
2114 listener = console.eventSource.createListener()
2115 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource])
2116 agg.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
2117 registered = True
2118 end = time.time() + dur
2119 while time.time() &lt; end:
2120 ev = agg.getEvent(listener, 1000)
2121 processEent(ev)
2122 agg.unregisterListener(listener)</screen> Without using aggregators
2123 consumer have to poll on both sources, or start multiple threads to
2124 block on those sources.</para>
2125 </sect1>
2126 </chapter>
2127
2128 <chapter id="vboxshell">
2129 <title>The VirtualBox shell</title>
2130
2131 <para>VirtualBox comes with an extensible shell, which allows you to
2132 control your virtual machines from the command line. It is also a
2133 nontrivial example of how to use the VirtualBox APIs from Python, for all
2134 three COM/XPCOM/WS styles of the API.</para>
2135
2136 <para>You can easily extend this shell with your own commands. Create a
2137 subdirectory named <computeroutput>.VirtualBox/shexts</computeroutput>
2138 below your home directory and put a Python file implementing your shell
2139 extension commands in this directory. This file must contain an array
2140 named <computeroutput>commands</computeroutput> containing your command
2141 definitions: <screen>
2142 commands = {
2143 'cmd1': ['Command cmd1 help', cmd1],
2144 'cmd2': ['Command cmd2 help', cmd2]
2145 }
2146 </screen> For example, to create a command for creating hard drive
2147 images, the following code can be used: <screen>
2148 def createHdd(ctx,args):
2149 # Show some meaningful error message on wrong input
2150 if (len(args) &lt; 3):
2151 print "usage: createHdd sizeM location type"
2152 return 0
2153
2154 # Get arguments
2155 size = int(args[1])
2156 loc = args[2]
2157 if len(args) &gt; 3:
2158 format = args[3]
2159 else:
2160 # And provide some meaningful defaults
2161 format = "vdi"
2162
2163 # Call VirtualBox API, using context's fields
2164 hdd = ctx['vb'].createHardDisk(format, loc)
2165 # Access constants using ctx['global'].constants
2166 progress = hdd.createBaseStorage(size, ctx['global'].constants.HardDiskVariant_Standard)
2167 # use standard progress bar mechanism
2168 ctx['progressBar'](progress)
2169
2170
2171 # Report errors
2172 if not hdd.id:
2173 print "cannot create disk (file %s exist?)" %(loc)
2174 return 0
2175
2176 # Give user some feedback on success too
2177 print "created HDD with id: %s" %(hdd.id)
2178
2179 # 0 means continue execution, other values mean exit from the interpreter
2180 return 0
2181
2182 commands = {
2183 'myCreateHDD': ['Create virtual HDD, createHdd size location type', createHdd]
2184 }
2185 </screen> Just store the above text in the file
2186 <computeroutput>createHdd</computeroutput> (or any other meaningful name)
2187 in <computeroutput>.VirtualBox/shexts/</computeroutput>. Start the
2188 VirtualBox shell, or just issue the
2189 <computeroutput>reloadExts</computeroutput> command, if the shell is
2190 already running. Your new command will now be available.</para>
2191 </chapter>
2192
2193 <!--$VIRTUALBOX_MAIN_API_REFERENCE-->
2194
2195 <chapter id="hgcm">
2196 <title>Host-Guest Communication Manager</title>
2197
2198 <para>The VirtualBox Host-Guest Communication Manager (HGCM) allows a
2199 guest application or a guest driver to call a host shared library. The
2200 following features of VirtualBox are implemented using HGCM: <itemizedlist>
2201 <listitem>
2202 <para>Shared Folders</para>
2203 </listitem>
2204
2205 <listitem>
2206 <para>Shared Clipboard</para>
2207 </listitem>
2208
2209 <listitem>
2210 <para>Guest configuration interface</para>
2211 </listitem>
2212 </itemizedlist></para>
2213
2214 <para>The shared library contains a so called HGCM service. The guest HGCM
2215 clients establish connections to the service to call it. When calling a
2216 HGCM service the client supplies a function code and a number of
2217 parameters for the function.</para>
2218
2219 <sect1>
2220 <title>Virtual hardware implementation</title>
2221
2222 <para>HGCM uses the VMM virtual PCI device to exchange data between the
2223 guest and the host. The guest always acts as an initiator of requests. A
2224 request is constructed in the guest physical memory, which must be
2225 locked by the guest. The physical address is passed to the VMM device
2226 using a 32 bit <computeroutput>out edx, eax</computeroutput>
2227 instruction. The physical memory must be allocated below 4GB by 64 bit
2228 guests.</para>
2229
2230 <para>The host parses the request header and data and queues the request
2231 for a host HGCM service. The guest continues execution and usually waits
2232 on a HGCM event semaphore.</para>
2233
2234 <para>When the request has been processed by the HGCM service, the VMM
2235 device sets the completion flag in the request header, sets the HGCM
2236 event and raises an IRQ for the guest. The IRQ handler signals the HGCM
2237 event semaphore and all HGCM callers check the completion flag in the
2238 corresponding request header. If the flag is set, the request is
2239 considered completed.</para>
2240 </sect1>
2241
2242 <sect1>
2243 <title>Protocol specification</title>
2244
2245 <para>The HGCM protocol definitions are contained in the
2246 <computeroutput>VBox/VBoxGuest.h</computeroutput></para>
2247
2248 <sect2>
2249 <title>Request header</title>
2250
2251 <para>HGCM request structures contains a generic header
2252 (VMMDevHGCMRequestHeader): <table>
2253 <title>HGCM Request Generic Header</title>
2254
2255 <tgroup cols="2">
2256 <tbody>
2257 <row>
2258 <entry><emphasis role="bold">Name</emphasis></entry>
2259
2260 <entry><emphasis role="bold">Description</emphasis></entry>
2261 </row>
2262
2263 <row>
2264 <entry>size</entry>
2265
2266 <entry>Size of the entire request.</entry>
2267 </row>
2268
2269 <row>
2270 <entry>version</entry>
2271
2272 <entry>Version of the header, must be set to
2273 <computeroutput>0x10001</computeroutput>.</entry>
2274 </row>
2275
2276 <row>
2277 <entry>type</entry>
2278
2279 <entry>Type of the request.</entry>
2280 </row>
2281
2282 <row>
2283 <entry>rc</entry>
2284
2285 <entry>HGCM return code, which will be set by the VMM
2286 device.</entry>
2287 </row>
2288
2289 <row>
2290 <entry>reserved1</entry>
2291
2292 <entry>A reserved field 1.</entry>
2293 </row>
2294
2295 <row>
2296 <entry>reserved2</entry>
2297
2298 <entry>A reserved field 2.</entry>
2299 </row>
2300
2301 <row>
2302 <entry>flags</entry>
2303
2304 <entry>HGCM flags, set by the VMM device.</entry>
2305 </row>
2306
2307 <row>
2308 <entry>result</entry>
2309
2310 <entry>The HGCM result code, set by the VMM device.</entry>
2311 </row>
2312 </tbody>
2313 </tgroup>
2314 </table> <note>
2315 <itemizedlist>
2316 <listitem>
2317 <para>All fields are 32 bit.</para>
2318 </listitem>
2319
2320 <listitem>
2321 <para>Fields from <computeroutput>size</computeroutput> to
2322 <computeroutput>reserved2</computeroutput> are a standard VMM
2323 device request header, which is used for other interfaces as
2324 well.</para>
2325 </listitem>
2326 </itemizedlist>
2327 </note></para>
2328
2329 <para>The <emphasis role="bold">type</emphasis> field indicates the
2330 type of the HGCM request: <table>
2331 <title>Request Types</title>
2332
2333 <tgroup cols="2">
2334 <tbody>
2335 <row>
2336 <entry><emphasis role="bold">Name (decimal
2337 value)</emphasis></entry>
2338
2339 <entry><emphasis role="bold">Description</emphasis></entry>
2340 </row>
2341
2342 <row>
2343 <entry>VMMDevReq_HGCMConnect
2344 (<computeroutput>60</computeroutput>)</entry>
2345
2346 <entry>Connect to a HGCM service.</entry>
2347 </row>
2348
2349 <row>
2350 <entry>VMMDevReq_HGCMDisconnect
2351 (<computeroutput>61</computeroutput>)</entry>
2352
2353 <entry>Disconnect from the service.</entry>
2354 </row>
2355
2356 <row>
2357 <entry>VMMDevReq_HGCMCall32
2358 (<computeroutput>62</computeroutput>)</entry>
2359
2360 <entry>Call a HGCM function using the 32 bit
2361 interface.</entry>
2362 </row>
2363
2364 <row>
2365 <entry>VMMDevReq_HGCMCall64
2366 (<computeroutput>63</computeroutput>)</entry>
2367
2368 <entry>Call a HGCM function using the 64 bit
2369 interface.</entry>
2370 </row>
2371
2372 <row>
2373 <entry>VMMDevReq_HGCMCancel
2374 (<computeroutput>64</computeroutput>)</entry>
2375
2376 <entry>Cancel a HGCM request currently being processed by a
2377 host HGCM service.</entry>
2378 </row>
2379 </tbody>
2380 </tgroup>
2381 </table></para>
2382
2383 <para>The <emphasis role="bold">flags</emphasis> field may contain:
2384 <table>
2385 <title>Flags</title>
2386
2387 <tgroup cols="2">
2388 <tbody>
2389 <row>
2390 <entry><emphasis role="bold">Name (hexadecimal
2391 value)</emphasis></entry>
2392
2393 <entry><emphasis role="bold">Description</emphasis></entry>
2394 </row>
2395
2396 <row>
2397 <entry>VBOX_HGCM_REQ_DONE
2398 (<computeroutput>0x00000001</computeroutput>)</entry>
2399
2400 <entry>The request has been processed by the host
2401 service.</entry>
2402 </row>
2403
2404 <row>
2405 <entry>VBOX_HGCM_REQ_CANCELLED
2406 (<computeroutput>0x00000002</computeroutput>)</entry>
2407
2408 <entry>This request was cancelled.</entry>
2409 </row>
2410 </tbody>
2411 </tgroup>
2412 </table></para>
2413 </sect2>
2414
2415 <sect2>
2416 <title>Connect</title>
2417
2418 <para>The connection request must be issued by the guest HGCM client
2419 before it can call the HGCM service (VMMDevHGCMConnect): <table>
2420 <title>Connect request</title>
2421
2422 <tgroup cols="2">
2423 <tbody>
2424 <row>
2425 <entry><emphasis role="bold">Name</emphasis></entry>
2426
2427 <entry><emphasis role="bold">Description</emphasis></entry>
2428 </row>
2429
2430 <row>
2431 <entry>header</entry>
2432
2433 <entry>The generic HGCM request header with type equal to
2434 VMMDevReq_HGCMConnect
2435 (<computeroutput>60</computeroutput>).</entry>
2436 </row>
2437
2438 <row>
2439 <entry>type</entry>
2440
2441 <entry>The type of the service location information (32
2442 bit).</entry>
2443 </row>
2444
2445 <row>
2446 <entry>location</entry>
2447
2448 <entry>The service location information (128 bytes).</entry>
2449 </row>
2450
2451 <row>
2452 <entry>clientId</entry>
2453
2454 <entry>The client identifier assigned to the connecting
2455 client by the HGCM subsystem (32 bit).</entry>
2456 </row>
2457 </tbody>
2458 </tgroup>
2459 </table> The <emphasis role="bold">type</emphasis> field tells the
2460 HGCM how to look for the requested service: <table>
2461 <title>Location Information Types</title>
2462
2463 <tgroup cols="2">
2464 <tbody>
2465 <row>
2466 <entry><emphasis role="bold">Name (hexadecimal
2467 value)</emphasis></entry>
2468
2469 <entry><emphasis role="bold">Description</emphasis></entry>
2470 </row>
2471
2472 <row>
2473 <entry>VMMDevHGCMLoc_LocalHost
2474 (<computeroutput>0x1</computeroutput>)</entry>
2475
2476 <entry>The requested service is a shared library located on
2477 the host and the location information contains the library
2478 name.</entry>
2479 </row>
2480
2481 <row>
2482 <entry>VMMDevHGCMLoc_LocalHost_Existing
2483 (<computeroutput>0x2</computeroutput>)</entry>
2484
2485 <entry>The requested service is a preloaded one and the
2486 location information contains the service name.</entry>
2487 </row>
2488 </tbody>
2489 </tgroup>
2490 </table> <note>
2491 <para>Currently preloaded HGCM services are hard-coded in
2492 VirtualBox: <itemizedlist>
2493 <listitem>
2494 <para>VBoxSharedFolders</para>
2495 </listitem>
2496
2497 <listitem>
2498 <para>VBoxSharedClipboard</para>
2499 </listitem>
2500
2501 <listitem>
2502 <para>VBoxGuestPropSvc</para>
2503 </listitem>
2504
2505 <listitem>
2506 <para>VBoxSharedOpenGL</para>
2507 </listitem>
2508 </itemizedlist></para>
2509 </note> There is no difference between both types of HGCM services,
2510 only the location mechanism is different.</para>
2511
2512 <para>The client identifier is returned by the host and must be used
2513 in all subsequent requests by the client.</para>
2514 </sect2>
2515
2516 <sect2>
2517 <title>Disconnect</title>
2518
2519 <para>This request disconnects the client and makes the client
2520 identifier invalid (VMMDevHGCMDisconnect): <table>
2521 <title>Disconnect request</title>
2522
2523 <tgroup cols="2">
2524 <tbody>
2525 <row>
2526 <entry><emphasis role="bold">Name</emphasis></entry>
2527
2528 <entry><emphasis role="bold">Description</emphasis></entry>
2529 </row>
2530
2531 <row>
2532 <entry>header</entry>
2533
2534 <entry>The generic HGCM request header with type equal to
2535 VMMDevReq_HGCMDisconnect
2536 (<computeroutput>61</computeroutput>).</entry>
2537 </row>
2538
2539 <row>
2540 <entry>clientId</entry>
2541
2542 <entry>The client identifier previously returned by the
2543 connect request (32 bit).</entry>
2544 </row>
2545 </tbody>
2546 </tgroup>
2547 </table></para>
2548 </sect2>
2549
2550 <sect2>
2551 <title>Call32 and Call64</title>
2552
2553 <para>Calls the HGCM service entry point (VMMDevHGCMCall) using 32 bit
2554 or 64 bit addresses: <table>
2555 <title>Call request</title>
2556
2557 <tgroup cols="2">
2558 <tbody>
2559 <row>
2560 <entry><emphasis role="bold">Name</emphasis></entry>
2561
2562 <entry><emphasis role="bold">Description</emphasis></entry>
2563 </row>
2564
2565 <row>
2566 <entry>header</entry>
2567
2568 <entry>The generic HGCM request header with type equal to
2569 either VMMDevReq_HGCMCall32
2570 (<computeroutput>62</computeroutput>) or
2571 VMMDevReq_HGCMCall64
2572 (<computeroutput>63</computeroutput>).</entry>
2573 </row>
2574
2575 <row>
2576 <entry>clientId</entry>
2577
2578 <entry>The client identifier previously returned by the
2579 connect request (32 bit).</entry>
2580 </row>
2581
2582 <row>
2583 <entry>function</entry>
2584
2585 <entry>The function code to be processed by the service (32
2586 bit).</entry>
2587 </row>
2588
2589 <row>
2590 <entry>cParms</entry>
2591
2592 <entry>The number of following parameters (32 bit). This
2593 value is 0 if the function requires no parameters.</entry>
2594 </row>
2595
2596 <row>
2597 <entry>parms</entry>
2598
2599 <entry>An array of parameter description structures
2600 (HGCMFunctionParameter32 or
2601 HGCMFunctionParameter64).</entry>
2602 </row>
2603 </tbody>
2604 </tgroup>
2605 </table></para>
2606
2607 <para>The 32 bit parameter description (HGCMFunctionParameter32)
2608 consists of 32 bit type field and 8 bytes of an opaque value, so 12
2609 bytes in total. The 64 bit variant (HGCMFunctionParameter64) consists
2610 of the type and 12 bytes of a value, so 16 bytes in total.</para>
2611
2612 <para><table>
2613 <title>Parameter types</title>
2614
2615 <tgroup cols="2">
2616 <tbody>
2617 <row>
2618 <entry><emphasis role="bold">Type</emphasis></entry>
2619
2620 <entry><emphasis role="bold">Format of the
2621 value</emphasis></entry>
2622 </row>
2623
2624 <row>
2625 <entry>VMMDevHGCMParmType_32bit (1)</entry>
2626
2627 <entry>A 32 bit value.</entry>
2628 </row>
2629
2630 <row>
2631 <entry>VMMDevHGCMParmType_64bit (2)</entry>
2632
2633 <entry>A 64 bit value.</entry>
2634 </row>
2635
2636 <row>
2637 <entry>VMMDevHGCMParmType_PhysAddr (3)</entry>
2638
2639 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2640 physical address.</entry>
2641 </row>
2642
2643 <row>
2644 <entry>VMMDevHGCMParmType_LinAddr (4)</entry>
2645
2646 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2647 linear address. The buffer is used both for guest to host
2648 and for host to guest data.</entry>
2649 </row>
2650
2651 <row>
2652 <entry>VMMDevHGCMParmType_LinAddr_In (5)</entry>
2653
2654 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2655 used only for host to guest data.</entry>
2656 </row>
2657
2658 <row>
2659 <entry>VMMDevHGCMParmType_LinAddr_Out (6)</entry>
2660
2661 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2662 used only for guest to host data.</entry>
2663 </row>
2664
2665 <row>
2666 <entry>VMMDevHGCMParmType_LinAddr_Locked (7)</entry>
2667
2668 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2669 already locked by the guest.</entry>
2670 </row>
2671
2672 <row>
2673 <entry>VMMDevHGCMParmType_LinAddr_Locked_In (1)</entry>
2674
2675 <entry>Same as VMMDevHGCMParmType_LinAddr_In but the buffer
2676 is already locked by the guest.</entry>
2677 </row>
2678
2679 <row>
2680 <entry>VMMDevHGCMParmType_LinAddr_Locked_Out (1)</entry>
2681
2682 <entry>Same as VMMDevHGCMParmType_LinAddr_Out but the buffer
2683 is already locked by the guest.</entry>
2684 </row>
2685 </tbody>
2686 </tgroup>
2687 </table></para>
2688
2689 <para>The</para>
2690 </sect2>
2691
2692 <sect2>
2693 <title>Cancel</title>
2694
2695 <para>This request cancels a call request (VMMDevHGCMCancel): <table>
2696 <title>Cancel request</title>
2697
2698 <tgroup cols="2">
2699 <tbody>
2700 <row>
2701 <entry><emphasis role="bold">Name</emphasis></entry>
2702
2703 <entry><emphasis role="bold">Description</emphasis></entry>
2704 </row>
2705
2706 <row>
2707 <entry>header</entry>
2708
2709 <entry>The generic HGCM request header with type equal to
2710 VMMDevReq_HGCMCancel
2711 (<computeroutput>64</computeroutput>).</entry>
2712 </row>
2713 </tbody>
2714 </tgroup>
2715 </table></para>
2716 </sect2>
2717 </sect1>
2718
2719 <sect1>
2720 <title>Guest software interface</title>
2721
2722 <para>The guest HGCM clients can call HGCM services from both drivers
2723 and applications.</para>
2724
2725 <sect2>
2726 <title>The guest driver interface</title>
2727
2728 <para>The driver interface is implemented in the VirtualBox guest
2729 additions driver (VBoxGuest), which works with the VMM virtual device.
2730 Drivers must use the VBox Guest Library (VBGL), which provides an API
2731 for HGCM clients (<computeroutput>VBox/VBoxGuestLib.h</computeroutput>
2732 and <computeroutput>VBox/VBoxGuest.h</computeroutput>).</para>
2733
2734 <para><screen>
2735DECLVBGL(int) VbglHGCMConnect (VBGLHGCMHANDLE *pHandle, VBoxGuestHGCMConnectInfo *pData);
2736 </screen> Connects to the service: <screen>
2737 VBoxGuestHGCMConnectInfo data;
2738
2739 memset (&amp;data, sizeof (VBoxGuestHGCMConnectInfo));
2740
2741 data.result = VINF_SUCCESS;
2742 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
2743 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
2744
2745 rc = VbglHGCMConnect (&amp;handle, &amp;data);
2746
2747 if (RT_SUCCESS (rc))
2748 {
2749 rc = data.result;
2750 }
2751
2752 if (RT_SUCCESS (rc))
2753 {
2754 /* Get the assigned client identifier. */
2755 ulClientID = data.u32ClientID;
2756 }
2757 </screen></para>
2758
2759 <para><screen>
2760DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData);
2761 </screen> Disconnects from the service. <screen>
2762 VBoxGuestHGCMDisconnectInfo data;
2763
2764 RtlZeroMemory (&amp;data, sizeof (VBoxGuestHGCMDisconnectInfo));
2765
2766 data.result = VINF_SUCCESS;
2767 data.u32ClientID = ulClientID;
2768
2769 rc = VbglHGCMDisconnect (handle, &amp;data);
2770 </screen></para>
2771
2772 <para><screen>
2773DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
2774 </screen> Calls a function in the service. <screen>
2775typedef struct _VBoxSFRead
2776{
2777 VBoxGuestHGCMCallInfo callInfo;
2778
2779 /** pointer, in: SHFLROOT
2780 * Root handle of the mapping which name is queried.
2781 */
2782 HGCMFunctionParameter root;
2783
2784 /** value64, in:
2785 * SHFLHANDLE of object to read from.
2786 */
2787 HGCMFunctionParameter handle;
2788
2789 /** value64, in:
2790 * Offset to read from.
2791 */
2792 HGCMFunctionParameter offset;
2793
2794 /** value64, in/out:
2795 * Bytes to read/How many were read.
2796 */
2797 HGCMFunctionParameter cb;
2798
2799 /** pointer, out:
2800 * Buffer to place data to.
2801 */
2802 HGCMFunctionParameter buffer;
2803
2804} VBoxSFRead;
2805
2806/** Number of parameters */
2807#define SHFL_CPARMS_READ (5)
2808
2809...
2810
2811 VBoxSFRead data;
2812
2813 /* The call information. */
2814 data.callInfo.result = VINF_SUCCESS; /* Will be returned by HGCM. */
2815 data.callInfo.u32ClientID = ulClientID; /* Client identifier. */
2816 data.callInfo.u32Function = SHFL_FN_READ; /* The function code. */
2817 data.callInfo.cParms = SHFL_CPARMS_READ; /* Number of parameters. */
2818
2819 /* Initialize parameters. */
2820 data.root.type = VMMDevHGCMParmType_32bit;
2821 data.root.u.value32 = pMap-&gt;root;
2822
2823 data.handle.type = VMMDevHGCMParmType_64bit;
2824 data.handle.u.value64 = hFile;
2825
2826 data.offset.type = VMMDevHGCMParmType_64bit;
2827 data.offset.u.value64 = offset;
2828
2829 data.cb.type = VMMDevHGCMParmType_32bit;
2830 data.cb.u.value32 = *pcbBuffer;
2831
2832 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
2833 data.buffer.u.Pointer.size = *pcbBuffer;
2834 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
2835
2836 rc = VbglHGCMCall (handle, &amp;data.callInfo, sizeof (data));
2837
2838 if (RT_SUCCESS (rc))
2839 {
2840 rc = data.callInfo.result;
2841 *pcbBuffer = data.cb.u.value32; /* This is returned by the HGCM service. */
2842 }
2843 </screen></para>
2844 </sect2>
2845
2846 <sect2>
2847 <title>Guest application interface</title>
2848
2849 <para>Applications call the VirtualBox Guest Additions driver to
2850 utilize the HGCM interface. There are IOCTL's which correspond to the
2851 <computeroutput>Vbgl*</computeroutput> functions: <itemizedlist>
2852 <listitem>
2853 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CONNECT</computeroutput></para>
2854 </listitem>
2855
2856 <listitem>
2857 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_DISCONNECT</computeroutput></para>
2858 </listitem>
2859
2860 <listitem>
2861 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CALL</computeroutput></para>
2862 </listitem>
2863 </itemizedlist></para>
2864
2865 <para>These IOCTL's get the same input buffer as
2866 <computeroutput>VbglHGCM*</computeroutput> functions and the output
2867 buffer has the same format as the input buffer. The same address can
2868 be used as the input and output buffers.</para>
2869
2870 <para>For example see the guest part of shared clipboard, which runs
2871 as an application and uses the HGCM interface.</para>
2872 </sect2>
2873 </sect1>
2874
2875 <sect1>
2876 <title>HGCM Service Implementation</title>
2877
2878 <para>The HGCM service is a shared library with a specific set of entry
2879 points. The library must export the
2880 <computeroutput>VBoxHGCMSvcLoad</computeroutput> entry point: <screen>
2881extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable)
2882 </screen></para>
2883
2884 <para>The service must check the
2885 <computeroutput>ptable-&gt;cbSize</computeroutput> and
2886 <computeroutput>ptable-&gt;u32Version</computeroutput> fields of the
2887 input structure and fill the remaining fields with function pointers of
2888 entry points and the size of the required client buffer size.</para>
2889
2890 <para>The HGCM service gets a dedicated thread, which calls service
2891 entry points synchronously, that is the service will be called again
2892 only when a previous call has returned. However, the guest calls can be
2893 processed asynchronously. The service must call a completion callback
2894 when the operation is actually completed. The callback can be issued
2895 from another thread as well.</para>
2896
2897 <para>Service entry points are listed in the
2898 <computeroutput>VBox/hgcmsvc.h</computeroutput> in the
2899 <computeroutput>VBOXHGCMSVCFNTABLE</computeroutput> structure. <table>
2900 <title>Service entry points</title>
2901
2902 <tgroup cols="2">
2903 <tbody>
2904 <row>
2905 <entry><emphasis role="bold">Entry</emphasis></entry>
2906
2907 <entry><emphasis role="bold">Description</emphasis></entry>
2908 </row>
2909
2910 <row>
2911 <entry>pfnUnload</entry>
2912
2913 <entry>The service is being unloaded.</entry>
2914 </row>
2915
2916 <row>
2917 <entry>pfnConnect</entry>
2918
2919 <entry>A client <computeroutput>u32ClientID</computeroutput>
2920 is connected to the service. The
2921 <computeroutput>pvClient</computeroutput> parameter points to
2922 an allocated memory buffer which can be used by the service to
2923 store the client information.</entry>
2924 </row>
2925
2926 <row>
2927 <entry>pfnDisconnect</entry>
2928
2929 <entry>A client is being disconnected.</entry>
2930 </row>
2931
2932 <row>
2933 <entry>pfnCall</entry>
2934
2935 <entry>A guest client calls a service function. The
2936 <computeroutput>callHandle</computeroutput> must be used in
2937 the VBOXHGCMSVCHELPERS::pfnCallComplete callback when the call
2938 has been processed.</entry>
2939 </row>
2940
2941 <row>
2942 <entry>pfnHostCall</entry>
2943
2944 <entry>Called by the VirtualBox host components to perform
2945 functions which should be not accessible by the guest. Usually
2946 this entry point is used by VirtualBox to configure the
2947 service.</entry>
2948 </row>
2949
2950 <row>
2951 <entry>pfnSaveState</entry>
2952
2953 <entry>The VM state is being saved and the service must save
2954 relevant information using the SSM API
2955 (<computeroutput>VBox/ssm.h</computeroutput>).</entry>
2956 </row>
2957
2958 <row>
2959 <entry>pfnLoadState</entry>
2960
2961 <entry>The VM is being restored from the saved state and the
2962 service must load the saved information and be able to
2963 continue operations from the saved state.</entry>
2964 </row>
2965 </tbody>
2966 </tgroup>
2967 </table></para>
2968 </sect1>
2969 </chapter>
2970
2971 <chapter id="rdpweb">
2972 <title>RDP Web Control</title>
2973
2974 <para>The VirtualBox <emphasis>RDP Web Control</emphasis> (RDPWeb)
2975 provides remote access to a running VM. RDPWeb is a RDP (Remote Desktop
2976 Protocol) client based on Flash technology and can be used from a Web
2977 browser with a Flash plugin.</para>
2978
2979 <sect1>
2980 <title>RDPWeb features</title>
2981
2982 <para>RDPWeb is embedded into a Web page and can connect to VRDP server
2983 in order to displays the VM screen and pass keyboard and mouse events to
2984 the VM.</para>
2985 </sect1>
2986
2987 <sect1>
2988 <title>RDPWeb reference</title>
2989
2990 <para>RDPWeb consists of two required components:<itemizedlist>
2991 <listitem>
2992 <para>Flash movie
2993 <computeroutput>RDPClientUI.swf</computeroutput></para>
2994 </listitem>
2995
2996 <listitem>
2997 <para>JavaScript helpers
2998 <computeroutput>webclient.js</computeroutput></para>
2999 </listitem>
3000 </itemizedlist></para>
3001
3002 <para>The VirtualBox SDK contains sample HTML code
3003 including:<itemizedlist>
3004 <listitem>
3005 <para>JavaScript library for embedding Flash content
3006 <computeroutput>SWFObject.js</computeroutput></para>
3007 </listitem>
3008
3009 <listitem>
3010 <para>Sample HTML page
3011 <computeroutput>webclient3.html</computeroutput></para>
3012 </listitem>
3013 </itemizedlist></para>
3014
3015 <sect2>
3016 <title>RDPWeb functions</title>
3017
3018 <para><computeroutput>RDPClientUI.swf</computeroutput> and
3019 <computeroutput>webclient.js</computeroutput> work with each other.
3020 JavaScript code is responsible for a proper SWF initialization,
3021 delivering mouse events to the SWF and processing resize requests from
3022 the SWF. On the other hand, the SWF contains a few JavaScript callable
3023 methods, which are used both from
3024 <computeroutput>webclient.js</computeroutput> and the user HTML
3025 page.</para>
3026
3027 <sect3>
3028 <title>JavaScript functions</title>
3029
3030 <para><computeroutput>webclient.js</computeroutput> contains helper
3031 functions. In the following table ElementId refers to an HTML
3032 element name or attribute, and Element to the HTML element itself.
3033 HTML code<programlisting>
3034 &lt;div id="FlashRDP"&gt;
3035 &lt;/div&gt;
3036</programlisting> would have ElementId equal to FlashRDP and Element equal to
3037 the div element.</para>
3038
3039 <para><itemizedlist>
3040 <listitem>
3041 <programlisting>RDPWebClient.embedSWF(SWFFileName, ElementId)</programlisting>
3042
3043 <para>Uses SWFObject library to replace the HTML element with
3044 the Flash movie.</para>
3045 </listitem>
3046
3047 <listitem>
3048 <programlisting>RDPWebClient.isRDPWebControlById(ElementId)</programlisting>
3049
3050 <para>Returns true if the given id refers to a RDPWeb Flash
3051 element.</para>
3052 </listitem>
3053
3054 <listitem>
3055 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting>
3056
3057 <para>Returns true if the given element is a RDPWeb Flash
3058 element.</para>
3059 </listitem>
3060
3061 <listitem>
3062 <programlisting>RDPWebClient.getFlashById(ElementId)</programlisting>
3063
3064 <para>Returns an element, which is referenced by the given id.
3065 This function will try to resolve any element, event if it is
3066 not a Flash movie.</para>
3067 </listitem>
3068 </itemizedlist></para>
3069 </sect3>
3070
3071 <sect3>
3072 <title>Flash methods callable from JavaScript</title>
3073
3074 <para><computeroutput>RDPWebClienUI.swf</computeroutput> methods can
3075 be called directly from JavaScript code on a HTML page.</para>
3076
3077 <itemizedlist>
3078 <listitem>
3079 <para>getProperty(Name)</para>
3080 </listitem>
3081
3082 <listitem>
3083 <para>setProperty(Name)</para>
3084 </listitem>
3085
3086 <listitem>
3087 <para>connect()</para>
3088 </listitem>
3089
3090 <listitem>
3091 <para>disconnect()</para>
3092 </listitem>
3093
3094 <listitem>
3095 <para>keyboardSendCAD()</para>
3096 </listitem>
3097 </itemizedlist>
3098 </sect3>
3099
3100 <sect3>
3101 <title>Flash JavaScript callbacks</title>
3102
3103 <para><computeroutput>RDPWebClienUI.swf</computeroutput> calls
3104 JavaScript functions provided by the HTML page.</para>
3105 </sect3>
3106 </sect2>
3107
3108 <sect2>
3109 <title>Embedding RDPWeb in an HTML page</title>
3110
3111 <para>It is necessary to include
3112 <computeroutput>webclient.js</computeroutput> helper script. If
3113 SWFObject library is used, the
3114 <computeroutput>swfobject.js</computeroutput> must be also included
3115 and RDPWeb flash content can be embedded to a Web page using dynamic
3116 HTML. The HTML must include a "placeholder", which consists of 2
3117 <computeroutput>div</computeroutput> elements.</para>
3118 </sect2>
3119 </sect1>
3120
3121 <sect1>
3122 <title>RDPWeb change log</title>
3123
3124 <sect2>
3125 <title>Version 1.2.28</title>
3126
3127 <itemizedlist>
3128 <listitem>
3129 <para><computeroutput>keyboardLayout</computeroutput>,
3130 <computeroutput>keyboardLayouts</computeroutput>,
3131 <computeroutput>UUID</computeroutput> properties.</para>
3132 </listitem>
3133
3134 <listitem>
3135 <para>Support for German keyboard layout on the client.</para>
3136 </listitem>
3137
3138 <listitem>
3139 <para>Rebranding to Oracle.</para>
3140 </listitem>
3141 </itemizedlist>
3142 </sect2>
3143
3144 <sect2>
3145 <title>Version 1.1.26</title>
3146
3147 <itemizedlist>
3148 <listitem>
3149 <para><computeroutput>webclient.js</computeroutput> is a part of
3150 the distribution package.</para>
3151 </listitem>
3152
3153 <listitem>
3154 <para><computeroutput>lastError</computeroutput> property.</para>
3155 </listitem>
3156
3157 <listitem>
3158 <para><computeroutput>keyboardSendScancodes</computeroutput> and
3159 <computeroutput>keyboardSendCAD</computeroutput> methods.</para>
3160 </listitem>
3161 </itemizedlist>
3162 </sect2>
3163
3164 <sect2>
3165 <title>Version 1.0.24</title>
3166
3167 <itemizedlist>
3168 <listitem>
3169 <para>Initial release.</para>
3170 </listitem>
3171 </itemizedlist>
3172 </sect2>
3173 </sect1>
3174 </chapter>
3175
3176 <chapter id="vbox-auth">
3177 <title>VirtualBox external authentication modules</title>
3178
3179 <para>VirtualBox supports arbitrary external modules to perform
3180 authentication. The module is used when the authentication method is set
3181 to "external" for a particular VM VRDE access and the library was
3182 specified with <computeroutput>VBoxManage setproperty
3183 vrdeauthlibrary</computeroutput>. Web service also use the authentication
3184 module which was specified with <computeroutput>VBoxManage setproperty
3185 websrvauthlibrary</computeroutput>.</para>
3186
3187 <para>This library will be loaded by the VM or web service process on
3188 demand, i.e. when the first remote desktop connection is made by a client
3189 or when a client that wants to use the web service logs on.</para>
3190
3191 <para>External authentication is the most flexible as the external handler
3192 can both choose to grant access to everyone (like the "null"
3193 authentication method would) and delegate the request to the guest
3194 authentication component. When delegating the request to the guest
3195 component, the handler will still be called afterwards with the option to
3196 override the result.</para>
3197
3198 <para>An authentication library is required to implement exactly one entry
3199 point:</para>
3200
3201 <screen>#include "VBoxAuth.h"
3202
3203/**
3204 * Authentication library entry point.
3205 *
3206 * Parameters:
3207 *
3208 * szCaller The name of the component which calls the library (UTF8).
3209 * pUuid Pointer to the UUID of the accessed virtual machine. Can be NULL.
3210 * guestJudgement Result of the guest authentication.
3211 * szUser User name passed in by the client (UTF8).
3212 * szPassword Password passed in by the client (UTF8).
3213 * szDomain Domain passed in by the client (UTF8).
3214 * fLogon Boolean flag. Indicates whether the entry point is called
3215 * for a client logon or the client disconnect.
3216 * clientId Server side unique identifier of the client.
3217 *
3218 * Return code:
3219 *
3220 * AuthResultAccessDenied Client access has been denied.
3221 * AuthResultAccessGranted Client has the right to use the
3222 * virtual machine.
3223 * AuthResultDelegateToGuest Guest operating system must
3224 * authenticate the client and the
3225 * library must be called again with
3226 * the result of the guest
3227 * authentication.
3228 *
3229 * Note: When 'fLogon' is 0, only pszCaller, pUuid and clientId are valid and the return
3230 * code is ignored.
3231 */
3232AuthResult AUTHCALL AuthEntry(
3233 const char *szCaller,
3234 PAUTHUUID pUuid,
3235 AuthGuestJudgement guestJudgement,
3236 const char *szUser,
3237 const char *szPassword
3238 const char *szDomain
3239 int fLogon,
3240 unsigned clientId)
3241{
3242 /* Process request against your authentication source of choice. */
3243 // if (authSucceeded(...))
3244 // return AuthResultAccessGranted;
3245 return AuthResultAccessDenied;
3246}</screen>
3247
3248 <para>A note regarding the UUID implementation of the
3249 <computeroutput>pUuid</computeroutput> argument: VirtualBox uses a
3250 consistent binary representation of UUIDs on all platforms. For this
3251 reason the integer fields comprising the UUID are stored as little endian
3252 values. If you want to pass such UUIDs to code which assumes that the
3253 integer fields are big endian (often also called network byte order), you
3254 need to adjust the contents of the UUID to e.g. achieve the same string
3255 representation. The required changes are:<itemizedlist>
3256 <listitem>
3257 <para>reverse the order of byte 0, 1, 2 and 3</para>
3258 </listitem>
3259
3260 <listitem>
3261 <para>reverse the order of byte 4 and 5</para>
3262 </listitem>
3263
3264 <listitem>
3265 <para>reverse the order of byte 6 and 7.</para>
3266 </listitem>
3267 </itemizedlist>Using this conversion you will get identical results when
3268 converting the binary UUID to the string representation.</para>
3269
3270 <para>The <computeroutput>guestJudgement</computeroutput> argument
3271 contains information about the guest authentication status. For the first
3272 call, it is always set to
3273 <computeroutput>AuthGuestNotAsked</computeroutput>. In case the
3274 <computeroutput>AuthEntry</computeroutput> function returns
3275 <computeroutput>AuthResultDelegateToGuest</computeroutput>, a guest
3276 authentication will be attempted and another call to the
3277 <computeroutput>AuthEntry</computeroutput> is made with its result. This
3278 can be either granted / denied or no judgement (the guest component chose
3279 for whatever reason to not make a decision). In case there is a problem
3280 with the guest authentication module (e.g. the Additions are not installed
3281 or not running or the guest did not respond within a timeout), the "not
3282 reacted" status will be returned.</para>
3283 </chapter>
3284
3285 <chapter id="javaapi">
3286 <title>Using Java API</title>
3287
3288 <sect1>
3289 <title>Introduction</title>
3290
3291 <para>VirtualBox can be controlled by a Java API, both locally
3292 (COM/XPCOM) and from remote (SOAP) clients. As with the Python bindings,
3293 a generic glue layer tries to hide all platform differences, allowing
3294 for source and binary compatibility on different platforms.</para>
3295 </sect1>
3296
3297 <sect1>
3298 <title>Requirements</title>
3299
3300 <para>To use the Java bindings, there are certain requirements depending
3301 on the platform. First of all, you need JDK 1.5 (Java 5) or later. Also
3302 please make sure that the version of the VirtualBox API .jar file
3303 exactly matches the version of VirtualBox you use. To avoid confusion,
3304 the VirtualBox API provides versioning in the Java package name, e.g.
3305 the package is named <computeroutput>org.virtualbox_3_2</computeroutput>
3306 for VirtualBox version 3.2. <itemizedlist>
3307 <listitem>
3308 <para><emphasis role="bold">XPCOM:</emphasis> - for all platforms,
3309 but Microsoft Windows. A Java bridge based on JavaXPCOM is shipped
3310 with VirtualBox. The classpath must contain
3311 <computeroutput>vboxjxpcom.jar</computeroutput> and the
3312 <computeroutput>vbox.home</computeroutput> property must be set to
3313 location where the VirtualBox binaries are. Please make sure that
3314 the JVM bitness matches bitness of VirtualBox you use as the XPCOM
3315 bridge relies on native libraries.</para>
3316
3317 <para>Start your application like this: <programlisting>
3318 java -cp vboxjxpcom.jar -Dvbox.home=/opt/virtualbox MyProgram
3319 </programlisting></para>
3320 </listitem>
3321
3322 <listitem>
3323 <para><emphasis role="bold">COM:</emphasis> - for Microsoft
3324 Windows. We rely on <computeroutput>Jacob</computeroutput> - a
3325 generic Java to COM bridge - which has to be installed seperately.
3326 See <ulink
3327 url="http://sourceforge.net/projects/jacob-project/">http://sourceforge.net/projects/jacob-project/</ulink>
3328 for installation instructions. Also, the VirtualBox provided
3329 <computeroutput>vboxjmscom.jar</computeroutput> must be in the
3330 class path.</para>
3331
3332 <para>Start your application like this: <programlisting>
3333 java -cp vboxjmscom.jar;c:\jacob\jacob.jar -Djava.library.path=c:\jacob MyProgram
3334 </programlisting></para>
3335 </listitem>
3336
3337 <listitem>
3338 <para><emphasis role="bold">SOAP</emphasis> - all platforms. Java
3339 6 is required, as it comes with builtin support for SOAP via the
3340 JAX-WS library. Also, the VirtualBox provided
3341 <computeroutput>vbojws.jar</computeroutput> must be in the class
3342 path. In the SOAP case it's possible to create several
3343 VirtualBoxManager instances to communicate with multiple
3344 VirtualBox hosts.</para>
3345
3346 <para>Start your application like this: <programlisting>
3347 java -cp vboxjws.jar MyProgram
3348 </programlisting></para>
3349 </listitem>
3350 </itemizedlist></para>
3351
3352 <para>Exception handling is also generalized by the generic glue layer,
3353 so that all methods could throw
3354 <computeroutput>VBoxException</computeroutput> containing human-readable
3355 text message (see <computeroutput>getMessage()</computeroutput> method)
3356 along with wrapped original exception (see
3357 <computeroutput>getWrapped()</computeroutput> method).</para>
3358 </sect1>
3359
3360 <sect1>
3361 <title>Example</title>
3362
3363 <para>This example shows a simple use case of the Java API. Differences
3364 for SOAP vs. local version are minimal, and limited to the connection
3365 setup phase (see <computeroutput>ws</computeroutput> variable). In the
3366 SOAP case it's possible to create several VirtualBoxManager instances to
3367 communicate with multiple VirtualBox hosts. <programlisting>
3368 import org.virtualbox_3_3.*;
3369 ....
3370 VirtualBoxManager mgr = VirtualBoxManager.createInstance(null);
3371 boolean ws = false; // or true, if we need the SOAP version
3372 if (ws)
3373 {
3374 String url = "http://myhost:18034";
3375 String user = "test";
3376 String passwd = "test";
3377 mgr.connect(url, user, passwd);
3378 }
3379 IVirtualBox vbox = mgr.getVBox();
3380 System.out.println("VirtualBox version: " + vbox.getVersion() + "\n");
3381 // get first VM name
3382 String m = vbox.getMachines().get(0).getName();
3383 System.out.println("\nAttempting to start VM '" + m + "'");
3384 // start it
3385 mgr.startVm(m, null, 7000);
3386
3387 if (ws)
3388 mgr.disconnect();
3389
3390 mgr.cleanup();
3391 </programlisting> For more a complete example, see
3392 <computeroutput>TestVBox.java</computeroutput>, shipped with the
3393 SDK.</para>
3394 </sect1>
3395 </chapter>
3396
3397 <chapter>
3398 <title>License information</title>
3399
3400 <para>The sample code files shipped with the SDK are generally licensed
3401 liberally to make it easy for anyone to use this code for their own
3402 application code.</para>
3403
3404 <para>The Java files under
3405 <computeroutput>bindings/webservice/java/jax-ws/</computeroutput> (library
3406 files for the object-oriented web service) are, by contrast, licensed
3407 under the GNU Lesser General Public License (LGPL) V2.1.</para>
3408
3409 <para>See
3410 <computeroutput>sdk/bindings/webservice/java/jax-ws/src/COPYING.LIB</computeroutput>
3411 for the full text of the LGPL 2.1.</para>
3412
3413 <para>When in doubt, please refer to the individual source code files
3414 shipped with this SDK.</para>
3415 </chapter>
3416
3417 <chapter>
3418 <title>Main API change log</title>
3419
3420 <para>Generally, VirtualBox will maintain API compatibility within a major
3421 release; a major release occurs when the first or the second of the three
3422 version components of VirtualBox change (that is, in the x.y.z scheme, a
3423 major release is one where x or y change, but not when only z
3424 changes).</para>
3425
3426 <para>In other words, updates like those from 2.0.0 to 2.0.2 will not come
3427 with API breakages.</para>
3428
3429 <para>Migration between major releases most likely will lead to API
3430 breakage, so please make sure you updated code accordingly. The OOWS Java
3431 wrappers enforce that mechanism by putting VirtualBox classes into
3432 version-specific packages such as
3433 <computeroutput>org.virtualbox_2_2</computeroutput>. This approach allows
3434 for connecting to multiple VirtualBox versions simultaneously from the
3435 same Java application.</para>
3436
3437 <para>The following sections list incompatible changes that the Main API
3438 underwent since the original release of this SDK Reference with VirtualBox
3439 2.0. A change is deemed "incompatible" only if it breaks existing client
3440 code (e.g. changes in method parameter lists, renamed or removed
3441 interfaces and similar). In other words, the list does not contain new
3442 interfaces, methods or attributes or other changes that do not affect
3443 existing client code.</para>
3444
3445 <sect1>
3446 <title>Incompatible API changes with version 4.1</title>
3447
3448 <itemizedlist>
3449 <listitem>
3450 <para>The method <xref linkend="IAppliance__importMachines"
3451 xreflabel="IAppliance::importMachines()" /> has one more parameter
3452 now, which allows to configure the import process in more detail.
3453 </para>
3454 </listitem>
3455
3456 <listitem>
3457 <para>The method <xref linkend="IVirtualBox__openMedium"
3458 xreflabel="IVirtualBox::openMedium()" /> has one more parameter
3459 now, which allows resolving duplicate medium UUIDs without the need
3460 for external tools.</para>
3461 </listitem>
3462
3463 <listitem>
3464 <para>The <xref linkend="INetworkAdapter" xreflabel="INetworkAdapter"/>
3465 interface has been cleaned up. The various methods to activate an
3466 attachment type have been replaced by the
3467 <xref linkend="INetworkAdapter__attachmentType" xreflabel="INetworkAdapter::attachmentType"/> setter.</para>
3468 <para>Additionally each attachment mode now has its own attribute,
3469 which means that host only networks no longer share the settings with
3470 bridged interfaces.</para>
3471 <para>To allow introducing new network attachment implementations
3472 without making API changes, the concept of a generic network
3473 attachment driver has been introduced, which is configurable through
3474 key/value properties.</para>
3475 </listitem>
3476
3477 <listitem>
3478 <para>This version introduces the guest facilities concept. A guest
3479 facility either represents a module or feature the guest is running or
3480 offering, which is defined by <xref linkend="AdditionsFacilityType"
3481 xreflabel="AdditionsFacilityType"/>. Each facility is member of a
3482 <xref linkend="AdditionsFacilityClass" xreflabel="AdditionsFacilityClass"/>
3483 and has a current status indicated by <xref linkend="AdditionsFacilityStatus"
3484 xreflabel="AdditionsFacilityStatus"/>, together with a timestamp (in ms) of
3485 the last status update.</para>
3486 <para>To address the above concept, the following changes were made:
3487 <itemizedlist>
3488 <listitem>
3489 <para>
3490 In the <xref linkend="IGuest" xreflabel="IGuest"/> interface, the following were removed:
3491 <itemizedlist>
3492 <listitem>
3493 <para>the <computeroutput>supportsSeamless</computeroutput> attribute;</para>
3494 </listitem>
3495 <listitem>
3496 <para>the <computeroutput>supportsGraphics</computeroutput> attribute;</para>
3497 </listitem>
3498 </itemizedlist>
3499 </para>
3500 </listitem>
3501 <listitem>
3502 <para>
3503 The function <xref linkend="IGuest__getFacilityStatus" xreflabel="IGuest::getFacilityStatus()"/>
3504 was added. It quickly provides a facility's status without the need to get the facility
3505 collection with <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>.
3506 </para>
3507 </listitem>
3508 <listitem>
3509 <para>
3510 The attribute <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>
3511 was added to provide an easy to access collection of all currently known guest
3512 facilities, that is, it contains all facilies where at least one status update was
3513 made since the guest was started.
3514 </para>
3515 </listitem>
3516 <listitem>
3517 <para>
3518 The interface <xref linkend="IAdditionsFacility" xreflabel="IAdditionsFacility"/>
3519 was added to represent a single facility returned by
3520 <xref linkend="IGuest__facilities" xreflabel="IGuest::facilities"/>.
3521 </para>
3522 </listitem>
3523 <listitem>
3524 <para>
3525 <xref linkend="AdditionsFacilityStatus" xreflabel="AdditionsFacilityStatus"/>
3526 was added to represent a facility's overall status.
3527 </para>
3528 </listitem>
3529 <listitem>
3530 <para>
3531 <xref linkend="AdditionsFacilityType" xreflabel="AdditionsFacilityType"/> and
3532 <xref linkend="AdditionsFacilityClass" xreflabel="AdditionsFacilityClass"/> were
3533 added to represent the facility's type and class.
3534 </para>
3535 </listitem>
3536 </itemizedlist>
3537 </para>
3538 </listitem>
3539 </itemizedlist>
3540 </sect1>
3541
3542 <sect1>
3543 <title>Incompatible API changes with version 4.0</title>
3544
3545 <itemizedlist>
3546 <listitem>
3547 <para>A new Java glue layer replacing the previous OOWS JAX-WS
3548 bindings was introduced. The new library allows for uniform code
3549 targeting both local (COM/XPCOM) and remote (SOAP) transports. Now,
3550 instead of <computeroutput>IWebsessionManager</computeroutput>, the
3551 new class <computeroutput>VirtualBoxManager</computeroutput> must be
3552 used. See <xref linkend="javaapi" xreflabel="Java API chapter" />
3553 for details.</para>
3554 </listitem>
3555
3556 <listitem>
3557 <para>The confusingly named and impractical session APIs were
3558 changed. In existing client code, the following changes need to be
3559 made:<itemizedlist>
3560 <listitem>
3561 <para>Replace any
3562 <computeroutput>IVirtualBox::openSession(uuidMachine,
3563 ...)</computeroutput> API call with the machine's <xref
3564 linkend="IMachine__lockMachine"
3565 xreflabel="IMachine::lockMachine()" /> call and a
3566 <computeroutput>LockType.Write</computeroutput> argument. The
3567 functionality is unchanged, but instead of "opening a direct
3568 session on a machine" all documentation now refers to
3569 "obtaining a write lock on a machine for the client
3570 session".</para>
3571 </listitem>
3572
3573 <listitem>
3574 <para>Similarly, replace any
3575 <computeroutput>IVirtualBox::openExistingSession(uuidMachine,
3576 ...)</computeroutput> call with the machine's <xref
3577 linkend="IMachine__lockMachine"
3578 xreflabel="IMachine::lockMachine()" /> call and a
3579 <computeroutput>LockType.Shared</computeroutput> argument.
3580 Whereas it was previously impossible to connect a client
3581 session to a running VM process in a race-free manner, the new
3582 API will atomically either write-lock the machine for the
3583 current session or establish a remote link to an existing
3584 session. Existing client code which tried calling both
3585 <computeroutput>openSession()</computeroutput> and
3586 <computeroutput>openExistingSession()</computeroutput> can now
3587 use this one call instead.</para>
3588 </listitem>
3589
3590 <listitem>
3591 <para>Third, replace any
3592 <computeroutput>IVirtualBox::openRemoteSession(uuidMachine,
3593 ...)</computeroutput> call with the machine's <xref
3594 linkend="IMachine__launchVMProcess"
3595 xreflabel="IMachine::launchVMProcess()" /> call. The
3596 functionality is unchanged.</para>
3597 </listitem>
3598
3599 <listitem>
3600 <para>The <xref linkend="SessionState"
3601 xreflabel="SessionState" /> enum was adjusted accordingly:
3602 "Open" is now "Locked", "Closed" is now "Unlocked", "Closing"
3603 is now "Unlocking".</para>
3604 </listitem>
3605 </itemizedlist></para>
3606 </listitem>
3607
3608 <listitem>
3609 <para>Virtual machines created with VirtualBox 4.0 or later no
3610 longer register their media in the global media registry in the
3611 <computeroutput>VirtualBox.xml</computeroutput> file. Instead, such
3612 machines list all their media in their own machine XML files. As a
3613 result, a number of media-related APIs had to be modified again.
3614 <itemizedlist>
3615 <listitem>
3616 <para>Neither <xref linkend="IVirtualBox__createHardDisk"
3617 xreflabel="IVirtualBox::createHardDisk()" /> nor <xref
3618 linkend="IVirtualBox__openMedium"
3619 xreflabel="IVirtualBox::openMedium()" /> register media
3620 automatically any more.</para>
3621 </listitem>
3622
3623 <listitem>
3624 <para><xref linkend="IMachine__attachDevice"
3625 xreflabel="IMachine::attachDevice()" /> and <xref
3626 linkend="IMachine__mountMedium"
3627 xreflabel="IMachine::mountMedium()" /> now take an IMedium
3628 object instead of a UUID as an argument. It is these two calls
3629 which add media to a registry now (either a machine registry
3630 for machines created with VirtualBox 4.0 or later or the
3631 global registry otherwise). As a consequence, if a medium is
3632 opened but never attached to a machine, it is no longer added
3633 to any registry any more.</para>
3634 </listitem>
3635
3636 <listitem>
3637 <para>To reduce code duplication, the APIs
3638 IVirtualBox::findHardDisk(), getHardDisk(), findDVDImage(),
3639 getDVDImage(), findFloppyImage() and getFloppyImage() have all
3640 been merged into <xref linkend="IVirtualBox__findMedium"
3641 xreflabel="IVirtualBox::findMedium()" />, and
3642 IVirtualBox::openHardDisk(), openDVDImage() and
3643 openFloppyImage() have all been merged into <xref
3644 linkend="IVirtualBox__openMedium"
3645 xreflabel="IVirtualBox::openMedium()" />.</para>
3646 </listitem>
3647
3648 <listitem>
3649 <para>The rare use case of changing the UUID and parent UUID
3650 of a medium previously handled by
3651 <computeroutput>openHardDisk()</computeroutput> is now in a
3652 separate <xref linkend="IMedium__setIDs"
3653 xreflabel="IMedium::setIDs" /> method.</para>
3654 </listitem>
3655
3656 <listitem>
3657 <para><computeroutput>ISystemProperties::get/setDefaultHardDiskFolder()</computeroutput>
3658 have been removed since disk images are now by default placed
3659 in each machine's folder.</para>
3660 </listitem>
3661
3662 <listitem>
3663 <para>The <xref linkend="ISystemProperties__infoVDSize"
3664 xreflabel="ISystemProperties::infoVDSize" /> attribute
3665 replaces the <computeroutput>getMaxVDISize()</computeroutput>
3666 API call; this now uses bytes instead of megabytes.</para>
3667 </listitem>
3668 </itemizedlist></para>
3669 </listitem>
3670
3671 <listitem>
3672 <para>Machine management APIs were enhanced as follows:<itemizedlist>
3673 <listitem>
3674 <para><xref linkend="IVirtualBox__createMachine"
3675 xreflabel="IVirtualBox::createMachine()" /> is no longer
3676 restricted to creating machines in the default "Machines"
3677 folder, but can now create machines at arbitrary locations.
3678 For this to work, the parameter list had to be changed.</para>
3679 </listitem>
3680
3681 <listitem>
3682 <para>The long-deprecated
3683 <computeroutput>IVirtualBox::createLegacyMachine()</computeroutput>
3684 API has been removed.</para>
3685 </listitem>
3686
3687 <listitem>
3688 <para>To reduce code duplication and for consistency with the
3689 aforementioned media APIs,
3690 <computeroutput>IVirtualBox::getMachine()</computeroutput> has
3691 been merged with <xref linkend="IVirtualBox__findMachine"
3692 xreflabel="IVirtualBox::findMachine()" />, and
3693 <computeroutput>IMachine::getSnapshot()</computeroutput> has
3694 been merged with <xref linkend="IMachine__findSnapshot"
3695 xreflabel="IMachine::findSnapshot()" />.</para>
3696 </listitem>
3697
3698 <listitem>
3699 <para><computeroutput>IVirtualBox::unregisterMachine()</computeroutput>
3700 was replaced with <xref linkend="IMachine__unregister"
3701 xreflabel="IMachine::unregister()" /> with additional
3702 functionality for cleaning up machine files.</para>
3703 </listitem>
3704
3705 <listitem>
3706 <para><computeroutput>IConsole::forgetSavedState</computeroutput>
3707 has been renamed to <xref
3708 linkend="IConsole__discardSavedState"
3709 xreflabel="IConsole::discardSavedState()" />.</para>
3710 </listitem>
3711 </itemizedlist></para>
3712 </listitem>
3713
3714 <listitem>
3715 <para>All event callbacks APIs were replaced with a new, generic
3716 event mechanism that can be used both locally (COM, XPCOM) and
3717 remotely (web services). Also, the new mechanism is usable from
3718 scripting languages and a local Java. See <xref linkend="IEvent"
3719 xreflabel="events" /> for details. The new concept will require
3720 changes to all clients that used event callbacks.</para>
3721 </listitem>
3722
3723 <listitem>
3724 <para><computeroutput>additionsActive()</computeroutput> was
3725 replaced with <xref linkend="IGuest__additionsRunLevel"
3726 xreflabel="additionsRunLevel()" /> and <xref
3727 linkend="IGuest__getAdditionsStatus"
3728 xreflabel="getAdditionsStatus()" /> in order to support a more
3729 detailed status of the current Guest Additions loading/readiness
3730 state. <xref linkend="IGuest__additionsVersion"
3731 xreflabel="IGuest::additionsVersion()" /> no longer returns the
3732 Guest Additions interface version but the installed Guest Additions
3733 version and revision in form of
3734 <computeroutput>3.3.0r12345</computeroutput>.</para>
3735 </listitem>
3736
3737 <listitem>
3738 <para>To address shared folders auto-mounting support, the following
3739 APIs were extended to require an additional
3740 <computeroutput>automount</computeroutput> parameter: <itemizedlist>
3741 <listitem>
3742 <para><xref linkend="IVirtualBox__createSharedFolder"
3743 xreflabel="IVirtualBox::createSharedFolder()" /></para>
3744 </listitem>
3745
3746 <listitem>
3747 <para><xref linkend="IMachine__createSharedFolder"
3748 xreflabel="IMachine::createSharedFolder()" /></para>
3749 </listitem>
3750
3751 <listitem>
3752 <para><xref linkend="IConsole__createSharedFolder"
3753 xreflabel="IConsole::createSharedFolder()" /></para>
3754 </listitem>
3755 </itemizedlist> Also, a new property named
3756 <computeroutput>autoMount</computeroutput> was added to the <xref
3757 linkend="ISharedFolder" xreflabel="ISharedFolder" />
3758 interface.</para>
3759 </listitem>
3760
3761 <listitem>
3762 <para>The appliance (OVF) APIs were enhanced as
3763 follows:<itemizedlist>
3764 <listitem>
3765 <para><xref linkend="IMachine__export"
3766 xreflabel="IMachine::export()" /> received an extra parameter
3767 <computeroutput>location</computeroutput>, which is used to
3768 decide for the disk naming.</para>
3769 </listitem>
3770
3771 <listitem>
3772 <para><xref linkend="IAppliance__write"
3773 xreflabel="IAppliance::write()" /> received an extra parameter
3774 <computeroutput>manifest</computeroutput>, which can suppress
3775 creating the manifest file on export.</para>
3776 </listitem>
3777
3778 <listitem>
3779 <para><xref linkend="IVFSExplorer__entryList"
3780 xreflabel="IVFSExplorer::entryList()" /> received two extra
3781 parameters <computeroutput>sizes</computeroutput> and
3782 <computeroutput>modes</computeroutput>, which contains the
3783 sizes (in bytes) and the file access modes (in octal form) of
3784 the returned files.</para>
3785 </listitem>
3786 </itemizedlist></para>
3787 </listitem>
3788
3789 <listitem>
3790 <para>Support for remote desktop access to virtual machines has been
3791 cleaned up to allow third party implementations of the remote
3792 desktop server. This is called the VirtualBox Remote Desktop
3793 Extension (VRDE) and can be added to VirtualBox by installing the
3794 corresponding extension package; see the VirtualBox User Manual for
3795 details.</para>
3796
3797 <para>The following API changes were made to support the VRDE
3798 interface: <itemizedlist>
3799 <listitem>
3800 <para><computeroutput>IVRDPServer</computeroutput> has been
3801 renamed to <xref linkend="IVRDEServer"
3802 xreflabel="IVRDEServer" />.</para>
3803 </listitem>
3804
3805 <listitem>
3806 <para><computeroutput>IRemoteDisplayInfo</computeroutput> has
3807 been renamed to <xref linkend="IVRDEServerInfo"
3808 xreflabel="IVRDEServerInfo" />.</para>
3809 </listitem>
3810
3811 <listitem>
3812 <para><xref linkend="IMachine__VRDEServer"
3813 xreflabel="IMachine::VRDEServer" /> replaces
3814 <computeroutput>VRDPServer.</computeroutput></para>
3815 </listitem>
3816
3817 <listitem>
3818 <para><xref linkend="IConsole__VRDEServerInfo"
3819 xreflabel="IConsole::VRDEServerInfo" /> replaces
3820 <computeroutput>RemoteDisplayInfo</computeroutput>.</para>
3821 </listitem>
3822
3823 <listitem>
3824 <para><xref linkend="ISystemProperties__VRDEAuthLibrary"
3825 xreflabel="ISystemProperties::VRDEAuthLibrary" /> replaces
3826 <computeroutput>RemoteDisplayAuthLibrary</computeroutput>.</para>
3827 </listitem>
3828
3829 <listitem>
3830 <para>The following methods have been implemented in
3831 <computeroutput>IVRDEServer</computeroutput> to support
3832 generic VRDE properties: <itemizedlist>
3833 <listitem>
3834 <para><xref linkend="IVRDEServer__setVRDEProperty"
3835 xreflabel="IVRDEServer::setVRDEProperty" /></para>
3836 </listitem>
3837
3838 <listitem>
3839 <para><xref linkend="IVRDEServer__getVRDEProperty"
3840 xreflabel="IVRDEServer::getVRDEProperty" /></para>
3841 </listitem>
3842
3843 <listitem>
3844 <para><xref linkend="IVRDEServer__VRDEProperties"
3845 xreflabel="IVRDEServer::VRDEProperties" /></para>
3846 </listitem>
3847 </itemizedlist></para>
3848
3849 <para>A few implementation-specific attributes of the old
3850 <computeroutput>IVRDPServer</computeroutput> interface have
3851 been removed and replaced with properties: <itemizedlist>
3852 <listitem>
3853 <para><computeroutput>IVRDPServer::Ports</computeroutput>
3854 has been replaced with the
3855 <computeroutput>"TCP/Ports"</computeroutput> property.
3856 The property value is a string, which contains a
3857 comma-separated list of ports or ranges of ports. Use a
3858 dash between two port numbers to specify a range.
3859 Example:
3860 <computeroutput>"5000,5010-5012"</computeroutput></para>
3861 </listitem>
3862
3863 <listitem>
3864 <para><computeroutput>IVRDPServer::NetAddress</computeroutput>
3865 has been replaced with the
3866 <computeroutput>"TCP/Address"</computeroutput> property.
3867 The property value is an IP address string. Example:
3868 <computeroutput>"127.0.0.1"</computeroutput></para>
3869 </listitem>
3870
3871 <listitem>
3872 <para><computeroutput>IVRDPServer::VideoChannel</computeroutput>
3873 has been replaced with the
3874 <computeroutput>"VideoChannel/Enabled"</computeroutput>
3875 property. The property value is either
3876 <computeroutput>"true"</computeroutput> or
3877 <computeroutput>"false"</computeroutput></para>
3878 </listitem>
3879
3880 <listitem>
3881 <para><computeroutput>IVRDPServer::VideoChannelQuality</computeroutput>
3882 has been replaced with the
3883 <computeroutput>"VideoChannel/Quality"</computeroutput>
3884 property. The property value is a string which contain a
3885 decimal number in range 10..100. Invalid values are
3886 ignored and the quality is set to the default value 75.
3887 Example: <computeroutput>"50"</computeroutput></para>
3888 </listitem>
3889 </itemizedlist></para>
3890 </listitem>
3891 </itemizedlist></para>
3892 </listitem>
3893
3894 <listitem>
3895 <para>The VirtualBox external authentication module interface has
3896 been updated and made more generic. Because of that,
3897 <computeroutput>VRDPAuthType</computeroutput> enumeration has been
3898 renamed to <xref linkend="AuthType" xreflabel="AuthType" />.</para>
3899 </listitem>
3900 </itemizedlist>
3901 </sect1>
3902
3903 <sect1>
3904 <title>Incompatible API changes with version 3.2</title>
3905
3906 <itemizedlist>
3907 <listitem>
3908 <para>The following interfaces were renamed for consistency:
3909 <itemizedlist>
3910 <listitem>
3911 <para>IMachine::getCpuProperty() is now <xref
3912 linkend="IMachine__getCPUProperty"
3913 xreflabel="IMachine::getCPUProperty()" />;</para>
3914 </listitem>
3915
3916 <listitem>
3917 <para>IMachine::setCpuProperty() is now <xref
3918 linkend="IMachine__setCPUProperty"
3919 xreflabel="IMachine::setCPUProperty()" />;</para>
3920 </listitem>
3921
3922 <listitem>
3923 <para>IMachine::getCpuIdLeaf() is now <xref
3924 linkend="IMachine__getCPUIDLeaf"
3925 xreflabel="IMachine::getCPUIDLeaf()" />;</para>
3926 </listitem>
3927
3928 <listitem>
3929 <para>IMachine::setCpuIdLeaf() is now <xref
3930 linkend="IMachine__setCPUIDLeaf"
3931 xreflabel="IMachine::setCPUIDLeaf()" />;</para>
3932 </listitem>
3933
3934 <listitem>
3935 <para>IMachine::removeCpuIdLeaf() is now <xref
3936 linkend="IMachine__removeCPUIDLeaf"
3937 xreflabel="IMachine::removeCPUIDLeaf()" />;</para>
3938 </listitem>
3939
3940 <listitem>
3941 <para>IMachine::removeAllCpuIdLeafs() is now <xref
3942 linkend="IMachine__removeAllCPUIDLeaves"
3943 xreflabel="IMachine::removeAllCPUIDLeaves()" />;</para>
3944 </listitem>
3945
3946 <listitem>
3947 <para>the CpuPropertyType enum is now <xref
3948 linkend="CPUPropertyType"
3949 xreflabel="CPUPropertyType" />.</para>
3950 </listitem>
3951
3952 <listitem>
3953 <para>IVirtualBoxCallback::onSnapshotDiscarded() is now
3954 IVirtualBoxCallback::onSnapshotDeleted.</para>
3955 </listitem>
3956 </itemizedlist></para>
3957 </listitem>
3958
3959 <listitem>
3960 <para>When creating a VM configuration with <xref
3961 linkend="IVirtualBox__createMachine"
3962 xreflabel="IVirtualBox::createMachine" />) it is now possible to
3963 ignore existing configuration files which would previously have
3964 caused a failure. For this the
3965 <computeroutput>override</computeroutput> parameter was
3966 added.</para>
3967 </listitem>
3968
3969 <listitem>
3970 <para>Deleting snapshots via <xref
3971 linkend="IConsole__deleteSnapshot"
3972 xreflabel="IConsole::deleteSnapshot()" /> is now possible while the
3973 associated VM is running in almost all cases. The API is unchanged,
3974 but client code that verifies machine states to determine whether
3975 snapshots can be deleted may need to be adjusted.</para>
3976 </listitem>
3977
3978 <listitem>
3979 <para>The IoBackendType enumeration was replaced with a boolean flag
3980 (see <xref linkend="IStorageController__useHostIOCache"
3981 xreflabel="IStorageController::useHostIOCache" />).</para>
3982 </listitem>
3983
3984 <listitem>
3985 <para>To address multi-monitor support, the following APIs were
3986 extended to require an additional
3987 <computeroutput>screenId</computeroutput> parameter: <itemizedlist>
3988 <listitem>
3989 <para><xref linkend="IMachine__querySavedThumbnailSize"
3990 xreflabel="IMachine::querySavedThumbnailSize()" /></para>
3991 </listitem>
3992
3993 <listitem>
3994 <para><xref linkend="IMachine__readSavedThumbnailToArray"
3995 xreflabel="IMachine::readSavedThumbnailToArray()" /></para>
3996 </listitem>
3997
3998 <listitem>
3999 <para><xref linkend="IMachine__querySavedScreenshotPNGSize"
4000 xreflabel="IMachine::querySavedScreenshotPNGSize()" /></para>
4001 </listitem>
4002
4003 <listitem>
4004 <para><xref linkend="IMachine__readSavedScreenshotPNGToArray"
4005 xreflabel="IMachine::readSavedScreenshotPNGToArray()" /></para>
4006 </listitem>
4007 </itemizedlist></para>
4008 </listitem>
4009
4010 <listitem>
4011 <para>The <computeroutput>shape</computeroutput> parameter of
4012 IConsoleCallback::onMousePointerShapeChange was changed from a
4013 implementation-specific pointer to a safearray, enabling scripting
4014 languages to process pointer shapes.</para>
4015 </listitem>
4016 </itemizedlist>
4017 </sect1>
4018
4019 <sect1>
4020 <title>Incompatible API changes with version 3.1</title>
4021
4022 <itemizedlist>
4023 <listitem>
4024 <para>Due to the new flexibility in medium attachments that was
4025 introduced with version 3.1 (in particular, full flexibility with
4026 attaching CD/DVD drives to arbitrary controllers), we seized the
4027 opportunity to rework all interfaces dealing with storage media to
4028 make the API more flexible as well as logical. The <xref
4029 linkend="IStorageController" xreflabel="IStorageController" />,
4030 <xref linkend="IMedium" xreflabel="IMedium" />, <xref
4031 linkend="IMediumAttachment" xreflabel="IMediumAttachment" /> and,
4032 <xref linkend="IMachine" xreflabel="IMachine" /> interfaces were
4033 affected the most. Existing code using them to configure storage and
4034 media needs to be carefully checked.</para>
4035
4036 <para>All media (hard disks, floppies and CDs/DVDs) are now
4037 uniformly handled through the <xref linkend="IMedium"
4038 xreflabel="IMedium" /> interface. The device-specific interfaces
4039 (<code>IHardDisk</code>, <code>IDVDImage</code>,
4040 <code>IHostDVDDrive</code>, <code>IFloppyImage</code> and
4041 <code>IHostFloppyDrive</code>) have been merged into IMedium; CD/DVD
4042 and floppy media no longer need special treatment. The device type
4043 of a medium determines in which context it can be used. Some
4044 functionality was moved to the other storage-related
4045 interfaces.</para>
4046
4047 <para><code>IMachine::attachHardDisk</code> and similar methods have
4048 been renamed and generalized to deal with any type of drive and
4049 medium. <xref linkend="IMachine__attachDevice"
4050 xreflabel="IMachine::attachDevice()" /> is the API method for adding
4051 any drive to a storage controller. The floppy and DVD/CD drives are
4052 no longer handled specially, and that means you can have more than
4053 one of them. As before, drives can only be changed while the VM is
4054 powered off. Mounting (or unmounting) removable media at runtime is
4055 possible with <xref linkend="IMachine__mountMedium"
4056 xreflabel="IMachine::mountMedium()" />.</para>
4057
4058 <para>Newly created virtual machines have no storage controllers
4059 associated with them. Even the IDE Controller needs to be created
4060 explicitly. The floppy controller is now visible as a separate
4061 controller, with a new storage bus type. For each storage bus type
4062 you can query the device types which can be attached, so that it is
4063 not necessary to hardcode any attachment rules.</para>
4064
4065 <para>This required matching changes e.g. in the callback interfaces
4066 (the medium specific change notification was replaced by a generic
4067 medium change notification) and removing associated enums (e.g.
4068 <code>DriveState</code>). In many places the incorrect use of the
4069 plural form "media" was replaced by "medium", to improve
4070 consistency.</para>
4071 </listitem>
4072
4073 <listitem>
4074 <para>Reading the <xref linkend="IMedium__state"
4075 xreflabel="IMedium::state" xrefstyle="" /> attribute no longer
4076 automatically performs an accessibility check; a new method <xref
4077 linkend="IMedium__refreshState"
4078 xreflabel="IMedium::refreshState()" /> does this. The attribute only
4079 returns the state any more.</para>
4080 </listitem>
4081
4082 <listitem>
4083 <para>There were substantial changes related to snapshots, triggered
4084 by the "branched snapshots" functionality introduced with version
4085 3.1. IConsole::discardSnapshot was renamed to <xref
4086 linkend="IConsole__deleteSnapshot"
4087 xreflabel="IConsole::deleteSnapshot()" />.
4088 IConsole::discardCurrentState and
4089 IConsole::discardCurrentSnapshotAndState were removed; corresponding
4090 new functionality is in <xref linkend="IConsole__restoreSnapshot"
4091 xreflabel="IConsole::restoreSnapshot()" />. Also, when <xref
4092 linkend="IConsole__takeSnapshot"
4093 xreflabel="IConsole::takeSnapshot()" /> is called on a running
4094 virtual machine, a live snapshot will be created. The old behavior
4095 was to temporarily pause the virtual machine while creating an
4096 online snapshot.</para>
4097 </listitem>
4098
4099 <listitem>
4100 <para>The <computeroutput>IVRDPServer</computeroutput>,
4101 <computeroutput>IRemoteDisplayInfo"</computeroutput> and
4102 <computeroutput>IConsoleCallback</computeroutput> interfaces were
4103 changed to reflect VRDP server ability to bind to one of available
4104 ports from a list of ports.</para>
4105
4106 <para>The <computeroutput>IVRDPServer::port</computeroutput>
4107 attribute has been replaced with
4108 <computeroutput>IVRDPServer::ports</computeroutput>, which is a
4109 comma-separated list of ports or ranges of ports.</para>
4110
4111 <para>An <computeroutput>IRemoteDisplayInfo::port"</computeroutput>
4112 attribute has been added for querying the actual port VRDP server
4113 listens on.</para>
4114
4115 <para>An IConsoleCallback::onRemoteDisplayInfoChange() notification
4116 callback has been added.</para>
4117 </listitem>
4118
4119 <listitem>
4120 <para>The parameter lists for the following functions were
4121 modified:<itemizedlist>
4122 <listitem>
4123 <para><xref linkend="IHost__removeHostOnlyNetworkInterface"
4124 xreflabel="IHost::removeHostOnlyNetworkInterface()" /></para>
4125 </listitem>
4126
4127 <listitem>
4128 <para><xref linkend="IHost__removeUSBDeviceFilter"
4129 xreflabel="IHost::removeUSBDeviceFilter()" /></para>
4130 </listitem>
4131 </itemizedlist></para>
4132 </listitem>
4133
4134 <listitem>
4135 <para>In the OOWS bindings for JAX-WS, the behavior of structures
4136 changed: for one, we implemented natural structures field access so
4137 you can just call a "get" method to obtain a field. Secondly,
4138 setters in structures were disabled as they have no expected effect
4139 and were at best misleading.</para>
4140 </listitem>
4141 </itemizedlist>
4142 </sect1>
4143
4144 <sect1>
4145 <title>Incompatible API changes with version 3.0</title>
4146
4147 <itemizedlist>
4148 <listitem>
4149 <para>In the object-oriented web service bindings for JAX-WS, proper
4150 inheritance has been introduced for some classes, so explicit
4151 casting is no longer needed to call methods from a parent class. In
4152 particular, IHardDisk and other classes now properly derive from
4153 <xref linkend="IMedium" xreflabel="IMedium" />.</para>
4154 </listitem>
4155
4156 <listitem>
4157 <para>All object identifiers (machines, snapshots, disks, etc)
4158 switched from GUIDs to strings (now still having string
4159 representation of GUIDs inside). As a result, no particular internal
4160 structure can be assumed for object identifiers; instead, they
4161 should be treated as opaque unique handles. This change mostly
4162 affects Java and C++ programs; for other languages, GUIDs are
4163 transparently converted to strings.</para>
4164 </listitem>
4165
4166 <listitem>
4167 <para>The uses of NULL strings have been changed greatly. All out
4168 parameters now use empty strings to signal a null value. For in
4169 parameters both the old NULL and empty string is allowed. This
4170 change was necessary to support more client bindings, especially
4171 using the webservice API. Many of them either have no special NULL
4172 value or have trouble dealing with it correctly in the respective
4173 library code.</para>
4174 </listitem>
4175
4176 <listitem>
4177 <para>Accidentally, the <code>TSBool</code> interface still appeared
4178 in 3.0.0, and was removed in 3.0.2. This is an SDK bug, do not use
4179 the SDK for VirtualBox 3.0.0 for developing clients.</para>
4180 </listitem>
4181
4182 <listitem>
4183 <para>The type of <xref linkend="IVirtualBoxErrorInfo__resultCode"
4184 xreflabel="IVirtualBoxErrorInfo::resultCode" /> changed from
4185 <computeroutput>result</computeroutput> to
4186 <computeroutput>long</computeroutput>.</para>
4187 </listitem>
4188
4189 <listitem>
4190 <para>The parameter list of IVirtualBox::openHardDisk was
4191 changed.</para>
4192 </listitem>
4193
4194 <listitem>
4195 <para>The method IConsole::discardSavedState was renamed to
4196 IConsole::forgetSavedState, and a parameter was added.</para>
4197 </listitem>
4198
4199 <listitem>
4200 <para>The method IConsole::powerDownAsync was renamed to <xref
4201 linkend="IConsole__powerDown" xreflabel="IConsole::powerDown" />,
4202 and the previous method with that name was deleted. So effectively a
4203 parameter was added.</para>
4204 </listitem>
4205
4206 <listitem>
4207 <para>In the <xref linkend="IFramebuffer"
4208 xreflabel="IFramebuffer" /> interface, the following were
4209 removed:<itemizedlist>
4210 <listitem>
4211 <para>the <computeroutput>operationSupported</computeroutput>
4212 attribute;</para>
4213
4214 <para>(as a result, the
4215 <computeroutput>FramebufferAccelerationOperation</computeroutput>
4216 enum was no longer needed and removed as well);</para>
4217 </listitem>
4218
4219 <listitem>
4220 <para>the <computeroutput>solidFill()</computeroutput>
4221 method;</para>
4222 </listitem>
4223
4224 <listitem>
4225 <para>the <computeroutput>copyScreenBits()</computeroutput>
4226 method.</para>
4227 </listitem>
4228 </itemizedlist></para>
4229 </listitem>
4230
4231 <listitem>
4232 <para>In the <xref linkend="IDisplay" xreflabel="IDisplay" />
4233 interface, the following were removed:<itemizedlist>
4234 <listitem>
4235 <para>the
4236 <computeroutput>setupInternalFramebuffer()</computeroutput>
4237 method;</para>
4238 </listitem>
4239
4240 <listitem>
4241 <para>the <computeroutput>lockFramebuffer()</computeroutput>
4242 method;</para>
4243 </listitem>
4244
4245 <listitem>
4246 <para>the <computeroutput>unlockFramebuffer()</computeroutput>
4247 method;</para>
4248 </listitem>
4249
4250 <listitem>
4251 <para>the
4252 <computeroutput>registerExternalFramebuffer()</computeroutput>
4253 method.</para>
4254 </listitem>
4255 </itemizedlist></para>
4256 </listitem>
4257 </itemizedlist>
4258 </sect1>
4259
4260 <sect1>
4261 <title>Incompatible API changes with version 2.2</title>
4262
4263 <itemizedlist>
4264 <listitem>
4265 <para>Added explicit version number into JAX-WS Java package names,
4266 such as <computeroutput>org.virtualbox_2_2</computeroutput>,
4267 allowing connect to multiple VirtualBox clients from single Java
4268 application.</para>
4269 </listitem>
4270
4271 <listitem>
4272 <para>The interfaces having a "2" suffix attached to them with
4273 version 2.1 were renamed again to have that suffix removed. This
4274 time around, this change involves only the name, there are no
4275 functional differences.</para>
4276
4277 <para>As a result, IDVDImage2 is now IDVDImage; IHardDisk2 is now
4278 IHardDisk; IHardDisk2Attachment is now IHardDiskAttachment.</para>
4279
4280 <para>Consequentially, all related methods and attributes that had a
4281 "2" suffix have been renamed; for example, IMachine::attachHardDisk2
4282 now becomes IMachine::attachHardDisk().</para>
4283 </listitem>
4284
4285 <listitem>
4286 <para>IVirtualBox::openHardDisk has an extra parameter for opening a
4287 disk read/write or read-only.</para>
4288 </listitem>
4289
4290 <listitem>
4291 <para>The remaining collections were replaced by more performant
4292 safe-arrays. This affects the following collections:</para>
4293
4294 <itemizedlist>
4295 <listitem>
4296 <para>IGuestOSTypeCollection</para>
4297 </listitem>
4298
4299 <listitem>
4300 <para>IHostDVDDriveCollection</para>
4301 </listitem>
4302
4303 <listitem>
4304 <para>IHostFloppyDriveCollection</para>
4305 </listitem>
4306
4307 <listitem>
4308 <para>IHostUSBDeviceCollection</para>
4309 </listitem>
4310
4311 <listitem>
4312 <para>IHostUSBDeviceFilterCollection</para>
4313 </listitem>
4314
4315 <listitem>
4316 <para>IProgressCollection</para>
4317 </listitem>
4318
4319 <listitem>
4320 <para>ISharedFolderCollection</para>
4321 </listitem>
4322
4323 <listitem>
4324 <para>ISnapshotCollection</para>
4325 </listitem>
4326
4327 <listitem>
4328 <para>IUSBDeviceCollection</para>
4329 </listitem>
4330
4331 <listitem>
4332 <para>IUSBDeviceFilterCollection</para>
4333 </listitem>
4334 </itemizedlist>
4335 </listitem>
4336
4337 <listitem>
4338 <para>Since "Host Interface Networking" was renamed to "bridged
4339 networking" and host-only networking was introduced, all associated
4340 interfaces needed renaming as well. In detail:</para>
4341
4342 <itemizedlist>
4343 <listitem>
4344 <para>The HostNetworkInterfaceType enum has been renamed to
4345 <xref linkend="HostNetworkInterfaceMediumType"
4346 xreflabel="HostNetworkInterfaceMediumType" /></para>
4347 </listitem>
4348
4349 <listitem>
4350 <para>The IHostNetworkInterface::type attribute has been renamed
4351 to <xref linkend="IHostNetworkInterface__mediumType"
4352 xreflabel="IHostNetworkInterface::mediumType" /></para>
4353 </listitem>
4354
4355 <listitem>
4356 <para>INetworkAdapter::attachToHostInterface() has been renamed
4357 to INetworkAdapter::attachToBridgedInterface</para>
4358 </listitem>
4359
4360 <listitem>
4361 <para>In the IHost interface, createHostNetworkInterface() has
4362 been renamed to <xref
4363 linkend="IHost__createHostOnlyNetworkInterface"
4364 xreflabel="createHostOnlyNetworkInterface()" /></para>
4365 </listitem>
4366
4367 <listitem>
4368 <para>Similarly, removeHostNetworkInterface() has been renamed
4369 to <xref linkend="IHost__removeHostOnlyNetworkInterface"
4370 xreflabel="removeHostOnlyNetworkInterface()" /></para>
4371 </listitem>
4372 </itemizedlist>
4373 </listitem>
4374 </itemizedlist>
4375 </sect1>
4376
4377 <sect1>
4378 <title>Incompatible API changes with version 2.1</title>
4379
4380 <itemizedlist>
4381 <listitem>
4382 <para>With VirtualBox 2.1, error codes were added to many error
4383 infos that give the caller a machine-readable (numeric) feedback in
4384 addition to the error string that has always been available. This is
4385 an ongoing process, and future versions of this SDK reference will
4386 document the error codes for each method call.</para>
4387 </listitem>
4388
4389 <listitem>
4390 <para>The hard disk and other media interfaces were completely
4391 redesigned. This was necessary to account for the support of VMDK,
4392 VHD and other image types; since backwards compatibility had to be
4393 broken anyway, we seized the moment to redesign the interfaces in a
4394 more logical way.</para>
4395
4396 <itemizedlist>
4397 <listitem>
4398 <para>Previously, the old IHardDisk interface had several
4399 derivatives called IVirtualDiskImage, IVMDKImage, IVHDImage,
4400 IISCSIHardDisk and ICustomHardDisk for the various disk formats
4401 supported by VirtualBox. The new IHardDisk2 interface that comes
4402 with version 2.1 now supports all hard disk image formats
4403 itself.</para>
4404 </listitem>
4405
4406 <listitem>
4407 <para>IHardDiskFormat is a new interface to describe the
4408 available back-ends for hard disk images (e.g. VDI, VMDK, VHD or
4409 iSCSI). The IHardDisk2::format attribute can be used to find out
4410 the back-end that is in use for a particular hard disk image.
4411 ISystemProperties::hardDiskFormats[] contains a list of all
4412 back-ends supported by the system. <xref
4413 linkend="ISystemProperties__defaultHardDiskFormat"
4414 xreflabel="ISystemProperties::defaultHardDiskFormat" /> contains
4415 the default system format.</para>
4416 </listitem>
4417
4418 <listitem>
4419 <para>In addition, the new <xref linkend="IMedium"
4420 xreflabel="IMedium" /> interface is a generic interface for hard
4421 disk, DVD and floppy images that contains the attributes and
4422 methods shared between them. It can be considered a parent class
4423 of the more specific interfaces for those images, which are now
4424 IHardDisk2, IDVDImage2 and IFloppyImage2.</para>
4425
4426 <para>In each case, the "2" versions of these interfaces replace
4427 the earlier versions that did not have the "2" suffix.
4428 Previously, the IDVDImage and IFloppyImage interfaces were
4429 entirely unrelated to IHardDisk.</para>
4430 </listitem>
4431
4432 <listitem>
4433 <para>As a result, all parts of the API that previously
4434 referenced IHardDisk, IDVDImage or IFloppyImage or any of the
4435 old subclasses are gone and will have replacements that use
4436 IHardDisk2, IDVDImage2 and IFloppyImage2; see, for example,
4437 IMachine::attachHardDisk2.</para>
4438 </listitem>
4439
4440 <listitem>
4441 <para>In particular, the IVirtualBox::hardDisks2 array replaces
4442 the earlier IVirtualBox::hardDisks collection.</para>
4443 </listitem>
4444 </itemizedlist>
4445 </listitem>
4446
4447 <listitem>
4448 <para><xref linkend="IGuestOSType" xreflabel="IGuestOSType" /> was
4449 extended to group operating systems into families and for 64-bit
4450 support.</para>
4451 </listitem>
4452
4453 <listitem>
4454 <para>The <xref linkend="IHostNetworkInterface"
4455 xreflabel="IHostNetworkInterface" /> interface was completely
4456 rewritten to account for the changes in how Host Interface
4457 Networking is now implemented in VirtualBox 2.1.</para>
4458 </listitem>
4459
4460 <listitem>
4461 <para>The IVirtualBox::machines2[] array replaces the former
4462 IVirtualBox::machines collection.</para>
4463 </listitem>
4464
4465 <listitem>
4466 <para>Added <xref linkend="IHost__getProcessorFeature"
4467 xreflabel="IHost::getProcessorFeature()" /> and <xref
4468 linkend="ProcessorFeature" xreflabel="ProcessorFeature" />
4469 enumeration.</para>
4470 </listitem>
4471
4472 <listitem>
4473 <para>The parameter list for <xref
4474 linkend="IVirtualBox__createMachine"
4475 xreflabel="IVirtualBox::createMachine()" /> was modified.</para>
4476 </listitem>
4477
4478 <listitem>
4479 <para>Added IMachine::pushGuestProperty.</para>
4480 </listitem>
4481
4482 <listitem>
4483 <para>New attributes in IMachine: <xref
4484 linkend="IMachine__accelerate3DEnabled"
4485 xreflabel="accelerate3DEnabled" />, HWVirtExVPIDEnabled, <xref
4486 linkend="IMachine__guestPropertyNotificationPatterns"
4487 xreflabel="guestPropertyNotificationPatterns" />, <xref
4488 linkend="IMachine__CPUCount" xreflabel="CPUCount" />.</para>
4489 </listitem>
4490
4491 <listitem>
4492 <para>Added <xref linkend="IConsole__powerUpPaused"
4493 xreflabel="IConsole::powerUpPaused()" /> and <xref
4494 linkend="IConsole__getGuestEnteredACPIMode"
4495 xreflabel="IConsole::getGuestEnteredACPIMode()" />.</para>
4496 </listitem>
4497
4498 <listitem>
4499 <para>Removed ResourceUsage enumeration.</para>
4500 </listitem>
4501 </itemizedlist>
4502 </sect1>
4503 </chapter>
4504</book>
4505<!-- 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