VirtualBox

Changeset 14666 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Nov 26, 2008 11:03:23 PM (16 years ago)
Author:
vboxsync
Message:

Main: Better result codes for VIrtualBox::createMachine(), documentation. Assgined new UUIDs to changed interfaces (important!).

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/MachineImpl.cpp

    r14664 r14666  
    419419    int vrc = mParent->calculateFullPath (Utf8Str (aConfigFile), configFileFull);
    420420    if (RT_FAILURE (vrc))
    421         return setError (E_FAIL,
     421        return setError (VBOX_E_FILE_ERROR,
    422422            tr ("Invalid machine settings file name '%ls' (%Rrc)"),
    423423            aConfigFile, vrc);
     
    448448            if (RT_SUCCESS (vrc) || vrc == VERR_SHARING_VIOLATION)
    449449            {
    450                 rc = setError (E_FAIL,
     450                rc = setError (VBOX_E_FILE_ERROR,
    451451                    tr ("Machine settings file '%s' already exists"),
    452452                    configFileFull.raw());
     
    457457            {
    458458                if (vrc != VERR_FILE_NOT_FOUND && vrc != VERR_PATH_NOT_FOUND)
    459                     rc = setError (E_FAIL,
     459                    rc = setError (VBOX_E_FILE_ERROR,
    460460                        tr ("Invalid machine settings file name '%ls' (%Rrc)"),
    461461                        mData->mConfigFileFull.raw(), vrc);
     
    497497                if (aOsType)
    498498                {
    499                     /* Store os type */
     499                    /* Store OS type */
    500500                    mUserData->mOSTypeId = aOsType->id();
    501501
    502                     /* Apply other machine defaults */
    503                     mHWData->mHWVirtExEnabled = aOsType->recommendedVirtEx() ? TSBool_True : TSBool_False;
     502                    /* Apply machine defaults */
     503                    mHWData->mHWVirtExEnabled = aOsType->recommendedVirtEx() ?
     504                                                TSBool_True : TSBool_False;
    504505
    505506                    /* Apply BIOS defaults */
    506507                    mBIOSSettings->applyDefaults (aOsType);
    507                    
     508
    508509                    /* Apply network adapters defaults */
    509510                    for (ULONG slot = 0; slot < RT_ELEMENTS (mNetworkAdapters); ++ slot)
  • trunk/src/VBox/Main/VirtualBoxImpl.cpp

    r14664 r14666  
    761761{
    762762    LogFlowThisFuncEnter();
    763     LogFlowThisFunc (("aBaseFolder='%ls', aName='%ls' aMachine={%p}\n",
    764                       aBaseFolder, aName, aMachine));
    765 
    766     if (!aName)
    767         return E_INVALIDARG;
    768     if (!aMachine)
    769         return E_POINTER;
    770 
    771     if (!*aName)
    772         return setError (E_INVALIDARG,
    773             tr ("Machine name cannot be empty"));
     763
     764    CheckComArgStrNotEmptyOrNull (aName);
     765    CheckComArgOutPointerValid (aMachine);
    774766
    775767    AutoCaller autoCaller (this);
     
    799791    ComObjPtr <Machine> machine;
    800792    rc = machine.createObject();
    801     if (SUCCEEDED (rc))
    802     {
    803         /* Create UUID if an empty one was specified. */
    804         Guid id = aId;
    805         if (id.isEmpty())
    806             id.create();
    807 
    808         /* Look for related GuestOsType */
    809         AssertMsg (mData.mGuestOSTypes.size(), ("Guest OS types array must be filled"));
    810         GuestOSTypeList::iterator it = mData.mGuestOSTypes.begin();
    811         GuestOSType *osType = *it;
    812         while (aOsTypeId && it != mData.mGuestOSTypes.end())
     793    CheckComRCReturnRC (rc);
     794
     795    /* Create UUID if an empty one was specified. */
     796    Guid id = aId;
     797    if (id.isEmpty())
     798        id.create();
     799
     800    /* Look for a GuestOSType object */
     801    AssertMsg (mData.mGuestOSTypes.size() != 0,
     802               ("Guest OS types array must be filled"));
     803
     804    GuestOSType *osType = NULL;
     805    if (aOsTypeId != NULL)
     806    {
     807        for (GuestOSTypeList::const_iterator it = mData.mGuestOSTypes.begin();
     808             it != mData.mGuestOSTypes.end(); ++ it)
    813809        {
    814810            if ((*it)->id() == aOsTypeId)
     
    817813                break;
    818814            }
    819             ++ it;
    820         }
    821 
    822         /* initialize the machine object */
    823         rc = machine->init (this, settingsFile, Machine::Init_New, aName, osType, TRUE, &id);
    824         if (SUCCEEDED (rc))
    825         {
    826             /* set the return value */
    827             rc = machine.queryInterfaceTo (aMachine);
    828             ComAssertComRC (rc);
    829         }
    830     }
    831 
    832     LogFlowThisFunc (("rc=%08X\n", rc));
     815        }
     816
     817        if (osType == NULL)
     818            return setError (VBOX_E_OBJECT_NOT_FOUND,
     819                tr ("Guest OS type '%ls' is invalid"), aOsTypeId);
     820    }
     821
     822    /* initialize the machine object */
     823    rc = machine->init (this, settingsFile, Machine::Init_New, aName, osType,
     824                        TRUE /* aNameSync */, &id);
     825    if (SUCCEEDED (rc))
     826    {
     827        /* set the return value */
     828        rc = machine.queryInterfaceTo (aMachine);
     829        AssertComRC (rc);
     830    }
     831
    833832    LogFlowThisFuncLeave();
    834833
     
    842841                                              IMachine **aMachine)
    843842{
    844     /* null and empty strings are not allowed as path names */
    845     if (!aSettingsFile || !(*aSettingsFile))
    846         return E_INVALIDARG;
    847 
    848     if (!aName)
    849         return E_INVALIDARG;
    850     if (!aMachine)
    851         return E_POINTER;
    852 
    853     if (!*aName)
    854         return setError (E_INVALIDARG,
    855             tr ("Machine name cannot be empty"));
     843    CheckComArgStrNotEmptyOrNull (aName);
     844    CheckComArgStrNotEmptyOrNull (aSettingsFile);
     845    CheckComArgOutPointerValid (aMachine);
    856846
    857847    AutoCaller autoCaller (this);
     
    868858    ComObjPtr<Machine> machine;
    869859    rc = machine.createObject();
    870     if (SUCCEEDED (rc))
    871     {
    872         /* Create UUID if an empty one was specified. */
    873         Guid id = aId;
    874         if (id.isEmpty())
    875             id.create();
    876 
    877         /* Look for related GuestOsType */
    878         AssertMsg (mData.mGuestOSTypes.size(), ("Guest OS types array must be filled"));
    879         GuestOSTypeList::iterator it = mData.mGuestOSTypes.begin();
    880         GuestOSType *osType = *it;
    881         while (aOsTypeId && it != mData.mGuestOSTypes.end())
     860    CheckComRCReturnRC (rc);
     861
     862    /* Create UUID if an empty one was specified. */
     863    Guid id = aId;
     864    if (id.isEmpty())
     865        id.create();
     866
     867    /* Look for a GuestOSType object */
     868    AssertMsg (mData.mGuestOSTypes.size() != 0,
     869               ("Guest OS types array must be filled"));
     870
     871    GuestOSType *osType = NULL;
     872    if (aOsTypeId != NULL)
     873    {
     874        for (GuestOSTypeList::const_iterator it = mData.mGuestOSTypes.begin();
     875             it != mData.mGuestOSTypes.end(); ++ it)
    882876        {
    883877            if ((*it)->id() == aOsTypeId)
     
    886880                break;
    887881            }
    888             ++ it;
    889         }
    890 
    891         /* initialize the machine object */
    892         rc = machine->init (this, Bstr (settingsFile), Machine::Init_New,
    893                             aName, osType, FALSE /* aNameSync */, &id);
    894         if (SUCCEEDED (rc))
    895         {
    896             /* set the return value */
    897             rc = machine.queryInterfaceTo (aMachine);
    898             ComAssertComRC (rc);
    899         }
    900     }
     882        }
     883
     884        if (osType == NULL)
     885            return setError (VBOX_E_OBJECT_NOT_FOUND,
     886                tr ("Guest OS type '%ls' is invalid"), aOsTypeId);
     887    }
     888
     889    /* initialize the machine object */
     890    rc = machine->init (this, Bstr (settingsFile), Machine::Init_New,
     891                        aName, osType, FALSE /* aNameSync */, &id);
     892    if (SUCCEEDED (rc))
     893    {
     894        /* set the return value */
     895        rc = machine.queryInterfaceTo (aMachine);
     896        AssertComRC (rc);
     897    }
     898
    901899    return rc;
    902900}
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r14664 r14666  
    11091109  <interface
    11101110    name="IVirtualBox" extends="$dispatched"
    1111     uuid="2aa11223-ba64-4610-84b8-066d2a89384f"
     1111    uuid="339abca2-f47a-4302-87f5-7bc324e6bbde"
    11121112    wsmap="managed"
    11131113  >
     
    12971297        Creates a new virtual machine.
    12981298
    1299         The new machine will have "empty" default settings and will not
    1300         yet be registered. The typical sequence to create a virtual machine
    1301         is therefore something like this:
     1299        The new machine is created unregistered, with the initial configuration
     1300        set according to the specified guest OS type. A typical sequence of
     1301        actions to create a new virtual machine is as follows:
    13021302
    13031303        <ol>
    1304            <li>Call this method (IVirtualBox::createMachine) to have a new
    1305            machine created. The machine object returned is "mutable", i.e.
    1306            automatically locked for the current session, as if
    1307            <link to="#openSession" /> had been called on it.</li>
    1308 
    1309            <li>Assign meaningful settings to the new machine by calling the
    1310            respective methods.</li>
    1311 
    1312            <li>Call <link to="IMachine::saveSettings" /> to have the settings written
    1313            to the machine's XML settings file. The configuration of the newly
    1314            created machine will not be saved to disk (and the settings subfolder
    1315            and file, as described below, will not be created) until this method
    1316            is called.</li>
    1317 
    1318            <li>Call <link to="#registerMachine" /> to have the
    1319            machine show up in the list of machines registered with VirtualBox.</li>
     1304          <li>
     1305            Call this method to have a new machine created. The returned machine
     1306            object will be "mutable" allowing to change any machine property.
     1307          </li>
     1308
     1309          <li>
     1310            Configure the machine using the appropriate attributes and methods.
     1311          </li>
     1312
     1313          <li>
     1314            Call <link to="IMachine::saveSettings" /> to write the settings
     1315            to the machine's XML settings file. The configuration of the newly
     1316            created machine will not be saved to disk (and the settings subfolder
     1317            and file, as described below, will not be created) until this method
     1318            is called.
     1319          </li>
     1320
     1321          <li>
     1322            Call <link to="#registerMachine" /> to have the machine show up in
     1323            the list of machines registered with VirtualBox.
     1324          </li>
    13201325        </ol>
     1326
     1327        You should specify valid name for the newly created machine when calling
     1328        this method. See the <link to="IMachine::name"/> attribute description
     1329        for more details about the machine name.
     1330
     1331        The specified guest OS type identifier must match an ID of one of known
     1332        guest OS types listed in the <link to="IVirtualBox::guestOSTypes"/>
     1333        array.
    13211334
    13221335        Every machine has a <i>settings file</i> that is used to store
     
    13271340        where to create the machine settings subfolder using the @a
    13281341        baseFolder argument. The base folder can be absolute (full path)
    1329         or relative to the <link to="IVirtualBox::homeFolder">
    1330           VirtualBox home directory</link>.
    1331 
    1332         If a null or empty string is given as the base folder (which is
    1333         recommended), the <link to="ISystemProperties::defaultMachineFolder">
    1334           default machine settings folder</link> will be used as the base
    1335         folder to create the machine settings subfolder and file. In
    1336         any case, the full path to the settings file will look like:
     1342        or relative to the <link to="IVirtualBox::homeFolder">VirtualBox home
     1343        directory</link>.
     1344
     1345        If @a baseFolder is a null or empty string (which is recommended), the
     1346        <link to="ISystemProperties::defaultMachineFolder">default machine
     1347        settings folder</link> will be used as a base folder to create the
     1348        machine settings subfolder and file, otherwise the given folder will be
     1349        used. The full path to the resulting settings file will have the
     1350        following structure:
    13371351        <pre>
    13381352          &lt;base_folder&gt;/&lt;machine_name&gt;/&lt;machine_name&gt;.xml
    13391353        </pre>
    13401354
    1341         Optionally the UUID of the machine can be predefined. If this is
    1342         not desired (i.e. a new UUID should be generated), pass just an
    1343         empty or null UUID.
    1344 
    1345         You should also specify a valid name for the machine.
    1346         See the <link to="IMachine::name"/> property
    1347         description for more details about the machine name.
    1348 
    1349         The created machine remains
    1350         unregistered until you call <link to="#registerMachine()"/>.
     1355        Note that if the resulting settings file already exists, this method
     1356        will fail.
     1357
     1358        Optionally, you may specify an UUID of to assign to the created machine.
     1359        However, this is not recommended and you should normally pass an empty
     1360        (null) UUID to this method so that a new UUID will be automatically
     1361        generated.
    13511362
    13521363        <note>
     
    13541365          subfolder of the created machine directly.
    13551366        </note>
    1356       </desc>
     1367
     1368        <result name="VBOX_E_OBJECT_NOT_FOUND">
     1369          @a osTypeId is invalid.
     1370        </result>
     1371        <result name="VBOX_E_FILE_ERROR">
     1372          Resulting settings file name is invalid or the settings file already
     1373          exists or could not be created due to an I/O error.
     1374        </result>
     1375        <result name="E_INVALIDARG">
     1376          @a name is empty or null.
     1377        </result>
     1378      </desc>
     1379
    13571380      <param name="name" type="wstring" dir="in">
    13581381        <desc>Machine name.</desc>
    13591382      </param>
    13601383      <param name="osTypeId" type="wstring" dir="in">
    1361         <desc>Machine OS Type ID.</desc>
     1384        <desc>Guest OS Type ID.</desc>
    13621385      </param>
    13631386      <param name="baseFolder" type="wstring" dir="in">
    1364         <desc>
    1365           Name of the folder where to create the machine settings
    1366           subfolder containing the settings file.
    1367         </desc>
     1387        <desc>Base machine folder (optional).</desc>
    13681388      </param>
    13691389      <param name="id" type="uuid" dir="in">
    1370         <desc>
    1371           UUID of the newly created VM, when non-null or non-empty.
    1372           Otherwise a UUID is automatically generated.
    1373         </desc>
     1390        <desc>Machine UUID (optional).</desc>
    13741391      </param>
    13751392      <param name="machine" type="IMachine" dir="return">
     
    13801397    <method name="createLegacyMachine">
    13811398      <desc>
    1382         Creates a new virtual machine in "legacy" mode, using the
    1383         specified settings file to store machine settings.
     1399        Creates a new virtual machine in "legacy" mode, using the specified
     1400        settings file to store machine settings.
    13841401
    13851402        As opposed to machines created by <link to="#createMachine()"/>,
    1386         the settings file of the machine created in "legacy" mode
    1387         is not automatically renamed when the machine name is
    1388         changed -- it will always remain the same as specified in this
    1389         method call.
    1390 
    1391         The specified settings file name can be absolute
    1392         (full path) or relative to the <link to="IVirtualBox::homeFolder">
    1393           VirtualBox home directory</link>. If the file name doesn't
    1394         contain an extension, the default extension (.xml) will be
    1395         appended.
    1396 
    1397         Optionally the UUID of the machine can be predefined. If this is
    1398         not desired (i.e. a new UUID should be generated), pass just an
    1399         empty or null UUID.
     1403        the settings file of the machine created in "legacy" mode is not
     1404        automatically renamed when the machine name is changed -- it will always
     1405        remain the same as specified in this method call.
     1406
     1407        The specified settings file name can be absolute (full path) or relative
     1408        to the <link to="IVirtualBox::homeFolder">VirtualBox home
     1409        directory</link>. If the file name doesn't contain an extension, the
     1410        default extension (.xml) will be appended.
    14001411
    14011412        Note that the configuration of the newly created machine is not
     
    14051416        <link to="IMachine::saveSettings()"/> will return an error.
    14061417
    1407         You should also specify a valid name for the machine.
    1408         See the <link to="IMachine::name"/> property
    1409         description for more details about the machine name.
    1410 
    1411         The created machine remains
    1412         unregistered until you call <link to="#registerMachine()"/>.
    1413 
    1414         @deprecated This method may be removed later. It is better
    1415         to use <link to="IVirtualBox::createMachine()"/>.
     1418        See <link to="#createMachine()"/> for more information.
     1419
     1420        @deprecated This method may be removed later. Use <link
     1421        to="IVirtualBox::createMachine()"/> instead.
    14161422
    14171423        <note>
    14181424          There is no way to change the name of the settings file
    1419           of the created machine.
    1420         </note>
    1421       </desc>
    1422       <param name="settingsFile" type="wstring" dir="in">
    1423         <desc>
    1424           Name of the file where to store machine settings.
    1425         </desc>
    1426       </param>
     1425          of the machine created in "legacy" mode.
     1426        </note>
     1427
     1428        <result name="VBOX_E_OBJECT_NOT_FOUND">
     1429          @a osTypeId is invalid.
     1430        </result>
     1431        <result name="VBOX_E_FILE_ERROR">
     1432          @a settingsFile is invalid or the settings file already exists or
     1433          could not be created due to an I/O error.
     1434        </result>
     1435        <result name="E_INVALIDARG">
     1436          @a name or @a settingsFile is empty or null.
     1437        </result>
     1438      </desc>
     1439
    14271440      <param name="name" type="wstring" dir="in">
    14281441        <desc>Machine name.</desc>
     
    14311444        <desc>Machine OS Type ID.</desc>
    14321445      </param>
     1446      <param name="settingsFile" type="wstring" dir="in">
     1447        <desc>Name of the machine settings file.</desc>
     1448      </param>
    14331449      <param name="id" type="uuid" dir="in">
    1434         <desc>
    1435           UUID of the newly created VM, when non-null or non-empty.
    1436           Otherwise a UUID is automatically generated.
    1437         </desc>
     1450        <desc>Machine UUID (optional).</desc>
    14381451      </param>
    14391452      <param name="machine" type="IMachine" dir="return">
     
    57245737
    57255738  <interface
    5726      name="IGuestOSType" extends="$unknown"
    5727      uuid="da94f478-1f37-4726-b750-2235950dc2fe"
    5728      wsmap="struct"
    5729      >
     5739    name="IGuestOSType" extends="$unknown"
     5740    uuid="bc415228-eed0-402c-92f5-96fc4e2dd7e4"
     5741    wsmap="struct"
     5742  >
    57305743    <desc>
    57315744    </desc>
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette