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