VirtualBox

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

Last change on this file since 35893 was 35296, checked in by vboxsync, 14 years ago

sdkref: formatting, grammar

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

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