Changeset 13580 in vbox for trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp
- Timestamp:
- Oct 27, 2008 2:04:18 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstVBoxAPILinux.cpp
r13386 r13580 113 113 * Get the list of all registered VMs 114 114 */ 115 IMachineCollection *collection = nsnull; 116 IMachineEnumerator *enumerator = nsnull; 117 rc = virtualBox->GetMachines(&collection); 115 IMachine **machines = NULL; 116 PRUint32 machineCnt = 0; 117 118 rc = virtualBox->GetMachines2(&machineCnt, &machines); 118 119 if (NS_SUCCEEDED(rc)) 119 rc = collection->Enumerate(&enumerator);120 if (NS_SUCCEEDED(rc))121 120 { 122 121 /* 123 122 * Iterate through the collection 124 123 */ 125 PRBool hasMore = false; 126 while (enumerator->HasMore(&hasMore), hasMore) 127 { 128 IMachine *machine = nsnull; 129 rc = enumerator->GetNext(&machine); 130 if ((NS_SUCCEEDED(rc)) && machine) 124 for (PRUint32 i = 0; i < machineCnt; ++ i) 125 { 126 IMachine *machine = machines [i]; 127 if (machine) 131 128 { 132 129 PRBool isAccessible = PR_FALSE; … … 177 174 } 178 175 176 /* don't forget to release the objects in the array... */ 179 177 machine->Release(); 180 178 } … … 182 180 } 183 181 printf("----------------------------------------------------\n\n"); 184 /* don't forget to release the objects... */185 if (enumerator)186 enumerator->Release();187 if (collection)188 collection->Release();189 182 } 190 183 … … 305 298 * Create a virtual harddisk 306 299 */ 307 nsCOMPtr<IHardDisk> hardDisk = 0; 308 nsCOMPtr<IVirtualDiskImage> vdi = 0; 309 rc = virtualBox->CreateHardDisk(HardDiskStorageType::VirtualDiskImage, 310 getter_AddRefs(hardDisk)); 311 if (NS_SUCCEEDED (rc)) 312 { 313 rc = hardDisk->QueryInterface(NS_GET_IID(IVirtualDiskImage), 314 (void **)(getter_AddRefs(vdi))); 315 if (NS_SUCCEEDED (rc)) 316 rc = vdi->SetFilePath(NS_LITERAL_STRING("TestHardDisk.vdi").get()); 317 } 318 300 nsCOMPtr<IHardDisk2> hardDisk = 0; 301 rc = virtualBox->CreateHardDisk2(NS_LITERAL_STRING("VDI").get(), 302 NS_LITERAL_STRING("TestHardDisk.vdi").get(), 303 getter_AddRefs(hardDisk)); 319 304 if (NS_FAILED(rc)) 320 305 { … … 329 314 */ 330 315 nsCOMPtr <IProgress> progress; 331 rc = vdi->CreateDynamicImage(100,// size in megabytes332 getter_AddRefs(progress));// optional progress object316 rc = hardDisk->CreateDynamicStorage(100, // size in megabytes 317 getter_AddRefs(progress)); // optional progress object 333 318 if (NS_FAILED(rc)) 334 319 { … … 353 338 { 354 339 /* 355 * Now we have to register the new hard disk with VirtualBox. 340 * Now that it's created, we can assign it to the VM. This is done 341 * by UUID, so query that one fist. The UUID has been assigned automatically 342 * when we've created the image. 356 343 */ 357 rc = virtualBox->RegisterHardDisk(hardDisk); 344 nsID *vdiUUID = nsnull; 345 hardDisk->GetId(&vdiUUID); 346 rc = machine->AttachHardDisk2(*vdiUUID, 347 StorageBus::IDE, // controler identifier 348 0, // channel number on the controller 349 0); // device number on the controller 350 nsMemory::Free(vdiUUID); 358 351 if (NS_FAILED(rc)) 359 352 { 360 printf("Error: could not register hard disk! rc=%08X\n", rc); 361 } 362 else 363 { 364 /* 365 * Now that it's registered, we can assign it to the VM. This is done 366 * by UUID, so query that one fist. The UUID has been assigned automatically 367 * when we've created the image. 368 */ 369 nsID *vdiUUID = nsnull; 370 hardDisk->GetId(&vdiUUID); 371 rc = machine->AttachHardDisk(*vdiUUID, 372 StorageBus::IDE, // controler identifier 373 0, // channel number on the controller 374 0); // device number on the controller 375 nsMemory::Free(vdiUUID); 376 if (NS_FAILED(rc)) 377 { 378 printf("Error: could not attach hard disk! rc=%08X\n", rc); 379 } 353 printf("Error: could not attach hard disk! rc=%08X\n", rc); 380 354 } 381 355 } … … 390 364 */ 391 365 nsID uuid = {0}; 392 nsCOMPtr<IDVDImage > dvdImage;366 nsCOMPtr<IDVDImage2> dvdImage; 393 367 394 368 rc = virtualBox->OpenDVDImage(NS_LITERAL_STRING("/home/achimha/isoimages/winnt4ger.iso").get(), … … 402 376 { 403 377 /* 404 * Register it with VBox 405 */ 406 rc = virtualBox->RegisterDVDImage(dvdImage); 407 if (NS_FAILED(rc)) 408 { 409 printf("Error: could not register CD image! rc=%08X\n", rc); 378 * Now assign it to our VM 379 */ 380 nsID *isoUUID = nsnull; 381 dvdImage->GetId(&isoUUID); 382 nsCOMPtr<IDVDDrive> dvdDrive; 383 machine->GetDVDDrive(getter_AddRefs(dvdDrive)); 384 rc = dvdDrive->MountImage(*isoUUID); 385 nsMemory::Free(isoUUID); 386 if (NS_FAILED(rc)) 387 { 388 printf("Error: could not mount ISO image! rc=%08X\n", rc); 410 389 } 411 390 else 412 391 { 413 392 /* 414 * Now assign it to our VM393 * Last step: tell the VM to boot from the CD. 415 394 */ 416 nsID *isoUUID = nsnull; 417 dvdImage->GetId(&isoUUID); 418 nsCOMPtr<IDVDDrive> dvdDrive; 419 machine->GetDVDDrive(getter_AddRefs(dvdDrive)); 420 rc = dvdDrive->MountImage(*isoUUID); 421 nsMemory::Free(isoUUID); 395 rc = machine->SetBootOrder (1, DeviceType::DVD); 422 396 if (NS_FAILED(rc)) 423 397 { 424 printf("Error: could not mount ISO image! rc=%08X\n", rc); 425 } 426 else 427 { 428 /* 429 * Last step: tell the VM to boot from the CD. 430 */ 431 rc = machine->SetBootOrder (1, DeviceType::DVD); 432 if (NS_FAILED(rc)) 433 { 434 printf("Could not set boot device! rc=%08X\n", rc); 435 } 398 printf("Could not set boot device! rc=%08X\n", rc); 436 399 } 437 400 }
Note:
See TracChangeset
for help on using the changeset viewer.