Changeset 16218 in vbox
- Timestamp:
- Jan 26, 2009 10:16:38 AM (16 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
-
ApplianceImpl.cpp (modified) (12 diffs)
-
include/ApplianceImpl.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r16212 r16218 185 185 186 186 /** 187 * Implementation for I Appliance::openAppliance. Loads the given appliance (see API reference).187 * Implementation for IVirtualBox::openAppliance. Loads the given appliance (see API reference). 188 188 * 189 189 * @param bstrPath Appliance to open (either .ovf or .ova file, see API reference) … … 191 191 * @return S_OK or error. 192 192 */ 193 STDMETHODIMP VirtualBox::OpenAppliance (IN_BSTR bstrPath, IAppliance** anAppliance)193 STDMETHODIMP VirtualBox::OpenAppliance (IN_BSTR bstrPath, IAppliance** anAppliance) 194 194 { 195 195 HRESULT rc; … … 197 197 ComObjPtr<Appliance> appliance; 198 198 appliance.createObject(); 199 rc = appliance->init (bstrPath);199 rc = appliance->init (this, bstrPath); 200 200 // ComAssertComRCThrowRC(rc); 201 201 202 202 if (SUCCEEDED(rc)) 203 {204 203 appliance.queryInterfaceTo(anAppliance); 205 }206 204 207 205 return rc; … … 715 713 */ 716 714 717 HRESULT Appliance::init (IN_BSTR &path)715 HRESULT Appliance::init (VirtualBox *aVirtualBox, IN_BSTR &path) 718 716 { 719 717 HRESULT rc; … … 722 720 AutoInitSpan autoInitSpan(this); 723 721 AssertReturn (autoInitSpan.isOk(), E_FAIL); 722 723 /* Weakly reference to a VirtualBox object */ 724 unconst (mVirtualBox) = aVirtualBox; 724 725 725 726 // initialize data … … 875 876 STDMETHODIMP Appliance::ImportAppliance() 876 877 { 877 /* We need a virtualbox object */ 878 ComPtr <IVirtualBox> virtualBox; 879 HRESULT rc = virtualBox.createLocalObject (CLSID_VirtualBox); 880 ComAssertComRCThrowRC (rc); 878 HRESULT rc = S_OK; 881 879 882 880 list<VirtualSystem>::const_iterator it; … … 899 897 /* Now that we know the base system get our internal defaults based on that. */ 900 898 IGuestOSType *osType = NULL; 901 rc = virtualBox->GetGuestOSType (Bstr (Utf8Str (osTypeVBox.c_str())), &osType);899 rc = mVirtualBox->GetGuestOSType (Bstr (Utf8Str (osTypeVBox.c_str())), &osType); 902 900 ComAssertComRCThrowRC (rc); 903 901 904 902 /* Create the machine */ 903 /* First get the name */ 904 list<VirtualSystemDescriptionEntry> vsdeName = vsd->findByType (VirtualSystemDescriptionType_Name); 905 Assert (vsdeName.size() == 1); 906 string nameVBox = vsdeName.front().strFinalValue; 905 907 IMachine *newMachine = NULL; 906 rc = virtualBox->CreateMachine (Bstr (Utf8StrFmt ("tescht_%d", i)), Bstr (Utf8Str (osTypeVBox.c_str())),907 Bstr (), Guid(),908 &newMachine);908 rc = mVirtualBox->CreateMachine (Bstr (nameVBox.c_str()), Bstr (osTypeVBox.c_str()), 909 Bstr (), Guid(), 910 &newMachine); 909 911 ComAssertComRCThrowRC (rc); 910 912 … … 963 965 } 964 966 /* Now its time to register the machine before we add any hard disks */ 965 rc = virtualBox->RegisterMachine (newMachine);967 rc = mVirtualBox->RegisterMachine (newMachine); 966 968 ComAssertComRCThrowRC (rc); 967 969 … … 986 988 // - Appropriate handle errors like not supported file formats 987 989 990 HRESULT rc = S_OK; 991 988 992 /* Clear any previous virtual system descriptions */ 989 993 // @todo: have the entries deleted also? 990 994 m->virtualSystemDescriptions.clear(); 991 995 992 /* We need a virtualbox object */993 ComPtr <IVirtualBox> virtualBox;994 HRESULT rc = virtualBox.createLocalObject (CLSID_VirtualBox);995 ComAssertComRCThrowRC (rc);996 997 996 /* We need the default path for storing disk images */ 998 997 ISystemProperties *systemProps = NULL; 999 rc = virtualBox->COMGETTER(SystemProperties) (&systemProps);998 rc = mVirtualBox->COMGETTER(SystemProperties) (&systemProps); 1000 999 ComAssertComRCThrowRC (rc); 1001 1000 BSTR defaultHardDiskLocation; … … 1015 1014 ComAssertComRCThrowRC(rc); 1016 1015 1017 /* VM name */1018 vsd->addEntry(VirtualSystemDescriptionType_Name, 0, vs.strName, vs.strName);1019 1020 1016 string osTypeVBox = SchemaDefs_OSTypeId_Other; 1021 1017 /* Guest OS type */ … … 1204 1200 vsd->addEntry (VirtualSystemDescriptionType_OS, 0, toString<ULONG> (vs.cimos), osTypeVBox); 1205 1201 1202 /* VM name */ 1203 /* If the there isn't any name specified create a default one out of 1204 * the OS type */ 1205 string nameVBox = vs.strName; 1206 if (nameVBox == "") 1207 nameVBox = osTypeVBox; 1208 /* @todo: make sure the name is unique (add some numbers if not) */ 1209 searchUniqueVMName (nameVBox); 1210 vsd->addEntry(VirtualSystemDescriptionType_Name, 0, nameVBox, nameVBox); 1211 1206 1212 /* Now that we know the base system get our internal defaults based on that. */ 1207 1213 IGuestOSType *osType = NULL; 1208 rc = virtualBox->GetGuestOSType (Bstr (Utf8Str (osTypeVBox.c_str())), &osType);1214 rc = mVirtualBox->GetGuestOSType (Bstr (Utf8Str (osTypeVBox.c_str())), &osType); 1209 1215 ComAssertComRCThrowRC (rc); 1210 1216 … … 1330 1336 } 1331 1337 1338 HRESULT Appliance::searchUniqueVMName (std::string& aName) 1339 { 1340 IMachine *machine = NULL; 1341 char *tmpName = RTStrDup (aName.c_str()); 1342 int i = 1; 1343 /* @todo: Maybe to cost intensive; try to find a lighter way */ 1344 while (mVirtualBox->FindMachine (Bstr (tmpName), &machine) != VBOX_E_OBJECT_NOT_FOUND) 1345 { 1346 RTStrFree (tmpName); 1347 RTStrAPrintf (&tmpName, "%s_%d", aName.c_str(), i); 1348 ++i; 1349 } 1350 aName = tmpName; 1351 RTStrFree (tmpName); 1352 1353 return S_OK; 1354 } 1355 1332 1356 // IVirtualSystemDescription constructor / destructor 1333 1357 //////////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/include/ApplianceImpl.h
r16205 r16218 26 26 27 27 #include "VirtualBoxBase.h" 28 29 class VirtualBox; 28 30 29 31 class ATL_NO_VTABLE Appliance : … … 55 57 void FinalRelease() { uninit(); } 56 58 57 HRESULT init (IN_BSTR &path);59 HRESULT init (VirtualBox *aVirtualBox, IN_BSTR &path); 58 60 void uninit(); 59 61 … … 75 77 /* private instance data */ 76 78 private: 79 /** weak VirtualBox parent */ 80 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox; 81 77 82 struct Data; // obscure, defined in AppliannceImpl.cpp 78 83 Data *m; … … 84 89 85 90 HRESULT construeAppliance(); 91 HRESULT searchUniqueVMName (std::string& aName); 86 92 }; 87 93
Note:
See TracChangeset
for help on using the changeset viewer.

