VirtualBox

Changeset 42569 in vbox


Ignore:
Timestamp:
Aug 3, 2012 9:52:23 AM (12 years ago)
Author:
vboxsync
Message:

Main/VirtualBox+Machine: new API method for getting VMs which are in the given groups, plus a bit of performance tuning/simplification

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r42551 r42569  
    14241424  <interface
    14251425    name="IVirtualBox" extends="$unknown"
    1426     uuid="53789455-fad2-425a-94c8-eb6dc4ceaa05"
     1426    uuid="3b90eded-f061-432f-9e0f-4b53cc7b6fa0"
    14271427    wsmap="managed"
    14281428    >
     
    18371837      <param name="machine" type="IMachine" dir="return">
    18381838        <desc>Machine object, if found.</desc>
     1839      </param>
     1840    </method>
     1841
     1842    <method name="getMachinesByGroups">
     1843      <desc>
     1844        Gets all machine references which are in one of the specified groups.
     1845      </desc>
     1846      <param name="groups" type="wstring" dir="in" safearray="yes">
     1847        <desc>What groups to match. The usual group list rules apply, i.e.
     1848        passing an empty list will match VMs in the toplevel group, likewise
     1849        the empty string.</desc>
     1850      </param>
     1851      <param name="machines" type="IMachine" dir="return" safearray="yes">
     1852        <desc>All machines which matched.</desc>
    18391853      </param>
    18401854    </method>
  • trunk/src/VBox/Main/include/MachineImpl.h

    r42551 r42569  
    673673
    674674    /**
    675      * Checks if this machine is accessible, without attempting to load the
    676      * config file.
    677      *
    678      * @note This method doesn't check this object's readiness. Intended to be
    679      * used by ready Machine children (whose readiness is bound to the parent's
    680      * one) or after doing addCaller() manually.
     675     * Returns various information about this machine.
     676     *
     677     * @note This method doesn't lock this object or check its readiness.
     678     * Intended to be used only after doing addCaller() manually and locking it
     679     * for reading.
    681680     */
    682681    ChipsetType_T getChipsetType() const { return mHWData->mChipsetType; }
     
    688687    void allowStateModification()           { mData->m_fAllowStateModification = true; }
    689688    void disallowStateModification()        { mData->m_fAllowStateModification = false; }
     689
     690    const StringsList &getGroups() const { return mUserData->s.llGroups; }
    690691
    691692    // callback handlers
  • trunk/src/VBox/Main/include/VirtualBoxImpl.h

    r42210 r42569  
    137137    STDMETHOD(RegisterMachine)(IMachine *aMachine);
    138138    STDMETHOD(FindMachine)(IN_BSTR aNameOrId, IMachine **aMachine);
     139    STDMETHOD(GetMachinesByGroups)(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines));
    139140    STDMETHOD(GetMachineStates)(ComSafeArrayIn(IMachine *, aMachines), ComSafeArrayOut(MachineState_T, aStates));
    140141    STDMETHOD(CreateAppliance)(IAppliance **anAppliance);
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r42383 r42569  
    985985        if (pMachine->isAccessible())
    986986        {
    987             SafeArray<BSTR> thisGroups;
    988             HRESULT rc = pMachine->COMGETTER(Groups)(ComSafeArrayAsOutParam(thisGroups));
    989             if (FAILED(rc))
    990                 continue;
    991 
    992             for (size_t i = 0; i < thisGroups.size(); i++)
    993                 allGroups.push_back(thisGroups[i]);
     987            const StringsList &thisGroups = pMachine->getGroups();
     988            for (StringsList::const_iterator it2 = thisGroups.begin();
     989                 it2 != thisGroups.end();
     990                 ++it2)
     991                allGroups.push_back(*it2);
    994992        }
    995993    }
     
    17221720
    17231721    return rc;
     1722}
     1723
     1724STDMETHODIMP VirtualBox::GetMachinesByGroups(ComSafeArrayIn(IN_BSTR, aGroups), ComSafeArrayOut(IMachine *, aMachines))
     1725{
     1726    CheckComArgSafeArrayNotNull(aGroups);
     1727    CheckComArgOutSafeArrayPointerValid(aMachines);
     1728
     1729    AutoCaller autoCaller(this);
     1730    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1731
     1732    StringsList llGroups;
     1733    HRESULT rc = convertMachineGroups(ComSafeArrayInArg(aGroups), &llGroups);
     1734    if (FAILED(rc))
     1735        return rc;
     1736    /* we want to rely on sorted groups during compare, to save time */
     1737    llGroups.sort();
     1738
     1739    /* get copy of all machine references, to avoid holding the list lock */
     1740    MachinesOList::MyList allMachines;
     1741    {
     1742        AutoReadLock al(m->allMachines.getLockHandle() COMMA_LOCKVAL_SRC_POS);
     1743        allMachines = m->allMachines.getList();
     1744    }
     1745
     1746    com::SafeIfaceArray<IMachine> saMachines;
     1747    for (MachinesOList::MyList::const_iterator it = allMachines.begin();
     1748         it != allMachines.end();
     1749         ++it)
     1750    {
     1751        const ComObjPtr<Machine> &pMachine = *it;
     1752        AutoCaller autoMachineCaller(pMachine);
     1753        if (FAILED(autoMachineCaller.rc()))
     1754            continue;
     1755        AutoReadLock mlock(pMachine COMMA_LOCKVAL_SRC_POS);
     1756
     1757        if (pMachine->isAccessible())
     1758        {
     1759            const StringsList &thisGroups = pMachine->getGroups();
     1760            for (StringsList::const_iterator it2 = thisGroups.begin();
     1761                 it2 != thisGroups.end();
     1762                 ++it2)
     1763            {
     1764                const Utf8Str &group = *it2;
     1765                bool fAppended = false;
     1766                for (StringsList::const_iterator it3 = llGroups.begin();
     1767                     it3 != llGroups.end();
     1768                     ++it3)
     1769                {
     1770                    int order = it3->compare(group);
     1771                    if (order == 0)
     1772                    {
     1773                        saMachines.push_back(pMachine);
     1774                        fAppended = true;
     1775                        break;
     1776                    }
     1777                    else if (order > 0)
     1778                        break;
     1779                    else
     1780                        continue;
     1781                }
     1782                /* avoid duplicates and save time */
     1783                if (fAppended)
     1784                    break;
     1785            }
     1786        }
     1787    }
     1788
     1789    saMachines.detachTo(ComSafeArrayOutArg(aMachines));
     1790
     1791    return S_OK;
    17241792}
    17251793
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