Changeset 101763 in vbox
- Timestamp:
- Nov 3, 2023 6:24:30 PM (16 months ago)
- svn:sync-xref-src-repo-rev:
- 159859
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/en_US/SDKRef.xml
r101041 r101763 72 72 <para>At the bottom of the stack resides the hypervisor -- the core of 73 73 the virtualization engine, controlling execution of the virtual machines 74 and making sure they do not conflict with each other or w hatever the75 host computer is doing otherwise.</para>74 and making sure they do not conflict with each other or with whatever else 75 the host computer is doing.</para> 76 76 77 77 <para>On top of the hypervisor, additional internal modules provide 78 78 extra functionality. For example, the RDP server, which can deliver the 79 79 graphical output of a VM remotely to an RDP client, is a separate module 80 that is only loosely tacked into the virtual graphics device. Live 81 Migration and Resource Monitor are additional modules currently in the 82 process of being added to VirtualBox.</para> 80 that is only loosely tacked onto the virtual graphics device.</para> 83 81 84 82 <para>What is primarily of interest for purposes of the SDK is the API … … 170 168 software components originally introduced by Microsoft for 171 169 Microsoft Windows. On a Windows host, VirtualBox will use 172 Microsoft COM; on other hosts where COM is not present, it ships173 with XPCOM, a free software implementation of COM originally170 Microsoft COM; on other hosts where COM is not present, VirtualBox 171 ships with XPCOM, a free software implementation of COM originally 174 172 created by the Mozilla project for their browsers.</para> 175 173 176 <para>So ,if you are familiar with COM and the C++ programming174 <para>So if you are familiar with COM and the C++ programming 177 175 language (or with any other programming language that can handle 178 176 COM/XPCOM objects, such as Java, Visual Basic or C#), then you can 179 use the COM/XPCOM API directly. VirtualBox comes with all 177 use the COM/XPCOM API directly. VirtualBox comes with all the 180 178 necessary files and documentation to build fully functional COM 181 179 applications. For an introduction, please see <xref … … 190 188 </orderedlist></para> 191 189 192 <para>If you wonder which wayto choose, here are a few190 <para>If you are wondering which approach to choose, here are a few 193 191 comparisons:<table> 194 192 <title>Comparison web service vs. COM/XPCOM</title> … … 235 233 <para>In the following chapters, we will describe the different ways in 236 234 which to program VirtualBox, starting with the method that is easiest to 237 use and then increas ecomplexity as we go along.</para>235 use and then increasing in complexity as we go along.</para> 238 236 </sect1> 239 237 … … 270 268 <para>In order to successfully use a web service, a number of things are 271 269 required -- primarily, a web service accepting connections; service 272 descriptions; and then a client that connects to that web service. The273 connections are governed by the SOAP standard, which describes how274 messages are to be exchanged between a service and its clients; the275 service descriptions are governed by WSDL.</para>270 descriptions; and a client that connects to that web service. Connections 271 to the VirtualBox web service are governed by the SOAP standard, which 272 describes how messages are to be exchanged between a service and its 273 clients; the service descriptions are governed by WSDL.</para> 276 274 277 275 <para>In the case of VirtualBox, this translates into the following … … 280 278 <para>The VirtualBox web service (the "server"): this is the 281 279 <computeroutput>vboxwebsrv</computeroutput> executable shipped 282 with VirtualBox. Once you start this executable (which acts as a 280 with VirtualBox. Once you start this executable (which acts as an 283 281 HTTP server on a specific TCP/IP port), clients can connect to the 284 282 web service and thus control a VirtualBox installation.</para> … … 293 291 easily access a web service even if you don't use our 294 292 object-oriented client layers. VirtualBox is shipped with 295 pre generated web service glue code for several languages (Python,293 pre-generated web service glue code for several languages (Python, 296 294 Perl, Java).</para> 297 295 </listitem> … … 301 299 control the VirtualBox installation.</para> 302 300 303 <para>Unless you play withsome of the samples shipped with301 <para>Unless you use some of the samples shipped with 304 302 VirtualBox, this needs to be written by you.</para> 305 303 </listitem> … … 310 308 <title>Running the web service</title> 311 309 312 <para>The web service ships in a nstand-alone executable,310 <para>The web service ships in a stand-alone executable, 313 311 <computeroutput>vboxwebsrv</computeroutput>, that, when running, acts as 314 a HTTP server, accepts SOAP connections and processes them -- remotely315 or from the same machine.<note>316 <para>The web service executable is not contained with the312 an HTTP server, accepts SOAP connections, remotely or from the same machine, 313 and processes them.<note> 314 <para>The web service executable is not delivered with the 317 315 VirtualBox SDK, but instead ships with the standard VirtualBox 318 binary package for your specific platform. Since the SDK contains319 only platform-independent text files and documentation, the binaries320 are instead shipped with the platform-specific packages. For this321 reason the information how to run itas a service is included in the322 VirtualBox documentation .</para>316 binary package for your specific platform. The SDK contains only 317 platform-independent text files and documentation so thus the vboxwebsrv 318 binary is shipped with the platform-specific packages. Therefore the 319 information on how to run vboxwebsrv as a service is included in the 320 VirtualBox documentation and not the SDK.</para> 323 321 </note></para> 324 322 … … 542 540 543 541 <para>For testing purposes, it is recommended that you first disable 544 authentication with th iscommand:542 authentication with the command: 545 543 <screen>VBoxManage setproperty websrvauthlibrary null</screen></para> 546 544 … … 565 563 <para>By default, after installation, the web service uses the 566 564 VBoxAuth module that ships with VirtualBox. This module uses PAM on 567 Linux hosts to authenticate users. Any valid username/password568 combination is accepted, it does not have to be the username and569 password of the user running the web service daemon. Unless570 <computeroutput>vboxwebsrv</computeroutput> runs as root,PAM571 authentication can fail, because sometimes the file572 <computeroutput>/etc/shadow</computeroutput> , which is used by PAM, is573 not readable. On most Linux distribution PAM uses a suid root helper574 internally, so make sure you test this before deploying it. One can575 override this behavior by setting the environment variable576 <computeroutput>VBOX_PAM_ALLOW_INACTIVE</computeroutput> which will577 suppress failures when unable to read the shadow password file. Please578 use this variable carefully,and only if you fully understand what565 FreeBSD, Linux, and Solaris hosts to authenticate users. Any valid 566 username/password combination is accepted, it does not have to be the 567 username and password of the user running the web service daemon. If 568 <computeroutput>vboxwebsrv</computeroutput> doesn't run as root PAM 569 authentication can fail, because the 570 <computeroutput>/etc/shadow</computeroutput> file, which is used by PAM, 571 is only readable by root. On most Linux distributions PAM uses a suid 572 root helper internally, so make sure you test this before deploying it. 573 One can override authentication failures due to lack of read privileges 574 of the shadow password file by setting the environment variable 575 <computeroutput>VBOX_PAM_ALLOW_INACTIVE</computeroutput>. 576 Please use this variable carefully and only if you fully understand what 579 577 you're doing.</para> 580 578 </sect2> … … 814 812 installation (VirtualBox ships the most important ones for each 815 813 platform<footnote> 816 <para>On OnMac OS X only the Python versions bundled with the OS817 are officially supported. This means 2.6 and 2.7 for 10.9 and later.</para>814 <para>On Mac OS X only the Python versions bundled with the OS 815 are officially supported.</para> 818 816 </footnote>). On Windows, you can use the Main API from Python if the 819 817 Win32 extensions package for Python<footnote> … … 829 827 url="http://pywebsvcs.sourceforge.net/zsi.html">http://pywebsvcs.sourceforge.net/zsi.html</ulink>), 830 828 which you will need to install locally before trying the examples. 831 Most Linux distributions come with package for ZSI, such as829 Most Linux distributions come with a package for ZSI, such as 832 830 <computeroutput>python-zsi</computeroutput> in Ubuntu.</para> 833 831 834 832 <para>To get started, open a terminal and change to the 835 <computeroutput> bindings/glue/python/sample</computeroutput>833 <computeroutput>sdk/bindings/glue/python/sample</computeroutput> 836 834 directory, which contains an example of a simple interactive shell 837 835 able to control a VirtualBox instance. The shell is written using the 838 836 API layer, thereby hiding different implementation details, so it is 839 actually an example of code share among XPCOM, MSCOM and web services.837 actually an example of code shared among XPCOM, MSCOM and web services. 840 838 If you are interested in how to interact with the web services layer 841 839 directly, have a look at … … 844 842 and web services).</para> 845 843 846 <para>To start the shell, perform the following commands: 847 <screen>/opt/VirtualBox/vboxwebsrv -t 0 848 # start web service with object autocollection disabled 849 export VBOX_PROGRAM_PATH=/opt/VirtualBox 850 # your VirtualBox installation directory 851 export VBOX_SDK_PATH=/home/youruser/vbox-sdk 852 # where you've extracted the SDK 844 <para>To start the shell, run the following commands: 845 <screen>/opt/VirtualBox/vboxwebsrv -t 0 # start web service with object autocollection disabled 846 export VBOX_PROGRAM_PATH=/opt/VirtualBox # your VirtualBox installation directory 847 export VBOX_SDK_PATH=/home/youruser/vbox-sdk # where you've extracted the SDK 853 848 ./vboxshell.py -w </screen> 854 849 See <xref linkend="vboxshell"/> for more … … 883 878 previous chapter.</para> 884 879 885 <para>Generally, when reading the documentation in <xref 886 linkend="sdkref_classes"/> and <xref linkend="sdkref_enums"/>, due to 887 the limitations of SOAP and WSDL lined out in <xref 888 linkend="rawws-conventions"/>, please have the following notes in 889 mind:</para> 880 <para>Due to the limitations of SOAP and WSDL outlined in 881 <xref linkend="rawws-conventions"/>, keep the following notes in 882 mind when reading the documentation in <xref linkend="sdkref_classes"/> 883 and <xref linkend="sdkref_enums"/>:</para> 890 884 891 885 <para><orderedlist> … … 937 931 foundation. If your distribution does not have it installed, you can 938 932 get a binary from <ulink 939 url="http:// www.apache.org">http://www.apache.org</ulink>. The933 url="http://axis.apache.org">http://axis.apache.org</ulink>. The 940 934 following examples assume that you have Axis 1.4 installed.</para> 941 935 942 936 <para>The VirtualBox SDK ships with an example for Axis that, again, 943 937 is called <computeroutput>clienttest.java</computeroutput> and that 944 imitates a few of the commands of 945 <computeroutput>VBoxManage</computeroutput> over the wire.</para> 946 947 <para>Then perform the following steps:<orderedlist> 938 imitates a few <computeroutput>VBoxManage</computeroutput> commands 939 and sends them to the VirtualBox web service.</para> 940 941 <para>To try out the raw web service with Axis complete the following 942 steps:<orderedlist> 948 943 <listitem> 949 944 <para>Create a working directory somewhere. Under your … … 1037 1032 communicating with the web service from Perl. You can generate such a 1038 1033 module yourself using the "stubmaker" tool that comes with SOAP::Lite, 1039 but since that tool is slow as well as sometimes unreliable, we are1040 shipping aworking module with the SDK for your convenience.</para>1034 but since that tool is slow as well as sometimes unreliable, we ship a 1035 working module with the SDK for your convenience.</para> 1041 1036 1042 1037 <para>Perform the following steps:<orderedlist> … … 1089 1084 <title>Fundamental conventions</title> 1090 1085 1091 <para>If you are familiar with other web services, you may find th e1092 VirtualBox web service to behavea bit differently to accommodate1093 for the fact that VirtualBox web service more or less maps the1094 VirtualBox Main COM API. The following main differences had to be1095 taken care of:<itemizedlist>1086 <para>If you are familiar with other web services, you may find that the 1087 VirtualBox web service behaves a bit differently to accommodate 1088 for the fact that the VirtualBox web service more or less maps the 1089 VirtualBox Main COM API. The primary challenges in mapping the VirtualBox 1090 Main COM API to the web service are as follows:<itemizedlist> 1096 1091 <listitem> 1097 1092 <para>Web services, as expressed by WSDL, are not … … 1121 1116 there are only functions ("operations") in WSDL, but no 1122 1117 classes, interfaces, or methods.</para> 1123 1124 <para>In addition, all calls to the VirtualBox web service 1125 (except for logon, see below) take a <emphasis1126 role="bold">managed object reference</emphasis> as the first1127 argument, representing the object upon which the underlying1128 method is invoked. (Managed object references are explained in1129 detail below; see <xref1130 linkend="managed-object-references"/>.)</para>1118 </listitem> 1119 1120 <listitem> 1121 <para>All calls to the VirtualBox web service (except for logon, see 1122 below) take a <emphasis role="bold">managed object reference</emphasis> 1123 as the first argument, representing the object upon which the underlying 1124 method is invoked. (Managed object references are explained in detail 1125 below; see <xref linkend="managed-object-references"/>.)</para> 1131 1126 1132 1127 <para>So, when one would normally code, in the pseudo-code of … … 1209 1204 1210 1205 <listitem> 1211 <para>The VirtualBox Main API documentation says that the1206 <para>The VirtualBox Main API documentation explains that the 1212 1207 <computeroutput>IVirtualBox</computeroutput> interface has a 1213 1208 <link linkend="IVirtualBox__version">version</link> 1214 1209 attribute, which is a string. For each attribute, there is a 1215 "get" and a "set" method in COM, which maps to according1210 "get" and a "set" method in COM, which maps to the corresponding 1216 1211 operations in the web service. So, to retrieve the "version" 1217 1212 attribute of this <computeroutput>IVirtualBox</computeroutput> … … 1362 1357 <para><orderedlist> 1363 1358 <listitem> 1364 <para> prepare a connection to aweb service running on port1365 18083 of "localhost" ;</para>1359 <para>Prepare a connection to the web service running on port 1360 18083 of "localhost".</para> 1366 1361 </listitem> 1367 1362 1368 1363 <listitem> 1369 <para>for the <computeroutput>SayHello()</computeroutput> 1370 function of the web service, generate a SOAP message like in 1371 the above example by encoding all arguments of the remote 1372 procedure call (which could involve all kinds of type 1373 conversions and complex marshalling for arrays and 1374 structures);</para> 1364 <para>Generate a SOAP message similar to the above example for the 1365 <computeroutput>SayHello()</computeroutput> function of the web service 1366 by encoding all arguments of the remote procedure call (which could 1367 involve all kinds of type conversions and complex marshalling for arrays 1368 and structures).</para> 1375 1369 </listitem> 1376 1370 1377 1371 <listitem> 1378 <para> connect to the web service via HTTP andsend that1379 message ;</para>1372 <para>Connect to the web service via HTTP and then send that 1373 message.</para> 1380 1374 </listitem> 1381 1375 1382 1376 <listitem> 1383 <para>wait for the web service to send a response 1384 message;</para> 1377 <para>Wait for the web service to send a response message.</para> 1385 1378 </listitem> 1386 1379 1387 1380 <listitem> 1388 <para> decode that response message and put the return value1381 <para>Decode that response message and put the return value 1389 1382 of the remote procedure into the "result" variable.</para> 1390 1383 </listitem> … … 1395 1388 <title>Service descriptions in WSDL</title> 1396 1389 1397 <para>In the above explanations about SOAP, it was left openhow1390 <para>In the above explanations about SOAP, it wasn't explained how 1398 1391 the programming language learns about how to translate function 1399 1392 calls in its own syntax into proper SOAP messages. In other words, … … 1404 1397 a web service operation expects a number in "double" floating 1405 1398 point format for a particular parameter, the programming language 1406 cannot send toit a string instead.</para>1399 cannot send it a string instead.</para> 1407 1400 1408 1401 <para>For this, the Web Service Definition Language (WSDL) was … … 1417 1410 services, this typically means that a programming language has 1418 1411 support for parsing WSDL files and somehow integrating the remote 1419 procedure calls into the native language syntax -- for example, 1420 like in the Java sample shownin <xref1412 procedure calls into the native language syntax -- for example, as 1413 shown in the Java sample in <xref 1421 1414 linkend="webservice-java-sample"/>.</para> 1422 1415 1423 1416 <para>For details about how programming languages support web 1424 1417 services, please refer to the documentation that comes with the 1425 individual language s. Here are a few pointers:</para>1418 individual language. Here are a few pointers:</para> 1426 1419 1427 1420 <orderedlist> … … 1476 1469 <para>COM has several advantages: it is language-neutral, meaning that 1477 1470 even though all of VirtualBox is internally written in C++, programs 1478 written in other languages c ouldcommunicate with it. COM also cleanly1479 separates interface from implementation, so that external programs need1480 not know anything about the messy and complicated details of VirtualBox1481 internals.</para>1471 written in other languages can communicate with it. COM also cleanly 1472 separates interface from implementation, so that external programs do 1473 not need to know anything about the messy and complicated details of 1474 VirtualBox internals.</para> 1482 1475 1483 1476 <para>On a Windows host, all parts of VirtualBox will use the COM … … 1494 1487 1495 1488 <para>On Windows, Python scripts can use COM and VirtualBox interfaces 1496 to control almost all aspects of virtual machine execution. As an1497 example, use the following commands to instantiate the VirtualBox1498 objectand start a VM: <screen>1489 to control almost all aspects of virtual machine execution. For example, 1490 you can use the following commands to instantiate the VirtualBox object 1491 and start a VM: <screen> 1499 1492 vbox = win32com.client.Dispatch("VirtualBox.VirtualBox") 1500 1493 session = win32com.client.Dispatch("VirtualBox.Session") … … 1503 1496 progress.waitForCompletion(-1) 1504 1497 </screen> Also, see 1505 <computeroutput> /bindings/glue/python/samples/vboxshell.py</computeroutput>1498 <computeroutput>sdk/bindings/glue/python/samples/vboxshell.py</computeroutput> 1506 1499 for more advanced usage scenarious. However, unless you have specific 1507 requirements, we strongly recommend t ouse the generic glue layer1500 requirements, we strongly recommend that you use the generic glue layer 1508 1501 described in the next section to access MS COM objects.</para> 1509 1502 </sect2> … … 1514 1507 <para>As different wrappers ultimately provide access to the same 1515 1508 underlying API, and to simplify porting and development of Python 1516 application using the VirtualBox Main API, we developed a common glue1509 applications using the VirtualBox Main API, we developed a common glue 1517 1510 layer that abstracts out most platform-specific details from the 1518 1511 application and allows the developer to focus on application logic. … … 1555 1548 other platforms). The second argument defines parameters, passed to 1556 1549 the platform-specific module, as we do in the second example, where we 1557 pass username and password to be used to authenticate against the web1550 pass a username and password to be used to authenticate against the web 1558 1551 service.</para> 1559 1552 … … 1574 1567 </screen> 1575 1568 <para> 1576 Following code will print all registered machines and their log1577 folders 1569 The following code will print all registered machines and their log 1570 folders: 1578 1571 </para> 1579 1572 <screen>from vboxapi import VirtualBoxManager … … 1585 1578 </screen> 1586 1579 1587 <para> Code above demonstrates cross-platform access to array properties1588 (certain limitations prevent one from using1580 <para>The code above demonstrates cross-platform access to array 1581 properties (certain limitations prevent one from using 1589 1582 <computeroutput>vbox.machines</computeroutput> to access a list of 1590 available virtual machines in case of XPCOM), and a mechanism of1591 uniform session creation and clos ing1583 available virtual machines in the case of XPCOM), and a mechanism for 1584 uniform session creation and closure 1592 1585 (<computeroutput>mgr.getSessionObject()</computeroutput>).</para> 1593 1586 … … 1595 1588 <title>Manual or subsequent setup</title> 1596 1589 1597 <para>I n caseyou want to use the glue layer with a different Python1598 installation or the installer failed to set it up, use these steps1590 <para>If you want to use the glue layer with a different Python 1591 installation or the installer failed to set it up, then use these steps 1599 1592 in a shell to install the necessary files:</para> 1600 1593 1601 1594 <screen> # cd VBOX_INSTALL_PATH/sdk/installer 1602 # PYTHONvboxapisetup.py install</screen>1595 # python vboxapisetup.py install</screen> 1603 1596 1604 1597 <note> <para>On Windows hosts, a Python distribution along with the … … 1619 1612 use the Main API to implement a number of tasks on your host platform. 1620 1613 These samples can be found in the 1621 <computeroutput> /bindings/xpcom/samples</computeroutput> directory for1614 <computeroutput>sdk/bindings/xpcom/samples</computeroutput> directory for 1622 1615 Linux, Mac OS X and Solaris and 1623 <computeroutput> /bindings/mscom/samples</computeroutput> for Windows.1616 <computeroutput>sdk/bindings/mscom/samples</computeroutput> for Windows. 1624 1617 The two samples are actually different, because the one for Windows 1625 1618 uses native COM, whereas the other uses our XPCOM implementation, as … … 1703 1696 <title>Event queue processing</title> 1704 1697 1705 <para>Both VirtualBox client programs and front ends should1698 <para>Both VirtualBox client programs and front-ends should 1706 1699 periodically perform processing of the main event queue, and do that 1707 on the application's main thread. In case of a typical GUI Windows/Mac 1708 OS application this happens automatically in the GUI's dispatch loop. 1709 However, for CLI only application, the appropriate actions have to be 1710 taken. For C++ applications, the VirtualBox SDK provided glue method 1700 on the application's main thread. In the case of a typical GUI 1701 Windows/Mac OS application this happens automatically in the GUI's 1702 dispatch loop. However, for CLI only application, the appropriate actions 1703 have to be taken. For C++ applications, the VirtualBox SDK provided glue 1704 method 1711 1705 <screen> 1712 1706 int EventQueue::processEventQueue(uint32_t cMsTimeout) … … 1719 1713 application using VirtualBox cannot directly control the main event 1720 1714 loop and the main event queue is separated from the event queue of the 1721 programming librar ly (for example in case of Qt on Unix platforms). In1715 programming library (for example in case of Qt on Unix platforms). In 1722 1716 such a case, the application developer is advised to use a 1723 1717 platform/toolkit specific event injection mechanism to force event 1724 queue checks either based on periodic altimer events delivered to the1718 queue checks either based on periodic timer events delivered to the 1725 1719 main thread, or by using custom platform messages to notify the main 1726 thread when events are available. See the VBoxSDL and Qt (VirtualBox)1727 frontends as examples.</para>1720 thread when events are available. See the Qt (VirtualBox) front-end as 1721 an example.</para> 1728 1722 </sect2> 1729 1723 … … 1744 1738 </footnote></para> 1745 1739 1746 <para>VBS is scripting language available in any recent Windows1747 environment. As an example, the following VBS code will print 1740 <para>VBS is a scripting language available in any recent Windows 1741 environment. As an example, the following VBS code will print the 1748 1742 VirtualBox version: <screen> 1749 1743 set vb = CreateObject("VirtualBox.VirtualBox") 1750 1744 Wscript.Echo "VirtualBox version " & vb.version 1751 1745 </screen> See 1752 <computeroutput> bindings/mscom/vbs/sample/vboxinfo.vbs</computeroutput>1746 <computeroutput>sdk/bindings/mscom/vbs/sample/vboxinfo.vbs</computeroutput> 1753 1747 for the complete sample.</para> 1754 1748 … … 1764 1758 Next 1765 1759 </screen> See 1766 <computeroutput> bindings/mscom/vb/sample/vboxinfo.vb</computeroutput>1760 <computeroutput>sdk/bindings/mscom/vb/sample/vboxinfo.vb</computeroutput> 1767 1761 for the complete sample.</para> 1768 1762 </sect2> 1769 1763 1770 1764 <sect2 id="cbinding"> 1771 <title>C binding toVirtualBox API</title>1772 1773 <para>The VirtualBox API originally is designed as object oriented,1774 using XPCOM or COM as the middleware, which translates natively to C++.1775 This means that in order to use it from C there needs to be some1776 helper code to bridge the language differences and reduce the1777 differences between platforms.</para>1765 <title>C bindings to the VirtualBox API</title> 1766 1767 <para>The VirtualBox API was originally designed to be object oriented 1768 and leverages XPCOM or COM as the middleware to natively map the API to 1769 C++. This means that in order to use the VirtualBox API from C there 1770 needs to be some helper code to bridge the language differences and 1771 reduce the differences between platforms.</para> 1778 1772 1779 1773 <sect3 id="capi_glue"> 1780 <title>Cross-platform C binding toVirtualBox API</title>1781 1782 <para>Starting with version 4.3, VirtualBox offers a C binding1774 <title>Cross-platform C bindings to the VirtualBox API</title> 1775 1776 <para>Starting with version 4.3, VirtualBox offers C bindings 1783 1777 which allows using the same C client sources for all platforms, 1784 1778 covering Windows, Linux, Mac OS X and Solaris. It is the … … 1800 1794 directory <computeroutput>sdk/bindings/c/samples</computeroutput> 1801 1795 which demonstrates 1802 using the C binding to initialize the API, get handles for1796 using the C bindings to initialize the API, get handles for 1803 1797 VirtualBox and Session objects, make calls to list and start virtual 1804 1798 machines, monitor events, and uninitialize resources when done. The … … 1825 1819 1826 1820 <para>The following sections document the important concepts needed 1827 to correctly use the C binding , as it is vital for developing API1821 to correctly use the C bindings, as it is vital for developing API 1828 1822 client code which manages memory correctly, updates the reference 1829 counters correctly, a voidingcrashes and memory leaks. Often API1823 counters correctly, and avoids crashes and memory leaks. Often API 1830 1824 clients need to handle events, so the C API specifics are also 1831 1825 described below.</para> … … 1837 1831 <para>Just like in C++, the API and the underlying middleware needs 1838 1832 to be initialized before it can be used. The 1839 <computeroutput>VBoxCAPI_v 4_3.h</computeroutput> header provides the1840 interface to the C binding, but you can alternatively and more1841 conveniently alsoinclude1833 <computeroutput>VBoxCAPI_v&VBOX_VERSION_MAJOR;_&VBOX_VERSION_MINOR;.h</computeroutput> 1834 header file provides the interface to the C bindings, but you can 1835 alternatively and more conveniently just include 1842 1836 <computeroutput>VBoxCAPIGlue.h</computeroutput>, 1843 1837 as this avoids the VirtualBox version dependent header file name and 1844 makes sure th e global variable <code>g_pVBoxFuncs</code> contains a1838 makes sure that the global variable <code>g_pVBoxFuncs</code> contains a 1845 1839 pointer to the structure which contains the helper function pointers. 1846 1840 Here's how to initialize the C API:<screen>#include "VBoxCAPIGlue.h" 1847 1841 ... 1848 1842 IVirtualBoxClient *vboxclient = NULL; 1849 IVirtualBox *vbox = NULL;1850 ISession *session = NULL;1851 HRESULT rc;1852 ULONG revision;1853 1843 1854 1844 /* … … 1893 1883 <code>g_pVBoxFuncs->pfnClientThreadUninitialize()</code>. You don't 1894 1884 have to use these functions in worker threads created by COM/XPCOM 1895 (which you might observe if your code uses active event handling),1896 everything is initialized correctly already. On Windows the C1885 (which you might utilize if your code uses active event handling), 1886 since everything is initialized correctly already. On Windows the C 1897 1887 bindings create a marshaller which supports a wide range of COM 1898 threading models, from STA to MTA, so you don't have to worry about 1888 threading models, from Single-Threaded Apartments (STA) to 1889 Multithreaded Apartments (MTA), so you don't have to worry about 1899 1890 these details unless you plan to use active event handlers. See 1900 the sample code how to get this to work reliably (in other words1891 the sample code for how to get this to work reliably (in other words 1901 1892 think twice if passive event handling isn't the better solution after 1902 1893 you looked at the sample code).</para> … … 1906 1897 <title>C API attribute and method invocation</title> 1907 1898 1908 <para>Method invocation is straightforward. It looks pretty much1909 like the C++ way, by using a macro which internally accesses the1910 vtable, and additionally needs to be passed a pointer to the objecti1911 as the first argument to serve as the1899 <para>Method invocation is straightforward. It looks very similar 1900 to the C++ mechanism since it also uses a macro which internally 1901 accesses the vtable and additionally needs to be passed a pointer to the 1902 object as the first argument to serve as the 1912 1903 <computeroutput>this</computeroutput> pointer.</para> 1913 1904 1914 <para>Using the C binding ,all method invocations return a numeric1905 <para>Using the C bindings all method invocations return a numeric 1915 1906 result code of type <code>HRESULT</code> (with a few exceptions 1916 1907 which normally are not relevant).</para> … … 1932 1923 <link linkend="IVirtualBox__revision">IVirtualBox::revision</link> 1933 1924 attribute: 1934 <screen>rc = IVirtualBoxClient_get_VirtualBox(vboxclient, &vbox); 1925 <screen> 1926 IVirtualBox *vbox = NULL; 1927 ISession *session = NULL; 1928 HRESULT rc; 1929 ULONG revision; 1930 1931 rc = IVirtualBoxClient_get_VirtualBox(vboxclient, &vbox); 1932 1935 1933 if (FAILED(rc) || !vbox) 1936 1934 { … … 1951 1949 }</screen></para> 1952 1950 1953 <para>The convenience macros for calling a method are named by 1954 prepending the method name with the interface name (using1955 <code>_</code>as theseparator).</para>1951 <para>The convenience macros for calling a method are named by prepending 1952 the method name with the interface name (using <code>_</code> as the 1953 separator).</para> 1956 1954 1957 1955 <para>So far only attribute getters were illustrated, but generic … … 2067 2065 free(machines);</screen></para> 2068 2066 2069 <para>Handling output parameters needs more special effortthan2070 input parameters, thus only for the former there are special helpers,2071 andthe latter is handled through the generic array support.</para>2067 <para>Handling output parameters needs more special handling than 2068 input parameters, thus only for the former are there special helpers 2069 while the latter is handled through the generic array support.</para> 2072 2070 </sect3> 2073 2071 … … 2084 2082 triggering the necessary handlers explicitly in the API client code. 2085 2083 Both approaches depend on an event loop to make sure that events 2086 get delivered in a timely manner , with differences what exactly needs2087 to be done.</para>2084 get delivered in a timely manner but otherwise differ in what 2085 else is required to implement the respective event handler type.</para> 2088 2086 2089 2087 <para>The C API sample contains code for both event handling styles, 2090 2088 and one has to modify the appropriate <code>#define</code> to select 2091 2089 which style is actually used by the compiled program. It allows a 2092 good comparison between the two variants ,and the code sequences are2090 good comparison between the two variants and the code sequences are 2093 2091 probably worth reusing without much change in other API clients 2094 2092 with only minor adaptions.</para> … … 2101 2099 it has to implement a complete API interface. Especially on Windows 2102 2100 it is a lot of work to implement the complicated 2103 <code>IDispatch</code> interface, requiring to loadCOM type2101 <code>IDispatch</code> interface, requiring loading COM type 2104 2102 information and using it in the <code>IDispatch</code> method 2105 2103 implementation. Overall this is quite tedious compared to passive … … 2116 2114 2117 2115 <para>This is vital for vetoable events, as they would be stuck 2118 otherwise, waiting whether the veto comes or not. It does not do any2116 otherwise, waiting on whether the veto comes or not. It does not do any 2119 2117 harm for other event types, and in the end is cheaper than checking 2120 2118 if the event at hand is vetoable or not.</para> … … 2127 2125 application. Additional hints are in the comments documenting 2128 2126 the helper methods in 2129 <computeroutput>VBoxCAPI_v 4_3.h</computeroutput>. The code complexity2130 of active event handling (and its inherenly platform/compiler2131 specific aspects) should be motivation to use passive event handling2132 whereever possible.</para>2127 <computeroutput>VBoxCAPI_v&VBOX_VERSION_MAJOR;_&VBOX_VERSION_MINOR;.h</computeroutput>. 2128 The code complexity of active event handling (and its inherently 2129 platform/compiler specific aspects) should be motivation to use passive 2130 event handling wherever possible.</para> 2133 2131 </sect3> 2134 2132 … … 2138 2136 <para>Uninitialization is performed by 2139 2137 <computeroutput>g_pVBoxFuncs->pfnClientUninitialize().</computeroutput> 2140 If your program can exit frommore than one place, it is a good idea2141 to install this function as an exit handler with Standard C's2138 If your program can exit in more than one place, it is a good idea 2139 to install this function as an exit handler using the C library function 2142 2140 <computeroutput>atexit()</computeroutput> just after calling 2143 2141 <computeroutput>g_pVBoxFuncs->pfnClientInitialize()</computeroutput> … … 2168 2166 <computeroutput>main.</computeroutput></para> 2169 2167 2170 <para>If you expect the program to be terminated by a signal (e.g.2168 <para>If you expect your program to be terminated by a signal (e.g. a 2171 2169 user types CTRL-C sending SIGINT) you might want to install a signal 2172 2170 handler setting a flag noting that a signal was sent and then … … 2179 2177 before it terminates, there is a mechanism in place which will 2180 2178 eventually release references held by the client. On Windows it can 2181 take quite a while, in the order of 6-7 minutes.</para>2179 take quite a while, on the order of 6-7 minutes.</para> 2182 2180 </sect3> 2183 2181 … … 2186 2184 2187 2185 <para>A program using the C binding has to open the library during 2188 runtime using the help of glue code provided and as shown in the2186 runtime using the help of the glue code provided and as shown in the 2189 2187 example <computeroutput>tstCAPIGlue.c</computeroutput>. 2190 2188 Compilation and linking can be achieved with a makefile fragment … … 2220 2218 2221 2219 <sect3 id="capi_conversion"> 2222 <title>Conversion of code using legacy C binding </title>2223 2224 <para>This section aims to make the task of converting code using 2225 the legacy C binding to the new style a breeze, by pointing out some2226 keysteps.</para>2220 <title>Conversion of code using legacy C bindings</title> 2221 2222 <para>This section aims to make the task of converting code using the 2223 legacy C bindings to the new style a breeze by following these key 2224 steps.</para> 2227 2225 2228 2226 <para>One necessary change is adjusting your Makefile to reflect the 2229 different include paths. See above. There are now 3 relevant include2230 directories, and most of it is pointing to the C binding directory.2231 The XPCOM include directory is still relevant for platforms where2232 the XPCOM middleware is used, but most of the include files live2233 elsewhere now, so it's good to have it last. Additionally the2234 <computeroutput>VirtualBox_i.c</computeroutput> file needs to be2235 compiled and linked to the program, it contains the IIDs relevant2236 for the VirtualBox API, making sure they are not replicated endlessly2237 if the code refers to themfrequently.</para>2227 different include paths. As shown in the makefile fragment above, there 2228 are now three relevant include directories. The XPCOM include directory 2229 is still relevant for platforms where the XPCOM middleware is used but 2230 most of its include files live elsewhere now so it's good to have it 2231 last. Additionally the <computeroutput>VirtualBox_i.c</computeroutput> 2232 file needs to be compiled and linked to the program since it contains 2233 the interface IDs (IIDs) relevant for the VirtualBox API, making sure 2234 they are not replicated endlessly if the code refers to them 2235 frequently.</para> 2238 2236 2239 2237 <para>The C API client code should include 2240 2238 <computeroutput>VBoxCAPIGlue.h</computeroutput> instead of 2241 2239 <computeroutput>VBoxXPCOMCGlue.h</computeroutput> or 2242 <computeroutput>VBoxCAPI_v4_3.h</computeroutput>, as this makes sure 2243 the correct macros and internal translations are selected.</para> 2240 <computeroutput>VBoxCAPI_v&VBOX_VERSION_MAJOR;_&VBOX_VERSION_MINOR;.h</computeroutput>, 2241 as this makes sure the correct macros and internal translations are 2242 selected.</para> 2244 2243 2245 2244 <para>All API method calls (anything mentioning <code>vtbl</code>) 2246 2245 should be rewritten using the convenience macros for calling methods, 2247 as these hide the internal details, are generally easier to use and2248 shorter to type. You should remove as many as possible2246 as these hide the internal details, are generally easier to 2247 use, and are shorter to type. You should remove as many as possible 2249 2248 <code>(nsISupports **)</code> or similar typecasts, as the new style 2250 2249 should use the correct type in most places, increasing the type … … 2263 2262 helpers, as these make sure the code works without changes with 2264 2263 both COM and XPCOM, which are significantly different in this area. 2265 The code should be double checked ifit uses the correct way to2266 manage memory ,and is freeing it only after the last use.</para>2264 The code should be double checked to see that it uses the correct way to 2265 manage memory and is freeing it only after the last use.</para> 2267 2266 </sect3> 2268 2267 2269 2268 <sect3 id="xpcom_cbinding"> 2270 <title>Legacy C binding to VirtualBox API for XPCOM</title>2269 <title>Legacy C bindings to VirtualBox API for XPCOM</title> 2271 2270 2272 2271 <note> … … 2275 2274 </note> 2276 2275 2277 <para>Starting with version 2.2, VirtualBox offers a C bindingfor2276 <para>Starting with version 2.2, VirtualBox offers C bindings for 2278 2277 its API which works only on platforms using XPCOM. Refer to the 2279 2278 old SDK documentation (included in the SDK packages for version 4.3.6 2280 or earlier) , it still applies unchanged. The fundamental concepts are2281 similar (but the syntactical details are quite different) to the2282 newer cross-platform C binding which should be used for all new code,2283 as the support for the old C binding will go away in a major release2279 or earlier) since it still applies unchanged. The fundamental concepts 2280 are similar (but the syntactical details are quite different) to the 2281 newer cross-platform C bindings which should be used for all new code, 2282 as the support for the old C bindings will go away in a major release 2284 2283 after version 4.3.</para> 2285 2284 </sect3> … … 2337 2336 <title>Changing machine settings: Sessions</title> 2338 2337 2339 <para>As said in the previous section, to read a machine's attribute,2338 <para>As described in the previous section, to read a machine's attribute, 2340 2339 one invokes the corresponding "get" method. One would think that to 2341 2340 change settings of a machine, it would suffice to call the corresponding … … 2385 2384 calling 2386 2385 <link linkend="ISession__unlockMachine">ISession::unlockMachine()</link>. 2387 Otherwise, when the calling process e nd, the machine will receivethe2386 Otherwise, when the calling process exits, the machine will be moved to the 2388 2387 "aborted" state, which can lead to loss of data.</para> 2389 2388 … … 2406 2405 <para>To launch a virtual machine, you call 2407 2406 <link linkend="IMachine__launchVMProcess">IMachine::launchVMProcess()</link>. 2408 In doing so, the caller instructs the VirtualBox engine to start a new2409 process with the virtual machine in it, since to the host, each virtual2410 machine looks like single process, even if it has hundreds of its own2411 processes inside. (This new VM process in turn obtains a write lock on2407 This instructs the VirtualBox engine to start a new process containing the 2408 virtual machine. The host system sees each virtual machine as a single 2409 process, even if the virtual machine has hundreds of its own processes 2410 running inside it. (This new VM process in turn obtains a write lock on 2412 2411 the machine, as described above, to prevent conflicting changes from 2413 2412 other processes; this is why opening another session will fail while the … … 2446 2445 <para>The IEvent interface is an abstract parent interface for all 2447 2446 events that can occur in VirtualBox. The actual events that the server 2448 sends out are then ofone of the specific subclasses, for example2447 sends out belong to one of the specific subclasses, for example 2449 2448 <link linkend="IMachineStateChangedEvent">IMachineStateChangedEvent</link> 2450 2449 or 2451 2450 <link linkend="IMediumChangedEvent">IMediumChangedEvent</link>.</para> 2452 2451 2453 <para>As an example, the VirtualBox GUI waits for machine events andcan2454 thus update its display when the machine state changes or machine2455 settings are modified, even if this happens in another client. This is2456 how the GUI can automatically refresh its display even if you manipulate2457 a machine from another client, for example, fromVBoxManage.</para>2458 2459 <para>To register an event listener to listen to events, use code like2460 this:<screen>EventSource es = console.getEventSource();2452 <para>As an example, the VirtualBox GUI waits for machine events so it can 2453 update its display when the machine state changes or machine settings are 2454 modified, even if this happens in another client. This is how the GUI can 2455 automatically refresh its display even if you manipulate a machine from 2456 a different client such as VBoxManage.</para> 2457 2458 <para>To register an event listener to listen for events, you would use code 2459 similar to the following:<screen>EventSource es = console.getEventSource(); 2461 2460 IEventListener listener = es.createListener(); 2462 2461 VBoxEventType aTypes[] = (VBoxEventType.OnMachineStateChanged); … … 2477 2476 es.unregisterListener(listener); </screen></para> 2478 2477 2479 <para>A graphical user interface would probably best start its own2480 thread to wait for events and then process these in a loop.</para>2478 <para>A graphical user interface application would most likely want to start 2479 its own thread to wait for events and then process these in a loop.</para> 2481 2480 2482 2481 <para>The events mechanism was introduced with VirtualBox 3.3 and 2483 2482 replaces various callback interfaces which were called for each event in 2484 2483 the interface. The callback mechanism was not compatible with scripting 2485 languages, local Java bindings and remote web services as they do not2484 languages, local Java bindings, and remote web services as they do not 2486 2485 support callbacks. The new mechanism with events and event listeners 2487 2486 works with all of these.</para> 2488 2487 2489 <para>To simplify developement of application using events, concept of 2490 event aggregator was introduced. Essentially it's mechanism to aggregate 2491 multiple event sources into single one, and then work with this single 2492 aggregated event source instead of original sources. As an example, one 2493 can evaluate demo recorder in VirtualBox Python shell, shipped with SDK 2494 - it records mouse and keyboard events, represented as separate event 2495 sources. Code is essentially like this:<screen> 2488 <para>To simplify development of applications using events, the concept of 2489 an event aggregator was introduced. Essentially it's a mechanism to 2490 aggregate multiple event sources into one single event source, and then work 2491 with this single aggregated event source instead of the original sources. As 2492 an example, one can try out the VirtualBox Python shell's 2493 <computeroutput>recordDemo</computeroutput> option which records mouse and 2494 keyboard events using an event aggregator and displays them as separate event 2495 sources. The VirtualBox Python shell (vboxshell.py) is shipped with the SDK. 2496 The <computeroutput>recordDemo</computeroutput> code is essentially:<screen> 2496 2497 listener = console.eventSource.createListener() 2497 2498 agg = console.eventSource.createAggregator([console.keyboard.eventSource, console.mouse.eventSource]) … … 2503 2504 processEent(ev) 2504 2505 agg.unregisterListener(listener)</screen> Without using aggregators 2505 consumer have to poll on both sources, or start multiple threads to2506 block on those sources.</para>2506 consumers would have to either poll on both sources or start multiple 2507 threads to block on those sources.</para> 2507 2508 </sect1> 2508 2509 </chapter> … … 2511 2512 <title>The VirtualBox shell</title> 2512 2513 2513 <para>VirtualBox comes with an extensible shell ,which allows you to2514 <para>VirtualBox comes with an extensible shell which allows you to 2514 2515 control your virtual machines from the command line. It is also a 2515 non trivial example of how to use the VirtualBox APIs from Python,for all2516 three COM/XPCOM/WS styles of the API.</para>2517 2518 <para>You can easily extend this shell with your own commands. Create a2519 subdirectory named2520 <computeroutput>.config/VirtualBox/shexts</computeroutput> belowyour home2521 directory ( respectively<computeroutput>.VirtualBox/shexts</computeroutput>2522 on a Windows systemand2523 <computeroutput>Library/VirtualBox/shexts</computeroutput> on OS X) and put2524 a Python file implementing your shell extension commands in this directory.2525 This file must containan array named2526 <computeroutput>commands</computeroutput> containingyour command2516 non-trivial example of how to use the VirtualBox APIs from Python for all 2517 three styles of the API (COM/XPCOM/WS).</para> 2518 2519 <para>You can easily extend this shell with your own commands. Simply create 2520 a subdirectory named 2521 <computeroutput>.config/VirtualBox/shexts</computeroutput> in your home 2522 directory (<computeroutput>.VirtualBox/shexts</computeroutput> 2523 on Windows systems and 2524 <computeroutput>Library/VirtualBox/shexts</computeroutput> on macOS systems) 2525 and put a Python file implementing your shell extension commands in this 2526 directory. This file must have an array named 2527 <computeroutput>commands</computeroutput> which contains your command 2527 2528 definitions: <screen> 2528 2529 commands = { … … 2570 2571 'myCreateHDD': ['Create virtual HDD, createHdd size location type', createHdd] 2571 2572 } 2572 </screen> Just store the above text in the file2573 </screen> Just store the above text in a file named 2573 2574 <computeroutput>createHdd</computeroutput> (or any other meaningful name) 2574 in <computeroutput>.config/VirtualBox/shexts/</computeroutput>. Start the2575 VirtualBox shell,or just issue the2576 <computeroutput>reloadExts</computeroutput> command ,if the shell is2575 in the <computeroutput>shexts</computeroutput> directory located as 2576 described above and then start the VirtualBox shell or just issue the 2577 <computeroutput>reloadExts</computeroutput> command if the shell is 2577 2578 already running. Your new command will now be available.</para> 2578 2579 </chapter> … … 2812 2813 </itemizedlist></para> 2813 2814 2814 <para>The shared library contains a so called HGCM service. The guest HGCM 2815 clients establish connections to the service to call it. When calling a 2816 HGCM service the client supplies a function code and a number of 2817 parameters for the function.</para> 2815 <para>The shared library on the host contains a so called HGCM service. 2816 The guest HGCM client establishes a connection to the HGCM service on the 2817 host in order to call that HGCM service's entry point. When calling an 2818 HGCM service the client supplies a function code, the number of parameters 2819 for the function, and an array of the parameter arguments.</para> 2818 2820 2819 2821 <sect1> 2820 2822 <title>Virtual hardware implementation</title> 2821 2823 2822 <para>HGCM uses the VMM virtual PCI device to exchange data between the 2823 guest and the host. The guest always acts as an initiator of requests. A 2824 request is constructed in the guest physical memory, which must be 2825 locked by the guest. The physical address is passed to the VMM device 2826 using a 32-bit <computeroutput>out edx, eax</computeroutput> 2827 instruction. The physical memory must be allocated below 4GB by 64-bit 2824 <para>HGCM uses the Virtual Machine Monitor (VMM) virtual PCI device to 2825 exchange data between the guest and the host. The guest always acts as an 2826 initiator of requests. A request is constructed in the guest's physical 2827 memory which must be locked by the guest. The physical address is passed 2828 to the VMM device using a 32-bit 2829 <computeroutput>out edx, eax</computeroutput> 2830 instruction. The physical memory must be allocated below 4GB on 64-bit 2828 2831 guests.</para> 2829 2832 2830 2833 <para>The host parses the request header and data and queues the request 2831 for a host HGCM service. The guest continues execution and usually waits2832 on aHGCM event semaphore.</para>2834 for the corresponding host HGCM service type. The guest continues 2835 execution and usually waits on an HGCM event semaphore.</para> 2833 2836 2834 2837 <para>When the request has been processed by the HGCM service, the VMM … … 2844 2847 2845 2848 <para>The HGCM protocol definitions are contained in the 2846 <computeroutput>VBox/VBoxGuest.h</computeroutput> </para>2849 <computeroutput>VBox/VBoxGuest.h</computeroutput> header file.</para> 2847 2850 2848 2851 <sect2> … … 2944 2947 (<computeroutput>60</computeroutput>)</entry> 2945 2948 2946 <entry>Connect to a HGCM service.</entry>2949 <entry>Connect to an HGCM service.</entry> 2947 2950 </row> 2948 2951 … … 2958 2961 (<computeroutput>62</computeroutput>)</entry> 2959 2962 2960 <entry>Call a HGCM function using the 32-bit2963 <entry>Call an HGCM function using the 32-bit 2961 2964 interface.</entry> 2962 2965 </row> … … 2966 2969 (<computeroutput>63</computeroutput>)</entry> 2967 2970 2968 <entry>Call a HGCM function using the 64-bit2971 <entry>Call an HGCM function using the 64-bit 2969 2972 interface.</entry> 2970 2973 </row> … … 2974 2977 (<computeroutput>64</computeroutput>)</entry> 2975 2978 2976 <entry>Cancel a HGCM request currently being processed by a2979 <entry>Cancel an HGCM request currently being processed by a 2977 2980 host HGCM service.</entry> 2978 2981 </row> … … 3206 3209 3207 3210 <para>The 32-bit parameter description (HGCMFunctionParameter32) 3208 consists of 32-bit type field and 8 bytes of an opaque value, so 123211 consists of a 32-bit type field and 8 bytes of an opaque value, so 12 3209 3212 bytes in total. The 64-bit variant (HGCMFunctionParameter64) consists 3210 of the type and 12 bytes of a value, so 16 bytes in total.</para>3213 of the 32-bit type and 12 bytes of a value, so 16 bytes in total.</para> 3211 3214 3212 3215 <para><table> … … 3287 3290 </table></para> 3288 3291 3289 <para>The</para>3290 3292 </sect2> 3291 3293 … … 3320 3322 <title>Guest software interface</title> 3321 3323 3322 <para> The guest HGCM clients can call HGCM services from both drivers3324 <para>Guest HGCM clients can call HGCM services from both drivers 3323 3325 and applications.</para> 3324 3326 … … 3327 3329 3328 3330 <para>The driver interface is implemented in the VirtualBox guest 3329 additions driver (VBoxGuest) ,which works with the VMM virtual device.3330 Drivers must use the VBox Guest Library (VBGL) ,which provides an API3331 additions driver (VBoxGuest) which works with the VMM virtual device. 3332 Drivers must use the VBox Guest Library (VBGL) which provides an API 3331 3333 for HGCM clients (<computeroutput>VBox/VBoxGuestLib.h</computeroutput> 3332 and <computeroutput>VBox/VBoxGuest.h</computeroutput>).</para> 3334 and <computeroutput>VBox/VBoxGuest.h</computeroutput>). The key VBGL API 3335 routines are as follows:</para> 3333 3336 3334 3337 <para><screen> 3335 3338 DECLR0VBGL(int) VbglR0HGCMConnect(VBGLHGCMHANDLE *pHandle, const char *pszServiceName, HGCMCLIENTID *pidClient); 3336 </screen> Connects to the service: <screen> 3339 </screen> VbglR0HGCMConnect() connects to the HGCM service on the host. An 3340 example of a guest driver connecting to the VirtualBox Shared Folder 3341 HGCM service follows:<screen> 3337 3342 VBoxGuestHGCMConnectInfo data; 3338 3343 … … 3341 3346 data.result = VINF_SUCCESS; 3342 3347 data.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; 3343 strcpy 3344 3345 rc = Vbgl HGCMConnect (&handle, "VBoxSharedFolders"&data);3346 3347 if (RT_SUCCESS 3348 strcpy(data.Loc.u.host.achName, "VBoxSharedFolders"); 3349 3350 rc = VbglR0HGCMConnect(&handle, "VBoxSharedFolders"&, data); 3351 3352 if (RT_SUCCESS(rc)) 3348 3353 { 3349 3354 rc = data.result; 3350 3355 } 3351 3356 3352 if (RT_SUCCESS 3357 if (RT_SUCCESS(rc)) 3353 3358 { 3354 3359 /* Get the assigned client identifier. */ … … 3358 3363 3359 3364 <para><screen> 3360 DECLVBGL(int) VbglHGCMDisconnect (VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData); 3361 </screen> Disconnects from the service. <screen> 3365 DECLVBGL(int) VbglR0HGCMDisconnect(VBGLHGCMHANDLE handle, VBoxGuestHGCMDisconnectInfo *pData); 3366 </screen> VbglR0HGCMDisconnect() disconnects from the HGCM service on the 3367 host. An example of a guest driver disconnecting from an HGCM service 3368 using the client identifier from an earlier call to VbglR0HGCMConnect() 3369 follows:<screen> 3362 3370 VBoxGuestHGCMDisconnectInfo data; 3363 3371 3364 RtlZeroMemory 3372 RtlZeroMemory(&data, sizeof (VBoxGuestHGCMDisconnectInfo)); 3365 3373 3366 3374 data.result = VINF_SUCCESS; 3367 3375 data.u32ClientID = ulClientID; 3368 3376 3369 rc = Vbgl HGCMDisconnect(handle, &data);3377 rc = VbglR0HGCMDisconnect(handle, &data); 3370 3378 </screen></para> 3371 3379 3372 3380 <para><screen> 3373 DECLVBGL(int) VbglHGCMCall (VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData); 3374 </screen> Calls a function in the service. <screen> 3381 DECLVBGL(int) VbglR0HGCMCall(VBGLHGCMHANDLE handle, VBoxGuestHGCMCallInfo *pData, uint32_t cbData); 3382 </screen> VbglR0HGCMCall() calls a function specified in the 3383 VBoxGuestHGCMCallInfo argument in the HGCM service on the host. An 3384 example of a guest driver calling the Shared Folders HGCM service to 3385 issue a read of an object in a shared folder follows:<screen> 3375 3386 typedef struct _VBoxSFRead 3376 3387 { … … 3434 3445 data.buffer.u.Pointer.u.linearAddr = (uintptr_t)pBuffer; 3435 3446 3436 rc = Vbgl HGCMCall(handle, &data.callInfo, sizeof (data));3437 3438 if (RT_SUCCESS 3447 rc = VbglR0HGCMCall(handle, &data.callInfo, sizeof (data)); 3448 3449 if (RT_SUCCESS(rc)) 3439 3450 { 3440 3451 rc = data.callInfo.result; … … 3448 3459 3449 3460 <para>Applications call the VirtualBox Guest Additions driver to 3450 utilize the HGCM interface. There are IOCTL's which correspond to the 3451 <computeroutput>Vbgl*</computeroutput> functions: <itemizedlist> 3452 <listitem> 3453 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CONNECT</computeroutput></para> 3454 </listitem> 3455 3456 <listitem> 3457 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_DISCONNECT</computeroutput></para> 3458 </listitem> 3459 3460 <listitem> 3461 <para><computeroutput>VBOXGUEST_IOCTL_HGCM_CALL</computeroutput></para> 3461 utilize the HGCM interface. The following IOCTLs correspond to the 3462 <computeroutput>VbglR0HGCM*</computeroutput> functions listed above: 3463 <itemizedlist> 3464 <listitem> 3465 <para><computeroutput>VBGL_IOCTL_HGCM_CONNECT => 3466 VbglR0HGCMConnect()</computeroutput></para> 3467 </listitem> 3468 3469 <listitem> 3470 <para><computeroutput>VBGL_IOCTL_HGCM_DISCONNECT => 3471 VbglR0HGCMDisconnect()</computeroutput></para> 3472 </listitem> 3473 3474 <listitem> 3475 <para><computeroutput>VBGL_IOCTL_HGCM_CALL => 3476 VbglR0HGCMCall()</computeroutput></para> 3462 3477 </listitem> 3463 3478 </itemizedlist></para> 3464 3479 3465 <para>These IOCTL 's get the same input buffer as3466 <computeroutput>Vbgl HGCM*</computeroutput> functions and the output3480 <para>These IOCTLs get the same input buffer as the 3481 <computeroutput>VbglR0HGCM*</computeroutput> functions and the output 3467 3482 buffer has the same format as the input buffer. The same address can 3468 be used as the input and output buffers.</para> 3469 3470 <para>For example see the guest part of shared clipboard, which runs 3471 as an application and uses the HGCM interface.</para> 3483 be used for both the input and output buffers.</para> 3472 3484 </sect2> 3473 3485 </sect1> … … 3479 3491 points. The library must export the 3480 3492 <computeroutput>VBoxHGCMSvcLoad</computeroutput> entry point: <screen> 3481 extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad 3493 extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *ptable) 3482 3494 </screen></para> 3483 3495 … … 3485 3497 <computeroutput>ptable->cbSize</computeroutput> and 3486 3498 <computeroutput>ptable->u32Version</computeroutput> fields of the 3487 input structure and fill the remaining fields with function pointers of 3488 entry points and the size of the required client buffer size.</para> 3489 3490 <para>The HGCM service gets a dedicated thread, which calls service 3491 entry points synchronously, that is the service will be called again 3492 only when a previous call has returned. However, the guest calls can be 3493 processed asynchronously. The service must call a completion callback 3494 when the operation is actually completed. The callback can be issued 3495 from another thread as well.</para> 3499 input structure and fill in the remaining fields with function pointers of 3500 service entry points (listed below) and the size of the required client 3501 buffer size.</para> 3502 3503 <para>The HGCM service gets a dedicated thread which calls service 3504 entry points synchronously, thus the service entry point will only be called 3505 again once a previous call has returned. However, the guest calls can be 3506 processed asynchronously. Therefore the service must call a completion 3507 callback when the operation is actually completed. The callback can be 3508 issued from another thread as well.</para> 3496 3509 3497 3510 <para>Service entry points are listed in the … … 3503 3516 <tbody> 3504 3517 <row> 3505 <entry><emphasis role="bold">Entry </emphasis></entry>3518 <entry><emphasis role="bold">Entry Point</emphasis></entry> 3506 3519 3507 3520 <entry><emphasis role="bold">Description</emphasis></entry> … … 3509 3522 3510 3523 <row> 3511 <entry> pfnUnload</entry>3524 <entry>int pfnUnload(void *pvService)</entry> 3512 3525 3513 3526 <entry>The service is being unloaded.</entry> … … 3515 3528 3516 3529 <row> 3517 <entry>pfnConnect</entry> 3530 <entry>int pfnConnect(void *pvService, uint32_t u32ClientID, void *pvClient, 3531 uint32_t fRequestor, bool fRestoring)</entry> 3518 3532 3519 3533 <entry>A client <computeroutput>u32ClientID</computeroutput> … … 3525 3539 3526 3540 <row> 3527 <entry>pfnDisconnect</entry> 3541 <entry>int pfnDisconnect(void *pvService, uint32_t u32ClientID, 3542 void *pvClient)</entry> 3528 3543 3529 3544 <entry>A client is being disconnected.</entry> … … 3531 3546 3532 3547 <row> 3533 <entry>pfnCall</entry> 3548 <entry>void pfnCall(void *pvService, VBOXHGCMCALLHANDLE callHandle, 3549 uint32_t u32ClientID, void *pvClient, uint32_t function, 3550 uint32_t cParms, VBOXHGCMSVCPARM paParms[], 3551 uint64_t tsArrival)</entry> 3534 3552 3535 3553 <entry>A guest client calls a service function. The … … 3540 3558 3541 3559 <row> 3542 <entry>pfnHostCall</entry> 3560 <entry>int pfnHostCall(void *pvService, uint32_t function, uint32_t cParms, 3561 VBOXHGCMSVCPARM paParms[])</entry> 3543 3562 3544 3563 <entry>Called by the VirtualBox host components to perform … … 3549 3568 3550 3569 <row> 3551 <entry>pfnSaveState</entry> 3570 <entry>int pfnSaveState(void *pvService, uint32_t u32ClientID, void *pvClient, 3571 PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM)</entry> 3552 3572 3553 3573 <entry>The VM state is being saved and the service must save … … 3557 3577 3558 3578 <row> 3559 <entry>pfnLoadState</entry> 3579 <entry>int pfnLoadState(void *pvService, uint32_t u32ClientID, void *pvClient, 3580 PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t uVersion)</entry> 3560 3581 3561 3582 <entry>The VM is being restored from the saved state and the … … 3573 3594 3574 3595 <para>The VirtualBox <emphasis>RDP Web Control</emphasis> (RDPWeb) 3575 provides remote access to a running VM. RDPWeb is a RDP (Remote Desktop3596 provides remote access to a running VM. RDPWeb is an RDP (Remote Desktop 3576 3597 Protocol) client based on Flash technology and can be used from a Web 3577 3598 browser with a Flash plugin.</para> … … 3580 3601 <title>RDPWeb features</title> 3581 3602 3582 <para>RDPWeb is embedded into a Web page and c an connect toVRDP server3583 in order to display s the VM screen and pass keyboard and mouse events to3584 t he VM.</para>3603 <para>RDPWeb is embedded into a Web page and connects to a VRDP server 3604 in order to display the remote VM screen and pass keyboard and mouse events 3605 to the VM.</para> 3585 3606 </sect1> 3586 3607 … … 3590 3611 <para>RDPWeb consists of two required components:<itemizedlist> 3591 3612 <listitem> 3592 <para>Flash movie 3613 <para>Flash movie file 3593 3614 <computeroutput>RDPClientUI.swf</computeroutput></para> 3594 3615 </listitem> 3595 3616 3596 3617 <listitem> 3597 <para>JavaScript helpers 3618 <para>JavaScript helpers contained in 3598 3619 <computeroutput>webclient.js</computeroutput></para> 3599 3620 </listitem> … … 3603 3624 including:<itemizedlist> 3604 3625 <listitem> 3605 <para> JavaScript library for embedding Flash content3626 <para>A JavaScript library for embedding Flash content: 3606 3627 <computeroutput>SWFObject.js</computeroutput></para> 3607 3628 </listitem> 3608 3629 3609 3630 <listitem> 3610 <para> Sample HTML page3631 <para>A sample HTML page: 3611 3632 <computeroutput>webclient3.html</computeroutput></para> 3612 3633 </listitem> … … 3617 3638 3618 3639 <para><computeroutput>RDPClientUI.swf</computeroutput> and 3619 <computeroutput>webclient.js</computeroutput> work with each other.3620 JavaScript code is responsible for a proper SWF initialization,3621 delivering mouse events to the SWF and processing resize requests from3622 the SWF. On the other hand, the SWF contains a few JavaScript callable3623 methods, which are used both from3624 <computeroutput>webclient.js</computeroutput> and the user HTML3640 <computeroutput>webclient.js</computeroutput> work together to provide the 3641 RDP Web Control functionality. The JavaScript code is responsible for 3642 proper Flash initialization, delivering mouse events to the Flash object, 3643 and processing resize requests from the Flash object. On the other hand, 3644 the SWF file contains a few JavaScript callable methods, which are used 3645 both from <computeroutput>webclient.js</computeroutput> and the user HTML 3625 3646 page.</para> 3626 3647 … … 3628 3649 <title>JavaScript functions</title> 3629 3650 3630 <para><computeroutput>webclient.js</computeroutput> contains helper 3631 functions. In the following table ElementId refers to an HTML 3632 element name or attribute, and Element to the HTML element itself. 3633 HTML code<programlisting> 3651 <para>The <computeroutput>webclient.js</computeroutput> file contains 3652 several helper JavaScript functions. In the following table ElementId 3653 refers to an HTML element name or attribute, and Element to the HTML 3654 element itself. 3655 The HTML code<programlisting> 3634 3656 <div id="FlashRDP"> 3635 3657 </div> … … 3641 3663 <programlisting>RDPWebClient.embedSWF(SWFFileName, ElementId)</programlisting> 3642 3664 3643 <para>Uses SWFObject library to replace the HTML element with3644 the Flash movie.</para>3665 <para>Uses the open-source SWFObject library to replace the HTML 3666 element with the Flash movie.</para> 3645 3667 </listitem> 3646 3668 … … 3648 3670 <programlisting>RDPWebClient.isRDPWebControlById(ElementId)</programlisting> 3649 3671 3650 <para>Returns true if the given id refers to a RDPWeb Flash 3672 <para>Returns true if the given ElementId refers to an RDPWeb 3673 Flash element.</para> 3674 </listitem> 3675 3676 <listitem> 3677 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting> 3678 3679 <para>Returns true if the given Element is an RDPWeb Flash 3651 3680 element.</para> 3652 3681 </listitem> 3653 3682 3654 3683 <listitem> 3655 <programlisting>RDPWebClient.isRDPWebControlByElement(Element)</programlisting>3656 3657 <para>Returns true if the given element is a RDPWeb Flash3658 element.</para>3659 </listitem>3660 3661 <listitem>3662 3684 <programlisting>RDPWebClient.getFlashById(ElementId)</programlisting> 3663 3685 3664 <para>Returns an element, which is referenced by the given id.3665 This function will try to resolve any element, event if it is3666 not a Flash movie.</para>3686 <para>Returns an element, which is referenced by the given 3687 ElementId. This function will try to resolve any element, even if 3688 it is not a Flash movie.</para> 3667 3689 </listitem> 3668 3690 </itemizedlist></para> … … 3672 3694 <title>Flash methods callable from JavaScript</title> 3673 3695 3674 <para> <computeroutput>RDPWebClienUI.swf</computeroutput> methods can3675 be called directly from JavaScript code on a HTML page.</para>3696 <para>The <computeroutput>RDPWebClienUI.swf</computeroutput> methods can 3697 be called directly from JavaScript code on an HTML page:</para> 3676 3698 3677 3699 <itemizedlist> … … 3709 3731 <title>Embedding RDPWeb in an HTML page</title> 3710 3732 3711 <para>It is necessary to include 3733 <para>It is necessary to include the 3712 3734 <computeroutput>webclient.js</computeroutput> helper script. If 3713 SWFObject library is used, the3714 <computeroutput>swfobject.js</computeroutput> must be also included3715 and RDPWeb flash content can be embedded to a Web page using dynamic3716 HTML. The HTML must include a "placeholder", which consists of 23717 <computeroutput>div</computeroutput> elements.</para>3735 the SWFObject library is used, the 3736 <computeroutput>swfobject.js</computeroutput> must also be included. 3737 Using the SWFObject library allows RDPWeb flash content to be embedded in 3738 a Web page using dynamic HTML. The HTML must include a "placeholder", 3739 which consists of 2 <computeroutput>div</computeroutput> elements.</para> 3718 3740 </sect2> 3719 3741 </sect1> … … 3777 3799 <title>Drag and Drop</title> 3778 3800 3779 <para> Since VirtualBox 4.2 it's possible to transfer files from host to the3780 Linux guests by dragging files, directories or text from the host into the3781 guest's screen. This is called <emphasis>drag and drop3801 <para>As of VirtualBox 4.2 it's possible to transfer files from the host to 3802 Linux, Solaris, and macOS guests by dragging files, directories, or text 3803 from the host into the guest's screen. This is called <emphasis>drag and drop 3782 3804 (DnD)</emphasis>.</para> 3783 3805 3784 <para> In version 5.0 support for Windows guests has been added, as well as3785 t he ability to transfer data the other way around, that is, from the guest3786 to thehost.</para>3787 3788 <note><para>Currently only the VirtualBox Manager front end supports drag and3806 <para>VirtualBox 5.0 added support for Windows guests as well as the ability 3807 to transfer data in the opposite direction, that is, from the guest to the 3808 host.</para> 3809 3810 <note><para>Currently only the VirtualBox Manager front-end supports drag and 3789 3811 drop.</para></note> 3790 3812 3791 3813 <para>This chapter will show how to use the required interfaces provided 3792 3814 by VirtualBox for adding drag and drop functionality to third-party 3793 front ends.</para>3815 front-ends.</para> 3794 3816 3795 3817 <sect1> … … 3797 3819 3798 3820 <para>In order to use the interfaces provided by VirtualBox, some basic 3799 concepts needs to be understood first: To successfully initiate a 3800 drag and drop operation at least two sides needs to be involved, a 3801 <emphasis>source</emphasis> and a <emphasis>target</emphasis>:</para> 3802 3803 <para>The <emphasis>source</emphasis> is the side which provides the 3804 data, e.g. is the origin of data. This data can be stored within the 3805 source directly or can be retrieved on-demand by the source itself. Other 3806 interfaces don't care where the data from this source actually came 3807 from.</para> 3808 3809 <para>The <emphasis>target</emphasis> on the other hand is the side which 3810 provides the source a visual representation where the user can drop the 3811 data the source offers. This representation can be a window (or just a 3812 certain part of it), for example.</para> 3821 concepts need to be understood first: a drag and drop operation logically 3822 contains both a <emphasis>source</emphasis> and a 3823 <emphasis>target</emphasis>:</para> 3824 3825 <para>The <emphasis>source</emphasis> provides the data, i.e., it is the 3826 origin of data. This data can be stored within the source directly or it can 3827 be retrieved on-demand by the source itself.</para> 3828 3829 <para>The <emphasis>target</emphasis> on the other hand provides a visual 3830 representation to the source where the user can drop the data the source 3831 offers. This representation can be a window (or just a certain part of 3832 it), for example.</para> 3813 3833 3814 3834 <para>The source and the target have abstract interfaces called … … 3818 3838 <link linkend="IGuestDnDSource">IGuestDnDSource</link> and 3819 3839 <link linkend="IGuestDnDTarget">IGuestDnDTarget</link>. Both 3820 implementations are also used in the VirtualBox Manager frontend.</para>3840 implementations are used in the VirtualBox Manager front-end.</para> 3821 3841 </sect1> 3822 3842 … … 3826 3846 <para>As the target needs to perform specific actions depending on the 3827 3847 data the source provided, the target first needs to know what type of 3828 data it actually isgoing to retrieve. It might be that the source offers3848 data it is actually going to retrieve. It might be that the source offers 3829 3849 data the target cannot (or intentionally does not want to) 3830 3850 support.</para> 3831 3851 3832 <para>VirtualBox handles those data types by providing so-called 3833 <emphasis>MIME types</emphasis> -- these MIME types were originally 3834 defined in 3852 <para>VirtualBox describes the data types using 3853 <emphasis>MIME types</emphasis> -- which were originally defined in 3835 3854 <ulink url="https://tools.ietf.org/html/rfc2046">RFC 2046</ulink> and 3836 are also called <emphasis>Content-types</emphasis>. 3855 are also called <emphasis>Content-types</emphasis> or 3856 <emphasis>media types</emphasis>. 3837 3857 <link linkend="IGuestDnDSource">IGuestDnDSource</link> and 3838 3858 <link linkend="IGuestDnDTarget">IGuestDnDTarget</link> support … … 3865 3885 removing and enumerating specific formats. 3866 3886 <note><para>Registering new or removing default formats on the guest side 3867 currently is notimplemented.</para></note></para>3887 is not currently implemented.</para></note></para> 3868 3888 </sect1> 3869 3889 … … 3874 3894 3875 3895 <para>VirtualBox supports arbitrary external modules to perform 3876 authentication. The module is used when the authentication method is set 3877 to "external" for a particular VM VRDE access and the library was 3878 specified with <computeroutput>VBoxManage setproperty 3879 vrdeauthlibrary</computeroutput>. Web service also use the authentication 3880 module which was specified with <computeroutput>VBoxManage setproperty 3881 websrvauthlibrary</computeroutput>.</para> 3896 authentication. External authentication modules are used for remote 3897 desktop access to a VM when the VRDE authentication type is set to 3898 "external". VRDE authentication will then use the authentication module 3899 which was specified with 3900 <computeroutput>VBoxManage setproperty vrdeauthlibrary</computeroutput>. 3901 The web service will use the external authentication module specified with 3902 <computeroutput>VBoxManage setproperty websrvauthlibrary</computeroutput>. 3903 </para> 3882 3904 3883 3905 <para>This library will be loaded by the VM or web service process on … … 3885 3907 or when a client that wants to use the web service logs on.</para> 3886 3908 3887 <para>External authentication is the most flexible a s the external handler3888 can both choose to grant access to everyone (like the "null"3889 authentication method would) and delegate the request to the guest3890 authentication component. When delegating the request to the guest3891 component , the handler will still be called afterwards with the option to3892 o verride the result.</para>3909 <para>External authentication is the most flexible authentication type 3910 since the external handler can choose to both grant access to everyone 3911 (like the "null" authentication method) as well as delegate the request to 3912 the guest authentication component. When delegating the request to the guest 3913 component the external handler will still be called afterwards with the 3914 option to override the result.</para> 3893 3915 3894 3916 <para>An authentication library is required to implement exactly one entry … … 3946 3968 consistent binary representation of UUIDs on all platforms. For this 3947 3969 reason the integer fields comprising the UUID are stored as little endian 3948 values. If you want to pass such UUIDs to code which assumes that the3970 values. If you want to pass such UUIDs to code which assumes that 3949 3971 integer fields are big endian (often also called network byte order), you 3950 need to adjust the contents of the UUID to e.g.achieve the same string3972 need to adjust the contents of the UUID to achieve the same string 3951 3973 representation. The required changes are:<itemizedlist> 3952 3974 <listitem> 3953 <para>reverse the order of byte 0, 1, 2 and 3</para>3954 </listitem> 3955 3956 <listitem> 3957 <para>reverse the order of byte 4 and 5</para>3958 </listitem> 3959 3960 <listitem> 3961 <para>reverse the order of byte 6 and 7.</para>3975 <para>reverse the order of bytes 0, 1, 2 and 3</para> 3976 </listitem> 3977 3978 <listitem> 3979 <para>reverse the order of bytes 4 and 5</para> 3980 </listitem> 3981 3982 <listitem> 3983 <para>reverse the order of bytes 6 and 7.</para> 3962 3984 </listitem> 3963 3985 </itemizedlist>Using this conversion you will get identical results when … … 3967 3989 contains information about the guest authentication status. For the first 3968 3990 call, it is always set to 3969 <computeroutput>AuthGuestNotAsked</computeroutput>. I n casethe3991 <computeroutput>AuthGuestNotAsked</computeroutput>. If the 3970 3992 <computeroutput>AuthEntry</computeroutput> function returns 3971 3993 <computeroutput>AuthResultDelegateToGuest</computeroutput>, a guest 3972 3994 authentication will be attempted and another call to the 3973 <computeroutput>AuthEntry</computeroutput> is made with its result. This3974 can be either granted / denied or no judgement (the guest component chose3975 for whatever reason to not make a decision). In case there is a problem3976 with the guest authentication module (e.g. the Additions are not installed3977 or not running or the guest did not respond within a timeout), the "not3978 re acted" status will be returned.</para>3995 <computeroutput>AuthEntry</computeroutput> is made with its result. The 3996 guest authentication can return either granted, denied, or no judgement 3997 (the guest component chose for whatever reason to not make a decision). 3998 In case there is a problem with the guest authentication module (e.g. the 3999 Guest Additions are not installed or not running or the guest did not 4000 respond within a timeout), the "not reacted" status will be returned.</para> 3979 4001 </chapter> 3980 4002 3981 4003 <chapter id="javaapi"> 3982 <title>Using Java API</title>4004 <title>Using the Java API</title> 3983 4005 3984 4006 <sect1> 3985 4007 <title>Introduction</title> 3986 4008 3987 <para>VirtualBox can be controlled by a Java API, both locally 3988 (COM/XPCOM) and from remote (SOAP) clients. As with the Python bindings,4009 <para>VirtualBox can be controlled by a Java API, both locally using 4010 COM/XPCOM and remotely using SOAP. As with the Python bindings, 3989 4011 a generic glue layer tries to hide all platform differences, allowing 3990 4012 for source and binary compatibility on different platforms.</para> … … 3997 4019 on the platform. First of all, you need JDK 1.5 (Java 5) or later. Also 3998 4020 please make sure that the version of the VirtualBox API .jar file 3999 exactly matches the version of VirtualBox youuse. To avoid confusion,4021 exactly matches the version of VirtualBox in use. To avoid confusion, 4000 4022 the VirtualBox API provides versioning in the Java package name, e.g. 4001 4023 the package is named <computeroutput>org.virtualbox_3_2</computeroutput> 4002 4024 for VirtualBox version 3.2. <itemizedlist> 4003 4025 <listitem> 4004 <para><emphasis role="bold">XPCOM</emphasis> - for all platforms ,4005 but Microsoft Windows. A Java bridge based on JavaXPCOM is shipped4026 <para><emphasis role="bold">XPCOM</emphasis> - for all platforms 4027 except Microsoft Windows. A Java bridge based on JavaXPCOM is shipped 4006 4028 with VirtualBox. The classpath must contain 4007 4029 <computeroutput>vboxjxpcom.jar</computeroutput> and the 4008 <computeroutput>vbox.home</computeroutput> property must be set to 4030 <computeroutput>vbox.home</computeroutput> property must be set to the 4009 4031 location where the VirtualBox binaries are. Please make sure that 4010 the JVM bitness matches bitness of VirtualBox youuse as the XPCOM4032 the JVM bitness matches the bitness of VirtualBox in use as the XPCOM 4011 4033 bridge relies on native libraries.</para> 4012 4034 … … 4019 4041 <para><emphasis role="bold">COM</emphasis> - for Microsoft 4020 4042 Windows. We rely on <computeroutput>Jacob</computeroutput> - a 4021 generic Java to COM bridge - which has to be installed sep erately.4043 generic Java to COM bridge - which has to be installed separately. 4022 4044 See <ulink 4023 4045 url="http://sourceforge.net/projects/jacob-project/">http://sourceforge.net/projects/jacob-project/</ulink> 4024 4046 for installation instructions. Also, the VirtualBox provided 4025 <computeroutput>vboxjmscom.jar</computeroutput> must be in the4047 <computeroutput>vboxjmscom.jar</computeroutput> file must be in the 4026 4048 class path.</para> 4027 4049 … … 4032 4054 <listitem> 4033 4055 <para><emphasis role="bold">SOAP</emphasis> - all platforms. Java 4034 6 is required , as it comes with builtin support for SOAP via the4056 6 is required as it comes with built-in support for SOAP via the 4035 4057 JAX-WS library. Also, the VirtualBox provided 4036 4058 <computeroutput>vbojws.jar</computeroutput> must be in the class … … 4046 4068 4047 4069 <para>Exception handling is also generalized by the generic glue layer, 4048 so that all methods c ouldthrow4049 <computeroutput>VBoxException</computeroutput> containing human-readable4070 so that all methods can throw 4071 <computeroutput>VBoxException</computeroutput> containing a human-readable 4050 4072 text message (see <computeroutput>getMessage()</computeroutput> method) 4051 along with wrapped original exception (see4073 along with the wrapped original exception (see 4052 4074 <computeroutput>getWrapped()</computeroutput> method).</para> 4053 4075 </sect1> … … 4057 4079 4058 4080 <para>This example shows a simple use case of the Java API. Differences 4059 for SOAP vs. local version are minimal,and limited to the connection4081 for SOAP vs. local execution are minimal and limited to the connection 4060 4082 setup phase (see <computeroutput>ws</computeroutput> variable). In the 4061 4083 SOAP case it's possible to create several VirtualBoxManager instances to … … 4084 4106 4085 4107 mgr.cleanup(); 4086 </programlisting> For more acomplete example, see4108 </programlisting> For a more complete example, see 4087 4109 <computeroutput>TestVBox.java</computeroutput>, shipped with the 4088 SDK. It contains exception handling and error printing code ,which4110 SDK. It contains exception handling and error printing code which 4089 4111 is important for reliable larger scale projects.</para> 4090 4112 4091 4113 <para>It is good practice in long-running API clients to process the 4092 system events every now and then in the main thread ( does not work4114 system events every now and then in the main thread (this does not work 4093 4115 in other threads). As a rule of thumb it makes sense to process them 4094 4116 every few 100msec to every few seconds). This is done by … … 4096 4118 mgr.waitForEvents(0); 4097 4119 </programlisting> 4098 This avoids that a large number of system events accumulate, which can4099 need a significant amount of memory, and as they also play a role in4120 This helps prevent a large number of system events from accumulating which 4121 can need a significant amount of memory, and as they also play a role in 4100 4122 object cleanup it helps freeing additional memory in a timely manner 4101 4123 which is used by the API implementation itself. Java's garbage collection 4102 4124 approach already needs more memory due to the delayed freeing of memory 4103 used by no longer accessible objects ,and not processing the system4125 used by no longer accessible objects and not processing the system 4104 4126 events exacerbates the memory usage. The 4105 4127 <computeroutput>TestVBox.java</computeroutput> example code sprinkles … … 4121 4143 4122 4144 <para>The Java files under 4123 <computeroutput> bindings/webservice/java/jax-ws/</computeroutput> (library4145 <computeroutput>sdk/bindings/webservice/java/jax-ws/</computeroutput> (library 4124 4146 files for the object-oriented web service) are, by contrast, licensed 4125 4147 under the GNU Lesser General Public License (LGPL) V2.1.</para> … … 4308 4330 4309 4331 <listitem><para>The webservice version of the <link linkend="ISharedFolder">ISharedFolder</link> 4310 interface was changed from a struct to a managed object. This causes incompatib lities on the4332 interface was changed from a struct to a managed object. This causes incompatibilities on the 4311 4333 protocol level as the shared folder attributes are not returned in the responses of 4312 4334 <link linkend="IVirtualBox__sharedFolders">IVirtualBox::getSharedFolders</link> and … … 4326 4348 <listitem><para>ProcessCreateFlag::NoProfile has been renamed to 4327 4349 <link linkend="ProcessCreateFlag__Profile">ProcessCreateFlag::Profile</link>, 4328 whereas the semantics also has been changed: ProcessCreateFlag::NoProfile 4329 explicitly <emphasis role="bold">did not</emphasis> utilize the guest user's profile data, 4330 which in turn <link linkend="ProcessCreateFlag__Profile">ProcessCreateFlag::Profile</link> 4331 explicitly <emphasis role="bold">does now</emphasis>.</para> 4350 and the semantics have also been changed: ProcessCreateFlag::NoProfile 4351 explicitly <emphasis role="bold">did not</emphasis> utilize the guest user's profile data 4352 whereas <link linkend="ProcessCreateFlag__Profile">ProcessCreateFlag::Profile</link> 4353 explicitly <emphasis role="bold">does</emphasis> utilize the guest 4354 user’s profile data.</para> 4332 4355 </listitem> 4333 4356 </itemizedlist> 4334 4357 4335 4358 </sect1> 4359 4360 <sect1> 4361 <title>Incompatible API changes with version 5.1.28</title> 4362 4363 <itemizedlist> 4364 <listitem><para>The Host-Guest Communication Manager (HGCM) guest driver 4365 interfaces were renamed: 4366 <itemizedlist> 4367 <listitem><para>VbglHGCMConnect() was renamed to VbglR0HGCMConnect() 4368 </para></listitem> 4369 <listitem><para>VbglHGCMDisconnect() was renamed to VbglR0HGCMDisconnect() 4370 </para></listitem> 4371 <listitem><para>VbglHGCMCall() was renamed to VbglR0HGCMCall() 4372 </para></listitem> 4373 </itemizedlist> 4374 </para> 4375 </listitem> 4376 4377 <listitem><para>The Host-Guest Communication Manager (HGCM) guest 4378 application interface IOCTLs were renamed: 4379 <itemizedlist> 4380 <listitem><para>VBOXGUEST_IOCTL_HGCM_CONNECT was renamed to 4381 VBGL_IOCTL_HGCM_CONNECT 4382 </para></listitem> 4383 <listitem><para>VBOXGUEST_IOCTL_HGCM_DISCONNECT was renamed to 4384 VBGL_IOCTL_HGCM_DISCONNECT 4385 </para></listitem> 4386 <listitem><para>VBOXGUEST_IOCTL_HGCM_CALL was renamed to 4387 VBGL_IOCTL_HGCM_CALL 4388 </para></listitem> 4389 </itemizedlist> 4390 </para> 4391 </listitem> 4392 4393 </itemizedlist> 4394 4395 </sect1> 4396 4336 4397 4337 4398 <sect1> … … 4518 4579 4519 4580 <listitem><para>IDisplay and IFramebuffer interfaces were changed to 4520 allow IFramebuffer object to reside in a separate front end4581 allow IFramebuffer object to reside in a separate front-end 4521 4582 process:<itemizedlist> 4522 4583 … … 4833 4894 the meaning of the <computeroutput>type</computeroutput> parameter 4834 4895 has changed slightly. Empty string now means that the per-VM or 4835 global default front end is launched. Most callers of this method4896 global default front-end is launched. Most callers of this method 4836 4897 should use the empty string now, unless they really want to override 4837 the default and launch a particular front end.</para>4898 the default and launch a particular front-end.</para> 4838 4899 </listitem> 4839 4900 … … 4909 4970 <link linkend="IGuestProcess">IGuestProcess</link> and so on - now 4910 4971 emit own events to provide clients much finer control and the ability 4911 to write own front ends for guest operations. The event4972 to write own front-ends for guest operations. The event 4912 4973 <link linkend="IGuestSessionEvent">IGuestSessionEvent</link> acts as 4913 4974 an abstract base class for all guest control events. Certain guest
Note:
See TracChangeset
for help on using the changeset viewer.