VirtualBox

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

Last change on this file since 32387 was 32306, checked in by vboxsync, 14 years ago

doc/SDK: removed references to obsolete methods

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

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