[55401] | 1 | /* $Id: tstAPI.cpp 99775 2023-05-12 12:21:58Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * tstAPI - test program for our COM/XPCOM interface
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
| 28 | #include <stdio.h>
|
---|
| 29 | #include <stdlib.h>
|
---|
| 30 |
|
---|
| 31 | #include <VBox/com/com.h>
|
---|
| 32 | #include <VBox/com/string.h>
|
---|
| 33 | #include <VBox/com/Guid.h>
|
---|
| 34 | #include <VBox/com/ErrorInfo.h>
|
---|
[20928] | 35 | #include <VBox/com/errorprint.h>
|
---|
[1] | 36 |
|
---|
| 37 | #include <VBox/com/VirtualBox.h>
|
---|
| 38 |
|
---|
| 39 | using namespace com;
|
---|
| 40 |
|
---|
| 41 | #define LOG_ENABLED
|
---|
| 42 | #define LOG_GROUP LOG_GROUP_MAIN
|
---|
| 43 | #include <VBox/log.h>
|
---|
| 44 |
|
---|
[14831] | 45 | #include <iprt/initterm.h>
|
---|
| 46 | #include <iprt/path.h>
|
---|
| 47 | #include <iprt/param.h>
|
---|
[437] | 48 | #include <iprt/stream.h>
|
---|
[16734] | 49 | #include <iprt/thread.h>
|
---|
[437] | 50 |
|
---|
[1] | 51 |
|
---|
[10725] | 52 | // forward declarations
|
---|
| 53 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 54 |
|
---|
[63378] | 55 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
| 56 | static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox, ComPtr<IUnknown> aObject);
|
---|
[32718] | 57 | static void queryMetrics(ComPtr<IVirtualBox> aVirtualBox,
|
---|
| 58 | ComPtr<IPerformanceCollector> collector,
|
---|
| 59 | ComSafeArrayIn(IUnknown *, objects));
|
---|
[12668] | 60 | static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox,
|
---|
| 61 | ComSafeArrayIn(IPerformanceMetric*, aMetrics));
|
---|
[63378] | 62 | #endif
|
---|
[10725] | 63 |
|
---|
[1] | 64 | // funcs
|
---|
| 65 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 66 |
|
---|
[99775] | 67 | #if 0 /* unused */
|
---|
| 68 | static HRESULT readAndChangeMachineSettings(IMachine *machine, IMachine *readonlyMachine = 0)
|
---|
[1] | 69 | {
|
---|
[95140] | 70 | HRESULT hrc = S_OK;
|
---|
[1] | 71 |
|
---|
| 72 | Bstr name;
|
---|
[32718] | 73 | RTPrintf("Getting machine name...\n");
|
---|
[95140] | 74 | CHECK_ERROR_RET(machine, COMGETTER(Name)(name.asOutParam()), hrc);
|
---|
[32718] | 75 | RTPrintf("Name: {%ls}\n", name.raw());
|
---|
[1] | 76 |
|
---|
[20928] | 77 | RTPrintf("Getting machine GUID...\n");
|
---|
| 78 | Bstr guid;
|
---|
[32718] | 79 | CHECK_ERROR(machine, COMGETTER(Id)(guid.asOutParam()));
|
---|
[95140] | 80 | if (SUCCEEDED(hrc) && !guid.isEmpty()) {
|
---|
[32718] | 81 | RTPrintf("Guid::toString(): {%s}\n", Utf8Str(guid).c_str());
|
---|
[1] | 82 | } else {
|
---|
[32718] | 83 | RTPrintf("WARNING: there's no GUID!");
|
---|
[1] | 84 | }
|
---|
| 85 |
|
---|
| 86 | ULONG memorySize;
|
---|
[32718] | 87 | RTPrintf("Getting memory size...\n");
|
---|
[95140] | 88 | CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySize), hrc);
|
---|
[32718] | 89 | RTPrintf("Memory size: %d\n", memorySize);
|
---|
[1] | 90 |
|
---|
| 91 | MachineState_T machineState;
|
---|
[32718] | 92 | RTPrintf("Getting machine state...\n");
|
---|
[95140] | 93 | CHECK_ERROR_RET(machine, COMGETTER(State)(&machineState), hrc);
|
---|
[32718] | 94 | RTPrintf("Machine state: %d\n", machineState);
|
---|
[1] | 95 |
|
---|
| 96 | BOOL modified;
|
---|
[32718] | 97 | RTPrintf("Are any settings modified?...\n");
|
---|
| 98 | CHECK_ERROR(machine, COMGETTER(SettingsModified)(&modified));
|
---|
[95140] | 99 | if (SUCCEEDED(hrc))
|
---|
[32718] | 100 | RTPrintf("%s\n", modified ? "yes" : "no");
|
---|
[1] | 101 |
|
---|
| 102 | ULONG memorySizeBig = memorySize * 10;
|
---|
[20928] | 103 | RTPrintf("Changing memory size to %d...\n", memorySizeBig);
|
---|
[32718] | 104 | CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySizeBig));
|
---|
[1] | 105 |
|
---|
[95140] | 106 | if (SUCCEEDED(hrc))
|
---|
[1128] | 107 | {
|
---|
[32718] | 108 | RTPrintf("Are any settings modified now?...\n");
|
---|
[95140] | 109 | CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
|
---|
[32718] | 110 | RTPrintf("%s\n", modified ? "yes" : "no");
|
---|
| 111 | ASSERT_RET(modified, 0);
|
---|
[1] | 112 |
|
---|
| 113 | ULONG memorySizeGot;
|
---|
[32718] | 114 | RTPrintf("Getting memory size again...\n");
|
---|
[95140] | 115 | CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
|
---|
[32718] | 116 | RTPrintf("Memory size: %d\n", memorySizeGot);
|
---|
| 117 | ASSERT_RET(memorySizeGot == memorySizeBig, 0);
|
---|
[1] | 118 |
|
---|
[1128] | 119 | if (readonlyMachine)
|
---|
| 120 | {
|
---|
[32718] | 121 | RTPrintf("Getting memory size of the counterpart readonly machine...\n");
|
---|
[1] | 122 | ULONG memorySizeRO;
|
---|
[32718] | 123 | readonlyMachine->COMGETTER(MemorySize)(&memorySizeRO);
|
---|
| 124 | RTPrintf("Memory size: %d\n", memorySizeRO);
|
---|
| 125 | ASSERT_RET(memorySizeRO != memorySizeGot, 0);
|
---|
[1] | 126 | }
|
---|
| 127 |
|
---|
[32718] | 128 | RTPrintf("Discarding recent changes...\n");
|
---|
[95140] | 129 | CHECK_ERROR_RET(machine, DiscardSettings(), hrc);
|
---|
[32718] | 130 | RTPrintf("Are any settings modified after discarding?...\n");
|
---|
[95140] | 131 | CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
|
---|
[32718] | 132 | RTPrintf("%s\n", modified ? "yes" : "no");
|
---|
| 133 | ASSERT_RET(!modified, 0);
|
---|
[1] | 134 |
|
---|
[32718] | 135 | RTPrintf("Getting memory size once more...\n");
|
---|
[95140] | 136 | CHECK_ERROR_RET(machine, COMGETTER(MemorySize)(&memorySizeGot), hrc);
|
---|
[32718] | 137 | RTPrintf("Memory size: %d\n", memorySizeGot);
|
---|
| 138 | ASSERT_RET(memorySizeGot == memorySize, 0);
|
---|
[1] | 139 |
|
---|
| 140 | memorySize = memorySize > 128 ? memorySize / 2 : memorySize * 2;
|
---|
[20928] | 141 | RTPrintf("Changing memory size to %d...\n", memorySize);
|
---|
[95140] | 142 | CHECK_ERROR_RET(machine, COMSETTER(MemorySize)(memorySize), hrc);
|
---|
[1] | 143 | }
|
---|
| 144 |
|
---|
[1128] | 145 | Bstr desc;
|
---|
[32718] | 146 | RTPrintf("Getting description...\n");
|
---|
[95140] | 147 | CHECK_ERROR_RET(machine, COMGETTER(Description)(desc.asOutParam()), hrc);
|
---|
[32718] | 148 | RTPrintf("Description is: \"%ls\"\n", desc.raw());
|
---|
[1128] | 149 |
|
---|
| 150 | desc = L"This is an exemplary description (changed).";
|
---|
[32718] | 151 | RTPrintf("Setting description to \"%ls\"...\n", desc.raw());
|
---|
[95140] | 152 | CHECK_ERROR_RET(machine, COMSETTER(Description)(desc.raw()), hrc);
|
---|
[1128] | 153 |
|
---|
[32718] | 154 | RTPrintf("Saving machine settings...\n");
|
---|
| 155 | CHECK_ERROR(machine, SaveSettings());
|
---|
[95140] | 156 | if (SUCCEEDED(hrc))
|
---|
[1128] | 157 | {
|
---|
[32718] | 158 | RTPrintf("Are any settings modified after saving?...\n");
|
---|
[95140] | 159 | CHECK_ERROR_RET(machine, COMGETTER(SettingsModified)(&modified), hrc);
|
---|
[32718] | 160 | RTPrintf("%s\n", modified ? "yes" : "no");
|
---|
| 161 | ASSERT_RET(!modified, 0);
|
---|
[1] | 162 |
|
---|
| 163 | if (readonlyMachine) {
|
---|
[32718] | 164 | RTPrintf("Getting memory size of the counterpart readonly machine...\n");
|
---|
[1] | 165 | ULONG memorySizeRO;
|
---|
[32718] | 166 | readonlyMachine->COMGETTER(MemorySize)(&memorySizeRO);
|
---|
| 167 | RTPrintf("Memory size: %d\n", memorySizeRO);
|
---|
| 168 | ASSERT_RET(memorySizeRO == memorySize, 0);
|
---|
[1] | 169 | }
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | Bstr extraDataKey = L"Blafasel";
|
---|
| 173 | Bstr extraData;
|
---|
[32718] | 174 | RTPrintf("Getting extra data key {%ls}...\n", extraDataKey.raw());
|
---|
[95140] | 175 | CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
|
---|
[1] | 176 | if (!extraData.isEmpty()) {
|
---|
[32718] | 177 | RTPrintf("Extra data value: {%ls}\n", extraData.raw());
|
---|
[1] | 178 | } else {
|
---|
[32718] | 179 | RTPrintf("No extra data exists\n");
|
---|
[1] | 180 | }
|
---|
| 181 |
|
---|
| 182 | if (extraData.isEmpty())
|
---|
| 183 | extraData = L"Das ist die Berliner Luft, Luft, Luft...";
|
---|
| 184 | else
|
---|
| 185 | extraData.setNull();
|
---|
[32718] | 186 | RTPrintf("Setting extra data key {%ls} to {%ls}...\n",
|
---|
| 187 | extraDataKey.raw(), extraData.raw());
|
---|
| 188 | CHECK_ERROR(machine, SetExtraData(extraDataKey.raw(), extraData.raw()));
|
---|
[1] | 189 |
|
---|
[95140] | 190 | if (SUCCEEDED(hrc)) {
|
---|
[32718] | 191 | RTPrintf("Getting extra data key {%ls} again...\n", extraDataKey.raw());
|
---|
[95140] | 192 | CHECK_ERROR_RET(machine, GetExtraData(extraDataKey.raw(), extraData.asOutParam()), hrc);
|
---|
[1] | 193 | if (!extraData.isEmpty()) {
|
---|
[32718] | 194 | RTPrintf("Extra data value: {%ls}\n", extraData.raw());
|
---|
[1] | 195 | } else {
|
---|
[32718] | 196 | RTPrintf("No extra data exists\n");
|
---|
[1] | 197 | }
|
---|
| 198 | }
|
---|
| 199 |
|
---|
[95140] | 200 | return hrc;
|
---|
[1] | 201 | }
|
---|
[99775] | 202 | #endif
|
---|
[1] | 203 |
|
---|
| 204 | // main
|
---|
| 205 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 206 |
|
---|
| 207 | int main(int argc, char *argv[])
|
---|
| 208 | {
|
---|
| 209 | /*
|
---|
| 210 | * Initialize the VBox runtime without loading
|
---|
| 211 | * the support driver.
|
---|
| 212 | */
|
---|
[38636] | 213 | RTR3InitExe(argc, &argv, 0);
|
---|
[1] | 214 |
|
---|
[95140] | 215 | HRESULT hrc;
|
---|
[1] | 216 |
|
---|
[3387] | 217 | {
|
---|
[32718] | 218 | char homeDir[RTPATH_MAX];
|
---|
| 219 | GetVBoxUserHomeDirectory(homeDir, sizeof(homeDir));
|
---|
| 220 | RTPrintf("VirtualBox Home Directory = '%s'\n", homeDir);
|
---|
[3387] | 221 | }
|
---|
| 222 |
|
---|
[32718] | 223 | RTPrintf("Initializing COM...\n");
|
---|
[1] | 224 |
|
---|
[95140] | 225 | hrc = com::Initialize();
|
---|
| 226 | if (FAILED(hrc))
|
---|
[20928] | 227 | {
|
---|
| 228 | RTPrintf("ERROR: failed to initialize COM!\n");
|
---|
[95140] | 229 | return hrc;
|
---|
[20928] | 230 | }
|
---|
[1] | 231 |
|
---|
| 232 | do
|
---|
| 233 | {
|
---|
| 234 | // scopes all the stuff till shutdown
|
---|
| 235 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 236 |
|
---|
[60063] | 237 | ComPtr<IVirtualBoxClient> virtualBoxClient;
|
---|
[21878] | 238 | ComPtr<IVirtualBox> virtualBox;
|
---|
| 239 | ComPtr<ISession> session;
|
---|
[1] | 240 |
|
---|
[3387] | 241 | #if 0
|
---|
| 242 | // Utf8Str test
|
---|
| 243 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 244 |
|
---|
| 245 | Utf8Str nullUtf8Str;
|
---|
[32718] | 246 | RTPrintf("nullUtf8Str='%s'\n", nullUtf8Str.raw());
|
---|
[6909] | 247 |
|
---|
[3387] | 248 | Utf8Str simpleUtf8Str = "simpleUtf8Str";
|
---|
[32718] | 249 | RTPrintf("simpleUtf8Str='%s'\n", simpleUtf8Str.raw());
|
---|
[3387] | 250 |
|
---|
[32718] | 251 | Utf8Str utf8StrFmt = Utf8StrFmt("[0=%d]%s[1=%d]", 0, "utf8StrFmt", 1);
|
---|
| 252 | RTPrintf("utf8StrFmt='%s'\n", utf8StrFmt.raw());
|
---|
[3387] | 253 |
|
---|
| 254 | #endif
|
---|
| 255 |
|
---|
[32718] | 256 | RTPrintf("Creating VirtualBox object...\n");
|
---|
[95140] | 257 | hrc = virtualBoxClient.createInprocObject(CLSID_VirtualBoxClient);
|
---|
| 258 | if (SUCCEEDED(hrc))
|
---|
| 259 | hrc = virtualBoxClient->COMGETTER(VirtualBox)(virtualBox.asOutParam());
|
---|
| 260 | if (FAILED(hrc))
|
---|
[20928] | 261 | RTPrintf("ERROR: failed to create the VirtualBox object!\n");
|
---|
| 262 | else
|
---|
[1] | 263 | {
|
---|
[95140] | 264 | hrc = session.createInprocObject(CLSID_Session);
|
---|
| 265 | if (FAILED(hrc))
|
---|
[20928] | 266 | RTPrintf("ERROR: failed to create a session object!\n");
|
---|
[1] | 267 | }
|
---|
| 268 |
|
---|
[95140] | 269 | if (FAILED(hrc))
|
---|
[1] | 270 | {
|
---|
[20928] | 271 | com::ErrorInfo info;
|
---|
| 272 | if (!info.isFullAvailable() && !info.isBasicAvailable())
|
---|
| 273 | {
|
---|
[95140] | 274 | com::GluePrintRCMessage(hrc);
|
---|
[20928] | 275 | RTPrintf("Most likely, the VirtualBox COM server is not running or failed to start.\n");
|
---|
| 276 | }
|
---|
| 277 | else
|
---|
| 278 | com::GluePrintErrorInfo(info);
|
---|
[1] | 279 | break;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
[6909] | 282 | #if 0
|
---|
[16817] | 283 | // Testing VirtualBox::COMGETTER(ProgressOperations).
|
---|
| 284 | // This is designed to be tested while running
|
---|
| 285 | // "./VBoxManage clonehd src.vdi clone.vdi" in parallel.
|
---|
| 286 | // It will then display the progress every 2 seconds.
|
---|
| 287 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 288 | {
|
---|
[32718] | 289 | RTPrintf("Testing VirtualBox::COMGETTER(ProgressOperations)...\n");
|
---|
[16817] | 290 |
|
---|
| 291 | for (;;) {
|
---|
[21878] | 292 | com::SafeIfaceArray<IProgress> operations;
|
---|
[16817] | 293 |
|
---|
[32718] | 294 | CHECK_ERROR_BREAK(virtualBox,
|
---|
[16817] | 295 | COMGETTER(ProgressOperations)(ComSafeArrayAsOutParam(operations)));
|
---|
| 296 |
|
---|
[32718] | 297 | RTPrintf("operations: %d\n", operations.size());
|
---|
[16817] | 298 | if (operations.size() == 0)
|
---|
| 299 | break; // No more operations left.
|
---|
| 300 |
|
---|
| 301 | for (size_t i = 0; i < operations.size(); ++i) {
|
---|
| 302 | PRInt32 percent;
|
---|
| 303 |
|
---|
| 304 | operations[i]->COMGETTER(Percent)(&percent);
|
---|
[32718] | 305 | RTPrintf("operations[%u]: %ld\n", (unsigned)i, (long)percent);
|
---|
[16817] | 306 | }
|
---|
[32718] | 307 | RTThreadSleep(2000); // msec
|
---|
[16817] | 308 | }
|
---|
| 309 | }
|
---|
| 310 | #endif
|
---|
| 311 |
|
---|
| 312 | #if 0
|
---|
[1] | 313 | // IUnknown identity test
|
---|
| 314 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 315 | {
|
---|
| 316 | {
|
---|
[21878] | 317 | ComPtr<IVirtualBox> virtualBox2;
|
---|
[1] | 318 |
|
---|
[32718] | 319 | RTPrintf("Creating one more VirtualBox object...\n");
|
---|
[60063] | 320 | CHECK_RC(virtualBoxClient->COMGETTER(virtualBox2.asOutParam()));
|
---|
[32718] | 321 | if (FAILED(rc))
|
---|
[3834] | 322 | {
|
---|
| 323 | CHECK_ERROR_NOCALL();
|
---|
| 324 | break;
|
---|
| 325 | }
|
---|
[1] | 326 |
|
---|
[32718] | 327 | RTPrintf("IVirtualBox(virtualBox)=%p IVirtualBox(virtualBox2)=%p\n",
|
---|
| 328 | (IVirtualBox *)virtualBox, (IVirtualBox *)virtualBox2);
|
---|
| 329 | Assert((IVirtualBox *)virtualBox == (IVirtualBox *)virtualBox2);
|
---|
[1] | 330 |
|
---|
[32718] | 331 | ComPtr<IUnknown> unk(virtualBox);
|
---|
[21878] | 332 | ComPtr<IUnknown> unk2;
|
---|
[3834] | 333 | unk2 = virtualBox2;
|
---|
[1] | 334 |
|
---|
[32718] | 335 | RTPrintf("IUnknown(virtualBox)=%p IUnknown(virtualBox2)=%p\n",
|
---|
| 336 | (IUnknown *)unk, (IUnknown *)unk2);
|
---|
| 337 | Assert((IUnknown *)unk == (IUnknown *)unk2);
|
---|
[1] | 338 |
|
---|
[21878] | 339 | ComPtr<IVirtualBox> vb = unk;
|
---|
| 340 | ComPtr<IVirtualBox> vb2 = unk;
|
---|
[1] | 341 |
|
---|
[32718] | 342 | RTPrintf("IVirtualBox(IUnknown(virtualBox))=%p IVirtualBox(IUnknown(virtualBox2))=%p\n",
|
---|
| 343 | (IVirtualBox *)vb, (IVirtualBox *)vb2);
|
---|
| 344 | Assert((IVirtualBox *)vb == (IVirtualBox *)vb2);
|
---|
[3834] | 345 | }
|
---|
| 346 |
|
---|
| 347 | {
|
---|
[21878] | 348 | ComPtr<IHost> host;
|
---|
[32718] | 349 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
| 350 | RTPrintf(" IHost(host)=%p\n", (IHost *)host);
|
---|
[21878] | 351 | ComPtr<IUnknown> unk = host;
|
---|
[32718] | 352 | RTPrintf(" IUnknown(host)=%p\n", (IUnknown *)unk);
|
---|
[21878] | 353 | ComPtr<IHost> host_copy = unk;
|
---|
[32718] | 354 | RTPrintf(" IHost(host_copy)=%p\n", (IHost *)host_copy);
|
---|
[21878] | 355 | ComPtr<IUnknown> unk_copy = host_copy;
|
---|
[32718] | 356 | RTPrintf(" IUnknown(host_copy)=%p\n", (IUnknown *)unk_copy);
|
---|
| 357 | Assert((IUnknown *)unk == (IUnknown *)unk_copy);
|
---|
[3834] | 358 |
|
---|
| 359 | /* query IUnknown on IUnknown */
|
---|
[21878] | 360 | ComPtr<IUnknown> unk_copy_copy;
|
---|
| 361 | unk_copy.queryInterfaceTo(unk_copy_copy.asOutParam());
|
---|
[32718] | 362 | RTPrintf(" IUnknown(unk_copy)=%p\n", (IUnknown *)unk_copy_copy);
|
---|
| 363 | Assert((IUnknown *)unk_copy == (IUnknown *)unk_copy_copy);
|
---|
[3834] | 364 | /* query IUnknown on IUnknown in the opposite direction */
|
---|
[21878] | 365 | unk_copy_copy.queryInterfaceTo(unk_copy.asOutParam());
|
---|
[32718] | 366 | RTPrintf(" IUnknown(unk_copy_copy)=%p\n", (IUnknown *)unk_copy);
|
---|
| 367 | Assert((IUnknown *)unk_copy == (IUnknown *)unk_copy_copy);
|
---|
[3834] | 368 |
|
---|
| 369 | /* query IUnknown again after releasing all previous IUnknown instances
|
---|
| 370 | * but keeping IHost -- it should remain the same (Identity Rule) */
|
---|
| 371 | IUnknown *oldUnk = unk;
|
---|
| 372 | unk.setNull();
|
---|
| 373 | unk_copy.setNull();
|
---|
| 374 | unk_copy_copy.setNull();
|
---|
| 375 | unk = host;
|
---|
[32718] | 376 | RTPrintf(" IUnknown(host)=%p\n", (IUnknown *)unk);
|
---|
| 377 | Assert(oldUnk == (IUnknown *)unk);
|
---|
[3834] | 378 | }
|
---|
| 379 |
|
---|
[32718] | 380 | // RTPrintf("Will be now released (press Enter)...");
|
---|
[3834] | 381 | // getchar();
|
---|
[1] | 382 | }
|
---|
| 383 | #endif
|
---|
| 384 |
|
---|
[5523] | 385 | #if 0
|
---|
| 386 | // the simplest COM API test
|
---|
| 387 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 388 | {
|
---|
| 389 | Bstr version;
|
---|
[32718] | 390 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Version)(version.asOutParam()));
|
---|
| 391 | RTPrintf("VirtualBox version = %ls\n", version.raw());
|
---|
[5523] | 392 | }
|
---|
| 393 | #endif
|
---|
| 394 |
|
---|
[13580] | 395 | #if 0
|
---|
[6909] | 396 | // Array test
|
---|
| 397 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 398 | {
|
---|
[32718] | 399 | RTPrintf("Calling IVirtualBox::Machines...\n");
|
---|
[6909] | 400 |
|
---|
[21878] | 401 | com::SafeIfaceArray<IMachine> machines;
|
---|
[32718] | 402 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 403 | COMGETTER(Machines)(ComSafeArrayAsOutParam(machines)));
|
---|
[6909] | 404 |
|
---|
[32718] | 405 | RTPrintf("%u machines registered (machines.isNull()=%d).\n",
|
---|
[6922] | 406 | machines.size(), machines.isNull());
|
---|
[6909] | 407 |
|
---|
| 408 | for (size_t i = 0; i < machines.size(); ++ i)
|
---|
| 409 | {
|
---|
| 410 | Bstr name;
|
---|
[32718] | 411 | CHECK_ERROR_BREAK(machines[i], COMGETTER(Name)(name.asOutParam()));
|
---|
| 412 | RTPrintf("machines[%u]='%s'\n", i, Utf8Str(name).raw());
|
---|
[6909] | 413 | }
|
---|
[13580] | 414 |
|
---|
| 415 | #if 0
|
---|
| 416 | {
|
---|
[32718] | 417 | RTPrintf("Testing [out] arrays...\n");
|
---|
[13580] | 418 | com::SafeGUIDArray uuids;
|
---|
[32718] | 419 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 420 | COMGETTER(Uuids)(ComSafeArrayAsOutParam(uuids)));
|
---|
[13580] | 421 |
|
---|
| 422 | for (size_t i = 0; i < uuids.size(); ++ i)
|
---|
[32718] | 423 | RTPrintf("uuids[%u]=%RTuuid\n", i, &uuids[i]);
|
---|
[13580] | 424 | }
|
---|
| 425 |
|
---|
| 426 | {
|
---|
[32718] | 427 | RTPrintf("Testing [in] arrays...\n");
|
---|
| 428 | com::SafeGUIDArray uuids(5);
|
---|
[13580] | 429 | for (size_t i = 0; i < uuids.size(); ++ i)
|
---|
| 430 | {
|
---|
| 431 | Guid id;
|
---|
| 432 | id.create();
|
---|
[32718] | 433 | uuids[i] = id;
|
---|
| 434 | RTPrintf("uuids[%u]=%RTuuid\n", i, &uuids[i]);
|
---|
[13580] | 435 | }
|
---|
| 436 |
|
---|
[32718] | 437 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 438 | SetUuids(ComSafeArrayAsInParam(uuids)));
|
---|
[13580] | 439 | }
|
---|
| 440 | #endif
|
---|
| 441 |
|
---|
[6909] | 442 | }
|
---|
| 443 | #endif
|
---|
| 444 |
|
---|
[5523] | 445 | #if 0
|
---|
[1] | 446 | // some outdated stuff
|
---|
| 447 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 448 |
|
---|
[20928] | 449 | RTPrintf("Getting IHost interface...\n");
|
---|
[1] | 450 | IHost *host;
|
---|
| 451 | rc = virtualBox->GetHost(&host);
|
---|
| 452 | if (SUCCEEDED(rc))
|
---|
| 453 | {
|
---|
| 454 | IHostDVDDriveCollection *dvdColl;
|
---|
| 455 | rc = host->GetHostDVDDrives(&dvdColl);
|
---|
| 456 | if (SUCCEEDED(rc))
|
---|
| 457 | {
|
---|
| 458 | IHostDVDDrive *dvdDrive = NULL;
|
---|
| 459 | dvdColl->GetNextHostDVDDrive(dvdDrive, &dvdDrive);
|
---|
| 460 | while (dvdDrive)
|
---|
| 461 | {
|
---|
| 462 | BSTR driveName;
|
---|
| 463 | char *driveNameUtf8;
|
---|
| 464 | dvdDrive->GetDriveName(&driveName);
|
---|
[7418] | 465 | RTUtf16ToUtf8((PCRTUTF16)driveName, &driveNameUtf8);
|
---|
[20928] | 466 | RTPrintf("Host DVD drive name: %s\n", driveNameUtf8);
|
---|
[1] | 467 | RTStrFree(driveNameUtf8);
|
---|
| 468 | SysFreeString(driveName);
|
---|
| 469 | IHostDVDDrive *dvdDriveTemp = dvdDrive;
|
---|
| 470 | dvdColl->GetNextHostDVDDrive(dvdDriveTemp, &dvdDrive);
|
---|
| 471 | dvdDriveTemp->Release();
|
---|
| 472 | }
|
---|
| 473 | dvdColl->Release();
|
---|
| 474 | } else
|
---|
| 475 | {
|
---|
[20928] | 476 | RTPrintf("Could not get host DVD drive collection\n");
|
---|
[1] | 477 | }
|
---|
| 478 |
|
---|
| 479 | IHostFloppyDriveCollection *floppyColl;
|
---|
| 480 | rc = host->GetHostFloppyDrives(&floppyColl);
|
---|
| 481 | if (SUCCEEDED(rc))
|
---|
| 482 | {
|
---|
| 483 | IHostFloppyDrive *floppyDrive = NULL;
|
---|
| 484 | floppyColl->GetNextHostFloppyDrive(floppyDrive, &floppyDrive);
|
---|
| 485 | while (floppyDrive)
|
---|
| 486 | {
|
---|
| 487 | BSTR driveName;
|
---|
| 488 | char *driveNameUtf8;
|
---|
| 489 | floppyDrive->GetDriveName(&driveName);
|
---|
[7418] | 490 | RTUtf16ToUtf8((PCRTUTF16)driveName, &driveNameUtf8);
|
---|
[20928] | 491 | RTPrintf("Host floppy drive name: %s\n", driveNameUtf8);
|
---|
[1] | 492 | RTStrFree(driveNameUtf8);
|
---|
| 493 | SysFreeString(driveName);
|
---|
| 494 | IHostFloppyDrive *floppyDriveTemp = floppyDrive;
|
---|
| 495 | floppyColl->GetNextHostFloppyDrive(floppyDriveTemp, &floppyDrive);
|
---|
| 496 | floppyDriveTemp->Release();
|
---|
| 497 | }
|
---|
| 498 | floppyColl->Release();
|
---|
| 499 | } else
|
---|
| 500 | {
|
---|
[20928] | 501 | RTPrintf("Could not get host floppy drive collection\n");
|
---|
[1] | 502 | }
|
---|
| 503 | host->Release();
|
---|
| 504 | } else
|
---|
| 505 | {
|
---|
[20928] | 506 | RTPrintf("Call failed\n");
|
---|
[1] | 507 | }
|
---|
[32718] | 508 | RTPrintf("\n");
|
---|
[1] | 509 | #endif
|
---|
| 510 |
|
---|
| 511 | #if 0
|
---|
| 512 | // IVirtualBoxErrorInfo test
|
---|
| 513 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 514 | {
|
---|
| 515 | // RPC calls
|
---|
| 516 |
|
---|
| 517 | // call a method that will definitely fail
|
---|
| 518 | Guid uuid;
|
---|
[21878] | 519 | ComPtr<IHardDisk> hardDisk;
|
---|
[1] | 520 | rc = virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
|
---|
[32718] | 521 | RTPrintf("virtualBox->GetHardDisk(null-uuid)=%08X\n", rc);
|
---|
[1] | 522 |
|
---|
| 523 | // {
|
---|
[32718] | 524 | // com::ErrorInfo info(virtualBox);
|
---|
| 525 | // PRINT_ERROR_INFO(info);
|
---|
[1] | 526 | // }
|
---|
| 527 |
|
---|
| 528 | // call a method that will definitely succeed
|
---|
| 529 | Bstr version;
|
---|
[32718] | 530 | rc = virtualBox->COMGETTER(Version)(version.asOutParam());
|
---|
| 531 | RTPrintf("virtualBox->COMGETTER(Version)=%08X\n", rc);
|
---|
[1] | 532 |
|
---|
| 533 | {
|
---|
[32718] | 534 | com::ErrorInfo info(virtualBox);
|
---|
| 535 | PRINT_ERROR_INFO(info);
|
---|
[1] | 536 | }
|
---|
| 537 |
|
---|
| 538 | // Local calls
|
---|
| 539 |
|
---|
| 540 | // call a method that will definitely fail
|
---|
[21878] | 541 | ComPtr<IMachine> machine;
|
---|
[1] | 542 | rc = session->COMGETTER(Machine)(machine.asOutParam());
|
---|
[32718] | 543 | RTPrintf("session->COMGETTER(Machine)=%08X\n", rc);
|
---|
[1] | 544 |
|
---|
| 545 | // {
|
---|
[32718] | 546 | // com::ErrorInfo info(virtualBox);
|
---|
| 547 | // PRINT_ERROR_INFO(info);
|
---|
[1] | 548 | // }
|
---|
| 549 |
|
---|
| 550 | // call a method that will definitely succeed
|
---|
| 551 | SessionState_T state;
|
---|
[32718] | 552 | rc = session->COMGETTER(State)(&state);
|
---|
| 553 | RTPrintf("session->COMGETTER(State)=%08X\n", rc);
|
---|
[1] | 554 |
|
---|
| 555 | {
|
---|
[32718] | 556 | com::ErrorInfo info(virtualBox);
|
---|
| 557 | PRINT_ERROR_INFO(info);
|
---|
[1] | 558 | }
|
---|
| 559 | }
|
---|
| 560 | #endif
|
---|
| 561 |
|
---|
[5523] | 562 | #if 0
|
---|
[1] | 563 | // register the existing hard disk image
|
---|
| 564 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 565 | do
|
---|
| 566 | {
|
---|
[21878] | 567 | ComPtr<IHardDisk> hd;
|
---|
[1] | 568 | Bstr src = L"E:\\develop\\innotek\\images\\NewHardDisk.vdi";
|
---|
[32718] | 569 | RTPrintf("Opening the existing hard disk '%ls'...\n", src.raw());
|
---|
| 570 | CHECK_ERROR_BREAK(virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, hd.asOutParam()));
|
---|
| 571 | RTPrintf("Enter to continue...\n");
|
---|
[5028] | 572 | getchar();
|
---|
[32718] | 573 | RTPrintf("Registering the existing hard disk '%ls'...\n", src.raw());
|
---|
| 574 | CHECK_ERROR_BREAK(virtualBox, RegisterHardDisk(hd));
|
---|
| 575 | RTPrintf("Enter to continue...\n");
|
---|
[5028] | 576 | getchar();
|
---|
[1] | 577 | }
|
---|
| 578 | while (FALSE);
|
---|
[32718] | 579 | RTPrintf("\n");
|
---|
[1] | 580 | #endif
|
---|
| 581 |
|
---|
| 582 | #if 0
|
---|
| 583 | // find and unregister the existing hard disk image
|
---|
| 584 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 585 | do
|
---|
| 586 | {
|
---|
[21878] | 587 | ComPtr<IVirtualDiskImage> vdi;
|
---|
[1] | 588 | Bstr src = L"CreatorTest.vdi";
|
---|
[32718] | 589 | RTPrintf("Unregistering the hard disk '%ls'...\n", src.raw());
|
---|
| 590 | CHECK_ERROR_BREAK(virtualBox, FindVirtualDiskImage(src, vdi.asOutParam()));
|
---|
[21878] | 591 | ComPtr<IHardDisk> hd = vdi;
|
---|
[1] | 592 | Guid id;
|
---|
[32718] | 593 | CHECK_ERROR_BREAK(hd, COMGETTER(Id)(id.asOutParam()));
|
---|
| 594 | CHECK_ERROR_BREAK(virtualBox, UnregisterHardDisk(id, hd.asOutParam()));
|
---|
[1] | 595 | }
|
---|
| 596 | while (FALSE);
|
---|
[32718] | 597 | RTPrintf("\n");
|
---|
[1] | 598 | #endif
|
---|
| 599 |
|
---|
| 600 | #if 0
|
---|
| 601 | // clone the registered hard disk
|
---|
| 602 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 603 | do
|
---|
| 604 | {
|
---|
[3668] | 605 | #if defined RT_OS_LINUX
|
---|
[1] | 606 | Bstr src = L"/mnt/hugaida/common/develop/innotek/images/freedos-linux.vdi";
|
---|
| 607 | #else
|
---|
| 608 | Bstr src = L"E:/develop/innotek/images/freedos.vdi";
|
---|
| 609 | #endif
|
---|
| 610 | Bstr dst = L"./clone.vdi";
|
---|
[32718] | 611 | RTPrintf("Cloning '%ls' to '%ls'...\n", src.raw(), dst.raw());
|
---|
[21878] | 612 | ComPtr<IVirtualDiskImage> vdi;
|
---|
[32718] | 613 | CHECK_ERROR_BREAK(virtualBox, FindVirtualDiskImage(src, vdi.asOutParam()));
|
---|
[21878] | 614 | ComPtr<IHardDisk> hd = vdi;
|
---|
| 615 | ComPtr<IProgress> progress;
|
---|
[32718] | 616 | CHECK_ERROR_BREAK(hd, CloneToImage(dst, vdi.asOutParam(), progress.asOutParam()));
|
---|
| 617 | RTPrintf("Waiting for completion...\n");
|
---|
| 618 | CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
|
---|
| 619 | ProgressErrorInfo ei(progress);
|
---|
| 620 | if (FAILED(ei.getResultCode()))
|
---|
[1] | 621 | {
|
---|
[32718] | 622 | PRINT_ERROR_INFO(ei);
|
---|
[1] | 623 | }
|
---|
| 624 | else
|
---|
| 625 | {
|
---|
[32718] | 626 | vdi->COMGETTER(FilePath)(dst.asOutParam());
|
---|
| 627 | RTPrintf("Actual clone path is '%ls'\n", dst.raw());
|
---|
[1] | 628 | }
|
---|
| 629 | }
|
---|
| 630 | while (FALSE);
|
---|
[32718] | 631 | RTPrintf("\n");
|
---|
[1] | 632 | #endif
|
---|
| 633 |
|
---|
[3387] | 634 | #if 0
|
---|
[14596] | 635 | // find a registered hard disk by location and get properties
|
---|
[2029] | 636 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 637 | do
|
---|
| 638 | {
|
---|
[21878] | 639 | ComPtr<IHardDisk> hd;
|
---|
[2333] | 640 | static const wchar_t *Names[] =
|
---|
[2029] | 641 | {
|
---|
[3668] | 642 | #ifndef RT_OS_LINUX
|
---|
[14596] | 643 | L"freedos.vdi",
|
---|
| 644 | L"MS-DOS.vmdk",
|
---|
| 645 | L"iscsi",
|
---|
| 646 | L"some/path/and/disk.vdi",
|
---|
[2029] | 647 | #else
|
---|
[14596] | 648 | L"xp.vdi",
|
---|
| 649 | L"Xp.vDI",
|
---|
[2029] | 650 | #endif
|
---|
| 651 | };
|
---|
[14596] | 652 |
|
---|
[32718] | 653 | RTPrintf("\n");
|
---|
[14596] | 654 |
|
---|
[32718] | 655 | for (size_t i = 0; i < RT_ELEMENTS(Names); ++ i)
|
---|
[2029] | 656 | {
|
---|
[32718] | 657 | Bstr src = Names[i];
|
---|
| 658 | RTPrintf("Searching for hard disk '%ls'...\n", src.raw());
|
---|
| 659 | rc = virtualBox->FindHardDisk(src, hd.asOutParam());
|
---|
[21878] | 660 | if (SUCCEEDED(rc))
|
---|
[2029] | 661 | {
|
---|
| 662 | Guid id;
|
---|
| 663 | Bstr location;
|
---|
[32718] | 664 | CHECK_ERROR_BREAK(hd, COMGETTER(Id)(id.asOutParam()));
|
---|
| 665 | CHECK_ERROR_BREAK(hd, COMGETTER(Location)(location.asOutParam()));
|
---|
| 666 | RTPrintf("Found, UUID={%RTuuid}, location='%ls'.\n",
|
---|
[2029] | 667 | id.raw(), location.raw());
|
---|
[14596] | 668 |
|
---|
[21878] | 669 | com::SafeArray<BSTR> names;
|
---|
| 670 | com::SafeArray<BSTR> values;
|
---|
[14596] | 671 |
|
---|
[32718] | 672 | CHECK_ERROR_BREAK(hd, GetProperties(NULL,
|
---|
| 673 | ComSafeArrayAsOutParam(names),
|
---|
| 674 | ComSafeArrayAsOutParam(values)));
|
---|
[14596] | 675 |
|
---|
[32718] | 676 | RTPrintf("Properties:\n");
|
---|
[14596] | 677 | for (size_t i = 0; i < names.size(); ++ i)
|
---|
[32718] | 678 | RTPrintf(" %ls = %ls\n", names[i], values[i]);
|
---|
[14596] | 679 |
|
---|
| 680 | if (names.size() == 0)
|
---|
[32718] | 681 | RTPrintf(" <none>\n");
|
---|
[14596] | 682 |
|
---|
[14783] | 683 | #if 0
|
---|
[32718] | 684 | Bstr name("TargetAddress");
|
---|
| 685 | Bstr value = Utf8StrFmt("lalala (%llu)", RTTimeMilliTS());
|
---|
[14698] | 686 |
|
---|
[32718] | 687 | RTPrintf("Settings property %ls to %ls...\n", name.raw(), value.raw());
|
---|
| 688 | CHECK_ERROR(hd, SetProperty(name, value));
|
---|
[14783] | 689 | #endif
|
---|
[2029] | 690 | }
|
---|
| 691 | else
|
---|
| 692 | {
|
---|
[32718] | 693 | com::ErrorInfo info(virtualBox);
|
---|
| 694 | PRINT_ERROR_INFO(info);
|
---|
[2029] | 695 | }
|
---|
[32718] | 696 | RTPrintf("\n");
|
---|
[2029] | 697 | }
|
---|
| 698 | }
|
---|
| 699 | while (FALSE);
|
---|
[32718] | 700 | RTPrintf("\n");
|
---|
[2029] | 701 | #endif
|
---|
| 702 |
|
---|
[1] | 703 | #if 0
|
---|
| 704 | // access the machine in read-only mode
|
---|
| 705 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 706 | do
|
---|
| 707 | {
|
---|
[21878] | 708 | ComPtr<IMachine> machine;
|
---|
[32718] | 709 | Bstr name = argc > 1 ? argv[1] : "dos";
|
---|
| 710 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 711 | CHECK_ERROR_BREAK(virtualBox, FindMachine(name, machine.asOutParam()));
|
---|
| 712 | RTPrintf("Accessing the machine in read-only mode:\n");
|
---|
| 713 | readAndChangeMachineSettings(machine);
|
---|
[1] | 714 | }
|
---|
[3422] | 715 | while (0);
|
---|
[32718] | 716 | RTPrintf("\n");
|
---|
[1] | 717 | #endif
|
---|
| 718 |
|
---|
[1471] | 719 | #if 0
|
---|
[1] | 720 | // create a new machine (w/o registering it)
|
---|
| 721 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 722 | do
|
---|
| 723 | {
|
---|
[21878] | 724 | ComPtr<IMachine> machine;
|
---|
[32718] | 725 | #if defined(RT_OS_LINUX)
|
---|
[1] | 726 | Bstr baseDir = L"/tmp/vbox";
|
---|
| 727 | #else
|
---|
| 728 | Bstr baseDir = L"C:\\vbox";
|
---|
| 729 | #endif
|
---|
| 730 | Bstr name = L"machina";
|
---|
| 731 |
|
---|
[32718] | 732 | RTPrintf("Creating a new machine object(base dir '%ls', name '%ls')...\n",
|
---|
[1] | 733 | baseDir.raw(), name.raw());
|
---|
[32718] | 734 | CHECK_ERROR_BREAK(virtualBox, CreateMachine(name, L"", baseDir, L"",
|
---|
| 735 | false,
|
---|
| 736 | machine.asOutParam()));
|
---|
[1] | 737 |
|
---|
[32718] | 738 | RTPrintf("Getting name...\n");
|
---|
| 739 | CHECK_ERROR_BREAK(machine, COMGETTER(Name)(name.asOutParam()));
|
---|
| 740 | RTPrintf("Name: {%ls}\n", name.raw());
|
---|
[1] | 741 |
|
---|
| 742 | BOOL modified = FALSE;
|
---|
[32718] | 743 | RTPrintf("Are any settings modified?...\n");
|
---|
| 744 | CHECK_ERROR_BREAK(machine, COMGETTER(SettingsModified)(&modified));
|
---|
| 745 | RTPrintf("%s\n", modified ? "yes" : "no");
|
---|
[1] | 746 |
|
---|
[32718] | 747 | ASSERT_BREAK(modified == TRUE);
|
---|
[1] | 748 |
|
---|
| 749 | name = L"Kakaya prekrasnaya virtual'naya mashina!";
|
---|
[32718] | 750 | RTPrintf("Setting new name ({%ls})...\n", name.raw());
|
---|
| 751 | CHECK_ERROR_BREAK(machine, COMSETTER(Name)(name));
|
---|
[1] | 752 |
|
---|
[32718] | 753 | RTPrintf("Setting memory size to 111...\n");
|
---|
| 754 | CHECK_ERROR_BREAK(machine, COMSETTER(MemorySize)(111));
|
---|
[1] | 755 |
|
---|
[1128] | 756 | Bstr desc = L"This is an exemplary description.";
|
---|
[32718] | 757 | RTPrintf("Setting description to \"%ls\"...\n", desc.raw());
|
---|
| 758 | CHECK_ERROR_BREAK(machine, COMSETTER(Description)(desc));
|
---|
[1128] | 759 |
|
---|
[21878] | 760 | ComPtr<IGuestOSType> guestOSType;
|
---|
[1] | 761 | Bstr type = L"os2warp45";
|
---|
[32718] | 762 | CHECK_ERROR_BREAK(virtualBox, GetGuestOSType(type, guestOSType.asOutParam()));
|
---|
[1] | 763 |
|
---|
[32718] | 764 | RTPrintf("Saving new machine settings...\n");
|
---|
| 765 | CHECK_ERROR_BREAK(machine, SaveSettings());
|
---|
[1] | 766 |
|
---|
[32718] | 767 | RTPrintf("Accessing the newly created machine:\n");
|
---|
| 768 | readAndChangeMachineSettings(machine);
|
---|
[1] | 769 | }
|
---|
| 770 | while (FALSE);
|
---|
[32718] | 771 | RTPrintf("\n");
|
---|
[1] | 772 | #endif
|
---|
| 773 |
|
---|
| 774 | #if 0
|
---|
| 775 | // enumerate host DVD drives
|
---|
| 776 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 777 | do
|
---|
| 778 | {
|
---|
[21878] | 779 | ComPtr<IHost> host;
|
---|
[32718] | 780 | CHECK_RC_BREAK(virtualBox->COMGETTER(Host)(host.asOutParam()));
|
---|
[1] | 781 |
|
---|
| 782 | {
|
---|
[21878] | 783 | ComPtr<IHostDVDDriveCollection> coll;
|
---|
[32718] | 784 | CHECK_RC_BREAK(host->COMGETTER(DVDDrives)(coll.asOutParam()));
|
---|
[21878] | 785 | ComPtr<IHostDVDDriveEnumerator> enumerator;
|
---|
[32718] | 786 | CHECK_RC_BREAK(coll->Enumerate(enumerator.asOutParam()));
|
---|
[1] | 787 | BOOL hasmore;
|
---|
[32718] | 788 | while (SUCCEEDED(enumerator->HasMore(&hasmore)) && hasmore)
|
---|
[1] | 789 | {
|
---|
[21878] | 790 | ComPtr<IHostDVDDrive> drive;
|
---|
[32718] | 791 | CHECK_RC_BREAK(enumerator->GetNext(drive.asOutParam()));
|
---|
[1] | 792 | Bstr name;
|
---|
[32718] | 793 | CHECK_RC_BREAK(drive->COMGETTER(Name)(name.asOutParam()));
|
---|
| 794 | RTPrintf("Host DVD drive: name={%ls}\n", name.raw());
|
---|
[1] | 795 | }
|
---|
[32718] | 796 | CHECK_RC_BREAK(rc);
|
---|
[1] | 797 |
|
---|
[21878] | 798 | ComPtr<IHostDVDDrive> drive;
|
---|
[32718] | 799 | CHECK_ERROR(enumerator, GetNext(drive.asOutParam()));
|
---|
| 800 | CHECK_ERROR(coll, GetItemAt(1000, drive.asOutParam()));
|
---|
| 801 | CHECK_ERROR(coll, FindByName(Bstr("R:"), drive.asOutParam()));
|
---|
[21878] | 802 | if (SUCCEEDED(rc))
|
---|
[1] | 803 | {
|
---|
| 804 | Bstr name;
|
---|
[32718] | 805 | CHECK_RC_BREAK(drive->COMGETTER(Name)(name.asOutParam()));
|
---|
| 806 | RTPrintf("Found by name: name={%ls}\n", name.raw());
|
---|
[1] | 807 | }
|
---|
| 808 | }
|
---|
| 809 | }
|
---|
| 810 | while (FALSE);
|
---|
[32718] | 811 | RTPrintf("\n");
|
---|
[1] | 812 | #endif
|
---|
| 813 |
|
---|
| 814 | #if 0
|
---|
[13580] | 815 | // check for available hd backends
|
---|
| 816 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 817 | {
|
---|
[13844] | 818 | RTPrintf("Supported hard disk backends: --------------------------\n");
|
---|
[13580] | 819 | ComPtr<ISystemProperties> systemProperties;
|
---|
[32718] | 820 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 821 | COMGETTER(SystemProperties)(systemProperties.asOutParam()));
|
---|
[21878] | 822 | com::SafeIfaceArray<IHardDiskFormat> hardDiskFormats;
|
---|
[32718] | 823 | CHECK_ERROR_BREAK(systemProperties,
|
---|
| 824 | COMGETTER(HardDiskFormats)(ComSafeArrayAsOutParam(hardDiskFormats)));
|
---|
[13580] | 825 |
|
---|
| 826 | for (size_t i = 0; i < hardDiskFormats.size(); ++ i)
|
---|
| 827 | {
|
---|
[13844] | 828 | /* General information */
|
---|
[13580] | 829 | Bstr id;
|
---|
[32718] | 830 | CHECK_ERROR_BREAK(hardDiskFormats[i],
|
---|
| 831 | COMGETTER(Id)(id.asOutParam()));
|
---|
[13580] | 832 |
|
---|
[13844] | 833 | Bstr description;
|
---|
[32718] | 834 | CHECK_ERROR_BREAK(hardDiskFormats[i],
|
---|
| 835 | COMGETTER(Id)(description.asOutParam()));
|
---|
[13844] | 836 |
|
---|
[13850] | 837 | ULONG caps;
|
---|
[32718] | 838 | CHECK_ERROR_BREAK(hardDiskFormats[i],
|
---|
| 839 | COMGETTER(Capabilities)(&caps));
|
---|
[13844] | 840 |
|
---|
| 841 | RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
|
---|
| 842 | i, id.raw(), description.raw(), caps);
|
---|
| 843 |
|
---|
| 844 | /* File extensions */
|
---|
[21878] | 845 | com::SafeArray<BSTR> fileExtensions;
|
---|
[32718] | 846 | CHECK_ERROR_BREAK(hardDiskFormats[i],
|
---|
| 847 | COMGETTER(FileExtensions)(ComSafeArrayAsOutParam(fileExtensions)));
|
---|
[13844] | 848 | for (size_t a = 0; a < fileExtensions.size(); ++ a)
|
---|
| 849 | {
|
---|
[32718] | 850 | RTPrintf("%ls", Bstr(fileExtensions[a]).raw());
|
---|
[13844] | 851 | if (a != fileExtensions.size()-1)
|
---|
[32718] | 852 | RTPrintf(",");
|
---|
[13844] | 853 | }
|
---|
[32718] | 854 | RTPrintf("'");
|
---|
[13580] | 855 |
|
---|
[13844] | 856 | /* Configuration keys */
|
---|
[21878] | 857 | com::SafeArray<BSTR> propertyNames;
|
---|
| 858 | com::SafeArray<BSTR> propertyDescriptions;
|
---|
| 859 | com::SafeArray<ULONG> propertyTypes;
|
---|
| 860 | com::SafeArray<ULONG> propertyFlags;
|
---|
| 861 | com::SafeArray<BSTR> propertyDefaults;
|
---|
[32718] | 862 | CHECK_ERROR_BREAK(hardDiskFormats[i],
|
---|
| 863 | DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
|
---|
| 864 | ComSafeArrayAsOutParam(propertyDescriptions),
|
---|
| 865 | ComSafeArrayAsOutParam(propertyTypes),
|
---|
| 866 | ComSafeArrayAsOutParam(propertyFlags),
|
---|
| 867 | ComSafeArrayAsOutParam(propertyDefaults)));
|
---|
[13844] | 868 |
|
---|
[32718] | 869 | RTPrintf(" config=(");
|
---|
[13844] | 870 | if (propertyNames.size() > 0)
|
---|
| 871 | {
|
---|
| 872 | for (size_t a = 0; a < propertyNames.size(); ++ a)
|
---|
| 873 | {
|
---|
[32718] | 874 | RTPrintf("key='%ls' desc='%ls' type=", Bstr(propertyNames[a]).raw(), Bstr(propertyDescriptions[a]).raw());
|
---|
| 875 | switch (propertyTypes[a])
|
---|
[13844] | 876 | {
|
---|
[32718] | 877 | case DataType_Int32Type: RTPrintf("int"); break;
|
---|
| 878 | case DataType_Int8Type: RTPrintf("byte"); break;
|
---|
| 879 | case DataType_StringType: RTPrintf("string"); break;
|
---|
[13844] | 880 | }
|
---|
[32718] | 881 | RTPrintf(" flags=%#04x", propertyFlags[a]);
|
---|
| 882 | RTPrintf(" default='%ls'", Bstr(propertyDefaults[a]).raw());
|
---|
[13844] | 883 | if (a != propertyNames.size()-1)
|
---|
[32718] | 884 | RTPrintf(",");
|
---|
[13844] | 885 | }
|
---|
| 886 | }
|
---|
[32718] | 887 | RTPrintf(")\n");
|
---|
[13580] | 888 | }
|
---|
[13844] | 889 | RTPrintf("-------------------------------------------------------\n");
|
---|
[13580] | 890 | }
|
---|
| 891 | #endif
|
---|
| 892 |
|
---|
| 893 | #if 0
|
---|
[1] | 894 | // enumerate hard disks & dvd images
|
---|
| 895 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 896 | do
|
---|
| 897 | {
|
---|
| 898 | {
|
---|
[21878] | 899 | com::SafeIfaceArray<IHardDisk> disks;
|
---|
[32718] | 900 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 901 | COMGETTER(HardDisks)(ComSafeArrayAsOutParam(disks)));
|
---|
[13580] | 902 |
|
---|
[32718] | 903 | RTPrintf("%u base hard disks registered (disks.isNull()=%d).\n",
|
---|
[13580] | 904 | disks.size(), disks.isNull());
|
---|
| 905 |
|
---|
| 906 | for (size_t i = 0; i < disks.size(); ++ i)
|
---|
[1] | 907 | {
|
---|
[13580] | 908 | Bstr loc;
|
---|
[32718] | 909 | CHECK_ERROR_BREAK(disks[i], COMGETTER(Location)(loc.asOutParam()));
|
---|
[1] | 910 | Guid id;
|
---|
[32718] | 911 | CHECK_ERROR_BREAK(disks[i], COMGETTER(Id)(id.asOutParam()));
|
---|
[13580] | 912 | MediaState_T state;
|
---|
[32718] | 913 | CHECK_ERROR_BREAK(disks[i], COMGETTER(State)(&state));
|
---|
[13580] | 914 | Bstr format;
|
---|
[32718] | 915 | CHECK_ERROR_BREAK(disks[i], COMGETTER(Format)(format.asOutParam()));
|
---|
[13580] | 916 |
|
---|
[32718] | 917 | RTPrintf(" disks[%u]: '%ls'\n"
|
---|
[26177] | 918 | " UUID: {%RTuuid}\n"
|
---|
[13580] | 919 | " State: %s\n"
|
---|
| 920 | " Format: %ls\n",
|
---|
| 921 | i, loc.raw(), id.raw(),
|
---|
| 922 | state == MediaState_NotCreated ? "Not Created" :
|
---|
| 923 | state == MediaState_Created ? "Created" :
|
---|
| 924 | state == MediaState_Inaccessible ? "Inaccessible" :
|
---|
| 925 | state == MediaState_LockedRead ? "Locked Read" :
|
---|
| 926 | state == MediaState_LockedWrite ? "Locked Write" :
|
---|
| 927 | "???",
|
---|
| 928 | format.raw());
|
---|
| 929 |
|
---|
| 930 | if (state == MediaState_Inaccessible)
|
---|
| 931 | {
|
---|
| 932 | Bstr error;
|
---|
[32718] | 933 | CHECK_ERROR_BREAK(disks[i],
|
---|
| 934 | COMGETTER(LastAccessError)(error.asOutParam()));
|
---|
| 935 | RTPrintf(" Access Error: %ls\n", error.raw());
|
---|
[13580] | 936 | }
|
---|
| 937 |
|
---|
| 938 | /* get usage */
|
---|
| 939 |
|
---|
[32718] | 940 | RTPrintf(" Used by VMs:\n");
|
---|
[13580] | 941 |
|
---|
| 942 | com::SafeGUIDArray ids;
|
---|
[32718] | 943 | CHECK_ERROR_BREAK(disks[i],
|
---|
| 944 | COMGETTER(MachineIds)(ComSafeArrayAsOutParam(ids)));
|
---|
[13580] | 945 | if (ids.size() == 0)
|
---|
| 946 | {
|
---|
[32718] | 947 | RTPrintf(" <not used>\n");
|
---|
[13580] | 948 | }
|
---|
[1] | 949 | else
|
---|
[13580] | 950 | {
|
---|
| 951 | for (size_t j = 0; j < ids.size(); ++ j)
|
---|
| 952 | {
|
---|
[32718] | 953 | RTPrintf(" {%RTuuid}\n", &ids[j]);
|
---|
[13580] | 954 | }
|
---|
| 955 | }
|
---|
[1] | 956 | }
|
---|
| 957 | }
|
---|
[13580] | 958 | {
|
---|
[21878] | 959 | com::SafeIfaceArray<IDVDImage> images;
|
---|
[32718] | 960 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 961 | COMGETTER(DVDImages)(ComSafeArrayAsOutParam(images)));
|
---|
[1] | 962 |
|
---|
[32718] | 963 | RTPrintf("%u DVD images registered (images.isNull()=%d).\n",
|
---|
[13580] | 964 | images.size(), images.isNull());
|
---|
| 965 |
|
---|
| 966 | for (size_t i = 0; i < images.size(); ++ i)
|
---|
[1] | 967 | {
|
---|
[13580] | 968 | Bstr loc;
|
---|
[32718] | 969 | CHECK_ERROR_BREAK(images[i], COMGETTER(Location)(loc.asOutParam()));
|
---|
[1] | 970 | Guid id;
|
---|
[32718] | 971 | CHECK_ERROR_BREAK(images[i], COMGETTER(Id)(id.asOutParam()));
|
---|
[13580] | 972 | MediaState_T state;
|
---|
[32718] | 973 | CHECK_ERROR_BREAK(images[i], COMGETTER(State)(&state));
|
---|
[13580] | 974 |
|
---|
[32718] | 975 | RTPrintf(" images[%u]: '%ls'\n"
|
---|
[26177] | 976 | " UUID: {%RTuuid}\n"
|
---|
[13580] | 977 | " State: %s\n",
|
---|
| 978 | i, loc.raw(), id.raw(),
|
---|
| 979 | state == MediaState_NotCreated ? "Not Created" :
|
---|
| 980 | state == MediaState_Created ? "Created" :
|
---|
| 981 | state == MediaState_Inaccessible ? "Inaccessible" :
|
---|
| 982 | state == MediaState_LockedRead ? "Locked Read" :
|
---|
| 983 | state == MediaState_LockedWrite ? "Locked Write" :
|
---|
| 984 | "???");
|
---|
| 985 |
|
---|
| 986 | if (state == MediaState_Inaccessible)
|
---|
| 987 | {
|
---|
| 988 | Bstr error;
|
---|
[32718] | 989 | CHECK_ERROR_BREAK(images[i],
|
---|
| 990 | COMGETTER(LastAccessError)(error.asOutParam()));
|
---|
| 991 | RTPrintf(" Access Error: %ls\n", error.raw());
|
---|
[13580] | 992 | }
|
---|
| 993 |
|
---|
| 994 | /* get usage */
|
---|
| 995 |
|
---|
[32718] | 996 | RTPrintf(" Used by VMs:\n");
|
---|
[13580] | 997 |
|
---|
| 998 | com::SafeGUIDArray ids;
|
---|
[32718] | 999 | CHECK_ERROR_BREAK(images[i],
|
---|
| 1000 | COMGETTER(MachineIds)(ComSafeArrayAsOutParam(ids)));
|
---|
[13580] | 1001 | if (ids.size() == 0)
|
---|
| 1002 | {
|
---|
[32718] | 1003 | RTPrintf(" <not used>\n");
|
---|
[13580] | 1004 | }
|
---|
[1] | 1005 | else
|
---|
[13580] | 1006 | {
|
---|
| 1007 | for (size_t j = 0; j < ids.size(); ++ j)
|
---|
| 1008 | {
|
---|
[32718] | 1009 | RTPrintf(" {%RTuuid}\n", &ids[j]);
|
---|
[13580] | 1010 | }
|
---|
| 1011 | }
|
---|
[1] | 1012 | }
|
---|
| 1013 | }
|
---|
| 1014 | }
|
---|
| 1015 | while (FALSE);
|
---|
[32718] | 1016 | RTPrintf("\n");
|
---|
[1] | 1017 | #endif
|
---|
| 1018 |
|
---|
[3834] | 1019 | #if 0
|
---|
[1] | 1020 | // open a (direct) session
|
---|
| 1021 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1022 | do
|
---|
| 1023 | {
|
---|
[21878] | 1024 | ComPtr<IMachine> machine;
|
---|
[32718] | 1025 | Bstr name = argc > 1 ? argv[1] : "dos";
|
---|
| 1026 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 1027 | CHECK_ERROR_BREAK(virtualBox, FindMachine(name, machine.asOutParam()));
|
---|
[1] | 1028 | Guid guid;
|
---|
[32718] | 1029 | CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
|
---|
| 1030 | RTPrintf("Opening a session for this machine...\n");
|
---|
| 1031 | CHECK_RC_BREAK(virtualBox->OpenSession(session, guid));
|
---|
[3480] | 1032 | #if 1
|
---|
[21878] | 1033 | ComPtr<IMachine> sessionMachine;
|
---|
[33595] | 1034 | RTPrintf("Getting machine session object...\n");
|
---|
[32718] | 1035 | CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
|
---|
| 1036 | RTPrintf("Accessing the machine within the session:\n");
|
---|
| 1037 | readAndChangeMachineSettings(sessionMachine, machine);
|
---|
[3422] | 1038 | #if 0
|
---|
[32718] | 1039 | RTPrintf("\n");
|
---|
[33386] | 1040 | RTPrintf("Enabling the VRDE server (must succeed even if the VM is saved):\n");
|
---|
| 1041 | ComPtr<IVRDEServer> vrdeServer;
|
---|
| 1042 | CHECK_ERROR_BREAK(sessionMachine, COMGETTER(VRDEServer)(vrdeServer.asOutParam()));
|
---|
| 1043 | if (FAILED(vrdeServer->COMSETTER(Enabled)(TRUE)))
|
---|
[3422] | 1044 | {
|
---|
[33386] | 1045 | PRINT_ERROR_INFO(com::ErrorInfo(vrdeServer));
|
---|
[3422] | 1046 | }
|
---|
| 1047 | else
|
---|
| 1048 | {
|
---|
| 1049 | BOOL enabled = FALSE;
|
---|
[33386] | 1050 | CHECK_ERROR_BREAK(vrdeServer, COMGETTER(Enabled)(&enabled));
|
---|
| 1051 | RTPrintf("VRDE server is %s\n", enabled ? "enabled" : "disabled");
|
---|
[3422] | 1052 | }
|
---|
[1] | 1053 | #endif
|
---|
[3422] | 1054 | #endif
|
---|
[1] | 1055 | #if 0
|
---|
[21878] | 1056 | ComPtr<IConsole> console;
|
---|
[32718] | 1057 | RTPrintf("Getting the console object...\n");
|
---|
| 1058 | CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
|
---|
| 1059 | RTPrintf("Discarding the current machine state...\n");
|
---|
[21878] | 1060 | ComPtr<IProgress> progress;
|
---|
[32718] | 1061 | CHECK_ERROR_BREAK(console, DiscardCurrentState(progress.asOutParam()));
|
---|
| 1062 | RTPrintf("Waiting for completion...\n");
|
---|
| 1063 | CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
|
---|
| 1064 | ProgressErrorInfo ei(progress);
|
---|
| 1065 | if (FAILED(ei.getResultCode()))
|
---|
[1] | 1066 | {
|
---|
[32718] | 1067 | PRINT_ERROR_INFO(ei);
|
---|
[1] | 1068 |
|
---|
[21878] | 1069 | ComPtr<IUnknown> initiator;
|
---|
[32718] | 1070 | CHECK_ERROR_BREAK(progress, COMGETTER(Initiator)(initiator.asOutParam()));
|
---|
[1] | 1071 |
|
---|
[32718] | 1072 | RTPrintf("initiator(unk) = %p\n", (IUnknown *)initiator);
|
---|
| 1073 | RTPrintf("console(unk) = %p\n", (IUnknown *)ComPtr<IUnknown>((IConsole *)console));
|
---|
| 1074 | RTPrintf("console = %p\n", (IConsole *)console);
|
---|
[1] | 1075 | }
|
---|
| 1076 | #endif
|
---|
[20928] | 1077 | RTPrintf("Press enter to close session...");
|
---|
[3480] | 1078 | getchar();
|
---|
[1] | 1079 | session->Close();
|
---|
| 1080 | }
|
---|
| 1081 | while (FALSE);
|
---|
[32718] | 1082 | RTPrintf("\n");
|
---|
[1] | 1083 | #endif
|
---|
| 1084 |
|
---|
| 1085 | #if 0
|
---|
| 1086 | // open a remote session
|
---|
| 1087 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1088 | do
|
---|
| 1089 | {
|
---|
[21878] | 1090 | ComPtr<IMachine> machine;
|
---|
[1] | 1091 | Bstr name = L"dos";
|
---|
[32718] | 1092 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 1093 | CHECK_RC_BREAK(virtualBox->FindMachine(name, machine.asOutParam()));
|
---|
[1] | 1094 | Guid guid;
|
---|
[32718] | 1095 | CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
|
---|
| 1096 | RTPrintf("Opening a remote session for this machine...\n");
|
---|
[21878] | 1097 | ComPtr<IProgress> progress;
|
---|
[32718] | 1098 | CHECK_RC_BREAK(virtualBox->OpenRemoteSession(session, guid, Bstr("gui"),
|
---|
[4064] | 1099 | NULL, progress.asOutParam()));
|
---|
[32718] | 1100 | RTPrintf("Waiting for the session to open...\n");
|
---|
| 1101 | CHECK_RC_BREAK(progress->WaitForCompletion(-1));
|
---|
[21878] | 1102 | ComPtr<IMachine> sessionMachine;
|
---|
[33595] | 1103 | RTPrintf("Getting machine session object...\n");
|
---|
[32718] | 1104 | CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
|
---|
[21878] | 1105 | ComPtr<IConsole> console;
|
---|
[32718] | 1106 | RTPrintf("Getting console object...\n");
|
---|
| 1107 | CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
|
---|
| 1108 | RTPrintf("Press enter to pause the VM execution in the remote session...");
|
---|
[1] | 1109 | getchar();
|
---|
[32718] | 1110 | CHECK_RC(console->Pause());
|
---|
| 1111 | RTPrintf("Press enter to close this session...");
|
---|
[1] | 1112 | getchar();
|
---|
| 1113 | session->Close();
|
---|
| 1114 | }
|
---|
| 1115 | while (FALSE);
|
---|
[32718] | 1116 | RTPrintf("\n");
|
---|
[1] | 1117 | #endif
|
---|
| 1118 |
|
---|
| 1119 | #if 0
|
---|
| 1120 | // open an existing remote session
|
---|
| 1121 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1122 | do
|
---|
| 1123 | {
|
---|
[21878] | 1124 | ComPtr<IMachine> machine;
|
---|
[1] | 1125 | Bstr name = "dos";
|
---|
[32718] | 1126 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 1127 | CHECK_RC_BREAK(virtualBox->FindMachine(name, machine.asOutParam()));
|
---|
[1] | 1128 | Guid guid;
|
---|
[32718] | 1129 | CHECK_RC_BREAK(machine->COMGETTER(Id)(guid.asOutParam()));
|
---|
| 1130 | RTPrintf("Opening an existing remote session for this machine...\n");
|
---|
| 1131 | CHECK_RC_BREAK(virtualBox->OpenExistingSession(session, guid));
|
---|
[21878] | 1132 | ComPtr<IMachine> sessionMachine;
|
---|
[33595] | 1133 | RTPrintf("Getting machine session object...\n");
|
---|
[32718] | 1134 | CHECK_RC_BREAK(session->COMGETTER(Machine)(sessionMachine.asOutParam()));
|
---|
[1] | 1135 | #if 0
|
---|
[21878] | 1136 | ComPtr<IConsole> console;
|
---|
[32718] | 1137 | RTPrintf("Getting console object...\n");
|
---|
| 1138 | CHECK_RC_BREAK(session->COMGETTER(Console)(console.asOutParam()));
|
---|
| 1139 | RTPrintf("Press enter to pause the VM execution in the remote session...");
|
---|
[1] | 1140 | getchar();
|
---|
[32718] | 1141 | CHECK_RC(console->Pause());
|
---|
| 1142 | RTPrintf("Press enter to close this session...");
|
---|
[1] | 1143 | getchar();
|
---|
| 1144 | #endif
|
---|
| 1145 | session->Close();
|
---|
| 1146 | }
|
---|
| 1147 | while (FALSE);
|
---|
[32718] | 1148 | RTPrintf("\n");
|
---|
[1] | 1149 | #endif
|
---|
| 1150 |
|
---|
[46326] | 1151 | #if 1
|
---|
[15579] | 1152 | do {
|
---|
| 1153 | // Get host
|
---|
[21878] | 1154 | ComPtr<IHost> host;
|
---|
[32718] | 1155 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
[15579] | 1156 |
|
---|
| 1157 | ULONG uMemSize, uMemAvail;
|
---|
[32718] | 1158 | CHECK_ERROR_BREAK(host, COMGETTER(MemorySize)(&uMemSize));
|
---|
[20928] | 1159 | RTPrintf("Total memory (MB): %u\n", uMemSize);
|
---|
[32718] | 1160 | CHECK_ERROR_BREAK(host, COMGETTER(MemoryAvailable)(&uMemAvail));
|
---|
[20928] | 1161 | RTPrintf("Free memory (MB): %u\n", uMemAvail);
|
---|
[15579] | 1162 | } while (0);
|
---|
| 1163 | #endif
|
---|
| 1164 |
|
---|
[16239] | 1165 | #if 0
|
---|
[16198] | 1166 | do {
|
---|
| 1167 | // Get host
|
---|
[21878] | 1168 | ComPtr<IHost> host;
|
---|
[32718] | 1169 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
[16198] | 1170 |
|
---|
[21878] | 1171 | com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
|
---|
[16198] | 1172 | CHECK_ERROR_BREAK(host,
|
---|
[32718] | 1173 | COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
|
---|
[16198] | 1174 | if (hostNetworkInterfaces.size() > 0)
|
---|
| 1175 | {
|
---|
| 1176 | ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[0];
|
---|
| 1177 | Bstr interfaceName;
|
---|
| 1178 | networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
|
---|
[38735] | 1179 | RTPrintf("Found %d network interfaces, testing with %ls...\n", hostNetworkInterfaces.size(), interfaceName.raw());
|
---|
[43445] | 1180 | Bstr interfaceGuid;
|
---|
[16198] | 1181 | networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
|
---|
| 1182 | // Find the interface by its name
|
---|
| 1183 | networkInterface.setNull();
|
---|
| 1184 | CHECK_ERROR_BREAK(host,
|
---|
[43445] | 1185 | FindHostNetworkInterfaceByName(interfaceName.raw(), networkInterface.asOutParam()));
|
---|
| 1186 | Bstr interfaceGuid2;
|
---|
[16198] | 1187 | networkInterface->COMGETTER(Id)(interfaceGuid2.asOutParam());
|
---|
| 1188 | if (interfaceGuid2 != interfaceGuid)
|
---|
[38735] | 1189 | RTPrintf("Failed to retrieve an interface by name %ls.\n", interfaceName.raw());
|
---|
[16198] | 1190 | // Find the interface by its guid
|
---|
| 1191 | networkInterface.setNull();
|
---|
| 1192 | CHECK_ERROR_BREAK(host,
|
---|
[43445] | 1193 | FindHostNetworkInterfaceById(interfaceGuid.raw(), networkInterface.asOutParam()));
|
---|
[16198] | 1194 | Bstr interfaceName2;
|
---|
| 1195 | networkInterface->COMGETTER(Name)(interfaceName2.asOutParam());
|
---|
| 1196 | if (interfaceName != interfaceName2)
|
---|
[43445] | 1197 | RTPrintf("Failed to retrieve an interface by GUID %ls.\n", interfaceGuid.raw());
|
---|
[16198] | 1198 | }
|
---|
| 1199 | else
|
---|
| 1200 | {
|
---|
[20928] | 1201 | RTPrintf("No network interfaces found!\n");
|
---|
[16198] | 1202 | }
|
---|
| 1203 | } while (0);
|
---|
| 1204 | #endif
|
---|
| 1205 |
|
---|
[48334] | 1206 | #if 0
|
---|
| 1207 | // DNS & Co.
|
---|
| 1208 | ///////////////////////////////////////////////////////////////////////////
|
---|
[48490] | 1209 | /* XXX: Note it's endless loop */
|
---|
[48334] | 1210 | do
|
---|
| 1211 | {
|
---|
| 1212 | ComPtr<IHost> host;
|
---|
| 1213 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
| 1214 |
|
---|
| 1215 | {
|
---|
| 1216 | Bstr domainName;
|
---|
| 1217 | CHECK_ERROR_BREAK(host,COMGETTER(DomainName)(domainName.asOutParam()));
|
---|
| 1218 | RTPrintf("Domain name: %ls\n", domainName.raw());
|
---|
| 1219 | }
|
---|
[48490] | 1220 |
|
---|
| 1221 | com::SafeArray<BSTR> strs;
|
---|
| 1222 | CHECK_ERROR_BREAK(host, COMGETTER(NameServers)(ComSafeArrayAsOutParam(strs)));
|
---|
| 1223 |
|
---|
| 1224 | unsigned int i;
|
---|
| 1225 | for (i = 0; i < strs.size(); ++i)
|
---|
| 1226 | RTPrintf("Name server[%d]:%s\n", i, com::Utf8Str(strs[i]).c_str());
|
---|
| 1227 |
|
---|
| 1228 | RTThreadSleep(1000);
|
---|
[48334] | 1229 | }
|
---|
[48490] | 1230 | while (1);
|
---|
[48334] | 1231 | RTPrintf("\n");
|
---|
| 1232 | #endif
|
---|
| 1233 |
|
---|
| 1234 |
|
---|
[32718] | 1235 | #if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API)
|
---|
[10589] | 1236 | do {
|
---|
[10725] | 1237 | // Get collector
|
---|
[21878] | 1238 | ComPtr<IPerformanceCollector> collector;
|
---|
[32718] | 1239 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 1240 | COMGETTER(PerformanceCollector)(collector.asOutParam()));
|
---|
[10725] | 1241 |
|
---|
| 1242 |
|
---|
| 1243 | // Fill base metrics array
|
---|
[43445] | 1244 | Bstr baseMetricNames[] = { L"Net/eth0/Load" };
|
---|
| 1245 | com::SafeArray<BSTR> baseMetrics(1);
|
---|
| 1246 | baseMetricNames[0].cloneTo(&baseMetrics[0]);
|
---|
| 1247 |
|
---|
| 1248 | // Get host
|
---|
| 1249 | ComPtr<IHost> host;
|
---|
| 1250 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
| 1251 |
|
---|
| 1252 | // Get host network interfaces
|
---|
| 1253 | // com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
|
---|
| 1254 | // CHECK_ERROR_BREAK(host,
|
---|
| 1255 | // COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
|
---|
| 1256 |
|
---|
| 1257 | // Setup base metrics
|
---|
| 1258 | // Note that one needs to set up metrics after a session is open for a machine.
|
---|
| 1259 | com::SafeIfaceArray<IPerformanceMetric> affectedMetrics;
|
---|
| 1260 | com::SafeIfaceArray<IUnknown> objects(1);
|
---|
| 1261 | host.queryInterfaceTo(&objects[0]);
|
---|
| 1262 | CHECK_ERROR_BREAK(collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
|
---|
| 1263 | ComSafeArrayAsInParam(objects), 1u, 10u,
|
---|
| 1264 | ComSafeArrayAsOutParam(affectedMetrics)));
|
---|
| 1265 | listAffectedMetrics(virtualBox,
|
---|
| 1266 | ComSafeArrayAsInParam(affectedMetrics));
|
---|
| 1267 | affectedMetrics.setNull();
|
---|
| 1268 |
|
---|
| 1269 | RTPrintf("Sleeping for 5 seconds...\n");
|
---|
| 1270 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
| 1271 |
|
---|
| 1272 | RTPrintf("\nMetrics collected: --------------------\n");
|
---|
| 1273 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
| 1274 | } while (false);
|
---|
| 1275 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
| 1276 | #if 0 && defined(VBOX_WITH_RESOURCE_USAGE_API)
|
---|
| 1277 | do {
|
---|
| 1278 | // Get collector
|
---|
| 1279 | ComPtr<IPerformanceCollector> collector;
|
---|
| 1280 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 1281 | COMGETTER(PerformanceCollector)(collector.asOutParam()));
|
---|
| 1282 |
|
---|
| 1283 |
|
---|
| 1284 | // Fill base metrics array
|
---|
[36128] | 1285 | //Bstr baseMetricNames[] = { L"CPU/Load,RAM/Usage" };
|
---|
| 1286 | Bstr baseMetricNames[] = { L"RAM/VMM" };
|
---|
[32718] | 1287 | com::SafeArray<BSTR> baseMetrics(1);
|
---|
| 1288 | baseMetricNames[0].cloneTo(&baseMetrics[0]);
|
---|
[10544] | 1289 |
|
---|
[10725] | 1290 | // Get host
|
---|
[21878] | 1291 | ComPtr<IHost> host;
|
---|
[32718] | 1292 | CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
|
---|
[10544] | 1293 |
|
---|
[10725] | 1294 | // Get machine
|
---|
[21878] | 1295 | ComPtr<IMachine> machine;
|
---|
[32718] | 1296 | Bstr name = argc > 1 ? argv[1] : "dsl";
|
---|
[33386] | 1297 | Bstr sessionType = argc > 2 ? argv[2] : "headless";
|
---|
[32718] | 1298 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
[36128] | 1299 | CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
|
---|
[10725] | 1300 |
|
---|
| 1301 | // Open session
|
---|
[21878] | 1302 | ComPtr<IProgress> progress;
|
---|
[36128] | 1303 | RTPrintf("Launching VM process...\n");
|
---|
| 1304 | CHECK_ERROR_BREAK(machine, LaunchVMProcess(session, sessionType.raw(),
|
---|
[80824] | 1305 | ComSafeArrayNullInParam(), progress.asOutParam()));
|
---|
[36128] | 1306 | RTPrintf("Waiting for the VM to power on...\n");
|
---|
| 1307 | CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
|
---|
[10725] | 1308 |
|
---|
[36128] | 1309 | // ComPtr<IMachine> sessionMachine;
|
---|
| 1310 | // RTPrintf("Getting machine session object...\n");
|
---|
| 1311 | // CHECK_ERROR_BREAK(session, COMGETTER(Machine)(sessionMachine.asOutParam()));
|
---|
| 1312 |
|
---|
[10868] | 1313 | // Setup base metrics
|
---|
| 1314 | // Note that one needs to set up metrics after a session is open for a machine.
|
---|
[13082] | 1315 | com::SafeIfaceArray<IPerformanceMetric> affectedMetrics;
|
---|
[36128] | 1316 | com::SafeIfaceArray<IUnknown> objects(1);
|
---|
[10868] | 1317 | host.queryInterfaceTo(&objects[0]);
|
---|
[36128] | 1318 | //machine.queryInterfaceTo(&objects[1]);
|
---|
[32718] | 1319 | CHECK_ERROR_BREAK(collector, SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
|
---|
[13082] | 1320 | ComSafeArrayAsInParam(objects), 1u, 10u,
|
---|
[32718] | 1321 | ComSafeArrayAsOutParam(affectedMetrics)));
|
---|
[13082] | 1322 | listAffectedMetrics(virtualBox,
|
---|
| 1323 | ComSafeArrayAsInParam(affectedMetrics));
|
---|
| 1324 | affectedMetrics.setNull();
|
---|
[10868] | 1325 |
|
---|
[10725] | 1326 | // Get console
|
---|
[21878] | 1327 | ComPtr<IConsole> console;
|
---|
[32718] | 1328 | RTPrintf("Getting console object...\n");
|
---|
[36128] | 1329 | CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
|
---|
[10725] | 1330 |
|
---|
[10878] | 1331 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
[10725] | 1332 |
|
---|
[20928] | 1333 | RTPrintf("\nMetrics collected with VM running: --------------------\n");
|
---|
[12668] | 1334 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
[10725] | 1335 |
|
---|
| 1336 | // Pause
|
---|
[32718] | 1337 | //RTPrintf("Press enter to pause the VM execution in the remote session...");
|
---|
[10878] | 1338 | //getchar();
|
---|
[36128] | 1339 | CHECK_ERROR_BREAK(console, Pause());
|
---|
[10725] | 1340 |
|
---|
[10878] | 1341 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
[10725] | 1342 |
|
---|
[20928] | 1343 | RTPrintf("\nMetrics collected with VM paused: ---------------------\n");
|
---|
[12668] | 1344 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
[10725] | 1345 |
|
---|
[20928] | 1346 | RTPrintf("\nDrop collected metrics: ----------------------------------------\n");
|
---|
[32718] | 1347 | CHECK_ERROR_BREAK(collector,
|
---|
[13082] | 1348 | SetupMetrics(ComSafeArrayAsInParam(baseMetrics),
|
---|
| 1349 | ComSafeArrayAsInParam(objects),
|
---|
[32718] | 1350 | 1u, 5u, ComSafeArrayAsOutParam(affectedMetrics)));
|
---|
[12668] | 1351 | listAffectedMetrics(virtualBox,
|
---|
| 1352 | ComSafeArrayAsInParam(affectedMetrics));
|
---|
| 1353 | affectedMetrics.setNull();
|
---|
| 1354 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
| 1355 |
|
---|
| 1356 | com::SafeIfaceArray<IUnknown> vmObject(1);
|
---|
| 1357 | machine.queryInterfaceTo(&vmObject[0]);
|
---|
| 1358 |
|
---|
[20928] | 1359 | RTPrintf("\nDisable collection of VM metrics: ------------------------------\n");
|
---|
[32718] | 1360 | CHECK_ERROR_BREAK(collector,
|
---|
[13082] | 1361 | DisableMetrics(ComSafeArrayAsInParam(baseMetrics),
|
---|
| 1362 | ComSafeArrayAsInParam(vmObject),
|
---|
[32718] | 1363 | ComSafeArrayAsOutParam(affectedMetrics)));
|
---|
[12668] | 1364 | listAffectedMetrics(virtualBox,
|
---|
| 1365 | ComSafeArrayAsInParam(affectedMetrics));
|
---|
| 1366 | affectedMetrics.setNull();
|
---|
| 1367 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
| 1368 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
| 1369 |
|
---|
[20928] | 1370 | RTPrintf("\nRe-enable collection of all metrics: ---------------------------\n");
|
---|
[32718] | 1371 | CHECK_ERROR_BREAK(collector,
|
---|
[13082] | 1372 | EnableMetrics(ComSafeArrayAsInParam(baseMetrics),
|
---|
| 1373 | ComSafeArrayAsInParam(objects),
|
---|
[32718] | 1374 | ComSafeArrayAsOutParam(affectedMetrics)));
|
---|
[12668] | 1375 | listAffectedMetrics(virtualBox,
|
---|
| 1376 | ComSafeArrayAsInParam(affectedMetrics));
|
---|
| 1377 | affectedMetrics.setNull();
|
---|
| 1378 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
| 1379 | queryMetrics(virtualBox, collector, ComSafeArrayAsInParam(objects));
|
---|
| 1380 |
|
---|
[10725] | 1381 | // Power off
|
---|
[32718] | 1382 | RTPrintf("Press enter to power off VM...");
|
---|
[9904] | 1383 | getchar();
|
---|
[36128] | 1384 | CHECK_ERROR_BREAK(console, PowerDown(progress.asOutParam()));
|
---|
| 1385 | RTPrintf("Waiting for the VM to power down...\n");
|
---|
| 1386 | CHECK_ERROR_BREAK(progress, WaitForCompletion(-1));
|
---|
[32718] | 1387 | RTPrintf("Press enter to close this session...");
|
---|
[9904] | 1388 | getchar();
|
---|
[36128] | 1389 | session->UnlockMachine();
|
---|
[10725] | 1390 | } while (false);
|
---|
[10868] | 1391 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
[16198] | 1392 | #if 0
|
---|
[16188] | 1393 | // check of OVF appliance handling
|
---|
| 1394 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1395 | do
|
---|
| 1396 | {
|
---|
[32718] | 1397 | Bstr ovf = argc > 1 ? argv[1] : "someOVF.ovf";
|
---|
| 1398 | RTPrintf("Try to open %ls ...\n", ovf.raw());
|
---|
[9904] | 1399 |
|
---|
[21878] | 1400 | ComPtr<IAppliance> appliance;
|
---|
[32718] | 1401 | CHECK_ERROR_BREAK(virtualBox,
|
---|
| 1402 | CreateAppliance(appliance.asOutParam()));
|
---|
| 1403 | CHECK_ERROR_BREAK(appliance, Read(ovf));
|
---|
[16188] | 1404 | Bstr path;
|
---|
[32718] | 1405 | CHECK_ERROR_BREAK(appliance, COMGETTER(Path)(path.asOutParam()));
|
---|
| 1406 | RTPrintf("Successfully opened %ls.\n", path.raw());
|
---|
| 1407 | CHECK_ERROR_BREAK(appliance, Interpret());
|
---|
| 1408 | RTPrintf("Successfully interpreted %ls.\n", path.raw());
|
---|
| 1409 | RTPrintf("Appliance:\n");
|
---|
[16188] | 1410 | // Fetch all disks
|
---|
| 1411 | com::SafeArray<BSTR> retDisks;
|
---|
[32718] | 1412 | CHECK_ERROR_BREAK(appliance,
|
---|
| 1413 | COMGETTER(Disks)(ComSafeArrayAsOutParam(retDisks)));
|
---|
[16188] | 1414 | if (retDisks.size() > 0)
|
---|
| 1415 | {
|
---|
[32718] | 1416 | RTPrintf("Disks:");
|
---|
[16188] | 1417 | for (unsigned i = 0; i < retDisks.size(); i++)
|
---|
[32718] | 1418 | RTPrintf(" %ls", Bstr(retDisks[i]).raw());
|
---|
| 1419 | RTPrintf("\n");
|
---|
[16188] | 1420 | }
|
---|
| 1421 | /* Fetch all virtual system descriptions */
|
---|
| 1422 | com::SafeIfaceArray<IVirtualSystemDescription> retVSD;
|
---|
[32718] | 1423 | CHECK_ERROR_BREAK(appliance,
|
---|
| 1424 | COMGETTER(VirtualSystemDescriptions)(ComSafeArrayAsOutParam(retVSD)));
|
---|
[16188] | 1425 | if (retVSD.size() > 0)
|
---|
| 1426 | {
|
---|
| 1427 | for (unsigned i = 0; i < retVSD.size(); ++i)
|
---|
| 1428 | {
|
---|
| 1429 | com::SafeArray<VirtualSystemDescriptionType_T> retTypes;
|
---|
[16568] | 1430 | com::SafeArray<BSTR> retRefValues;
|
---|
[16188] | 1431 | com::SafeArray<BSTR> retOrigValues;
|
---|
| 1432 | com::SafeArray<BSTR> retAutoValues;
|
---|
| 1433 | com::SafeArray<BSTR> retConfiguration;
|
---|
[32718] | 1434 | CHECK_ERROR_BREAK(retVSD[i],
|
---|
| 1435 | GetDescription(ComSafeArrayAsOutParam(retTypes),
|
---|
| 1436 | ComSafeArrayAsOutParam(retRefValues),
|
---|
| 1437 | ComSafeArrayAsOutParam(retOrigValues),
|
---|
| 1438 | ComSafeArrayAsOutParam(retAutoValues),
|
---|
| 1439 | ComSafeArrayAsOutParam(retConfiguration)));
|
---|
[16188] | 1440 |
|
---|
[32718] | 1441 | RTPrintf("VirtualSystemDescription:\n");
|
---|
[16188] | 1442 | for (unsigned a = 0; a < retTypes.size(); ++a)
|
---|
| 1443 | {
|
---|
[32718] | 1444 | RTPrintf(" %d %ls %ls %ls\n",
|
---|
| 1445 | retTypes[a],
|
---|
| 1446 | Bstr(retOrigValues[a]).raw(),
|
---|
| 1447 | Bstr(retAutoValues[a]).raw(),
|
---|
| 1448 | Bstr(retConfiguration[a]).raw());
|
---|
[16188] | 1449 | }
|
---|
[16568] | 1450 | /* Show warnings from interpret */
|
---|
| 1451 | com::SafeArray<BSTR> retWarnings;
|
---|
[32718] | 1452 | CHECK_ERROR_BREAK(retVSD[i],
|
---|
| 1453 | GetWarnings(ComSafeArrayAsOutParam(retWarnings)));
|
---|
[16568] | 1454 | if (retWarnings.size() > 0)
|
---|
| 1455 | {
|
---|
[32718] | 1456 | RTPrintf("The following warnings occurs on interpret:\n");
|
---|
[16568] | 1457 | for (unsigned r = 0; r < retWarnings.size(); ++r)
|
---|
[32718] | 1458 | RTPrintf("%ls\n", Bstr(retWarnings[r]).raw());
|
---|
| 1459 | RTPrintf("\n");
|
---|
[16568] | 1460 | }
|
---|
[16188] | 1461 | }
|
---|
[32718] | 1462 | RTPrintf("\n");
|
---|
[16188] | 1463 | }
|
---|
[32718] | 1464 | RTPrintf("Try to import the appliance ...\n");
|
---|
[16507] | 1465 | ComPtr<IProgress> progress;
|
---|
[32718] | 1466 | CHECK_ERROR_BREAK(appliance,
|
---|
| 1467 | ImportMachines(progress.asOutParam()));
|
---|
| 1468 | CHECK_ERROR(progress, WaitForCompletion(-1));
|
---|
[21878] | 1469 | if (SUCCEEDED(rc))
|
---|
[16507] | 1470 | {
|
---|
[16568] | 1471 | /* Check if the import was successfully */
|
---|
[32718] | 1472 | progress->COMGETTER(ResultCode)(&rc);
|
---|
| 1473 | if (FAILED(rc))
|
---|
[16507] | 1474 | {
|
---|
[32718] | 1475 | com::ProgressErrorInfo info(progress);
|
---|
[16507] | 1476 | if (info.isBasicAvailable())
|
---|
[38735] | 1477 | RTPrintf("Error: failed to import appliance. Error message: %ls\n", info.getText().raw());
|
---|
[16507] | 1478 | else
|
---|
[32718] | 1479 | RTPrintf("Error: failed to import appliance. No error message available!\n");
|
---|
[42261] | 1480 | }
|
---|
| 1481 | else
|
---|
[32718] | 1482 | RTPrintf("Successfully imported the appliance.\n");
|
---|
[16507] | 1483 | }
|
---|
| 1484 |
|
---|
[16188] | 1485 | }
|
---|
| 1486 | while (FALSE);
|
---|
[32718] | 1487 | RTPrintf("\n");
|
---|
[16188] | 1488 | #endif
|
---|
[43445] | 1489 | #if 0
|
---|
[40473] | 1490 | // check of network bandwidth control
|
---|
| 1491 | ///////////////////////////////////////////////////////////////////////////
|
---|
| 1492 | do
|
---|
| 1493 | {
|
---|
| 1494 | Bstr name = argc > 1 ? argv[1] : "ubuntu";
|
---|
| 1495 | Bstr sessionType = argc > 2 ? argv[2] : "headless";
|
---|
| 1496 | Bstr grpName = "tstAPI";
|
---|
| 1497 | {
|
---|
[40478] | 1498 | // Get machine
|
---|
| 1499 | ComPtr<IMachine> machine;
|
---|
| 1500 | ComPtr<IBandwidthControl> bwCtrl;
|
---|
| 1501 | ComPtr<IBandwidthGroup> bwGroup;
|
---|
| 1502 | ComPtr<INetworkAdapter> nic;
|
---|
| 1503 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 1504 | CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
|
---|
| 1505 | /* open a session for the VM (new or shared) */
|
---|
| 1506 | CHECK_ERROR_BREAK(machine, LockMachine(session, LockType_Shared));
|
---|
| 1507 | SessionType_T st;
|
---|
| 1508 | CHECK_ERROR_BREAK(session, COMGETTER(Type)(&st));
|
---|
| 1509 | bool fRunTime = (st == SessionType_Shared);
|
---|
| 1510 | if (fRunTime)
|
---|
| 1511 | {
|
---|
| 1512 | RTPrintf("Machine %ls must not be running!\n");
|
---|
| 1513 | break;
|
---|
| 1514 | }
|
---|
| 1515 | /* get the mutable session machine */
|
---|
| 1516 | session->COMGETTER(Machine)(machine.asOutParam());
|
---|
| 1517 | CHECK_ERROR_BREAK(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
|
---|
[48955] | 1518 |
|
---|
[40478] | 1519 | RTPrintf("Creating bandwidth group named '%ls'...\n", grpName.raw());
|
---|
| 1520 | CHECK_ERROR_BREAK(bwCtrl, CreateBandwidthGroup(grpName.raw(), BandwidthGroupType_Network, 123));
|
---|
[16188] | 1521 |
|
---|
[40473] | 1522 |
|
---|
[40478] | 1523 | CHECK_ERROR_BREAK(bwCtrl, GetBandwidthGroup(grpName.raw(), bwGroup.asOutParam()));
|
---|
| 1524 | CHECK_ERROR_BREAK(machine, GetNetworkAdapter(0, nic.asOutParam()));
|
---|
| 1525 | RTPrintf("Assigning the group to the first network adapter...\n");
|
---|
| 1526 | CHECK_ERROR_BREAK(nic, COMSETTER(BandwidthGroup)(bwGroup));
|
---|
| 1527 | CHECK_ERROR_BREAK(machine, SaveSettings());
|
---|
| 1528 | RTPrintf("Press enter to close this session...");
|
---|
| 1529 | getchar();
|
---|
| 1530 | session->UnlockMachine();
|
---|
| 1531 | }
|
---|
[40473] | 1532 | {
|
---|
[40478] | 1533 | // Get machine
|
---|
| 1534 | ComPtr<IMachine> machine;
|
---|
| 1535 | ComPtr<IBandwidthControl> bwCtrl;
|
---|
| 1536 | ComPtr<IBandwidthGroup> bwGroup;
|
---|
[40473] | 1537 | Bstr grpNameReadFromNic;
|
---|
[40478] | 1538 | ComPtr<INetworkAdapter> nic;
|
---|
| 1539 | RTPrintf("Getting a machine object named '%ls'...\n", name.raw());
|
---|
| 1540 | CHECK_ERROR_BREAK(virtualBox, FindMachine(name.raw(), machine.asOutParam()));
|
---|
| 1541 | /* open a session for the VM (new or shared) */
|
---|
| 1542 | CHECK_ERROR_BREAK(machine, LockMachine(session, LockType_Shared));
|
---|
| 1543 | /* get the mutable session machine */
|
---|
| 1544 | session->COMGETTER(Machine)(machine.asOutParam());
|
---|
| 1545 | CHECK_ERROR_BREAK(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
|
---|
| 1546 | CHECK_ERROR_BREAK(machine, GetNetworkAdapter(0, nic.asOutParam()));
|
---|
| 1547 |
|
---|
[40473] | 1548 | RTPrintf("Reading the group back from the first network adapter...\n");
|
---|
[40478] | 1549 | CHECK_ERROR_BREAK(nic, COMGETTER(BandwidthGroup)(bwGroup.asOutParam()));
|
---|
| 1550 | if (bwGroup.isNull())
|
---|
| 1551 | RTPrintf("Error: Bandwidth group is null at the first network adapter!\n");
|
---|
[40473] | 1552 | else
|
---|
[40478] | 1553 | {
|
---|
| 1554 | CHECK_ERROR_BREAK(bwGroup, COMGETTER(Name)(grpNameReadFromNic.asOutParam()));
|
---|
| 1555 | if (grpName != grpNameReadFromNic)
|
---|
| 1556 | RTPrintf("Error: Bandwidth group names do not match (%ls != %ls)!\n", grpName.raw(), grpNameReadFromNic.raw());
|
---|
| 1557 | else
|
---|
| 1558 | RTPrintf("Successfully retrieved bandwidth group attribute from NIC (name=%ls)\n", grpNameReadFromNic.raw());
|
---|
| 1559 | ComPtr<IBandwidthGroup> bwGroupEmpty;
|
---|
| 1560 | RTPrintf("Assigning an empty group to the first network adapter...\n");
|
---|
| 1561 | CHECK_ERROR_BREAK(nic, COMSETTER(BandwidthGroup)(bwGroupEmpty));
|
---|
| 1562 | }
|
---|
| 1563 | RTPrintf("Removing bandwidth group named '%ls'...\n", grpName.raw());
|
---|
| 1564 | CHECK_ERROR_BREAK(bwCtrl, DeleteBandwidthGroup(grpName.raw()));
|
---|
| 1565 | CHECK_ERROR_BREAK(machine, SaveSettings());
|
---|
| 1566 | RTPrintf("Press enter to close this session...");
|
---|
| 1567 | getchar();
|
---|
| 1568 | session->UnlockMachine();
|
---|
[40473] | 1569 | }
|
---|
| 1570 | } while (FALSE);
|
---|
| 1571 | RTPrintf("\n");
|
---|
| 1572 | #endif
|
---|
| 1573 |
|
---|
[32718] | 1574 | RTPrintf("Press enter to release Session and VirtualBox instances...");
|
---|
[1] | 1575 | getchar();
|
---|
| 1576 |
|
---|
| 1577 | // end "all-stuff" scope
|
---|
| 1578 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1579 | }
|
---|
| 1580 | while (0);
|
---|
| 1581 |
|
---|
[20928] | 1582 | RTPrintf("Press enter to shutdown COM...");
|
---|
[1] | 1583 | getchar();
|
---|
| 1584 |
|
---|
| 1585 | com::Shutdown();
|
---|
| 1586 |
|
---|
[32718] | 1587 | RTPrintf("tstAPI FINISHED.\n");
|
---|
[1] | 1588 |
|
---|
[95140] | 1589 | return SUCCEEDED(hrc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
|
---|
[1] | 1590 | }
|
---|
[10725] | 1591 |
|
---|
[10868] | 1592 | #ifdef VBOX_WITH_RESOURCE_USAGE_API
|
---|
[63378] | 1593 |
|
---|
[32718] | 1594 | static void queryMetrics(ComPtr<IVirtualBox> aVirtualBox,
|
---|
| 1595 | ComPtr<IPerformanceCollector> collector,
|
---|
| 1596 | ComSafeArrayIn(IUnknown *, objects))
|
---|
[10725] | 1597 | {
|
---|
| 1598 | HRESULT rc;
|
---|
| 1599 |
|
---|
[10868] | 1600 | //Bstr metricNames[] = { L"CPU/Load/User:avg,CPU/Load/System:avg,CPU/Load/Idle:avg,RAM/Usage/Total,RAM/Usage/Used:avg" };
|
---|
| 1601 | Bstr metricNames[] = { L"*" };
|
---|
[32718] | 1602 | com::SafeArray<BSTR> metrics(1);
|
---|
| 1603 | metricNames[0].cloneTo(&metrics[0]);
|
---|
[10725] | 1604 | com::SafeArray<BSTR> retNames;
|
---|
| 1605 | com::SafeIfaceArray<IUnknown> retObjects;
|
---|
[13082] | 1606 | com::SafeArray<BSTR> retUnits;
|
---|
| 1607 | com::SafeArray<ULONG> retScales;
|
---|
| 1608 | com::SafeArray<ULONG> retSequenceNumbers;
|
---|
[10725] | 1609 | com::SafeArray<ULONG> retIndices;
|
---|
| 1610 | com::SafeArray<ULONG> retLengths;
|
---|
| 1611 | com::SafeArray<LONG> retData;
|
---|
[32718] | 1612 | CHECK_ERROR(collector, QueryMetricsData(ComSafeArrayAsInParam(metrics),
|
---|
| 1613 | ComSafeArrayInArg(objects),
|
---|
| 1614 | ComSafeArrayAsOutParam(retNames),
|
---|
| 1615 | ComSafeArrayAsOutParam(retObjects),
|
---|
| 1616 | ComSafeArrayAsOutParam(retUnits),
|
---|
| 1617 | ComSafeArrayAsOutParam(retScales),
|
---|
| 1618 | ComSafeArrayAsOutParam(retSequenceNumbers),
|
---|
| 1619 | ComSafeArrayAsOutParam(retIndices),
|
---|
| 1620 | ComSafeArrayAsOutParam(retLengths),
|
---|
| 1621 | ComSafeArrayAsOutParam(retData)));
|
---|
[12668] | 1622 | RTPrintf("Object Metric Values\n"
|
---|
| 1623 | "---------- -------------------- --------------------------------------------\n");
|
---|
[10725] | 1624 | for (unsigned i = 0; i < retNames.size(); i++)
|
---|
| 1625 | {
|
---|
[13082] | 1626 | Bstr metricUnit(retUnits[i]);
|
---|
[10725] | 1627 | Bstr metricName(retNames[i]);
|
---|
[13082] | 1628 | RTPrintf("%-10ls %-20ls ", getObjectName(aVirtualBox, retObjects[i]).raw(), metricName.raw());
|
---|
[12668] | 1629 | const char *separator = "";
|
---|
[10725] | 1630 | for (unsigned j = 0; j < retLengths[i]; j++)
|
---|
| 1631 | {
|
---|
[13082] | 1632 | if (retScales[i] == 1)
|
---|
[12668] | 1633 | RTPrintf("%s%d %ls", separator, retData[retIndices[i] + j], metricUnit.raw());
|
---|
| 1634 | else
|
---|
[13082] | 1635 | RTPrintf("%s%d.%02d%ls", separator, retData[retIndices[i] + j] / retScales[i],
|
---|
| 1636 | (retData[retIndices[i] + j] * 100 / retScales[i]) % 100, metricUnit.raw());
|
---|
[12668] | 1637 | separator = ", ";
|
---|
[10725] | 1638 | }
|
---|
[12668] | 1639 | RTPrintf("\n");
|
---|
[10725] | 1640 | }
|
---|
| 1641 | }
|
---|
[12668] | 1642 |
|
---|
| 1643 | static Bstr getObjectName(ComPtr<IVirtualBox> aVirtualBox,
|
---|
| 1644 | ComPtr<IUnknown> aObject)
|
---|
| 1645 | {
|
---|
| 1646 | HRESULT rc;
|
---|
| 1647 |
|
---|
| 1648 | ComPtr<IHost> host = aObject;
|
---|
| 1649 | if (!host.isNull())
|
---|
| 1650 | return Bstr("host");
|
---|
| 1651 |
|
---|
| 1652 | ComPtr<IMachine> machine = aObject;
|
---|
| 1653 | if (!machine.isNull())
|
---|
| 1654 | {
|
---|
| 1655 | Bstr name;
|
---|
| 1656 | CHECK_ERROR(machine, COMGETTER(Name)(name.asOutParam()));
|
---|
| 1657 | if (SUCCEEDED(rc))
|
---|
| 1658 | return name;
|
---|
| 1659 | }
|
---|
| 1660 | return Bstr("unknown");
|
---|
| 1661 | }
|
---|
| 1662 |
|
---|
| 1663 | static void listAffectedMetrics(ComPtr<IVirtualBox> aVirtualBox,
|
---|
| 1664 | ComSafeArrayIn(IPerformanceMetric*, aMetrics))
|
---|
| 1665 | {
|
---|
| 1666 | HRESULT rc;
|
---|
| 1667 | com::SafeIfaceArray<IPerformanceMetric> metrics(ComSafeArrayInArg(aMetrics));
|
---|
| 1668 | if (metrics.size())
|
---|
| 1669 | {
|
---|
| 1670 | ComPtr<IUnknown> object;
|
---|
| 1671 | Bstr metricName;
|
---|
| 1672 | RTPrintf("The following metrics were modified:\n\n"
|
---|
| 1673 | "Object Metric\n"
|
---|
| 1674 | "---------- --------------------\n");
|
---|
| 1675 | for (size_t i = 0; i < metrics.size(); i++)
|
---|
| 1676 | {
|
---|
| 1677 | CHECK_ERROR(metrics[i], COMGETTER(Object)(object.asOutParam()));
|
---|
| 1678 | CHECK_ERROR(metrics[i], COMGETTER(MetricName)(metricName.asOutParam()));
|
---|
| 1679 | RTPrintf("%-10ls %-20ls\n",
|
---|
| 1680 | getObjectName(aVirtualBox, object).raw(), metricName.raw());
|
---|
| 1681 | }
|
---|
| 1682 | RTPrintf("\n");
|
---|
| 1683 | }
|
---|
| 1684 | else
|
---|
| 1685 | {
|
---|
| 1686 | RTPrintf("No metrics match the specified filter!\n");
|
---|
| 1687 | }
|
---|
| 1688 | }
|
---|
| 1689 |
|
---|
[10868] | 1690 | #endif /* VBOX_WITH_RESOURCE_USAGE_API */
|
---|
[16817] | 1691 | /* vim: set shiftwidth=4 tabstop=4 expandtab: */
|
---|