VirtualBox

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

Last change on this file since 35285 was 35217, checked in by vboxsync, 14 years ago

SDKRef: VRDE API changes.

File size: 190.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 authentication
426 modules as laid out in section <emphasis role="bold">VRDE authentication</emphasis>
427 of the VirtualBox User Manual; the web service uses the same kind of modules as the
428 VirtualBox VRDE server. For technical details on VirtualBox external authentication
429 modules see <xref linkend="vbox-auth" /></para>
430
431 <para>By default, after installation, the web service uses the
432 VBoxAuth module that ships with VirtualBox. This module uses PAM on
433 Linux hosts to authenticate users. Any valid username/password
434 combination is accepted, it does not have to be the username and
435 password of the user running the webservice daemon. Unless
436 <computeroutput>vboxwebsrv</computeroutput> runs as root, PAM
437 authentication can fail, because sometimes the file
438 <computeroutput>/etc/shadow</computeroutput>, which is used by PAM, is
439 not readable. On most Linux distribution PAM uses a suid root helper
440 internally, so make sure you test this before deploying it. One can
441 override this behavior by setting the environment variable
442 <computeroutput>VBOX_PAM_ALLOW_INACTIVE</computeroutput> which will
443 suppress failures when unable to read the shadow password file. Please
444 use this variable carefully, and only if you fully understand what
445 you're doing.</para>
446 </sect2>
447
448 <sect2>
449 <title>Solaris host: starting the web service via SMF</title>
450
451 <para>On Solaris hosts, the VirtualBox web service daemon is
452 integrated into the SMF framework. You can change the parameters, but
453 don't have to if the defaults below already match your needs:<screen>svccfg -s svc:/application/virtualbox/webservice:default setprop config/host=localhost
454svccfg -s svc:/application/virtualbox/webservice:default setprop config/port=18083
455svccfg -s svc:/application/virtualbox/webservice:default setprop config/user=root</screen></para>
456
457 <para>If you made any change, don't forget to run the following
458 command to put the changes into effect immediately:<screen>svcadm refresh svc:/application/virtualbox/webservice:default</screen></para>
459
460 <para>If you forget the above command then the previous settings will
461 be used when enabling the service. Check the current property settings
462 with:<screen>svcprop -p config svc:/application/virtualbox/webservice:default</screen></para>
463
464 <para>When everything is configured correctly you can start the
465 VirtualBox webservice with the following command:<screen>svcadm enable svc:/application/virtualbox/webservice:default</screen></para>
466
467 <para>For more information about SMF, please refer to the Solaris
468 documentation.</para>
469 </sect2>
470 </sect1>
471 </chapter>
472
473 <chapter>
474 <title>Environment-specific notes</title>
475
476 <para>The Main API described in <xref linkend="sdkref_classes" /> and
477 <xref linkend="sdkref_enums" /> is mostly identical in all the supported
478 programming environments which have been briefly mentioned in the
479 introduction of this book. As a result, the Main API's general concepts
480 described in <xref linkend="concepts" /> are the same whether you use the
481 object-oriented web service (OOWS) for JAX-WS or a raw web service
482 connection via, say, Perl, or whether you use C++ COM bindings.</para>
483
484 <para>Some things are different depending on your environment, however.
485 These differences are explained in this chapter.</para>
486
487 <sect1 id="glue">
488 <title>Using the object-oriented web service (OOWS)</title>
489
490 <para>As explained in <xref linkend="webservice-or-com" />, VirtualBox
491 ships with client-side libraries for Java, Python and PHP that allow you
492 to use the VirtualBox web service in an intuitive, object-oriented way.
493 These libraries shield you from the client-side complications of managed
494 object references and other implementation details that come with the
495 VirtualBox web service. (If you are interested in these complications,
496 have a look at <xref linkend="raw-webservice" />).</para>
497
498 <para>We recommend that you start your experiments with the VirtualBox
499 web service by using our object-oriented client libraries for JAX-WS, a
500 web service toolkit for Java, which enables you to write code to
501 interact with VirtualBox in the simplest manner possible.</para>
502
503 <para>As "interfaces", "attributes" and "methods" are COM concepts,
504 please read the documentation in <xref linkend="sdkref_classes" /> and
505 <xref linkend="sdkref_enums" /> with the following notes in mind.</para>
506
507 <para>The OOWS bindings attempt to map the Main API as closely as
508 possible to the Java, Python and PHP languages. In other words, objects
509 are objects, interfaces become classes, and you can call methods on
510 objects as you would on local objects.</para>
511
512 <para>The main difference remains with attributes: to read an attribute,
513 call a "getXXX" method, with "XXX" being the attribute name with a
514 capitalized first letter. So when the Main API Reference says that
515 <computeroutput>IMachine</computeroutput> has a "name" attribute (see
516 <xref linkend="IMachine__name" xreflabel="IMachine::name" />), call
517 <computeroutput>getName()</computeroutput> on an IMachine object to
518 obtain a machine's name. Unless the attribute is marked as read-only in
519 the documentation, there will also be a corresponding "set"
520 method.</para>
521
522 <sect2 id="glue-jax-ws">
523 <title>The object-oriented web service for JAX-WS</title>
524
525 <para>JAX-WS is a powerful toolkit by Sun Microsystems to build both
526 server and client code with Java. It is part of Java 6 (JDK 1.6), but
527 can also be obtained separately for Java 5 (JDK 1.5). The VirtualBox
528 SDK comes with precompiled OOWS bindings working with both Java 5 and
529 6.</para>
530
531 <para>The following sections explain how to get the JAX-WS sample code
532 running and explain a few common practices when using the JAX-WS
533 object-oriented web service.</para>
534
535 <sect3>
536 <title>Preparations</title>
537
538 <para>Since JAX-WS is already integrated into Java 6, no additional
539 preparations are needed for Java 6.</para>
540
541 <para>If you are using Java 5 (JDK 1.5.x), you will first need to
542 download and install an external JAX-WS implementation, as Java 5
543 does not support JAX-WS out of the box; for example, you can
544 download one from here: <ulink
545 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>.
546 Then perform the installation (<computeroutput>java -jar
547 JAXWS2.1.4-20080502.jar</computeroutput>).</para>
548 </sect3>
549
550 <sect3>
551 <title>Getting started: running the sample code</title>
552
553 <para>To run the OOWS for JAX-WS samples that we ship with the SDK,
554 perform the following steps: <orderedlist>
555 <listitem>
556 <para>Open a terminal and change to the directory where the
557 JAX-WS samples reside.<footnote>
558 <para>In
559 <computeroutput>sdk/bindings/webservice/java/jax-ws/samples/</computeroutput>.</para>
560 </footnote> Examine the header of
561 <computeroutput>Makefile</computeroutput> to see if the
562 supplied variables (Java compiler, Java executable) and a few
563 other details match your system settings.</para>
564 </listitem>
565
566 <listitem>
567 <para>To start the VirtualBox web service, open a second
568 terminal and change to the directory where the VirtualBox
569 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
570
571 <para>The web service now waits for connections and will run
572 until you press Ctrl+C in this second terminal. The -v
573 argument causes it to log all connections to the terminal.
574 (See <xref linkend="runvboxwebsrv" os="" /> for details on how
575 to run the web service.)</para>
576 </listitem>
577
578 <listitem>
579 <para>Back in the first terminal and still in the samples
580 directory, to start a simple client example just type:<screen>make run16</screen></para>
581
582 <para>if you're on a Java 6 system; on a Java 5 system, run
583 <computeroutput>make run15</computeroutput> instead.</para>
584
585 <para>This should work on all Unix-like systems such as Linux
586 and Solaris. For Windows systems, use commands similar to what
587 is used in the Makefile.</para>
588
589 <para>This will compile the
590 <computeroutput>clienttest.java</computeroutput> code on the
591 first call and then execute the resulting
592 <computeroutput>clienttest</computeroutput> class to show the
593 locally installed VMs (see below).</para>
594 </listitem>
595 </orderedlist></para>
596
597 <para>The <computeroutput>clienttest</computeroutput> sample
598 imitates a few typical command line tasks that
599 <computeroutput>VBoxManage</computeroutput>, VirtualBox's regular
600 command-line front-end, would provide (see the VirtualBox User
601 Manual for details). In particular, you can run:<itemizedlist>
602 <listitem>
603 <para><computeroutput>java clienttest show
604 vms</computeroutput>: show the virtual machines that are
605 registered locally.</para>
606 </listitem>
607
608 <listitem>
609 <para><computeroutput>java clienttest list
610 hostinfo</computeroutput>: show various information about the
611 host this VirtualBox installation runs on.</para>
612 </listitem>
613
614 <listitem>
615 <para><computeroutput>java clienttest startvm
616 &lt;vmname|uuid&gt;</computeroutput>: start the given virtual
617 machine.</para>
618 </listitem>
619 </itemizedlist></para>
620
621 <para>The <computeroutput>clienttest.java</computeroutput> sample
622 code illustrates common basic practices how to use the VirtualBox
623 OOWS for JAX-WS, which we will explain in more detail in the
624 following chapters.</para>
625 </sect3>
626
627 <sect3>
628 <title>Logging on to the web service</title>
629
630 <para>Before a web service client can do anything useful, two
631 objects need to be created, as can be seen in the
632 <computeroutput>clienttest</computeroutput> constructor:<orderedlist>
633 <listitem>
634 <para>An instance of <xref linkend="IWebsessionManager"
635 xreflabel="IWebsessionManager" />, which is an interface
636 provided by the web service to manage "web sessions" -- that
637 is, stateful connections to the web service with persistent
638 objects upon which methods can be invoked.</para>
639
640 <para>In the OOWS for JAX-WS, the IWebsessionManager class
641 must be constructed explicitly, and a URL must be provided in
642 the constructor that specifies where the web service (the
643 server) awaits connections. The code in
644 <computeroutput>clienttest.java</computeroutput> connects to
645 "http://localhost:18083/", which is the default.</para>
646
647 <para>The port number, by default 18083, must match the port
648 number given to the
649 <computeroutput>vboxwebsrv</computeroutput> command line; see
650 <xref linkend="vboxwebsrv-ref" />.</para>
651 </listitem>
652
653 <listitem>
654 <para>After that, the code calls <xref
655 linkend="IWebsessionManager__logon"
656 xreflabel="IWebsessionManager::logon()" />, which is the first
657 call that actually communicates with the server. This
658 authenticates the client with the web service and returns an
659 instance of <xref linkend="IVirtualBox"
660 xreflabel="IVirtualBox" />, the most fundamental interface of
661 the VirtualBox web service, from which all other functionality
662 can be derived.</para>
663
664 <para>If logon doesn't work, please take another look at <xref
665 linkend="websrv_authenticate" />.</para>
666 </listitem>
667 </orderedlist></para>
668 </sect3>
669
670 <sect3>
671 <title>Object management</title>
672
673 <para>The current OOWS for JAX-WS has certain memory management
674 related limitations. When you no longer need an object, call its
675 <xref linkend="IManagedObjectRef__release"
676 xreflabel="IManagedObjectRef::release()" /> method explicitly, which
677 frees appropriate managed reference, as is required by the raw
678 webservice; see <xref linkend="managed-object-references" /> for
679 details. This limitation may be reconsidered in a future version of
680 the VirtualBox SDK.</para>
681 </sect3>
682 </sect2>
683
684 <sect2 id="glue-python-ws">
685 <title>The object-oriented web service for Python</title>
686
687 <para>VirtualBox comes with two flavors of a Python API: one for web
688 service, discussed here, and one for the COM/XPCOM API discussed in
689 <xref linkend="pycom" />. The client code is mostly similar, except
690 for the initialization part, so it is up to the application developer
691 to choose the appropriate technology. Moreover, a common Python glue
692 layer exists, abstracting out concrete platform access details, see
693 <xref linkend="glue-python" />.</para>
694
695 <para>As indicated in <xref linkend="webservice-or-com" />, the
696 COM/XPCOM API gives better performance without the SOAP overhead, and
697 does not require a web server to be running. On the other hand, the
698 COM/XPCOM Python API requires a suitable Python bridge for your Python
699 installation (VirtualBox ships the most important ones for each
700 platform<footnote>
701 <para>On On Mac OS X only the Python versions bundled with the OS
702 are officially supported. This means Python 2.3 for 10.4, Python
703 2.5 for 10.5 and Python 2.5 and 2.6 for 10.6.</para>
704 </footnote>), and you cannot connect to VirtualBox remotely. On
705 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.</para>
710
711 <para>The VirtualBox OOWS for Python relies on the Python ZSI SOAP
712 implementation (see <ulink
713 url="http://pywebsvcs.sourceforge.net/zsi.html">http://pywebsvcs.sourceforge.net/zsi.html</ulink>),
714 which you will need to install locally before trying the examples.
715 Most Linux distributions come with package for ZSI, such as
716 <computeroutput>python-zsi</computeroutput> in Ubuntu.</para>
717
718 <para>To get started, open a terminal and change to the
719 <computeroutput>bindings/glue/python/sample</computeroutput>
720 directory, which contains an example of a simple interactive shell
721 able to control a VirtualBox instance. The shell is written using the
722 API layer, thereby hiding different implementation details, so it is
723 actually an example of code share among XPCOM, MSCOM and web services.
724 If you are interested in how to interact with the webservices layer
725 directly, have a look at
726 <computeroutput>install/vboxapi/__init__.py</computeroutput> which
727 contains the glue layer for all target platforms (i.e. XPCOM, MSCOM
728 and web services).</para>
729
730 <para>To start the shell, perform the following commands: <screen>/opt/VirtualBox/vboxwebsrv -t 0
731 # start webservice with object autocollection disabled
732export VBOX_PROGRAM_PATH=/opt/VirtualBox
733 # your VirtualBox installation directory
734export VBOX_SDK_PATH=/home/youruser/vbox-sdk
735 # where you've extracted the SDK
736./vboxshell.py -w </screen>See <xref linkend="vboxshell" /> for more
737 details on the shell's functionality. For you, as a VirtualBox
738 application developer, the vboxshell sample could be interesting as an
739 example of how to write code targeting both local and remote cases
740 (COM/XPCOM and SOAP). The common part of the shell is the same -- the
741 only difference is how it interacts with the invocation layer. You can
742 use the <computeroutput>connect</computeroutput> shell command to
743 connect to remote VirtualBox servers; in this case you can skip
744 starting the local webserver.</para>
745 </sect2>
746
747 <sect2>
748 <title>The object-oriented web service for PHP</title>
749
750 <para>VirtualBox also comes with object-oriented web service (OOWS)
751 wrappers for PHP5. These wrappers rely on the PHP SOAP
752 Extension<footnote>
753 <para>See <ulink url="???">http://www.php.net/soap</ulink>.</para>
754 </footnote>, which can be installed by configuring PHP with
755 <computeroutput>--enable-soap</computeroutput>.</para>
756 </sect2>
757 </sect1>
758
759 <sect1 id="raw-webservice">
760 <title>Using the raw web service with any language</title>
761
762 <para>The following examples show you how to use the raw web service,
763 without the object-oriented client-side code that was described in the
764 previous chapter.</para>
765
766 <para>Generally, when reading the documentation in <xref
767 linkend="sdkref_classes" /> and <xref linkend="sdkref_enums" />, due to
768 the limitations of SOAP and WSDL lined out in <xref
769 linkend="rawws-conventions" />, please have the following notes in
770 mind:</para>
771
772 <para><orderedlist>
773 <listitem>
774 <para>Any COM method call becomes a <emphasis role="bold">plain
775 function call</emphasis> in the raw web service, with the object
776 as an additional first parameter (before the "real" parameters
777 listed in the documentation). So when the documentation says that
778 the <computeroutput>IVirtualBox</computeroutput> interface
779 supports the <computeroutput>createMachine()</computeroutput>
780 method (see <xref linkend="IVirtualBox__createMachine"
781 xreflabel="IVirtualBox::createMachine()" />), the web service
782 operation is
783 <computeroutput>IVirtualBox_createMachine(...)</computeroutput>,
784 and a managed object reference to an
785 <computeroutput>IVirtualBox</computeroutput> object must be passed
786 as the first argument.</para>
787 </listitem>
788
789 <listitem>
790 <para>For <emphasis role="bold">attributes</emphasis> in
791 interfaces, there will be at least one "get" function; there will
792 also be a "set" function, unless the attribute is "readonly". The
793 attribute name will be appended to the "get" or "set" prefix, with
794 a capitalized first letter. So, the "version" readonly attribute
795 of the <computeroutput>IVirtualBox</computeroutput> interface can
796 be retrieved by calling
797 <computeroutput>IVirtualBox_getVersion(vbox)</computeroutput>,
798 with <computeroutput>vbox</computeroutput> being the VirtualBox
799 object.</para>
800 </listitem>
801
802 <listitem>
803 <para>Whenever the API documentation says that a method (or an
804 attribute getter) returns an <emphasis
805 role="bold">object</emphasis>, it will returned a managed object
806 reference in the web service instead. As said above, managed
807 object references should be released if the web service client
808 does not log off again immediately!</para>
809 </listitem>
810 </orderedlist></para>
811
812 <para></para>
813
814 <sect2 id="webservice-java-sample">
815 <title>Raw web service example for Java with Axis</title>
816
817 <para>Axis is an older web service toolkit created by the Apache
818 foundation. If your distribution does not have it installed, you can
819 get a binary from <ulink
820 url="http://www.apache.org">http://www.apache.org</ulink>. The
821 following examples assume that you have Axis 1.4 installed.</para>
822
823 <para>The VirtualBox SDK ships with an example for Axis that, again,
824 is called <computeroutput>clienttest.java</computeroutput> and that
825 imitates a few of the commands of
826 <computeroutput>VBoxManage</computeroutput> over the wire.</para>
827
828 <para>Then perform the following steps:<orderedlist>
829 <listitem>
830 <para>Create a working directory somewhere. Under your
831 VirtualBox installation directory, find the
832 <computeroutput>sdk/webservice/samples/java/axis/</computeroutput>
833 directory and copy the file
834 <computeroutput>clienttest.java</computeroutput> to your working
835 directory.</para>
836 </listitem>
837
838 <listitem>
839 <para>Open a terminal in your working directory. Execute the
840 following command:<screen> java org.apache.axis.wsdl.WSDL2Java /path/to/vboxwebService.wsdl</screen></para>
841
842 <para>The <computeroutput>vboxwebService.wsdl</computeroutput>
843 file should be located in the
844 <computeroutput>sdk/webservice/</computeroutput>
845 directory.</para>
846
847 <para>If this fails, your Apache Axis may not be located on your
848 system classpath, and you may have to adjust the CLASSPATH
849 environment variable. Something like this:<screen>export CLASSPATH="/path-to-axis-1_4/lib/*":$CLASSPATH</screen></para>
850
851 <para>Use the directory where the Axis JAR files are located.
852 Mind the quotes so that your shell passes the "*" character to
853 the java executable without expanding. Alternatively, add a
854 corresponding <computeroutput>-classpath</computeroutput>
855 argument to the "java" call above.</para>
856
857 <para>If the command executes successfully, you should see an
858 "org" directory with subdirectories containing Java source files
859 in your working directory. These classes represent the
860 interfaces that the VirtualBox web service offers, as described
861 by the WSDL file.</para>
862
863 <para>This is the bit that makes using web services so
864 attractive to client developers: if a language's toolkit
865 understands WSDL, it can generate large amounts of support code
866 automatically. Clients can then easily use this support code and
867 can be done with just a few lines of code.</para>
868 </listitem>
869
870 <listitem>
871 <para>Next, compile the
872 <computeroutput>clienttest.java</computeroutput> source:<screen>javac clienttest.java </screen></para>
873
874 <para>This should yield a "clienttest.class" file.</para>
875 </listitem>
876
877 <listitem>
878 <para>To start the VirtualBox web service, open a second
879 terminal and change to the directory where the VirtualBox
880 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
881
882 <para>The web service now waits for connections and will run
883 until you press Ctrl+C in this second terminal. The -v argument
884 causes it to log all connections to the terminal. (See <xref
885 linkend="runvboxwebsrv" os="" /> for details on how to run the
886 web service.)</para>
887 </listitem>
888
889 <listitem>
890 <para>Back in the original terminal where you compiled the Java
891 source, run the resulting binary, which will then connect to the
892 web service:<screen>java clienttest</screen></para>
893
894 <para>The client sample will connect to the web service (on
895 localhost, but the code could be changed to connect remotely if
896 the web service was running on a different machine) and make a
897 number of method calls. It will output the version number of
898 your VirtualBox installation and a list of all virtual machines
899 that are currently registered (with a bit of seemingly random
900 data, which will be explained later).</para>
901 </listitem>
902 </orderedlist></para>
903 </sect2>
904
905 <sect2 id="raw-webservice-perl">
906 <title>Raw web service example for Perl</title>
907
908 <para>We also ship a small sample for Perl. It uses the SOAP::Lite
909 perl module to communicate with the VirtualBox web service.</para>
910
911 <para>The
912 <computeroutput>sdk/bindings/webservice/perl/lib/</computeroutput>
913 directory contains a pre-generated Perl module that allows for
914 communicating with the web service from Perl. You can generate such a
915 module yourself using the "stubmaker" tool that comes with SOAP::Lite,
916 but since that tool is slow as well as sometimes unreliable, we are
917 shipping a working module with the SDK for your convenience.</para>
918
919 <para>Perform the following steps:<orderedlist>
920 <listitem>
921 <para>If SOAP::Lite is not yet installed on your system, you
922 will need to install the package first. On Debian-based systems,
923 the package is called
924 <computeroutput>libsoap-lite-perl</computeroutput>; on Gentoo,
925 it's <computeroutput>dev-perl/SOAP-Lite</computeroutput>.</para>
926 </listitem>
927
928 <listitem>
929 <para>Open a terminal in the
930 <computeroutput>sdk/bindings/webservice/perl/samples/</computeroutput>
931 directory.</para>
932 </listitem>
933
934 <listitem>
935 <para>To start the VirtualBox web service, open a second
936 terminal and change to the directory where the VirtualBox
937 executables are located. Then type:<screen>./vboxwebsrv -v</screen></para>
938
939 <para>The web service now waits for connections and will run
940 until you press Ctrl+C in this second terminal. The -v argument
941 causes it to log all connections to the terminal. (See <xref
942 linkend="runvboxwebsrv" os="" /> for details on how to run the
943 web service.)</para>
944 </listitem>
945
946 <listitem>
947 <para>In the first terminal with the Perl sample, run the
948 clienttest.pl script:<screen>perl -I ../lib clienttest.pl</screen></para>
949 </listitem>
950 </orderedlist></para>
951 </sect2>
952
953 <sect2>
954 <title>Programming considerations for the raw web service</title>
955
956 <para>If you use the raw web service, you need to keep a number of
957 things in mind, or you will sooner or later run into issues that are
958 not immediately obvious. By contrast, the object-oriented client-side
959 libraries described in <xref linkend="glue" /> take care of these
960 things automatically and thus greatly simplify using the web
961 service.</para>
962
963 <sect3 id="rawws-conventions">
964 <title>Fundamental conventions</title>
965
966 <para>If you are familiar with other web services, you may find the
967 VirtualBox web service to behave a bit differently to accommodate
968 for the fact that VirtualBox web service more or less maps the
969 VirtualBox Main COM API. The following main differences had to be
970 taken care of:<itemizedlist>
971 <listitem>
972 <para>Web services, as expressed by WSDL, are not
973 object-oriented. Even worse, they are normally stateless (or,
974 in web services terminology, "loosely coupled"). Web service
975 operations are entirely procedural, and one cannot normally
976 make assumptions about the state of a web service between
977 function calls.</para>
978
979 <para>In particular, this normally means that you cannot work
980 on objects in one method call that were created by another
981 call.</para>
982 </listitem>
983
984 <listitem>
985 <para>By contrast, the VirtualBox Main API, being expressed in
986 COM, is object-oriented and works entirely on objects, which
987 are grouped into public interfaces, which in turn have
988 attributes and methods associated with them.</para>
989 </listitem>
990 </itemizedlist> For the VirtualBox web service, this results in
991 three fundamental conventions:<orderedlist>
992 <listitem>
993 <para>All <emphasis role="bold">function names</emphasis> in
994 the VirtualBox web service consist of an interface name and a
995 method name, joined together by an underscore. This is because
996 there are only functions ("operations") in WSDL, but no
997 classes, interfaces, or methods.</para>
998
999 <para>In addition, all calls to the VirtualBox web service
1000 (except for logon, see below) take a <emphasis
1001 role="bold">managed object reference</emphasis> as the first
1002 argument, representing the object upon which the underlying
1003 method is invoked. (Managed object references are explained in
1004 detail below; see <xref
1005 linkend="managed-object-references" />.)</para>
1006
1007 <para>So, when one would normally code, in the pseudo-code of
1008 an object-oriented language, to invoke a method upon an
1009 object:<screen>IMachine machine;
1010result = machine.getName();</screen></para>
1011
1012 <para>In the VirtualBox web service, this looks something like
1013 this (again, pseudo-code):<screen>IMachineRef machine;
1014result = IMachine_getName(machine);</screen></para>
1015 </listitem>
1016
1017 <listitem>
1018 <para>To make the web service stateful, and objects persistent
1019 between method calls, the VirtualBox web service introduces a
1020 <emphasis role="bold">session manager</emphasis> (by way of
1021 the <xref linkend="IWebsessionManager"
1022 xreflabel="IWebsessionManager" /> interface), which manages
1023 object references. Any client wishing to interact with the web
1024 service must first log on to the session manager and in turn
1025 receives a managed object reference to an object that supports
1026 the <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />
1027 interface (the basic interface in the Main API).</para>
1028 </listitem>
1029 </orderedlist></para>
1030
1031 <para>In other words, as opposed to other web services, <emphasis
1032 role="bold">the VirtualBox web service is both object-oriented and
1033 stateful.</emphasis></para>
1034 </sect3>
1035
1036 <sect3>
1037 <title>Example: A typical web service client session</title>
1038
1039 <para>A typical short web service session to retrieve the version
1040 number of the VirtualBox web service (to be precise, the underlying
1041 Main API version number) looks like this:<orderedlist>
1042 <listitem>
1043 <para>A client logs on to the web service by calling <xref
1044 linkend="IWebsessionManager__logon"
1045 xreflabel="IWebsessionManager::logon()" /> with a valid user
1046 name and password. See <xref linkend="websrv_authenticate" />
1047 for details about how authentication works.</para>
1048 </listitem>
1049
1050 <listitem>
1051 <para>On the server side,
1052 <computeroutput>vboxwebsrv</computeroutput> creates a session,
1053 which persists until the client calls <xref
1054 linkend="IWebsessionManager__logoff"
1055 xreflabel="IWebsessionManager::logoff()" /> or the session
1056 times out after a configurable period of inactivity (see <xref
1057 linkend="vboxwebsrv-ref" />).</para>
1058
1059 <para>For the new session, the web service creates an instance
1060 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" />.
1061 This interface is the most central one in the Main API and
1062 allows access to all other interfaces, either through
1063 attributes or method calls. For example, IVirtualBox contains
1064 a list of all virtual machines that are currently registered
1065 (as they would be listed on the left side of the VirtualBox
1066 main program).</para>
1067
1068 <para>The web service then creates a managed object reference
1069 for this instance of IVirtualBox and returns it to the calling
1070 client, which receives it as the return value of the logon
1071 call. Something like this:</para>
1072
1073 <screen>string oVirtualBox;
1074oVirtualBox = webservice.IWebsessionManager_logon("user", "pass");</screen>
1075
1076 <para>(The managed object reference "oVirtualBox" is just a
1077 string consisting of digits and dashes. However, it is a
1078 string with a meaning and will be checked by the web service.
1079 For details, see below. As hinted above, <xref
1080 linkend="IWebsessionManager__logon"
1081 xreflabel="IWebsessionManager::logon()" /> is the
1082 <emphasis>only</emphasis> operation provided by the web
1083 service which does not take a managed object reference as the
1084 first argument!)</para>
1085 </listitem>
1086
1087 <listitem>
1088 <para>The VirtualBox Main API documentation says that the
1089 <computeroutput>IVirtualBox</computeroutput> interface has a
1090 <xref linkend="IVirtualBox__version" xreflabel="version" />
1091 attribute, which is a string. For each attribute, there is a
1092 "get" and a "set" method in COM, which maps to according
1093 operations in the web service. So, to retrieve the "version"
1094 attribute of this <computeroutput>IVirtualBox</computeroutput>
1095 object, the web service client does this:<screen>string version;
1096version = webservice.IVirtualBox_getVersion(oVirtualBox);
1097
1098print version;</screen></para>
1099
1100 <para>And it will print
1101 "$VBOX_VERSION_MAJOR.$VBOX_VERSION_MINOR.$VBOX_VERSION_BUILD".</para>
1102 </listitem>
1103
1104 <listitem>
1105 <para>The web service client calls <xref
1106 linkend="IWebsessionManager__logoff"
1107 xreflabel="IWebsessionManager::logoff()" /> with the
1108 VirtualBox managed object reference. This will clean up all
1109 allocated resources.</para>
1110 </listitem>
1111 </orderedlist></para>
1112 </sect3>
1113
1114 <sect3 id="managed-object-references">
1115 <title>Managed object references</title>
1116
1117 <para>To a web service client, a managed object reference looks like
1118 a string: two 64-bit hex numbers separated by a dash. This string,
1119 however, represents a COM object that "lives" in the web service
1120 process. The two 64-bit numbers encoded in the managed object
1121 reference represent a session ID (which is the same for all objects
1122 in the same web service session, i.e. for all objects after one
1123 logon) and a unique object ID within that session.</para>
1124
1125 <para>Managed object references are created in two
1126 situations:<orderedlist>
1127 <listitem>
1128 <para>When a client logs on, by calling <xref
1129 linkend="IWebsessionManager__logon"
1130 xreflabel="IWebsessionManager::logon()" />.</para>
1131
1132 <para>Upon logon, the websession manager creates one instance
1133 of <xref linkend="IVirtualBox" xreflabel="IVirtualBox" /> and
1134 another object of <xref linkend="ISession"
1135 xreflabel="ISession" /> representing the web service session.
1136 This can be retrieved using <xref
1137 linkend="IWebsessionManager__getSessionObject"
1138 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
1139
1140 <para>(Technically, there is always only one <xref
1141 linkend="IVirtualBox" xreflabel="IVirtualBox" /> object, which
1142 is shared between all sessions and clients, as it is a COM
1143 singleton. However, each session receives its own managed
1144 object reference to it. The <xref linkend="ISession"
1145 xreflabel="ISession" /> object, however, is created and
1146 destroyed for each session.)</para>
1147 </listitem>
1148
1149 <listitem>
1150 <para>Whenever a web service clients invokes an operation
1151 whose COM implementation creates COM objects.</para>
1152
1153 <para>For example, <xref linkend="IVirtualBox__createMachine"
1154 xreflabel="IVirtualBox::createMachine()" /> creates a new
1155 instance of <xref linkend="IMachine" xreflabel="IMachine" />;
1156 the COM object returned by the COM method call is then wrapped
1157 into a managed object reference by the web server, and this
1158 reference is returned to the web service client.</para>
1159 </listitem>
1160 </orderedlist></para>
1161
1162 <para>Internally, in the web service process, each managed object
1163 reference is simply a small data structure, containing a COM pointer
1164 to the "real" COM object, the web session ID and the object ID. This
1165 structure is allocated on creation and stored efficiently in hashes,
1166 so that the web service can look up the COM object quickly whenever
1167 a web service client wishes to make a method call. The random
1168 session ID also ensures that one web service client cannot intercept
1169 the objects of another.</para>
1170
1171 <para>Managed object references are not destroyed automatically and
1172 must be released by explicitly calling <xref
1173 linkend="IManagedObjectRef__release"
1174 xreflabel="IManagedObjectRef::release()" />. This is important, as
1175 otherwise hundreds or thousands of managed object references (and
1176 corresponding COM objects, which can consume much more memory!) can
1177 pile up in the web service process and eventually cause it to deny
1178 service.</para>
1179
1180 <para>To reiterate: The underlying COM object, which the reference
1181 points to, is only freed if the managed object reference is
1182 released. It is therefore vital that web service clients properly
1183 clean up after the managed object references that are returned to
1184 them.</para>
1185
1186 <para>When a web service client calls <xref
1187 linkend="IWebsessionManager__logoff"
1188 xreflabel="IWebsessionManager::logoff()" />, all managed object
1189 references created during the session are automatically freed. For
1190 short-lived sessions that do not create a lot of objects, logging
1191 off may therefore be sufficient, although it is certainly not "best
1192 practice".</para>
1193 </sect3>
1194
1195 <sect3>
1196 <title>Some more detail about web service operation</title>
1197
1198 <sect4 id="soap">
1199 <title>SOAP messages</title>
1200
1201 <para>Whenever a client makes a call to a web service, this
1202 involves a complicated procedure internally. These calls are
1203 remote procedure calls. Each such procedure call typically
1204 consists of two "message" being passed, where each message is a
1205 plain-text HTTP request with a standard HTTP header and a special
1206 XML document following. This XML document encodes the name of the
1207 procedure to call and the argument names and values passed to
1208 it.</para>
1209
1210 <para>To give you an idea of what such a message looks like,
1211 assuming that a web service provides a procedure called
1212 "SayHello", which takes a string "name" as an argument and returns
1213 "Hello" with a space and that name appended, the request message
1214 could look like this:</para>
1215
1216 <para><screen>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
1217&lt;SOAP-ENV:Envelope
1218 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
1219 xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
1220 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1221 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1222 xmlns:test="http://test/"&gt;
1223&lt;SOAP-ENV:Body&gt;
1224 &lt;test:SayHello&gt;
1225 &lt;name&gt;Peter&lt;/name&gt;
1226 &lt;/test:SayHello&gt;
1227 &lt;/SOAP-ENV:Body&gt;
1228&lt;/SOAP-ENV:Envelope&gt;</screen>A similar message -- the "response" message
1229 -- would be sent back from the web service to the client,
1230 containing the return value "Hello Peter".</para>
1231
1232 <para>Most programming languages provide automatic support to
1233 generate such messages whenever code in that programming language
1234 makes such a request. In other words, these programming languages
1235 allow for writing something like this (in pseudo-C++ code):</para>
1236
1237 <para><screen>webServiceClass service("localhost", 18083); // server and port
1238string result = service.SayHello("Peter"); // invoke remote procedure</screen>and
1239 would, for these two pseudo-lines, automatically perform these
1240 steps:</para>
1241
1242 <para><orderedlist>
1243 <listitem>
1244 <para>prepare a connection to a web service running on port
1245 18083 of "localhost";</para>
1246 </listitem>
1247
1248 <listitem>
1249 <para>for the <computeroutput>SayHello()</computeroutput>
1250 function of the web service, generate a SOAP message like in
1251 the above example by encoding all arguments of the remote
1252 procedure call (which could involve all kinds of type
1253 conversions and complex marshalling for arrays and
1254 structures);</para>
1255 </listitem>
1256
1257 <listitem>
1258 <para>connect to the web service via HTTP and send that
1259 message;</para>
1260 </listitem>
1261
1262 <listitem>
1263 <para>wait for the web service to send a response
1264 message;</para>
1265 </listitem>
1266
1267 <listitem>
1268 <para>decode that response message and put the return value
1269 of the remote procedure into the "result" variable.</para>
1270 </listitem>
1271 </orderedlist></para>
1272 </sect4>
1273
1274 <sect4 id="wsdl">
1275 <title>Service descriptions in WSDL</title>
1276
1277 <para>In the above explanations about SOAP, it was left open how
1278 the programming language learns about how to translate function
1279 calls in its own syntax into proper SOAP messages. In other words,
1280 the programming language needs to know what operations the web
1281 service supports and what types of arguments are required for the
1282 operation's data in order to be able to properly serialize and
1283 deserialize the data to and from the web service. For example, if
1284 a web service operation expects a number in "double" floating
1285 point format for a particular parameter, the programming language
1286 cannot send to it a string instead.</para>
1287
1288 <para>For this, the Web Service Definition Language (WSDL) was
1289 invented, another XML substandard that describes exactly what
1290 operations the web service supports and, for each operation, which
1291 parameters and types are needed with each request and response
1292 message. WSDL descriptions can be incredibly verbose, and one of
1293 the few good things that can be said about this standard is that
1294 it is indeed supported by most programming languages.</para>
1295
1296 <para>So, if it is said that a programming language "supports" web
1297 services, this typically means that a programming language has
1298 support for parsing WSDL files and somehow integrating the remote
1299 procedure calls into the native language syntax -- for example,
1300 like in the Java sample shown in <xref
1301 linkend="webservice-java-sample" />.</para>
1302
1303 <para>For details about how programming languages support web
1304 services, please refer to the documentation that comes with the
1305 individual languages. Here are a few pointers:</para>
1306
1307 <orderedlist>
1308 <listitem>
1309 <para>For <emphasis role="bold">C++,</emphasis> among many
1310 others, the gSOAP toolkit is a good option. Parts of gSOAP are
1311 also used in VirtualBox to implement the VirtualBox web
1312 service.</para>
1313 </listitem>
1314
1315 <listitem>
1316 <para>For <emphasis role="bold">Java,</emphasis> there are
1317 several implementations already described in this document
1318 (see <xref linkend="glue-jax-ws" /> and <xref
1319 linkend="webservice-java-sample" />).</para>
1320 </listitem>
1321
1322 <listitem>
1323 <para><emphasis role="bold">Perl</emphasis> supports WSDL via
1324 the SOAP::Lite package. This in turn comes with a tool called
1325 <computeroutput>stubmaker.pl</computeroutput> that allows you
1326 to turn any WSDL file into a Perl package that you can import.
1327 (You can also import any WSDL file "live" by having it parsed
1328 every time the script runs, but that can take a while.) You
1329 can then code (again, assuming the above example):<screen>my $result = servicename-&gt;sayHello("Peter");</screen></para>
1330
1331 <para>A sample that uses SOAP::Lite was described in <xref
1332 linkend="raw-webservice-perl" />.</para>
1333 </listitem>
1334 </orderedlist>
1335 </sect4>
1336 </sect3>
1337 </sect2>
1338 </sect1>
1339
1340 <sect1 id="api_com">
1341 <title>Using COM/XPCOM directly</title>
1342
1343 <para>If you do not require <emphasis>remote</emphasis> procedure calls
1344 such as those offered by the VirtualBox web service, and if you know
1345 Python or C++ as well as COM, you might find it preferable to program
1346 VirtualBox's Main API directly via COM.</para>
1347
1348 <para>COM stands for "Component Object Model" and is a standard
1349 originally introduced by Microsoft in the 1990s for Microsoft Windows.
1350 It allows for organizing software in an object-oriented way and across
1351 processes; code in one process may access objects that live in another
1352 process.</para>
1353
1354 <para>COM has several advantages: it is language-neutral, meaning that
1355 even though all of VirtualBox is internally written in C++, programs
1356 written in other languages could communicate with it. COM also cleanly
1357 separates interface from implementation, so that external programs need
1358 not know anything about the messy and complicated details of VirtualBox
1359 internals.</para>
1360
1361 <para>On a Windows host, all parts of VirtualBox will use the COM
1362 functionality that is native to Windows. On other hosts (including
1363 Linux), VirtualBox comes with a built-in implementation of XPCOM, as
1364 originally created by the Mozilla project, which we have enhanced to
1365 support interprocess communication on a level comparable to Microsoft
1366 COM. Internally, VirtualBox has an abstraction layer that allows the
1367 same VirtualBox code to work both with native COM as well as our XPCOM
1368 implementation.</para>
1369
1370 <sect2 id="pycom">
1371 <title>Python COM API</title>
1372
1373 <para>On Windows, Python scripts can use COM and VirtualBox interfaces
1374 to control almost all aspects of virtual machine execution. As an
1375 example, use the following commands to instantiate the VirtualBox
1376 object and start a VM: <screen>
1377 vbox = win32com.client.Dispatch("VirtualBox.VirtualBox")
1378 session = win32com.client.Dispatch("VirtualBox.Session")
1379 mach = vbox.findMachine("uuid or name of machine to start")
1380 progress = mach.launchVMProcess(session, "gui", "")
1381 progress.waitForCompletion(-1)
1382 </screen> Also, see
1383 <computeroutput>/bindings/glue/python/samples/vboxshell.py</computeroutput>
1384 for more advanced usage scenarious. However, unless you have specific
1385 requirements, we strongly recommend to use the generic glue layer
1386 described in the next section to access MS COM objects.</para>
1387 </sect2>
1388
1389 <sect2 id="glue-python">
1390 <title>Common Python bindings layer</title>
1391
1392 <para>As different wrappers ultimately provide access to the same
1393 underlying API, and to simplify porting and development of Python
1394 application using the VirtualBox Main API, we developed a common glue
1395 layer that abstracts out most platform-specific details from the
1396 application and allows the developer to focus on application logic.
1397 The VirtualBox installer automatically sets up this glue layer for the
1398 system default Python install. See below for details on how to set up
1399 the glue layer if you want to use a different Python
1400 installation.</para>
1401
1402 <para>In this layer, the class
1403 <computeroutput>VirtualBoxManager</computeroutput> hides most
1404 platform-specific details. It can be used to access both the local
1405 (COM) and the webservice-based API. The following code can be used by
1406 an application to use the glue layer.</para>
1407
1408 <screen># This code assumes vboxapi.py from VirtualBox distribution
1409# being in PYTHONPATH, or installed system-wide
1410from vboxapi import VirtualBoxManager
1411
1412# This code initializes VirtualBox manager with default style
1413# and parameters
1414virtualBoxManager = VirtualBoxManager(None, None)
1415
1416# Alternatively, one can be more verbose, and initialize
1417# glue with webservice backend, and provide authentication
1418# information
1419virtualBoxManager = VirtualBoxManager("WEBSERVICE",
1420 {'url':'http://myhost.com::18083/',
1421 'user':'me',
1422 'password':'secret'}) </screen>
1423
1424 <para>We supply the <computeroutput>VirtualBoxManager</computeroutput>
1425 constructor with 2 arguments: style and parameters. Style defines
1426 which bindings style to use (could be "MSCOM", "XPCOM" or
1427 "WEBSERVICE"), and if set to <computeroutput>None</computeroutput>
1428 defaults to usable platform bindings (MS COM on Windows, XPCOM on
1429 other platforms). The second argument defines parameters, passed to
1430 the platform-specific module, as we do in the second example, where we
1431 pass username and password to be used to authenticate against the web
1432 service.</para>
1433
1434 <para>After obtaining the
1435 <computeroutput>VirtualBoxManager</computeroutput> instance, one can
1436 perform operations on the IVirtualBox class. For example, the
1437 following code will a start virtual machine by name or ID:</para>
1438
1439 <screen>vbox = virtualBoxManager.vbox
1440mgr = virtualBoxManager.mgr
1441print "Version is",vbox.version
1442
1443def machById(id):
1444 mach = None
1445 for m in virtualBoxManager.getArray(vbox, 'machines'):
1446 if m.name == id or mach.id == id:
1447 mach = m
1448 break
1449 return mach
1450
1451name = "Linux"
1452mach = machById(name)
1453if mach is None:
1454 print "cannot find machine",name
1455else:
1456 session = mgr.getSessionObject(vbox)
1457 # one can also start headless session with "headless" instead of "gui"
1458 progress = vb.openRemoteSession(session, mach.id, "gui", "")
1459 progress.waitForCompletion(-1)
1460 session.close()
1461 </screen>
1462
1463 <para>This code also shows 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
1468 (<computeroutput>virtualBoxManager.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="IVirtualBox__openRemoteSession"
1749 xreflabel="IVirtualBox::openRemoteSession" /> 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;OpenRemoteSession(
1756 vbox, /* this */
1757 session, /* arg 1 */
1758 id, /* arg 2 */
1759 sessionType, /* arg 3 */
1760 env, /* arg 4 */
1761 &amp;progress /* Out */
1762);
1763</screen>
1764 </sect3>
1765
1766 <sect3 id="c-attributes">
1767 <title>XPCOM attribute access</title>
1768
1769 <para>A construct similar to calling non-void methods is used to
1770 access object attributes. For each attribute there exists a getter
1771 method, the name of which is composed of
1772 <computeroutput>Get</computeroutput> followed by the capitalized
1773 attribute name. Unless the attribute is read-only, an analogous
1774 <computeroutput>Set</computeroutput> method exists. Let's apply
1775 these rules to read the <xref linkend="IVirtualBox__revision"
1776 xreflabel="IVirtualBox::revision" /> attribute.</para>
1777
1778 <para>Using the <computeroutput>IVirtualBox</computeroutput> handle
1779 <computeroutput>vbox</computeroutput> obtained above, calling its
1780 <computeroutput>GetRevision</computeroutput> method looks like
1781 this:</para>
1782
1783 <screen>PRUint32 rev;
1784
1785rc = vbox-&gt;vtbl-&gt;GetRevision(vbox, &amp;rev);
1786if (NS_SUCCEEDED(rc))
1787{
1788 printf("Revision: %u\n", (unsigned)rev);
1789}
1790</screen>
1791
1792 <para>All objects with their methods and attributes are documented
1793 in <xref linkend="sdkref_classes" />.</para>
1794 </sect3>
1795
1796 <sect3 id="c-string-handling">
1797 <title>String handling</title>
1798
1799 <para>When dealing with strings you have to be aware of a string's
1800 encoding and ownership.</para>
1801
1802 <para>Internally, XPCOM uses UTF-16 encoded strings. A set of
1803 conversion functions is provided to convert other encodings to and
1804 from UTF-16. The type of a UTF-16 character is
1805 <computeroutput>PRUnichar</computeroutput>. Strings of UTF-16
1806 characters are arrays of that type. Most string handling functions
1807 take pointers to that type. Prototypes for the following conversion
1808 functions are declared in
1809 <computeroutput>VBoxCAPI_v2_5.h</computeroutput>.</para>
1810
1811 <sect4>
1812 <title>Conversion of UTF-16 to and from UTF-8</title>
1813
1814 <screen>int (*pfnUtf16ToUtf8)(const PRUnichar *pwszString, char **ppszString);
1815int (*pfnUtf8ToUtf16)(const char *pszString, PRUnichar **ppwszString);
1816</screen>
1817 </sect4>
1818
1819 <sect4>
1820 <title>Ownership</title>
1821
1822 <para>The ownership of a string determines who is responsible for
1823 releasing resources associated with the string. Whenever XPCOM
1824 creates a string, ownership is transferred to the caller. To avoid
1825 resource leaks, the caller should release resources once the
1826 string is no longer needed.</para>
1827 </sect4>
1828 </sect3>
1829
1830 <sect3 id="c-uninitialization">
1831 <title>XPCOM uninitialization</title>
1832
1833 <para>Uninitialization is performed by
1834 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize().</computeroutput>
1835 If your program can exit from more than one place, it is a good idea
1836 to install this function as an exit handler with Standard C's
1837 <computeroutput>atexit()</computeroutput> just after calling
1838 <computeroutput>g_pVBoxFuncs-&gt;pfnComInitialize()</computeroutput>
1839 , e.g. <screen>#include &lt;stdlib.h&gt;
1840#include &lt;stdio.h&gt;
1841
1842...
1843
1844/*
1845 * Make sure g_pVBoxFuncs-&gt;pfnComUninitialize() is called at exit, no
1846 * matter if we return from the initial call to main or call exit()
1847 * somewhere else. Note that atexit registered functions are not
1848 * called upon abnormal termination, i.e. when calling abort() or
1849 * signal(). Separate provisions must be taken for these cases.
1850 */
1851
1852if (atexit(g_pVBoxFuncs-&gt;pfnComUninitialize()) != 0) {
1853 fprintf(stderr, "failed to register g_pVBoxFuncs-&gt;pfnComUninitialize()\n");
1854 exit(EXIT_FAILURE);
1855}
1856</screen></para>
1857
1858 <para>Another idea would be to write your own <computeroutput>void
1859 myexit(int status)</computeroutput> function, calling
1860 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1861 followed by the real <computeroutput>exit()</computeroutput>, and
1862 use it instead of <computeroutput>exit()</computeroutput> throughout
1863 your program and at the end of
1864 <computeroutput>main.</computeroutput></para>
1865
1866 <para>If you expect the program to be terminated by a signal (e.g.
1867 user types CTRL-C sending SIGINT) you might want to install a signal
1868 handler setting a flag noting that a signal was sent and then
1869 calling
1870 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1871 later on (usually <emphasis>not</emphasis> from the handler itself
1872 .)</para>
1873
1874 <para>That said, if a client program forgets to call
1875 <computeroutput>g_pVBoxFuncs-&gt;pfnComUninitialize()</computeroutput>
1876 before it terminates, there is a mechanism in place which will
1877 eventually release references held by the client. You should not
1878 rely on this, however.</para>
1879 </sect3>
1880
1881 <sect3 id="c-linking">
1882 <title>Compiling and linking</title>
1883
1884 <para>A program using the C binding has to open the library during
1885 runtime using the help of glue code provided and as shown in the
1886 example <computeroutput>tstXPCOMCGlue.c</computeroutput>.
1887 Compilation and linking can be achieved, e.g., with a makefile
1888 fragment similar to</para>
1889
1890 <screen># Where is the XPCOM include directory?
1891INCS_XPCOM = -I../../include
1892# Where is the glue code directory?
1893GLUE_DIR = ..
1894GLUE_INC = -I..
1895
1896#Compile Glue Library
1897VBoxXPCOMCGlue.o: $(GLUE_DIR)/VBoxXPCOMCGlue.c
1898 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $&lt;
1899
1900# Compile.
1901program.o: program.c VBoxCAPI_v2_5.h
1902 $(CC) $(CFLAGS) $(INCS_XPCOM) $(GLUE_INC) -o $@ -c $&lt;
1903
1904# Link.
1905program: program.o VBoxXPCOMCGlue.o
1906 $(CC) -o $@ $^ -ldl</screen>
1907 </sect3>
1908 </sect2>
1909 </sect1>
1910 </chapter>
1911
1912 <chapter id="concepts">
1913 <title>Basic VirtualBox concepts; some examples</title>
1914
1915 <para>The following explains some basic VirtualBox concepts such as the
1916 VirtualBox object, sessions and how virtual machines are manipulated and
1917 launched using the Main API. The coding examples use a pseudo-code style
1918 closely related to the object-oriented web service (OOWS) for JAX-WS.
1919 Depending on which environment you are using, you will need to adjust the
1920 examples.</para>
1921
1922 <sect1>
1923 <title>Obtaining basic machine information. Reading attributes</title>
1924
1925 <para>Any program using the Main API will first need access to the
1926 global VirtualBox object (see <xref linkend="IVirtualBox"
1927 xreflabel="IVirtualBox" />), from which all other functionality of the
1928 API is derived. With the OOWS for JAX-WS, this is returned from the
1929 <xref linkend="IWebsessionManager__logon"
1930 xreflabel="IWebsessionManager::logon()" /> call.</para>
1931
1932 <para>To enumerate virtual machines, one would look at the "machines"
1933 array attribute in the VirtualBox object (see <xref
1934 linkend="IVirtualBox__machines" xreflabel="IVirtualBox::machines" />).
1935 This array contains all virtual machines currently registered with the
1936 host, each of them being an instance of <xref linkend="IMachine"
1937 xreflabel="IMachine" />. From each such instance, one can query
1938 additional information, such as the UUID, the name, memory, operating
1939 system and more by looking at the attributes; see the attributes list in
1940 <xref linkend="IMachine" xreflabel="IMachine documentation" />.</para>
1941
1942 <para>As mentioned in the preceding chapters, depending on your
1943 programming environment, attributes are mapped to corresponding "get"
1944 and (if the attribute is not read-only) "set" methods. So when the
1945 documentation says that IMachine has a "<xref linkend="IMachine__name"
1946 xreflabel="name" />" attribute, this means you need to code something
1947 like the following to get the machine's name:<screen>IMachine machine = ...;
1948String name = machine.getName();</screen>Boolean attribute getters can
1949 sometimes be called <computeroutput>isAttribute()</computeroutput> due
1950 to JAX-WS naming conventions.</para>
1951 </sect1>
1952
1953 <sect1>
1954 <title>Changing machine settings. Sessions</title>
1955
1956 <para>As said in the previous section, to read a machine's attribute,
1957 one invokes the corresponding "get" method. One would think that to
1958 change settings of a machine, it would suffice to call the corresponding
1959 "set" method -- for example, to set a VM's memory to 1024 MB, one would
1960 call <computeroutput>setMemorySize(1024)</computeroutput>. Try that, and
1961 you will get an error: "The machine is not mutable."</para>
1962
1963 <para>So unfortunately, things are not that easy. VirtualBox is a
1964 complicated environment in which multiple processes compete for possibly
1965 the same resources, especially machine settings. As a result, machines
1966 must be "locked" before they can either be modified or started. This is
1967 to prevent multiple processes from making conflicting changes to a
1968 machine: it should, for example, not be allowed to change the memory
1969 size of a virtual machine while it is running. (You can't add more
1970 memory to a real computer while it is running either, at least not to an
1971 ordinary PC.) Also, two processes must not change settings at the same
1972 time, or start a machine at the same time.</para>
1973
1974 <para>These requirements are implemented in the Main API by way of
1975 "sessions", in particular, the <xref linkend="ISession"
1976 xreflabel="ISession" /> interface. Each process which talks to
1977 VirtualBox needs its own instance of ISession. In the web service, you
1978 cannot create such an object, but
1979 <computeroutput>vboxwebsrv</computeroutput> creates one for you when you
1980 log on, which you can obtain by calling <xref
1981 linkend="IWebsessionManager__getSessionObject"
1982 xreflabel="IWebsessionManager::getSessionObject()" />.</para>
1983
1984 <para>This session object must then be used like a mutex semaphore in
1985 common programming environments. Before you can change machine settings,
1986 you must write-lock the machine by calling <xref
1987 linkend="IMachine__lockMachine" xreflabel="IMachine::lockMachine()" />
1988 with your process's session object.</para>
1989
1990 <para>After the machine has been locked, the <xref
1991 linkend="ISession__machine" xreflabel="ISession::machine" /> attribute
1992 contains a copy of the original IMachine object upon which the session
1993 was opened, but this copy is "mutable": you can invoke "set" methods on
1994 it.</para>
1995
1996 <para>When done making the changes to the machine, you must call <xref
1997 linkend="IMachine__saveSettings"
1998 xreflabel="IMachine::saveSettings()" />, which will copy the changes you
1999 have made from your "mutable" machine back to the real machine and write
2000 them out to the machine settings XML file. This will make your changes
2001 permanent.</para>
2002
2003 <para>Finally, it is important to always unlock the machine again, by
2004 calling <xref linkend="ISession__unlockMachine"
2005 xreflabel="ISession::unlockMachine()" />. Otherwise, when the calling
2006 process end, the machine will receive the "aborted" state, which can
2007 lead to loss of data.</para>
2008
2009 <para>So, as an example, the sequence to change a machine's memory to
2010 1024 MB is something like this:<screen>IWebsessionManager mgr ...;
2011IVirtualBox vbox = mgr.logon(user, pass);
2012...
2013IMachine machine = ...; // read-only machine
2014ISession session = mgr.getSessionObject();
2015machine.lockMachine(session, LockType.Write); // machine is now locked for writing
2016IMachine mutable = session.getMachine(); // obtain the mutable machine copy
2017mutable.setMemorySize(1024);
2018mutable.saveSettings(); // write settings to XML
2019session.unlockMachine();</screen></para>
2020 </sect1>
2021
2022 <sect1>
2023 <title>Launching virtual machines</title>
2024
2025 <para>To launch a virtual machine, you call <xref
2026 linkend="IMachine__launchVMProcess"
2027 xreflabel="IMachine::launchVMProcess()" />. In doing so, the caller
2028 instructs the VirtualBox engine to start a new process with the virtual
2029 machine in it, since to the host, each virtual machine looks like a
2030 single process, even if it has hundreds of its own processes inside.
2031 (This new VM process in turn obtains a write lock on the machine, as
2032 described above, to prevent conflicting changes from other processes;
2033 this is why opening another session will fail while the VM is
2034 running.)</para>
2035
2036 <para>Starting a machine looks something like this:<screen>IWebsessionManager mgr ...;
2037IVirtualBox vbox = mgr.logon(user, pass);
2038...
2039IMachine machine = ...; // read-only machine
2040ISession session = mgr.getSessionObject();
2041IProgress prog = machine.launchVMProcess(session,
2042 "gui", // session type
2043 ""); // possibly environment setting
2044prog.waitForCompletion(10000); // give the process 10 secs
2045if (prog.getResultCode() != 0) // check success
2046 System.out.println("Cannot launch VM!")</screen></para>
2047
2048 <para>The caller's session object can then be used as a sort of remote
2049 control to the VM process that was launched. It contains a "console"
2050 object (see <xref linkend="ISession__console"
2051 xreflabel="ISession::console" />) with which the VM can be paused,
2052 stopped, snapshotted or other things.</para>
2053 </sect1>
2054
2055 <sect1>
2056 <title>VirtualBox events</title>
2057
2058 <para>In VirtualBox, "events" provide a uniform mechanism to register
2059 for and consume specific events. A VirtualBox client can register an
2060 "event listener" (represented by the <xref linkend="IEventListener"
2061 xreflabel="IEventListener" /> interface), which will then get notified
2062 by the server when an event (represented by the <xref linkend="IEvent"
2063 xreflabel="IEvent" /> interface) happens.</para>
2064
2065 <para>The IEvent interface is an abstract parent interface for all
2066 events that can occur in VirtualBox. The actual events that the server
2067 sends out are then of one of the specific subclasses, for example <xref
2068 linkend="IMachineStateChangedEvent"
2069 xreflabel="IMachineStateChangedEvent" /> or <xref
2070 linkend="IMediumChangedEvent" xreflabel="IMediumChangedEvent" />.</para>
2071
2072 <para>As an example, the VirtualBox GUI waits for machine events and can
2073 thus update its display when the machine state changes or machine
2074 settings are modified, even if this happens in another client. This is
2075 how the GUI can automatically refresh its display even if you manipulate
2076 a machine from another client, for example, from VBoxManage.</para>
2077
2078 <para>To register an event listener to listen to events, use code like
2079 this:<screen>EventSource es = console.getEventSource();
2080IEventListener listener = es.createListener();
2081VBoxEventType aTypes[] = (VBoxEventType.OnMachineStateChanged);
2082 // list of event types to listen for
2083es.registerListener(listener, aTypes, false /* active */);
2084 // register passive listener
2085IEvent ev = es.getEvent(listener, 1000);
2086 // wait up to one second for event to happen
2087if (ev != null)
2088{
2089 // downcast to specific event interface (in this case we have only registered
2090 // for one type, otherwise IEvent::type would tell us)
2091 IMachineStateChangedEvent mcse = IMachineStateChangedEvent.queryInterface(ev);
2092 ... // inspect and do something
2093 es.eventProcessed(listener, ev);
2094}
2095...
2096es.unregisterListener(listener); </screen></para>
2097
2098 <para>A graphical user interface would probably best start its own
2099 thread to wait for events and then process these in a loop.</para>
2100
2101 <para>The events mechanism was introduced with VirtualBox 3.3 and
2102 replaces various callback interfaces which were called for each event in
2103 the interface. The callback mechanism was not compatible with scripting
2104 languages, local Java bindings and remote web services as they do not
2105 support callbacks. The new mechanism with events and event listeners
2106 works with all of these.</para>
2107
2108 <para>To simplify developement of application using events, concept of
2109 event aggregator was introduced. Essentially it's mechanism to aggregate
2110 multiple event sources into single one, and then work with this single
2111 aggregated event source instead of original sources. As an example, one
2112 can evaluate demo recorder in VirtualBox Python shell, shipped with SDK
2113 - it records mouse and keyboard events, represented as separate event
2114 sources. Code is essentially like this:<screen>
2115 listener = console.eventSource.createListener()
2116 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource])
2117 agg.registerListener(listener, [ctx['global'].constants.VBoxEventType_Any], False)
2118 registered = True
2119 end = time.time() + dur
2120 while time.time() &lt; end:
2121 ev = agg.getEvent(listener, 1000)
2122 processEent(ev)
2123 agg.unregisterListener(listener)</screen> Without using aggregators
2124 consumer have to poll on both sources, or start multiple threads to
2125 block on those sources.</para>
2126 </sect1>
2127 </chapter>
2128
2129 <chapter id="vboxshell">
2130 <title>The VirtualBox shell</title>
2131
2132 <para>VirtualBox comes with an extensible shell, which allows you to
2133 control your virtual machines from the command line. It is also a
2134 nontrivial example of how to use the VirtualBox APIs from Python, for all
2135 three COM/XPCOM/WS styles of the API.</para>
2136
2137 <para>You can easily extend this shell with your own commands. Create a
2138 subdirectory named <computeroutput>.VirtualBox/shexts</computeroutput>
2139 below your home directory and put a Python file implementing your shell
2140 extension commands in this directory. This file must contain an array
2141 named <computeroutput>commands</computeroutput> containing your command
2142 definitions: <screen>
2143 commands = {
2144 'cmd1': ['Command cmd1 help', cmd1],
2145 'cmd2': ['Command cmd2 help', cmd2]
2146 }
2147 </screen> For example, to create a command for creating hard drive
2148 images, the following code can be used: <screen>
2149 def createHdd(ctx,args):
2150 # Show some meaningful error message on wrong input
2151 if (len(args) &lt; 3):
2152 print "usage: createHdd sizeM location type"
2153 return 0
2154
2155 # Get arguments
2156 size = int(args[1])
2157 loc = args[2]
2158 if len(args) &gt; 3:
2159 format = args[3]
2160 else:
2161 # And provide some meaningful defaults
2162 format = "vdi"
2163
2164 # Call VirtualBox API, using context's fields
2165 hdd = ctx['vb'].createHardDisk(format, loc)
2166 # Access constants using ctx['global'].constants
2167 progress = hdd.createBaseStorage(size, ctx['global'].constants.HardDiskVariant_Standard)
2168 # use standard progress bar mechanism
2169 ctx['progressBar'](progress)
2170
2171
2172 # Report errors
2173 if not hdd.id:
2174 print "cannot create disk (file %s exist?)" %(loc)
2175 return 0
2176
2177 # Give user some feedback on success too
2178 print "created HDD with id: %s" %(hdd.id)
2179
2180 # 0 means continue execution, other values mean exit from the interpreter
2181 return 0
2182
2183 commands = {
2184 'myCreateHDD': ['Create virtual HDD, createHdd size location type', createHdd]
2185 }
2186 </screen> Just store the above text in the file
2187 <computeroutput>createHdd</computeroutput> (or any other meaningful name)
2188 in <computeroutput>.VirtualBox/shexts/</computeroutput>. Start the
2189 VirtualBox shell, or just issue the
2190 <computeroutput>reloadExts</computeroutput> command, if the shell is
2191 already running. Your new command will now be available.</para>
2192 </chapter>
2193
2194 <!--$VIRTUALBOX_MAIN_API_REFERENCE-->
2195
2196 <chapter id="hgcm">
2197 <title>Host-Guest Communication Manager</title>
2198
2199 <para>The VirtualBox Host-Guest Communication Manager (HGCM) allows a
2200 guest application or a guest driver to call a host shared library. The
2201 following features of VirtualBox are implemented using HGCM: <itemizedlist>
2202 <listitem>
2203 <para>Shared Folders</para>
2204 </listitem>
2205
2206 <listitem>
2207 <para>Shared Clipboard</para>
2208 </listitem>
2209
2210 <listitem>
2211 <para>Guest configuration interface</para>
2212 </listitem>
2213 </itemizedlist></para>
2214
2215 <para>The shared library contains a so called HGCM service. The guest HGCM
2216 clients establish connections to the service to call it. When calling a
2217 HGCM service the client supplies a function code and a number of
2218 parameters for the function.</para>
2219
2220 <sect1>
2221 <title>Virtual hardware implementation</title>
2222
2223 <para>HGCM uses the VMM virtual PCI device to exchange data between the
2224 guest and the host. The guest always acts as an initiator of requests. A
2225 request is constructed in the guest physical memory, which must be
2226 locked by the guest. The physical address is passed to the VMM device
2227 using a 32 bit <computeroutput>out edx, eax</computeroutput>
2228 instruction. The physical memory must be allocated below 4GB by 64 bit
2229 guests.</para>
2230
2231 <para>The host parses the request header and data and queues the request
2232 for a host HGCM service. The guest continues execution and usually waits
2233 on a HGCM event semaphore.</para>
2234
2235 <para>When the request has been processed by the HGCM service, the VMM
2236 device sets the completion flag in the request header, sets the HGCM
2237 event and raises an IRQ for the guest. The IRQ handler signals the HGCM
2238 event semaphore and all HGCM callers check the completion flag in the
2239 corresponding request header. If the flag is set, the request is
2240 considered completed.</para>
2241 </sect1>
2242
2243 <sect1>
2244 <title>Protocol specification</title>
2245
2246 <para>The HGCM protocol definitions are contained in the
2247 <computeroutput>VBox/VBoxGuest.h</computeroutput></para>
2248
2249 <sect2>
2250 <title>Request header</title>
2251
2252 <para>HGCM request structures contains a generic header
2253 (VMMDevHGCMRequestHeader): <table>
2254 <title>HGCM Request Generic Header</title>
2255
2256 <tgroup cols="2">
2257 <tbody>
2258 <row>
2259 <entry><emphasis role="bold">Name</emphasis></entry>
2260
2261 <entry><emphasis role="bold">Description</emphasis></entry>
2262 </row>
2263
2264 <row>
2265 <entry>size</entry>
2266
2267 <entry>Size of the entire request.</entry>
2268 </row>
2269
2270 <row>
2271 <entry>version</entry>
2272
2273 <entry>Version of the header, must be set to
2274 <computeroutput>0x10001</computeroutput>.</entry>
2275 </row>
2276
2277 <row>
2278 <entry>type</entry>
2279
2280 <entry>Type of the request.</entry>
2281 </row>
2282
2283 <row>
2284 <entry>rc</entry>
2285
2286 <entry>HGCM return code, which will be set by the VMM
2287 device.</entry>
2288 </row>
2289
2290 <row>
2291 <entry>reserved1</entry>
2292
2293 <entry>A reserved field 1.</entry>
2294 </row>
2295
2296 <row>
2297 <entry>reserved2</entry>
2298
2299 <entry>A reserved field 2.</entry>
2300 </row>
2301
2302 <row>
2303 <entry>flags</entry>
2304
2305 <entry>HGCM flags, set by the VMM device.</entry>
2306 </row>
2307
2308 <row>
2309 <entry>result</entry>
2310
2311 <entry>The HGCM result code, set by the VMM device.</entry>
2312 </row>
2313 </tbody>
2314 </tgroup>
2315 </table> <note>
2316 <itemizedlist>
2317 <listitem>
2318 <para>All fields are 32 bit.</para>
2319 </listitem>
2320
2321 <listitem>
2322 <para>Fields from <computeroutput>size</computeroutput> to
2323 <computeroutput>reserved2</computeroutput> are a standard VMM
2324 device request header, which is used for other interfaces as
2325 well.</para>
2326 </listitem>
2327 </itemizedlist>
2328 </note></para>
2329
2330 <para>The <emphasis role="bold">type</emphasis> field indicates the
2331 type of the HGCM request: <table>
2332 <title>Request Types</title>
2333
2334 <tgroup cols="2">
2335 <tbody>
2336 <row>
2337 <entry><emphasis role="bold">Name (decimal
2338 value)</emphasis></entry>
2339
2340 <entry><emphasis role="bold">Description</emphasis></entry>
2341 </row>
2342
2343 <row>
2344 <entry>VMMDevReq_HGCMConnect
2345 (<computeroutput>60</computeroutput>)</entry>
2346
2347 <entry>Connect to a HGCM service.</entry>
2348 </row>
2349
2350 <row>
2351 <entry>VMMDevReq_HGCMDisconnect
2352 (<computeroutput>61</computeroutput>)</entry>
2353
2354 <entry>Disconnect from the service.</entry>
2355 </row>
2356
2357 <row>
2358 <entry>VMMDevReq_HGCMCall32
2359 (<computeroutput>62</computeroutput>)</entry>
2360
2361 <entry>Call a HGCM function using the 32 bit
2362 interface.</entry>
2363 </row>
2364
2365 <row>
2366 <entry>VMMDevReq_HGCMCall64
2367 (<computeroutput>63</computeroutput>)</entry>
2368
2369 <entry>Call a HGCM function using the 64 bit
2370 interface.</entry>
2371 </row>
2372
2373 <row>
2374 <entry>VMMDevReq_HGCMCancel
2375 (<computeroutput>64</computeroutput>)</entry>
2376
2377 <entry>Cancel a HGCM request currently being processed by a
2378 host HGCM service.</entry>
2379 </row>
2380 </tbody>
2381 </tgroup>
2382 </table></para>
2383
2384 <para>The <emphasis role="bold">flags</emphasis> field may contain:
2385 <table>
2386 <title>Flags</title>
2387
2388 <tgroup cols="2">
2389 <tbody>
2390 <row>
2391 <entry><emphasis role="bold">Name (hexadecimal
2392 value)</emphasis></entry>
2393
2394 <entry><emphasis role="bold">Description</emphasis></entry>
2395 </row>
2396
2397 <row>
2398 <entry>VBOX_HGCM_REQ_DONE
2399 (<computeroutput>0x00000001</computeroutput>)</entry>
2400
2401 <entry>The request has been processed by the host
2402 service.</entry>
2403 </row>
2404
2405 <row>
2406 <entry>VBOX_HGCM_REQ_CANCELLED
2407 (<computeroutput>0x00000002</computeroutput>)</entry>
2408
2409 <entry>This request was cancelled.</entry>
2410 </row>
2411 </tbody>
2412 </tgroup>
2413 </table></para>
2414 </sect2>
2415
2416 <sect2>
2417 <title>Connect</title>
2418
2419 <para>The connection request must be issued by the guest HGCM client
2420 before it can call the HGCM service (VMMDevHGCMConnect): <table>
2421 <title>Connect request</title>
2422
2423 <tgroup cols="2">
2424 <tbody>
2425 <row>
2426 <entry><emphasis role="bold">Name</emphasis></entry>
2427
2428 <entry><emphasis role="bold">Description</emphasis></entry>
2429 </row>
2430
2431 <row>
2432 <entry>header</entry>
2433
2434 <entry>The generic HGCM request header with type equal to
2435 VMMDevReq_HGCMConnect
2436 (<computeroutput>60</computeroutput>).</entry>
2437 </row>
2438
2439 <row>
2440 <entry>type</entry>
2441
2442 <entry>The type of the service location information (32
2443 bit).</entry>
2444 </row>
2445
2446 <row>
2447 <entry>location</entry>
2448
2449 <entry>The service location information (128 bytes).</entry>
2450 </row>
2451
2452 <row>
2453 <entry>clientId</entry>
2454
2455 <entry>The client identifier assigned to the connecting
2456 client by the HGCM subsystem (32 bit).</entry>
2457 </row>
2458 </tbody>
2459 </tgroup>
2460 </table> The <emphasis role="bold">type</emphasis> field tells the
2461 HGCM how to look for the requested service: <table>
2462 <title>Location Information Types</title>
2463
2464 <tgroup cols="2">
2465 <tbody>
2466 <row>
2467 <entry><emphasis role="bold">Name (hexadecimal
2468 value)</emphasis></entry>
2469
2470 <entry><emphasis role="bold">Description</emphasis></entry>
2471 </row>
2472
2473 <row>
2474 <entry>VMMDevHGCMLoc_LocalHost
2475 (<computeroutput>0x1</computeroutput>)</entry>
2476
2477 <entry>The requested service is a shared library located on
2478 the host and the location information contains the library
2479 name.</entry>
2480 </row>
2481
2482 <row>
2483 <entry>VMMDevHGCMLoc_LocalHost_Existing
2484 (<computeroutput>0x2</computeroutput>)</entry>
2485
2486 <entry>The requested service is a preloaded one and the
2487 location information contains the service name.</entry>
2488 </row>
2489 </tbody>
2490 </tgroup>
2491 </table> <note>
2492 <para>Currently preloaded HGCM services are hard-coded in
2493 VirtualBox: <itemizedlist>
2494 <listitem>
2495 <para>VBoxSharedFolders</para>
2496 </listitem>
2497
2498 <listitem>
2499 <para>VBoxSharedClipboard</para>
2500 </listitem>
2501
2502 <listitem>
2503 <para>VBoxGuestPropSvc</para>
2504 </listitem>
2505
2506 <listitem>
2507 <para>VBoxSharedOpenGL</para>
2508 </listitem>
2509 </itemizedlist></para>
2510 </note> There is no difference between both types of HGCM services,
2511 only the location mechanism is different.</para>
2512
2513 <para>The client identifier is returned by the host and must be used
2514 in all subsequent requests by the client.</para>
2515 </sect2>
2516
2517 <sect2>
2518 <title>Disconnect</title>
2519
2520 <para>This request disconnects the client and makes the client
2521 identifier invalid (VMMDevHGCMDisconnect): <table>
2522 <title>Disconnect request</title>
2523
2524 <tgroup cols="2">
2525 <tbody>
2526 <row>
2527 <entry><emphasis role="bold">Name</emphasis></entry>
2528
2529 <entry><emphasis role="bold">Description</emphasis></entry>
2530 </row>
2531
2532 <row>
2533 <entry>header</entry>
2534
2535 <entry>The generic HGCM request header with type equal to
2536 VMMDevReq_HGCMDisconnect
2537 (<computeroutput>61</computeroutput>).</entry>
2538 </row>
2539
2540 <row>
2541 <entry>clientId</entry>
2542
2543 <entry>The client identifier previously returned by the
2544 connect request (32 bit).</entry>
2545 </row>
2546 </tbody>
2547 </tgroup>
2548 </table></para>
2549 </sect2>
2550
2551 <sect2>
2552 <title>Call32 and Call64</title>
2553
2554 <para>Calls the HGCM service entry point (VMMDevHGCMCall) using 32 bit
2555 or 64 bit addresses: <table>
2556 <title>Call request</title>
2557
2558 <tgroup cols="2">
2559 <tbody>
2560 <row>
2561 <entry><emphasis role="bold">Name</emphasis></entry>
2562
2563 <entry><emphasis role="bold">Description</emphasis></entry>
2564 </row>
2565
2566 <row>
2567 <entry>header</entry>
2568
2569 <entry>The generic HGCM request header with type equal to
2570 either VMMDevReq_HGCMCall32
2571 (<computeroutput>62</computeroutput>) or
2572 VMMDevReq_HGCMCall64
2573 (<computeroutput>63</computeroutput>).</entry>
2574 </row>
2575
2576 <row>
2577 <entry>clientId</entry>
2578
2579 <entry>The client identifier previously returned by the
2580 connect request (32 bit).</entry>
2581 </row>
2582
2583 <row>
2584 <entry>function</entry>
2585
2586 <entry>The function code to be processed by the service (32
2587 bit).</entry>
2588 </row>
2589
2590 <row>
2591 <entry>cParms</entry>
2592
2593 <entry>The number of following parameters (32 bit). This
2594 value is 0 if the function requires no parameters.</entry>
2595 </row>
2596
2597 <row>
2598 <entry>parms</entry>
2599
2600 <entry>An array of parameter description structures
2601 (HGCMFunctionParameter32 or
2602 HGCMFunctionParameter64).</entry>
2603 </row>
2604 </tbody>
2605 </tgroup>
2606 </table></para>
2607
2608 <para>The 32 bit parameter description (HGCMFunctionParameter32)
2609 consists of 32 bit type field and 8 bytes of an opaque value, so 12
2610 bytes in total. The 64 bit variant (HGCMFunctionParameter64) consists
2611 of the type and 12 bytes of a value, so 16 bytes in total.</para>
2612
2613 <para><table>
2614 <title>Parameter types</title>
2615
2616 <tgroup cols="2">
2617 <tbody>
2618 <row>
2619 <entry><emphasis role="bold">Type</emphasis></entry>
2620
2621 <entry><emphasis role="bold">Format of the
2622 value</emphasis></entry>
2623 </row>
2624
2625 <row>
2626 <entry>VMMDevHGCMParmType_32bit (1)</entry>
2627
2628 <entry>A 32 bit value.</entry>
2629 </row>
2630
2631 <row>
2632 <entry>VMMDevHGCMParmType_64bit (2)</entry>
2633
2634 <entry>A 64 bit value.</entry>
2635 </row>
2636
2637 <row>
2638 <entry>VMMDevHGCMParmType_PhysAddr (3)</entry>
2639
2640 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2641 physical address.</entry>
2642 </row>
2643
2644 <row>
2645 <entry>VMMDevHGCMParmType_LinAddr (4)</entry>
2646
2647 <entry>A 32 bit size followed by a 32 bit or 64 bit guest
2648 linear address. The buffer is used both for guest to host
2649 and for host to guest data.</entry>
2650 </row>
2651
2652 <row>
2653 <entry>VMMDevHGCMParmType_LinAddr_In (5)</entry>
2654
2655 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2656 used only for host to guest data.</entry>
2657 </row>
2658
2659 <row>
2660 <entry>VMMDevHGCMParmType_LinAddr_Out (6)</entry>
2661
2662 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2663 used only for guest to host data.</entry>
2664 </row>
2665
2666 <row>
2667 <entry>VMMDevHGCMParmType_LinAddr_Locked (7)</entry>
2668
2669 <entry>Same as VMMDevHGCMParmType_LinAddr but the buffer is
2670 already locked by the guest.</entry>
2671 </row>
2672
2673 <row>
2674 <entry>VMMDevHGCMParmType_LinAddr_Locked_In (1)</entry>
2675
2676 <entry>Same as VMMDevHGCMParmType_LinAddr_In but the buffer
2677 is already locked by the guest.</entry>
2678 </row>
2679
2680 <row>
2681 <entry>VMMDevHGCMParmType_LinAddr_Locked_Out (1)</entry>
2682
2683 <entry>Same as VMMDevHGCMParmType_LinAddr_Out but the buffer
2684 is already locked by the guest.</entry>
2685 </row>
2686 </tbody>
2687 </tgroup>
2688 </table></para>
2689
2690 <para>The</para>
2691 </sect2>
2692
2693 <sect2>
2694 <title>Cancel</title>
2695
2696 <para>This request cancels a call request (VMMDevHGCMCancel): <table>
2697 <title>Cancel request</title>
2698
2699 <tgroup cols="2">
2700 <tbody>
2701 <row>
2702 <entry><emphasis role="bold">Name</emphasis></entry>
2703
2704 <entry><emphasis role="bold">Description</emphasis></entry>
2705 </row>
2706
2707 <row>
2708 <entry>header</entry>
2709
2710 <entry>The generic HGCM request header with type equal to
2711 VMMDevReq_HGCMCancel
2712 (<computeroutput>64</computeroutput>).</entry>
2713 </row>
2714 </tbody>
2715 </tgroup>
2716 </table></para>
2717 </sect2>
2718 </sect1>
2719
2720 <sect1>
2721 <title>Guest software interface</title>
2722
2723 <para>The guest HGCM clients can call HGCM services from both drivers
2724 and applications.</para>
2725
2726 <sect2>
2727 <title>The guest driver interface</title>
2728
2729 <para>The driver interface is implemented in the VirtualBox guest
2730 additions driver (VBoxGuest), which works with the VMM virtual device.
2731 Drivers must use the VBox Guest Library (VBGL), which provides an API
2732 for HGCM clients (<computeroutput>VBox/VBoxGuestLib.h</computeroutput>
2733 and <computeroutput>VBox/VBoxGuest.h</computeroutput>).</para>
2734
2735 <para><screen>
2736DECLVBGL(int) VbglHGCMConnect (VBGLHGCMHANDLE *pHandle, VBoxGuestHGCMConnectInfo *pData);
2737 </screen> Connects to the service: <screen>
2738 VBoxGuestHGCMConnectInfo data;
2739
2740 memset (&amp;data, sizeof (VBoxGuestHGCMConnectInfo));
2741
2742 data.result = VINF_SUCCESS;
2743 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing;
2744 strcpy (data.Loc.u.host.achName, "VBoxSharedFolders");
2745
2746 rc = VbglHGCMConnect (&amp;handle, &amp;data);
2747
2748 if (RT_SUCCESS (rc))
2749 {
2750 rc = data.result;
2751 }
2752
2753 if (RT_SUCCESS (rc))
2754 {
2755 /* Get the assigned client identifier. */
2756 ulClientID = data.u32ClientID;
2757 }
2758 </screen></para>
2759
2760 <para><screen>
2761DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData);
2762 </screen> Disconnects from the service. <screen>
2763 VBoxGuestHGCMDisconnectInfo data;
2764
2765 RtlZeroMemory (&amp;data, sizeof (VBoxGuestHGCMDisconnectInfo));
2766
2767 data.result = VINF_SUCCESS;
2768 data.u32ClientID = ulClientID;
2769
2770 rc = VbglHGCMDisconnect (handle, &amp;data);
2771 </screen></para>
2772
2773 <para><screen>
2774DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData);
2775 </screen> Calls a function in the service. <screen>
2776typedef struct _VBoxSFRead
2777{
2778 VBoxGuestHGCMCallInfo callInfo;
2779
2780 /** pointer, in: SHFLROOT
2781 * Root handle of the mapping which name is queried.
2782 */
2783 HGCMFunctionParameter root;
2784
2785 /** value64, in:
2786 * SHFLHANDLE of object to read from.
2787 */
2788 HGCMFunctionParameter handle;
2789
2790 /** value64, in:
2791 * Offset to read from.
2792 */
2793 HGCMFunctionParameter offset;
2794
2795 /** value64, in/out:
2796 * Bytes to read/How many were read.
2797 */
2798 HGCMFunctionParameter cb;
2799
2800 /** pointer, out:
2801 * Buffer to place data to.
2802 */
2803 HGCMFunctionParameter buffer;
2804
2805} VBoxSFRead;
2806
2807/** Number of parameters */
2808#define SHFL_CPARMS_READ (5)
2809
2810...
2811
2812 VBoxSFRead data;
2813
2814 /* The call information. */
2815 data.callInfo.result = VINF_SUCCESS; /* Will be returned by HGCM. */
2816 data.callInfo.u32ClientID = ulClientID; /* Client identifier. */
2817 data.callInfo.u32Function = SHFL_FN_READ; /* The function code. */
2818 data.callInfo.cParms = SHFL_CPARMS_READ; /* Number of parameters. */
2819
2820 /* Initialize parameters. */
2821 data.root.type = VMMDevHGCMParmType_32bit;
2822 data.root.u.value32 = pMap-&gt;root;
2823
2824 data.handle.type = VMMDevHGCMParmType_64bit;
2825 data.handle.u.value64 = hFile;
2826
2827 data.offset.type = VMMDevHGCMParmType_64bit;
2828 data.offset.u.value64 = offset;
2829
2830 data.cb.type = VMMDevHGCMParmType_32bit;
2831 data.cb.u.value32 = *pcbBuffer;
2832
2833 data.buffer.type = VMMDevHGCMParmType_LinAddr_Out;
2834 data.buffer.u.Pointer.size = *pcbBuffer;
2835 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer;
2836
2837 rc = VbglHGCMCall (handle, &amp;data.callInfo, sizeof (data));
2838
2839 if (RT_SUCCESS (rc))
2840 {
2841 rc = data.callInfo.result;
2842 *pcbBuffer = data.cb.u.value32; /* This is returned by the HGCM service. */
2843 }
2844 </screen></para>
2845 </sect2>
2846
2847 <sect2>
2848 <title>Guest application interface</title>
2849
2850 <para>Applications call the VirtualBox Guest Additions driver to
2851 utilize the HGCM interface. There are IOCTL's which correspond to the
2852 <computeroutput>Vbgl*</computeroutput> functions: <itemizedlist>
2853 <listitem>
2854 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CONNECT</computeroutput></para>
2855 </listitem>
2856
2857 <listitem>
2858 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_DISCONNECT</computeroutput></para>
2859 </listitem>
2860
2861 <listitem>
2862 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CALL</computeroutput></para>
2863 </listitem>
2864 </itemizedlist></para>
2865
2866 <para>These IOCTL's get the same input buffer as
2867 <computeroutput>VbglHGCM*</computeroutput> functions and the output
2868 buffer has the same format as the input buffer. The same address can
2869 be used as the input and output buffers.</para>
2870
2871 <para>For example see the guest part of shared clipboard, which runs
2872 as an application and uses the HGCM interface.</para>
2873 </sect2>
2874 </sect1>
2875
2876 <sect1>
2877 <title>HGCM Service Implementation</title>
2878
2879 <para>The HGCM service is a shared library with a specific set of entry
2880 points. The library must export the
2881 <computeroutput>VBoxHGCMSvcLoad</computeroutput> entry point: <screen>
2882extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable)
2883 </screen></para>
2884
2885 <para>The service must check the
2886 <computeroutput>ptable-&gt;cbSize</computeroutput> and
2887 <computeroutput>ptable-&gt;u32Version</computeroutput> fields of the
2888 input structure and fill the remaining fields with function pointers of
2889 entry points and the size of the required client buffer size.</para>
2890
2891 <para>The HGCM service gets a dedicated thread, which calls service
2892 entry points synchronously, that is the service will be called again
2893 only when a previous call has returned. However, the guest calls can be
2894 processed asynchronously. The service must call a completion callback
2895 when the operation is actually completed. The callback can be issued
2896 from another thread as well.</para>
2897
2898 <para>Service entry points are listed in the
2899 <computeroutput>VBox/hgcmsvc.h</computeroutput> in the
2900 <computeroutput>VBOXHGCMSVCFNTABLE</computeroutput> structure. <table>
2901 <title>Service entry points</title>
2902
2903 <tgroup cols="2">
2904 <tbody>
2905 <row>
2906 <entry><emphasis role="bold">Entry</emphasis></entry>
2907
2908 <entry><emphasis role="bold">Description</emphasis></entry>
2909 </row>
2910
2911 <row>
2912 <entry>pfnUnload</entry>
2913
2914 <entry>The service is being unloaded.</entry>
2915 </row>
2916
2917 <row>
2918 <entry>pfnConnect</entry>
2919
2920 <entry>A client <computeroutput>u32ClientID</computeroutput>
2921 is connected to the service. The
2922 <computeroutput>pvClient</computeroutput> parameter points to
2923 an allocated memory buffer which can be used by the service to
2924 store the client information.</entry>
2925 </row>
2926
2927 <row>
2928 <entry>pfnDisconnect</entry>
2929
2930 <entry>A client is being disconnected.</entry>
2931 </row>
2932
2933 <row>
2934 <entry>pfnCall</entry>
2935
2936 <entry>A guest client calls a service function. The
2937 <computeroutput>callHandle</computeroutput> must be used in
2938 the VBOXHGCMSVCHELPERS::pfnCallComplete callback when the call
2939 has been processed.</entry>
2940 </row>
2941
2942 <row>
2943 <entry>pfnHostCall</entry>
2944
2945 <entry>Called by the VirtualBox host components to perform
2946 functions which should be not accessible by the guest. Usually
2947 this entry point is used by VirtualBox to configure the
2948 service.</entry>
2949 </row>
2950
2951 <row>
2952 <entry>pfnSaveState</entry>
2953
2954 <entry>The VM state is being saved and the service must save
2955 relevant information using the SSM API
2956 (<computeroutput>VBox/ssm.h</computeroutput>).</entry>
2957 </row>
2958
2959 <row>
2960 <entry>pfnLoadState</entry>
2961
2962 <entry>The VM is being restored from the saved state and the
2963 service must load the saved information and be able to
2964 continue operations from the saved state.</entry>
2965 </row>
2966 </tbody>
2967 </tgroup>
2968 </table></para>
2969 </sect1>
2970 </chapter>
2971
2972 <chapter id="rdpweb">
2973 <title>RDP Web Control</title>
2974
2975 <para>The VirtualBox <emphasis>RDP Web Control</emphasis> (RDPWeb)
2976 provides remote access to a running VM. RDPWeb is a RDP (Remote Desktop
2977 Protocol) client based on Flash technology and can be used from a Web
2978 browser with a Flash plugin.</para>
2979
2980 <sect1>
2981 <title>RDPWeb features</title>
2982
2983 <para>RDPWeb is embedded into a Web page and can connect to VRDP server
2984 in order to displays the VM screen and pass keyboard and mouse events to
2985 the VM.</para>
2986 </sect1>
2987
2988 <sect1>
2989 <title>RDPWeb reference</title>
2990
2991 <para>RDPWeb consists of two required components:<itemizedlist>
2992 <listitem>
2993 <para>Flash movie
2994 <computeroutput>RDPClientUI.swf</computeroutput></para>
2995 </listitem>
2996
2997 <listitem>
2998 <para>JavaScript helpers
2999 <computeroutput>webclient.js</computeroutput></para>
3000 </listitem>
3001 </itemizedlist></para>
3002
3003 <para>The VirtualBox SDK contains sample HTML code
3004 including:<itemizedlist>
3005 <listitem>
3006 <para>JavaScript library for embedding Flash content
3007 <computeroutput>SWFObject.js</computeroutput></para>
3008 </listitem>
3009
3010 <listitem>
3011 <para>Sample HTML page
3012 <computeroutput>webclient3.html</computeroutput></para>
3013 </listitem>
3014 </itemizedlist></para>
3015
3016 <sect2>
3017 <title>RDPWeb functions</title>
3018
3019 <para><computeroutput>RDPClientUI.swf</computeroutput> and
3020 <computeroutput>webclient.js</computeroutput> work with each other.
3021 JavaScript code is responsible for a proper SWF initialization,
3022 delivering mouse events to the SWF and processing resize requests from
3023 the SWF. On the other hand, the SWF contains a few JavaScript callable
3024 methods, which are used both from
3025 <computeroutput>webclient.js</computeroutput> and the user HTML
3026 page.</para>
3027
3028 <sect3>
3029 <title>JavaScript functions</title>
3030
3031 <para><computeroutput>webclient.js</computeroutput> contains helper
3032 functions. In the following table ElementId refers to an HTML
3033 element name or attribute, and Element to the HTML element itself.
3034 HTML code<programlisting>
3035 &lt;div id="FlashRDP"&gt;
3036 &lt;/div&gt;
3037</programlisting> would have ElementId equal to FlashRDP and Element equal to
3038 the div element.</para>
3039
3040 <para><itemizedlist>
3041 <listitem>
3042 <programlisting>RDPWebClient.embedSWF(SWFFileName, ElementId)</programlisting>
3043
3044 <para>Uses SWFObject library to replace the HTML element with
3045 the Flash movie.</para>
3046 </listitem>
3047
3048 <listitem>
3049 <programlisting>RDPWebClient.isRDPWebControlById(ElementId)</programlisting>
3050
3051 <para>Returns true if the given id refers to a RDPWeb Flash
3052 element.</para>
3053 </listitem>
3054
3055 <listitem>
3056 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting>
3057
3058 <para>Returns true if the given element is a RDPWeb Flash
3059 element.</para>
3060 </listitem>
3061
3062 <listitem>
3063 <programlisting>RDPWebClient.getFlashById(ElementId)</programlisting>
3064
3065 <para>Returns an element, which is referenced by the given id.
3066 This function will try to resolve any element, event if it is
3067 not a Flash movie.</para>
3068 </listitem>
3069 </itemizedlist></para>
3070 </sect3>
3071
3072 <sect3>
3073 <title>Flash methods callable from JavaScript</title>
3074
3075 <para><computeroutput>RDPWebClienUI.swf</computeroutput> methods can
3076 be called directly from JavaScript code on a HTML page.</para>
3077
3078 <itemizedlist>
3079 <listitem>
3080 <para>getProperty(Name)</para>
3081 </listitem>
3082
3083 <listitem>
3084 <para>setProperty(Name)</para>
3085 </listitem>
3086
3087 <listitem>
3088 <para>connect()</para>
3089 </listitem>
3090
3091 <listitem>
3092 <para>disconnect()</para>
3093 </listitem>
3094
3095 <listitem>
3096 <para>keyboardSendCAD()</para>
3097 </listitem>
3098 </itemizedlist>
3099 </sect3>
3100
3101 <sect3>
3102 <title>Flash JavaScript callbacks</title>
3103
3104 <para><computeroutput>RDPWebClienUI.swf</computeroutput> calls
3105 JavaScript functions provided by the HTML page.</para>
3106 </sect3>
3107 </sect2>
3108
3109 <sect2>
3110 <title>Embedding RDPWeb in an HTML page</title>
3111
3112 <para>It is necessary to include
3113 <computeroutput>webclient.js</computeroutput> helper script. If
3114 SWFObject library is used, the
3115 <computeroutput>swfobject.js</computeroutput> must be also included
3116 and RDPWeb flash content can be embedded to a Web page using dynamic
3117 HTML. The HTML must include a "placeholder", which consists of 2
3118 <computeroutput>div</computeroutput> elements.</para>
3119 </sect2>
3120 </sect1>
3121
3122 <sect1>
3123 <title>RDPWeb change log</title>
3124
3125 <sect2>
3126 <title>Version 1.2.28</title>
3127
3128 <itemizedlist>
3129 <listitem>
3130 <para><computeroutput>keyboardLayout</computeroutput>,
3131 <computeroutput>keyboardLayouts</computeroutput>,
3132 <computeroutput>UUID</computeroutput> properties.</para>
3133 </listitem>
3134
3135 <listitem>
3136 <para>Support for German keyboard layout on the client.</para>
3137 </listitem>
3138
3139 <listitem>
3140 <para>Rebranding to Oracle.</para>
3141 </listitem>
3142 </itemizedlist>
3143 </sect2>
3144
3145 <sect2>
3146 <title>Version 1.1.26</title>
3147
3148 <itemizedlist>
3149 <listitem>
3150 <para><computeroutput>webclient.js</computeroutput> is a part of
3151 the distribution package.</para>
3152 </listitem>
3153
3154 <listitem>
3155 <para><computeroutput>lastError</computeroutput> property.</para>
3156 </listitem>
3157
3158 <listitem>
3159 <para><computeroutput>keyboardSendScancodes</computeroutput> and
3160 <computeroutput>keyboardSendCAD</computeroutput> methods.</para>
3161 </listitem>
3162 </itemizedlist>
3163 </sect2>
3164
3165 <sect2>
3166 <title>Version 1.0.24</title>
3167
3168 <itemizedlist>
3169 <listitem>
3170 <para>Initial release.</para>
3171 </listitem>
3172 </itemizedlist>
3173 </sect2>
3174 </sect1>
3175 </chapter>
3176
3177 <chapter id="vbox-auth">
3178 <title>VirtualBox external authentication modules</title>
3179
3180 <para>VirtualBox supports arbitrary external modules to perform authentication.
3181 The module is used when the authentication method is set to "external" for a
3182 particular VM VRDE access and the library was specified with
3183 <computeroutput>VBoxManage setproperty vrdeauthlibrary</computeroutput>.
3184 Web service also use the authentication module which was specified with
3185 <computeroutput>VBoxManage setproperty websrvauthlibrary</computeroutput>.</para>
3186
3187 <para>This library will be loaded by the VM or web service process on demand, i.e.
3188 when the first remote desktop connection is made by a client or when
3189 a client that wants to use the web service logs on.</para>
3190
3191 <para>External authentication is the most flexible as the external
3192 handler 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
3199 entry 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:
3250 VirtualBox uses a consistent binary representation of UUIDs on all
3251 platforms. For this reason the integer fields comprising the UUID are
3252 stored as little endian values. If you want to pass such UUIDs to code
3253 which assumes that the integer fields are big endian (often also called
3254 network byte order), you need to adjust the contents of the UUID to e.g.
3255 achieve the same string representation. The required changes
3256 are:<itemizedlist>
3257 <listitem>
3258 <para>reverse the order of byte 0, 1, 2 and 3</para>
3259 </listitem>
3260
3261 <listitem>
3262 <para>reverse the order of byte 4 and 5</para>
3263 </listitem>
3264
3265 <listitem>
3266 <para>reverse the order of byte 6 and 7.</para>
3267 </listitem>
3268 </itemizedlist>Using this conversion you will get identical results
3269 when converting the binary UUID to the string representation.</para>
3270
3271 <para>The <computeroutput>guestJudgement</computeroutput> argument contains
3272 information about the guest authentication status. For the first call, it is
3273 always set to <computeroutput>AuthGuestNotAsked</computeroutput>. In case the
3274 <computeroutput>AuthEntry</computeroutput> function returns
3275 <computeroutput>AuthResultDelegateToGuest</computeroutput>, a
3276 guest authentication will be attempted and another call to the
3277 <computeroutput>AuthEntry</computeroutput> is made with its result.
3278 This can be either granted / denied or no judgement (the guest component
3279 chose 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 or
3281 not running or the guest did not respond within a timeout), the "not reacted"
3282 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.0</title>
3447
3448 <itemizedlist>
3449 <listitem>
3450 <para>The confusingly named and impractical session APIs were
3451 changed. In existing client code, the following changes need to be
3452 made:<itemizedlist>
3453 <listitem>
3454 <para>Replace any
3455 <computeroutput>IVirtualBox::openSession(uuidMachine,
3456 ...)</computeroutput> API call with the machine's <xref
3457 linkend="IMachine__lockMachine"
3458 xreflabel="IMachine::lockMachine()" /> call and a
3459 <computeroutput>LockType.Write</computeroutput> argument. The
3460 functionality is unchanged, but instead of "opening a direct
3461 session on a machine" all documentation now refers to
3462 "obtaining a write lock on a machine for the client
3463 session".</para>
3464 </listitem>
3465
3466 <listitem>
3467 <para>Similarly, replace any
3468 <computeroutput>IVirtualBox::openExistingSession(uuidMachine,
3469 ...)</computeroutput> call with the machine's <xref
3470 linkend="IMachine__lockMachine"
3471 xreflabel="IMachine::lockMachine()" /> call and a
3472 <computeroutput>LockType.Shared</computeroutput> argument.
3473 Whereas it was previously impossible to connect a client
3474 session to a running VM process in a race-free manner, the new
3475 API will atomically either write-lock the machine for the
3476 current session or establish a remote link to an existing
3477 session. Existing client code which tried calling both
3478 <computeroutput>openSession()</computeroutput> and
3479 <computeroutput>openExistingSession()</computeroutput> can now
3480 use this one call instead.</para>
3481 </listitem>
3482
3483 <listitem>
3484 <para>Third, replace any
3485 <computeroutput>IVirtualBox::openRemoteSession(uuidMachine,
3486 ...)</computeroutput> call with the machine's <xref
3487 linkend="IMachine__launchVMProcess"
3488 xreflabel="IMachine::launchVMProcess()" /> call. The
3489 functionality is unchanged.</para>
3490 </listitem>
3491
3492 <listitem>
3493 <para>The <xref linkend="SessionState"
3494 xreflabel="SessionState" /> enum was adjusted accordingly:
3495 "Open" is now "Locked", "Closed" is now "Unlocked", "Closing"
3496 is now "Unlocking".</para>
3497 </listitem>
3498 </itemizedlist></para>
3499 </listitem>
3500
3501 <listitem>
3502 <para>Virtual machines created with VirtualBox 4.0 or later no
3503 longer register their media in the global media registry in the
3504 <computeroutput>VirtualBox.xml</computeroutput> file. Instead, such
3505 machines list all their media in their own machine XML files. As a
3506 result, a number of media-related APIs had to be modified again.
3507 <itemizedlist>
3508 <listitem>
3509 <para>Neither <xref linkend="IVirtualBox__createHardDisk"
3510 xreflabel="IVirtualBox::createHardDisk()" /> nor <xref
3511 linkend="IVirtualBox__openMedium"
3512 xreflabel="IVirtualBox::openMedium()" /> register media
3513 automatically any more.</para>
3514 </listitem>
3515
3516 <listitem>
3517 <para><xref linkend="IMachine__attachDevice"
3518 xreflabel="IMachine::attachDevice()" /> and <xref
3519 linkend="IMachine__mountMedium"
3520 xreflabel="IMachine::mountMedium()" /> now take an IMedium
3521 object instead of a UUID as an argument. It is these two calls
3522 which add media to a registry now (either a machine registry
3523 for machines created with VirtualBox 4.0 or later or the
3524 global registry otherwise). As a consequence, if a medium is
3525 opened but never attached to a machine, it is no longer added
3526 to any registry any more.</para>
3527 </listitem>
3528
3529 <listitem>
3530 <para>To reduce code duplication, the APIs
3531 IVirtualBox::findHardDisk(), getHardDisk(), findDVDImage(),
3532 getDVDImage(), findFloppyImage() and getFloppyImage() have all
3533 been merged into <xref linkend="IVirtualBox__findMedium"
3534 xreflabel="IVirtualBox::findMedium()" />, and
3535 IVirtualBox::openHardDisk(), openDVDImage() and
3536 openFloppyImage() have all been merged into <xref
3537 linkend="IVirtualBox__openMedium"
3538 xreflabel="IVirtualBox::openMedium()" />.</para>
3539 </listitem>
3540
3541 <listitem>
3542 <para>The rare use case of changing the UUID and parent UUID
3543 of a medium previously handled by openHardDisk() is now in a
3544 separate <xref linkend="IMedium__setIDs"
3545 xreflabel="IMedium::setIDs" /> method.</para>
3546 </listitem>
3547 </itemizedlist></para>
3548 </listitem>
3549
3550 <listitem>
3551 <para>To reduce code duplication and for consistency with the
3552 aforementioned changes, IVirtualBox::getMachine() has been merged
3553 with <xref linkend="IVirtualBox__findMachine"
3554 xreflabel="IVirtualBox::findMachine()" />, and
3555 IMachine::getSnapshot() has been merged with <xref
3556 linkend="IMachine__findSnapshot"
3557 xreflabel="IMachine::findSnapshot()" />.</para>
3558 </listitem>
3559
3560 <listitem>
3561 <para>IVirtualBox::unregisterMachine() was replaced with <xref
3562 linkend="IMachine__unregister" xreflabel="IMachine::unregister()" />
3563 with additional functionality.</para>
3564 </listitem>
3565
3566 <listitem>
3567 <para><xref linkend="IVirtualBox__createMachine"
3568 xreflabel="IVirtualBox::createMachine()" /> is no longer restricted
3569 to creating machines in the default "Machines" folder, but can now
3570 create machines at arbitrary locations. For this to work, the
3571 parameter list had to be changed.</para>
3572 </listitem>
3573
3574 <listitem>
3575 <para>IConsole::forgetSavedState has been renamed to <xref
3576 linkend="IConsole__discardSavedState"
3577 xreflabel="IConsole::discardSavedState()" />.</para>
3578 </listitem>
3579
3580 <listitem>
3581 <para>All event callbacks APIs were replaced with a new, generic
3582 event mechanism that can be used both locally (COM, XPCOM) and
3583 remotely (web services). Also, the new mechanism is usable from
3584 scripting languages and a local Java. See <xref linkend="IEvent"
3585 xreflabel="events" /> for details. The new concept will require
3586 changes to all clients that used event callbacks.</para>
3587 </listitem>
3588
3589 <listitem>
3590 <para><xref linkend="IGuest__additionsVersion"
3591 xreflabel="IGuest::additionsVersion()" /> no longer returns the
3592 Guest Additions interface version but the installed Guest Additions
3593 version and revision in form of
3594 <computeroutput>3.3.0r12345</computeroutput>.</para>
3595 </listitem>
3596
3597 <listitem>
3598 <para>additionsActive() was replaced with <xref
3599 linkend="IGuest__additionsRunLevel"
3600 xreflabel="additionsRunLevel()" /> and <xref
3601 linkend="IGuest__getAdditionsStatus"
3602 xreflabel="getAdditionsStatus()" /> in order to support a more
3603 detailed status of the current Guest Additions loading/readiness
3604 state.</para>
3605 </listitem>
3606
3607 <listitem>
3608 <para>To address shared folders auto-mounting support, the following
3609 APIs were extended to require an additional
3610 <computeroutput>automount</computeroutput> parameter: <itemizedlist>
3611 <listitem>
3612 <para><xref linkend="IVirtualBox__createSharedFolder"
3613 xreflabel="IVirtualBox::createSharedFolder()" /></para>
3614 </listitem>
3615
3616 <listitem>
3617 <para><xref linkend="IMachine__createSharedFolder"
3618 xreflabel="IMachine::createSharedFolder()" /></para>
3619 </listitem>
3620
3621 <listitem>
3622 <para><xref linkend="IConsole__createSharedFolder"
3623 xreflabel="IConsole::createSharedFolder()" /></para>
3624 </listitem>
3625 </itemizedlist> Also, a new property named
3626 <computeroutput>autoMount</computeroutput> was added to the <xref
3627 linkend="ISharedFolder" xreflabel="ISharedFolder" />
3628 interface.</para>
3629 </listitem>
3630
3631 <listitem>
3632 <para><xref linkend="IMachine__export"
3633 xreflabel="IMachine::export()" /> received an extra parameter
3634 <computeroutput>location</computeroutput>, which is used to decide
3635 for the disk naming.</para>
3636 </listitem>
3637
3638 <listitem>
3639 <para><xref linkend="IAppliance__write"
3640 xreflabel="IAppliance::write()" /> received an extra parameter
3641 <computeroutput>manifest</computeroutput>, which can suppress
3642 creating the manifest file on export.</para>
3643 </listitem>
3644
3645 <listitem>
3646 <para><xref linkend="IVFSExplorer__entryList"
3647 xreflabel="IVFSExplorer::entryList()" /> received two extra
3648 parameters <computeroutput>sizes</computeroutput> and
3649 <computeroutput>modes</computeroutput>, which contains the sizes (in
3650 bytes) and the file access modes (in octal form) of the returned
3651 files.</para>
3652 </listitem>
3653
3654 <listitem>
3655 <para>The long-deprecated IVirtualBox::createLegacyMachine() API has
3656 been removed.</para>
3657 </listitem>
3658
3659 <listitem>
3660 <para>ISystemProperties::get/setDefaultHardDiskFolder() have been
3661 removed.</para>
3662 </listitem>
3663
3664 <listitem>
3665 <para>ISystemProperties::getMaxVDISize() is now <xref
3666 linkend="ISystemProperties__getMaxVDSize"
3667 xreflabel="ISystemProperties::getMaxVDSize()" /> and the returned
3668 unit has changed from megabytes to bytes.</para>
3669 </listitem>
3670
3671 <listitem>
3672 <para>A new Java glue layer replacing the previous OOWS JAX-WS
3673 bindings was introduced. The new library allows for uniform code
3674 targeting both local (COM/XPCOM) and remote (SOAP) transports. Now,
3675 instead of <computeroutput>IWebsessionManager</computeroutput>, the
3676 new class <computeroutput>VirtualBoxManager</computeroutput> must be
3677 used. See <xref linkend="javaapi" xreflabel="Java API chapter" />
3678 for details.</para>
3679 </listitem>
3680
3681 <listitem>
3682 <para>Support for remote desktop access to virtual machines
3683 has been cleaned up to allow third party implementations of
3684 the remote desktop server. This is called VirtualBox Remote Desktop Extension
3685 and can be added to VirtualBox by installing the corresponding
3686 extension package.</para>
3687 <para>The following API changes were made to support the VRDE interface:
3688 <itemizedlist>
3689 <listitem>
3690 <para><computeroutput>IVRDPServer</computeroutput> interface has been
3691 renamed to <xref linkend="IVRDEServer" xreflabel="IVRDEServer" />.</para>
3692 </listitem>
3693
3694 <listitem>
3695 <para><computeroutput>IRemoteDisplayInfo</computeroutput> interface has been
3696 renamed to <xref linkend="IVRDEServerInfo" xreflabel="IVRDEServerInfo" />.</para>
3697 </listitem>
3698
3699 <listitem>
3700 <para><computeroutput>IMachine::VRDPServer</computeroutput> attribute has
3701 been renamed to <xref linkend="IMachine__VRDEServer"
3702 xreflabel="IMachine::VRDEServer" />.</para>
3703 </listitem>
3704
3705 <listitem>
3706 <para><computeroutput>IConsole::RemoteDisplayInfo</computeroutput> attribute
3707 has been renamed to <xref linkend="IConsole__VRDEServerInfo"
3708 xreflabel="IConsole::VRDEServerInfo" />.</para>
3709 </listitem>
3710
3711 <listitem>
3712 <para><computeroutput>ISystemProperties::RemoteDisplayAuthLibrary</computeroutput>
3713 attribute has been renamed to <xref linkend="ISystemProperties__VRDEAuthLibrary"
3714 xreflabel="ISystemProperties::VRDEAuthLibrary" />.</para>
3715 </listitem>
3716
3717 <listitem>
3718 <para>Following methods has been implemented in <computeroutput>IVRDEServer</computeroutput>
3719 to support generic VRDE properties:
3720 <itemizedlist>
3721 <listitem>
3722 <para><xref linkend="IVRDEServer__setVRDEProperty" xreflabel="IVRDEServer::SetVRDEProperty" />
3723 </para>
3724 </listitem>
3725 <listitem>
3726 <para><xref linkend="IVRDEServer__getVRDEProperty" xreflabel="IVRDEServer::GetVRDEProperty"/>
3727 </para>
3728 </listitem>
3729 <listitem>
3730 <para><xref linkend="IVRDEServer__VRDEProperties" xreflabel="IVRDEServer::VRDEProperties" />
3731 </para>
3732 </listitem>
3733 </itemizedlist>
3734 </para>
3735 <para>A few implementation specific attributes of the old <computeroutput>IVRDPServer</computeroutput>
3736 interface have been removed and replaced with properties:
3737 <itemizedlist>
3738 <listitem>
3739 <para><computeroutput>IVRDPServer::Ports</computeroutput> -- replaced with
3740 <computeroutput>"TCP/Ports"</computeroutput> property. The property value is
3741 a string, which contains a comma-separated list of ports or ranges of ports.
3742 Use a dash between two port numbers to specify a range. Example:
3743 <computeroutput>"5000,5010-5012"</computeroutput>
3744 </para>
3745 </listitem>
3746 <listitem>
3747 <para><computeroutput>IVRDPServer::NetAddress</computeroutput> -- replaced with
3748 <computeroutput>"TCP/Address"</computeroutput> property. The property value is
3749 an IP address string. Example: <computeroutput>"127.0.0.1"</computeroutput>
3750 </para>
3751 </listitem>
3752 <listitem>
3753 <para><computeroutput>IVRDPServer::VideoChannel</computeroutput> -- replaced with
3754 <computeroutput>"VideoChannel/Enabled"</computeroutput> property. The property value
3755 is either <computeroutput>"true"</computeroutput> or <computeroutput>"false"</computeroutput>
3756 </para>
3757 </listitem>
3758 <listitem>
3759 <para><computeroutput>IVRDPServer::VideoChannelQuality</computeroutput> -- replaced with
3760 <computeroutput>"VideoChannel/Quality"</computeroutput> property. The property value is a
3761 string which contain a decimal number in range 10..100. Invalid values are ignored and
3762 the quality is set to the default value 75. Example: <computeroutput>"50"</computeroutput>
3763 </para>
3764 </listitem>
3765 </itemizedlist>
3766 </para>
3767 </listitem>
3768 </itemizedlist>
3769 </para>
3770 </listitem>
3771
3772 <listitem>
3773 <para>VirtualBox external authentication module interface
3774 has been updated and made more general.</para>
3775 <para>Because of that, <computeroutput>VRDPAuthType</computeroutput> enumeration has been
3776 renamed to <xref linkend="AuthType" xreflabel="AuthType" />.
3777 </para>
3778 </listitem>
3779 </itemizedlist>
3780 </sect1>
3781
3782 <sect1>
3783 <title>Incompatible API changes with version 3.2</title>
3784
3785 <itemizedlist>
3786 <listitem>
3787 <para>The following interfaces were renamed for consistency:
3788 <itemizedlist>
3789 <listitem>
3790 <para>IMachine::getCpuProperty() is now <xref
3791 linkend="IMachine__getCPUProperty"
3792 xreflabel="IMachine::getCPUProperty()" />;</para>
3793 </listitem>
3794
3795 <listitem>
3796 <para>IMachine::setCpuProperty() is now <xref
3797 linkend="IMachine__setCPUProperty"
3798 xreflabel="IMachine::setCPUProperty()" />;</para>
3799 </listitem>
3800
3801 <listitem>
3802 <para>IMachine::getCpuIdLeaf() is now <xref
3803 linkend="IMachine__getCPUIDLeaf"
3804 xreflabel="IMachine::getCPUIDLeaf()" />;</para>
3805 </listitem>
3806
3807 <listitem>
3808 <para>IMachine::setCpuIdLeaf() is now <xref
3809 linkend="IMachine__setCPUIDLeaf"
3810 xreflabel="IMachine::setCPUIDLeaf()" />;</para>
3811 </listitem>
3812
3813 <listitem>
3814 <para>IMachine::removeCpuIdLeaf() is now <xref
3815 linkend="IMachine__removeCPUIDLeaf"
3816 xreflabel="IMachine::removeCPUIDLeaf()" />;</para>
3817 </listitem>
3818
3819 <listitem>
3820 <para>IMachine::removeAllCpuIdLeafs() is now <xref
3821 linkend="IMachine__removeAllCPUIDLeaves"
3822 xreflabel="IMachine::removeAllCPUIDLeaves()" />;</para>
3823 </listitem>
3824
3825 <listitem>
3826 <para>the CpuPropertyType enum is now <xref
3827 linkend="CPUPropertyType"
3828 xreflabel="CPUPropertyType" />.</para>
3829 </listitem>
3830
3831 <listitem>
3832 <para>IVirtualBoxCallback::onSnapshotDiscarded() is now
3833 IVirtualBoxCallback::onSnapshotDeleted.</para>
3834 </listitem>
3835 </itemizedlist></para>
3836 </listitem>
3837
3838 <listitem>
3839 <para>When creating a VM configuration with <xref
3840 linkend="IVirtualBox__createMachine"
3841 xreflabel="IVirtualBox::createMachine" />) it is now possible to
3842 ignore existing configuration files which would previously have
3843 caused a failure. For this the
3844 <computeroutput>override</computeroutput> parameter was
3845 added.</para>
3846 </listitem>
3847
3848 <listitem>
3849 <para>Deleting snapshots via <xref
3850 linkend="IConsole__deleteSnapshot"
3851 xreflabel="IConsole::deleteSnapshot()" /> is now possible while the
3852 associated VM is running in almost all cases. The API is unchanged,
3853 but client code that verifies machine states to determine whether
3854 snapshots can be deleted may need to be adjusted.</para>
3855 </listitem>
3856
3857 <listitem>
3858 <para>The IoBackendType enumeration was replaced with a boolean flag
3859 (see <xref linkend="IStorageController__useHostIOCache"
3860 xreflabel="IStorageController::useHostIOCache" />).</para>
3861 </listitem>
3862
3863 <listitem>
3864 <para>To address multi-monitor support, the following APIs were
3865 extended to require an additional
3866 <computeroutput>screenId</computeroutput> parameter: <itemizedlist>
3867 <listitem>
3868 <para><xref linkend="IMachine__querySavedThumbnailSize"
3869 xreflabel="IMachine::querySavedThumbnailSize()" /></para>
3870 </listitem>
3871
3872 <listitem>
3873 <para><xref linkend="IMachine__readSavedThumbnailToArray"
3874 xreflabel="IMachine::readSavedThumbnailToArray()" /></para>
3875 </listitem>
3876
3877 <listitem>
3878 <para><xref linkend="IMachine__querySavedScreenshotPNGSize"
3879 xreflabel="IMachine::querySavedScreenshotPNGSize()" /></para>
3880 </listitem>
3881
3882 <listitem>
3883 <para><xref linkend="IMachine__readSavedScreenshotPNGToArray"
3884 xreflabel="IMachine::readSavedScreenshotPNGToArray()" /></para>
3885 </listitem>
3886 </itemizedlist></para>
3887 </listitem>
3888
3889 <listitem>
3890 <para>The <computeroutput>shape</computeroutput> parameter of
3891 IConsoleCallback::onMousePointerShapeChange was changed from a
3892 implementation-specific pointer to a safearray, enabling scripting
3893 languages to process pointer shapes.</para>
3894 </listitem>
3895 </itemizedlist>
3896 </sect1>
3897
3898 <sect1>
3899 <title>Incompatible API changes with version 3.1</title>
3900
3901 <itemizedlist>
3902 <listitem>
3903 <para>Due to the new flexibility in medium attachments that was
3904 introduced with version 3.1 (in particular, full flexibility with
3905 attaching CD/DVD drives to arbitrary controllers), we seized the
3906 opportunity to rework all interfaces dealing with storage media to
3907 make the API more flexible as well as logical. The <xref
3908 linkend="IStorageController" xreflabel="IStorageController" />,
3909 <xref linkend="IMedium" xreflabel="IMedium" />, <xref
3910 linkend="IMediumAttachment" xreflabel="IMediumAttachment" /> and,
3911 <xref linkend="IMachine" xreflabel="IMachine" /> interfaces were
3912 affected the most. Existing code using them to configure storage and
3913 media needs to be carefully checked.</para>
3914
3915 <para>All media (hard disks, floppies and CDs/DVDs) are now
3916 uniformly handled through the <xref linkend="IMedium"
3917 xreflabel="IMedium" /> interface. The device-specific interfaces
3918 (<code>IHardDisk</code>, <code>IDVDImage</code>,
3919 <code>IHostDVDDrive</code>, <code>IFloppyImage</code> and
3920 <code>IHostFloppyDrive</code>) have been merged into IMedium; CD/DVD
3921 and floppy media no longer need special treatment. The device type
3922 of a medium determines in which context it can be used. Some
3923 functionality was moved to the other storage-related
3924 interfaces.</para>
3925
3926 <para><code>IMachine::attachHardDisk</code> and similar methods have
3927 been renamed and generalized to deal with any type of drive and
3928 medium. <xref linkend="IMachine__attachDevice"
3929 xreflabel="IMachine::attachDevice()" /> is the API method for adding
3930 any drive to a storage controller. The floppy and DVD/CD drives are
3931 no longer handled specially, and that means you can have more than
3932 one of them. As before, drives can only be changed while the VM is
3933 powered off. Mounting (or unmounting) removable media at runtime is
3934 possible with <xref linkend="IMachine__mountMedium"
3935 xreflabel="IMachine::mountMedium()" />.</para>
3936
3937 <para>Newly created virtual machines have no storage controllers
3938 associated with them. Even the IDE Controller needs to be created
3939 explicitly. The floppy controller is now visible as a separate
3940 controller, with a new storage bus type. For each storage bus type
3941 you can query the device types which can be attached, so that it is
3942 not necessary to hardcode any attachment rules.</para>
3943
3944 <para>This required matching changes e.g. in the callback interfaces
3945 (the medium specific change notification was replaced by a generic
3946 medium change notification) and removing associated enums (e.g.
3947 <code>DriveState</code>). In many places the incorrect use of the
3948 plural form "media" was replaced by "medium", to improve
3949 consistency.</para>
3950 </listitem>
3951
3952 <listitem>
3953 <para>Reading the <xref linkend="IMedium__state"
3954 xreflabel="IMedium::state" xrefstyle="" /> attribute no longer
3955 automatically performs an accessibility check; a new method <xref
3956 linkend="IMedium__refreshState"
3957 xreflabel="IMedium::refreshState()" /> does this. The attribute only
3958 returns the state any more.</para>
3959 </listitem>
3960
3961 <listitem>
3962 <para>There were substantial changes related to snapshots, triggered
3963 by the "branched snapshots" functionality introduced with version
3964 3.1. IConsole::discardSnapshot was renamed to <xref
3965 linkend="IConsole__deleteSnapshot"
3966 xreflabel="IConsole::deleteSnapshot()" />.
3967 IConsole::discardCurrentState and
3968 IConsole::discardCurrentSnapshotAndState were removed; corresponding
3969 new functionality is in <xref linkend="IConsole__restoreSnapshot"
3970 xreflabel="IConsole::restoreSnapshot()" />. Also, when <xref
3971 linkend="IConsole__takeSnapshot"
3972 xreflabel="IConsole::takeSnapshot()" /> is called on a running
3973 virtual machine, a live snapshot will be created. The old behavior
3974 was to temporarily pause the virtual machine while creating an
3975 online snapshot.</para>
3976 </listitem>
3977
3978 <listitem>
3979 <para>The <xref linkend="IVRDPServer" xreflabel="IVRDPServer" />,
3980 <xref linkend="IRemoteDisplayInfo" xreflabel="IRemoteDisplayInfo" />
3981 and IConsoleCallback interfaces were changed to reflect VRDP server
3982 ability to bind to one of available ports from a list of
3983 ports.</para>
3984
3985 <para>The <computeroutput>IVRDPServer::port</computeroutput>
3986 attribute has been replaced with <xref linkend="IVRDPServer__ports"
3987 xreflabel="IVRDPServer::ports" />, which is a comma-separated list
3988 of ports or ranges of ports.</para>
3989
3990 <para>An <xref linkend="IRemoteDisplayInfo__port"
3991 xreflabel="IRemoteDisplayInfo::port" /> attribute has been added for
3992 querying the actual port VRDP server listens on.</para>
3993
3994 <para>An IConsoleCallback::onRemoteDisplayInfoChange() notification
3995 callback has been added.</para>
3996 </listitem>
3997
3998 <listitem>
3999 <para>The parameter lists for the following functions were
4000 modified:<itemizedlist>
4001 <listitem>
4002 <para><xref linkend="IHost__removeHostOnlyNetworkInterface"
4003 xreflabel="IHost::removeHostOnlyNetworkInterface()" /></para>
4004 </listitem>
4005
4006 <listitem>
4007 <para><xref linkend="IHost__removeUSBDeviceFilter"
4008 xreflabel="IHost::removeUSBDeviceFilter()" /></para>
4009 </listitem>
4010 </itemizedlist></para>
4011 </listitem>
4012
4013 <listitem>
4014 <para>In the OOWS bindings for JAX-WS, the behavior of structures
4015 changed: for one, we implemented natural structures field access so
4016 you can just call a "get" method to obtain a field. Secondly,
4017 setters in structures were disabled as they have no expected effect
4018 and were at best misleading.</para>
4019 </listitem>
4020 </itemizedlist>
4021 </sect1>
4022
4023 <sect1>
4024 <title>Incompatible API changes with version 3.0</title>
4025
4026 <itemizedlist>
4027 <listitem>
4028 <para>In the object-oriented web service bindings for JAX-WS, proper
4029 inheritance has been introduced for some classes, so explicit
4030 casting is no longer needed to call methods from a parent class. In
4031 particular, IHardDisk and other classes now properly derive from
4032 <xref linkend="IMedium" xreflabel="IMedium" />.</para>
4033 </listitem>
4034
4035 <listitem>
4036 <para>All object identifiers (machines, snapshots, disks, etc)
4037 switched from GUIDs to strings (now still having string
4038 representation of GUIDs inside). As a result, no particular internal
4039 structure can be assumed for object identifiers; instead, they
4040 should be treated as opaque unique handles. This change mostly
4041 affects Java and C++ programs; for other languages, GUIDs are
4042 transparently converted to strings.</para>
4043 </listitem>
4044
4045 <listitem>
4046 <para>The uses of NULL strings have been changed greatly. All out
4047 parameters now use empty strings to signal a null value. For in
4048 parameters both the old NULL and empty string is allowed. This
4049 change was necessary to support more client bindings, especially
4050 using the webservice API. Many of them either have no special NULL
4051 value or have trouble dealing with it correctly in the respective
4052 library code.</para>
4053 </listitem>
4054
4055 <listitem>
4056 <para>Accidentally, the <code>TSBool</code> interface still appeared
4057 in 3.0.0, and was removed in 3.0.2. This is an SDK bug, do not use
4058 the SDK for VirtualBox 3.0.0 for developing clients.</para>
4059 </listitem>
4060
4061 <listitem>
4062 <para>The type of <xref linkend="IVirtualBoxErrorInfo__resultCode"
4063 xreflabel="IVirtualBoxErrorInfo::resultCode" /> changed from
4064 <computeroutput>result</computeroutput> to
4065 <computeroutput>long</computeroutput>.</para>
4066 </listitem>
4067
4068 <listitem>
4069 <para>The parameter list of IVirtualBox::openHardDisk was
4070 changed.</para>
4071 </listitem>
4072
4073 <listitem>
4074 <para>The method IConsole::discardSavedState was renamed to
4075 IConsole::forgetSavedState, and a parameter was added.</para>
4076 </listitem>
4077
4078 <listitem>
4079 <para>The method IConsole::powerDownAsync was renamed to <xref
4080 linkend="IConsole__powerDown" xreflabel="IConsole::powerDown" />,
4081 and the previous method with that name was deleted. So effectively a
4082 parameter was added.</para>
4083 </listitem>
4084
4085 <listitem>
4086 <para>In the <xref linkend="IFramebuffer"
4087 xreflabel="IFramebuffer" /> interface, the following were
4088 removed:<itemizedlist>
4089 <listitem>
4090 <para>the <computeroutput>operationSupported</computeroutput>
4091 attribute;</para>
4092
4093 <para>(as a result, the
4094 <computeroutput>FramebufferAccelerationOperation</computeroutput>
4095 enum was no longer needed and removed as well);</para>
4096 </listitem>
4097
4098 <listitem>
4099 <para>the <computeroutput>solidFill()</computeroutput>
4100 method;</para>
4101 </listitem>
4102
4103 <listitem>
4104 <para>the <computeroutput>copyScreenBits()</computeroutput>
4105 method.</para>
4106 </listitem>
4107 </itemizedlist></para>
4108 </listitem>
4109
4110 <listitem>
4111 <para>In the <xref linkend="IDisplay" xreflabel="IDisplay" />
4112 interface, the following were removed:<itemizedlist>
4113 <listitem>
4114 <para>the
4115 <computeroutput>setupInternalFramebuffer()</computeroutput>
4116 method;</para>
4117 </listitem>
4118
4119 <listitem>
4120 <para>the <computeroutput>lockFramebuffer()</computeroutput>
4121 method;</para>
4122 </listitem>
4123
4124 <listitem>
4125 <para>the <computeroutput>unlockFramebuffer()</computeroutput>
4126 method;</para>
4127 </listitem>
4128
4129 <listitem>
4130 <para>the
4131 <computeroutput>registerExternalFramebuffer()</computeroutput>
4132 method.</para>
4133 </listitem>
4134 </itemizedlist></para>
4135 </listitem>
4136 </itemizedlist>
4137 </sect1>
4138
4139 <sect1>
4140 <title>Incompatible API changes with version 2.2</title>
4141
4142 <itemizedlist>
4143 <listitem>
4144 <para>Added explicit version number into JAX-WS Java package names,
4145 such as <computeroutput>org.virtualbox_2_2</computeroutput>,
4146 allowing connect to multiple VirtualBox clients from single Java
4147 application.</para>
4148 </listitem>
4149
4150 <listitem>
4151 <para>The interfaces having a "2" suffix attached to them with
4152 version 2.1 were renamed again to have that suffix removed. This
4153 time around, this change involves only the name, there are no
4154 functional differences.</para>
4155
4156 <para>As a result, IDVDImage2 is now IDVDImage; IHardDisk2 is now
4157 IHardDisk; IHardDisk2Attachment is now IHardDiskAttachment.</para>
4158
4159 <para>Consequentially, all related methods and attributes that had a
4160 "2" suffix have been renamed; for example, IMachine::attachHardDisk2
4161 now becomes IMachine::attachHardDisk().</para>
4162 </listitem>
4163
4164 <listitem>
4165 <para>IVirtualBox::openHardDisk has an extra parameter for opening a
4166 disk read/write or read-only.</para>
4167 </listitem>
4168
4169 <listitem>
4170 <para>The remaining collections were replaced by more performant
4171 safe-arrays. This affects the following collections:</para>
4172
4173 <itemizedlist>
4174 <listitem>
4175 <para>IGuestOSTypeCollection</para>
4176 </listitem>
4177
4178 <listitem>
4179 <para>IHostDVDDriveCollection</para>
4180 </listitem>
4181
4182 <listitem>
4183 <para>IHostFloppyDriveCollection</para>
4184 </listitem>
4185
4186 <listitem>
4187 <para>IHostUSBDeviceCollection</para>
4188 </listitem>
4189
4190 <listitem>
4191 <para>IHostUSBDeviceFilterCollection</para>
4192 </listitem>
4193
4194 <listitem>
4195 <para>IProgressCollection</para>
4196 </listitem>
4197
4198 <listitem>
4199 <para>ISharedFolderCollection</para>
4200 </listitem>
4201
4202 <listitem>
4203 <para>ISnapshotCollection</para>
4204 </listitem>
4205
4206 <listitem>
4207 <para>IUSBDeviceCollection</para>
4208 </listitem>
4209
4210 <listitem>
4211 <para>IUSBDeviceFilterCollection</para>
4212 </listitem>
4213 </itemizedlist>
4214 </listitem>
4215
4216 <listitem>
4217 <para>Since "Host Interface Networking" was renamed to "bridged
4218 networking" and host-only networking was introduced, all associated
4219 interfaces needed renaming as well. In detail:</para>
4220
4221 <itemizedlist>
4222 <listitem>
4223 <para>The HostNetworkInterfaceType enum has been renamed to
4224 <xref linkend="HostNetworkInterfaceMediumType"
4225 xreflabel="HostNetworkInterfaceMediumType" /></para>
4226 </listitem>
4227
4228 <listitem>
4229 <para>The IHostNetworkInterface::type attribute has been renamed
4230 to <xref linkend="IHostNetworkInterface__mediumType"
4231 xreflabel="IHostNetworkInterface::mediumType" /></para>
4232 </listitem>
4233
4234 <listitem>
4235 <para>INetworkAdapter::attachToHostInterface() has been renamed
4236 to <xref linkend="INetworkAdapter__attachToBridgedInterface"
4237 xreflabel="INetworkAdapter::attachToBridgedInterface()" /></para>
4238 </listitem>
4239
4240 <listitem>
4241 <para>In the IHost interface, createHostNetworkInterface() has
4242 been renamed to <xref
4243 linkend="IHost__createHostOnlyNetworkInterface"
4244 xreflabel="createHostOnlyNetworkInterface()" /></para>
4245 </listitem>
4246
4247 <listitem>
4248 <para>Similarly, removeHostNetworkInterface() has been renamed
4249 to <xref linkend="IHost__removeHostOnlyNetworkInterface"
4250 xreflabel="removeHostOnlyNetworkInterface()" /></para>
4251 </listitem>
4252 </itemizedlist>
4253 </listitem>
4254 </itemizedlist>
4255 </sect1>
4256
4257 <sect1>
4258 <title>Incompatible API changes with version 2.1</title>
4259
4260 <itemizedlist>
4261 <listitem>
4262 <para>With VirtualBox 2.1, error codes were added to many error
4263 infos that give the caller a machine-readable (numeric) feedback in
4264 addition to the error string that has always been available. This is
4265 an ongoing process, and future versions of this SDK reference will
4266 document the error codes for each method call.</para>
4267 </listitem>
4268
4269 <listitem>
4270 <para>The hard disk and other media interfaces were completely
4271 redesigned. This was necessary to account for the support of VMDK,
4272 VHD and other image types; since backwards compatibility had to be
4273 broken anyway, we seized the moment to redesign the interfaces in a
4274 more logical way.</para>
4275
4276 <itemizedlist>
4277 <listitem>
4278 <para>Previously, the old IHardDisk interface had several
4279 derivatives called IVirtualDiskImage, IVMDKImage, IVHDImage,
4280 IISCSIHardDisk and ICustomHardDisk for the various disk formats
4281 supported by VirtualBox. The new IHardDisk2 interface that comes
4282 with version 2.1 now supports all hard disk image formats
4283 itself.</para>
4284 </listitem>
4285
4286 <listitem>
4287 <para>IHardDiskFormat is a new interface to describe the
4288 available back-ends for hard disk images (e.g. VDI, VMDK, VHD or
4289 iSCSI). The IHardDisk2::format attribute can be used to find out
4290 the back-end that is in use for a particular hard disk image.
4291 ISystemProperties::hardDiskFormats[] contains a list of all
4292 back-ends supported by the system. <xref
4293 linkend="ISystemProperties__defaultHardDiskFormat"
4294 xreflabel="ISystemProperties::defaultHardDiskFormat" /> contains
4295 the default system format.</para>
4296 </listitem>
4297
4298 <listitem>
4299 <para>In addition, the new <xref linkend="IMedium"
4300 xreflabel="IMedium" /> interface is a generic interface for hard
4301 disk, DVD and floppy images that contains the attributes and
4302 methods shared between them. It can be considered a parent class
4303 of the more specific interfaces for those images, which are now
4304 IHardDisk2, IDVDImage2 and IFloppyImage2.</para>
4305
4306 <para>In each case, the "2" versions of these interfaces replace
4307 the earlier versions that did not have the "2" suffix.
4308 Previously, the IDVDImage and IFloppyImage interfaces were
4309 entirely unrelated to IHardDisk.</para>
4310 </listitem>
4311
4312 <listitem>
4313 <para>As a result, all parts of the API that previously
4314 referenced IHardDisk, IDVDImage or IFloppyImage or any of the
4315 old subclasses are gone and will have replacements that use
4316 IHardDisk2, IDVDImage2 and IFloppyImage2; see, for example,
4317 IMachine::attachHardDisk2.</para>
4318 </listitem>
4319
4320 <listitem>
4321 <para>In particular, the IVirtualBox::hardDisks2 array replaces
4322 the earlier IVirtualBox::hardDisks collection.</para>
4323 </listitem>
4324 </itemizedlist>
4325 </listitem>
4326
4327 <listitem>
4328 <para><xref linkend="IGuestOSType" xreflabel="IGuestOSType" /> was
4329 extended to group operating systems into families and for 64-bit
4330 support.</para>
4331 </listitem>
4332
4333 <listitem>
4334 <para>The <xref linkend="IHostNetworkInterface"
4335 xreflabel="IHostNetworkInterface" /> interface was completely
4336 rewritten to account for the changes in how Host Interface
4337 Networking is now implemented in VirtualBox 2.1.</para>
4338 </listitem>
4339
4340 <listitem>
4341 <para>The IVirtualBox::machines2[] array replaces the former
4342 IVirtualBox::machines collection.</para>
4343 </listitem>
4344
4345 <listitem>
4346 <para>Added <xref linkend="IHost__getProcessorFeature"
4347 xreflabel="IHost::getProcessorFeature()" /> and <xref
4348 linkend="ProcessorFeature" xreflabel="ProcessorFeature" />
4349 enumeration.</para>
4350 </listitem>
4351
4352 <listitem>
4353 <para>The parameter list for <xref
4354 linkend="IVirtualBox__createMachine"
4355 xreflabel="IVirtualBox::createMachine()" /> was modified.</para>
4356 </listitem>
4357
4358 <listitem>
4359 <para>Added IMachine::pushGuestProperty.</para>
4360 </listitem>
4361
4362 <listitem>
4363 <para>New attributes in IMachine: <xref
4364 linkend="IMachine__accelerate3DEnabled"
4365 xreflabel="accelerate3DEnabled" />, HWVirtExVPIDEnabled, <xref
4366 linkend="IMachine__guestPropertyNotificationPatterns"
4367 xreflabel="guestPropertyNotificationPatterns" />, <xref
4368 linkend="IMachine__CPUCount" xreflabel="CPUCount" />.</para>
4369 </listitem>
4370
4371 <listitem>
4372 <para>Added <xref linkend="IConsole__powerUpPaused"
4373 xreflabel="IConsole::powerUpPaused()" /> and <xref
4374 linkend="IConsole__getGuestEnteredACPIMode"
4375 xreflabel="IConsole::getGuestEnteredACPIMode()" />.</para>
4376 </listitem>
4377
4378 <listitem>
4379 <para>Removed ResourceUsage enumeration.</para>
4380 </listitem>
4381 </itemizedlist>
4382 </sect1>
4383 </chapter>
4384</book>
4385<!-- 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