VirtualBox

Changeset 42176 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 17, 2012 12:23:50 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
79173
Message:

Main+Frontends/VBoxManage: implement saving the settings, and add the matching VBoxManage support

Location:
trunk/src/VBox
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h

    r41347 r42176  
    2424#include <VBox/com/VirtualBox.h>
    2525#include <VBox/com/string.h>
     26#include <VBox/com/array.h>
    2627#endif /* !VBOX_ONLY_DOCS */
    2728
     
    171172
    172173/* VBoxManageModifyVM.cpp */
     174#ifndef VBOX_ONLY_DOCS
     175void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups);
     176#endif
    173177int handleModifyVM(HandlerArg *a);
    174178
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r42129 r42176  
    137137        RTStrmPrintf(pStrm,
    138138                     "VBoxManage createvm         --name <name>\n"
     139                     "                            [--groups <group>, ...]\n"
    139140                     "                            [--ostype <ostype>]\n"
    140141                     "                            [--register]\n"
     
    148149                     "VBoxManage modifyvm         <uuid|name>\n"
    149150                     "                            [--name <name>]\n"
     151                     "                            [--groups <group>, ...]\n"
    150152                     "                            [--ostype <ostype>]\n"
    151153                     "                            [--memory <memorysize in MB>]\n"
     
    355357                     "                                       keepdisknames]\n"
    356358                     "                            [--name <name>]\n"
     359                     "                            [--groups <group>, ...]\n"
    357360                     "                            [--basefolder <basefolder>]\n"
    358361                     "                            [--uuid <uuid>]\n"
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageMisc.cpp

    r42131 r42176  
    191191    Bstr bstrBaseFolder;
    192192    Bstr bstrName;
    193     Bstr bstrGroups;
    194193    Bstr bstrOsTypeId;
    195194    Bstr bstrUuid;
    196195    bool fRegister = false;
     196    com::SafeArray<BSTR> groups;
    197197
    198198    int c;
     
    211211
    212212            case 'g':   // --groups
    213                 bstrGroups = ValueUnion.psz;
    214                 /// @todo implement group string parsing to safearray
     213                parseGroups(ValueUnion.psz, &groups);
    215214                break;
    216215
     
    242241    do
    243242    {
     243        Bstr bstrPrimaryGroup;
     244        if (groups.size())
     245            bstrPrimaryGroup = groups[0];
    244246        Bstr bstrSettingsFile;
    245247        CHECK_ERROR_BREAK(a->virtualBox,
    246248                          ComposeMachineFilename(bstrName.raw(),
    247                                                  NULL /* aGroup */,
     249                                                 bstrPrimaryGroup.raw(),
    248250                                                 bstrBaseFolder.raw(),
    249251                                                 bstrSettingsFile.asOutParam()));
    250252        ComPtr<IMachine> machine;
    251         com::SafeArray<BSTR> groups; /* no groups */
    252253        CHECK_ERROR_BREAK(a->virtualBox,
    253254                          CreateMachine(bstrSettingsFile.raw(),
     
    347348    com::SafeArray<CloneOptions_T> options;
    348349    const char                    *pszTrgName       = NULL;
    349     const char                    *pszTrgGroups     = NULL;
    350350    const char                    *pszTrgBaseFolder = NULL;
    351351    bool                           fRegister        = false;
    352352    Bstr                           bstrUuid;
     353    com::SafeArray<BSTR> groups;
    353354
    354355    int c;
     
    371372
    372373            case 'g':   // --groups
    373                 pszTrgGroups = ValueUnion.psz;
    374                 /// @todo implement group string parsing to safearray
     374                parseGroups(ValueUnion.psz, &groups);
    375375                break;
    376376
     
    435435        pszTrgName = RTStrAPrintf2("%s Clone", pszSrcName);
    436436
     437    Bstr bstrPrimaryGroup;
     438    if (groups.size())
     439        bstrPrimaryGroup = groups[0];
    437440    Bstr bstrSettingsFile;
    438441    CHECK_ERROR_RET(a->virtualBox,
    439442                    ComposeMachineFilename(Bstr(pszTrgName).raw(),
    440                                            NULL /* aGroup */,
     443                                           bstrPrimaryGroup.raw(),
    441444                                           Bstr(pszTrgBaseFolder).raw(),
    442445                                           bstrSettingsFile.asOutParam()),
     
    444447
    445448    ComPtr<IMachine> trgMachine;
    446     com::SafeArray<BSTR> groups; /* no groups */
    447449    CHECK_ERROR_RET(a->virtualBox, CreateMachine(bstrSettingsFile.raw(),
    448450                                                 Bstr(pszTrgName).raw(),
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp

    r41925 r42176  
    5353{
    5454    MODIFYVM_NAME = 1000,
     55    MODIFYVM_GROUPS,
    5556    MODIFYVM_OSTYPE,
    5657    MODIFYVM_MEMORY,
     
    196197{
    197198    { "--name",                     MODIFYVM_NAME,                      RTGETOPT_REQ_STRING },
     199    { "--groups",                   MODIFYVM_GROUPS,                    RTGETOPT_REQ_STRING },
    198200    { "--ostype",                   MODIFYVM_OSTYPE,                    RTGETOPT_REQ_STRING },
    199201    { "--memory",                   MODIFYVM_MEMORY,                    RTGETOPT_REQ_UINT32 },
     
    364366}
    365367
     368void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
     369{
     370    while (pcszGroups)
     371    {
     372        char *pComma = RTStrStr(pcszGroups, ",");
     373        if (pComma)
     374        {
     375            Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
     376            pcszGroups = pComma + 1;
     377        }
     378        else
     379        {
     380            Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
     381            pcszGroups = NULL;
     382        }
     383    }
     384}
     385
    366386int handleModifyVM(HandlerArg *a)
    367387{
     
    405425            {
    406426                CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
     427                break;
     428            }
     429            case MODIFYVM_GROUPS:
     430            {
     431                com::SafeArray<BSTR> groups;
     432                parseGroups(ValueUnion.psz, &groups);
     433                CHECK_ERROR(machine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
    407434                break;
    408435            }
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r42133 r42176  
    491491      <desc>Settings version "1.13", written by VirtualBox 4.2.x.</desc>
    492492      <!--
    493           Machine changes: tracing config;
     493          Machine changes: tracing config, groups, autostart;
     494          NetworkAdapter changes: unit for bandwidth group limits.
    494495      -->
    495496    </const>
  • trunk/src/VBox/Main/xml/Settings.cpp

    r41914 r42176  
    1717 *
    1818 * Certainly ConfigFileBase::ConfigFileBase() will. Change VBOX_XML_VERSION below as well.
     19 * VBOX_XML_VERSION does not have to be changed if the settings for a default VM do not
     20 * touch newly introduced attributes or tags. It has the benefit that older VirtualBox
     21 * versions do not trigger their "newer" code path.
    1922 *
    2023 * Once a new settings version has been added, these are the rules for introducing a new
     
    323326                else if (ulMinor == 12)
    324327                    m->sv = SettingsVersion_v1_12;
    325                 else if (ulMinor > 12)
     328                else if (ulMinor == 13)
     329                    m->sv = SettingsVersion_v1_13;
     330                else if (ulMinor > 13)
    326331                    m->sv = SettingsVersion_Future;
    327332            }
     
    32243229
    32253230/**
     3231 * Called for reading the <Groups> element under <Machine>.
     3232 */
     3233void MachineConfigFile::readGroups(const xml::ElementNode *pElmGroups, StringsList *pllGroups)
     3234{
     3235    pllGroups->clear();
     3236    if (!pElmGroups || m->sv < SettingsVersion_v1_13)
     3237    {
     3238        pllGroups->push_back("/");
     3239        return;
     3240    }
     3241
     3242    xml::NodesLoop nlGroups(*pElmGroups);
     3243    const xml::ElementNode *pelmGroup;
     3244    while ((pelmGroup = nlGroups.forAllNodes()))
     3245    {
     3246        if (pelmGroup->nameEquals("Group"))
     3247        {
     3248            Utf8Str strGroup;
     3249            if (!pelmGroup->getAttributeValue("name", strGroup))
     3250                throw ConfigFileError(this, pelmGroup, N_("Required Group/@name attribute is missing"));
     3251            pllGroups->push_back(strGroup);
     3252        }
     3253    }
     3254}
     3255
     3256/**
    32263257 * Called initially for the <Snapshot> element under <Machine>, if present,
    32273258 * to store the snapshot's data into the given Snapshot structure (which is
     
    32983329    readDebugging(elmSnapshot.findChildElement("Debugging"), &snap.debugging);
    32993330    readAutostart(elmSnapshot.findChildElement("Autostart"), &snap.autostart);
     3331    // note: Groups exist only for Machine, not for Snapshot
    33003332}
    33013333
     
    34503482            else if (pelmMachineChild->nameEquals("Autostart"))
    34513483                readAutostart(pelmMachineChild, &autostart);
     3484            else if (pelmMachineChild->nameEquals("Groups"))
     3485                readGroups(pelmMachineChild, &machineUserData.llGroups);
    34523486        }
    34533487
     
    44314465
    44324466/**
     4467 * Creates a <Groups> node under elmParent and then writes out the XML
     4468 * keys under that. Called for the <Machine> node only.
     4469 *
     4470 * @param pElmParent    Pointer to the parent element.
     4471 * @param pllGroups     Pointer to the groups list.
     4472 */
     4473void MachineConfigFile::buildGroupsXML(xml::ElementNode *pElmParent, const StringsList *pllGroups)
     4474{
     4475    if (   m->sv < SettingsVersion_v1_13 || pllGroups->size() == 0
     4476        || (pllGroups->size() == 1 && pllGroups->front() == "/"))
     4477        return;
     4478
     4479    xml::ElementNode *pElmGroups = pElmParent->createChild("Groups");
     4480    for (StringsList::const_iterator it = pllGroups->begin();
     4481         it != pllGroups->end();
     4482         ++it)
     4483    {
     4484        const Utf8Str &group = *it;
     4485        xml::ElementNode *pElmGroup = pElmGroups->createChild("Group");
     4486        pElmGroup->setAttribute("name", group);
     4487    }
     4488}
     4489
     4490/**
    44334491 * Writes a single snapshot into the DOM tree. Initially this gets called from MachineConfigFile::write()
    44344492 * for the root snapshot of a machine, if present; elmParent then points to the <Snapshots> node under the
     
    44614519    buildDebuggingXML(pelmSnapshot, &snap.debugging);
    44624520    buildAutostartXML(pelmSnapshot, &snap.autostart);
     4521    // note: Groups exist only for Machine, not for Snapshot
    44634522
    44644523    if (snap.llChildSnapshots.size())
     
    46104669    buildDebuggingXML(&elmMachine, &debugging);
    46114670    buildAutostartXML(&elmMachine, &autostart);
     4671    buildGroupsXML(&elmMachine, &machineUserData.llGroups);
    46124672}
    46134673
     
    47274787    if (m->sv < SettingsVersion_v1_13)
    47284788    {
    4729         // VirtualBox 4.2 adds tracing and autostart.
     4789        // VirtualBox 4.2 adds tracing, autostart and groups.
    47304790        if (   !debugging.areDefaultSettings()
    4731             || !autostart.areDefaultSettings())
     4791            || !autostart.areDefaultSettings()
     4792            || machineUserData.llGroups.size() > 1
     4793            || machineUserData.llGroups.front() != "/")
    47324794            m->sv = SettingsVersion_v1_13;
    47334795    }
Note: See TracChangeset for help on using the changeset viewer.

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