VirtualBox

Ignore:
Timestamp:
Oct 21, 2010 10:45:26 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
66862
Message:

Main: API change, merge IVirtualBox::getMachine() with findMachine()

File:
1 edited

Legend:

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

    r33254 r33294  
    13061306}
    13071307
    1308 /** @note Locks objects! */
    1309 STDMETHODIMP VirtualBox::GetMachine(IN_BSTR aId, IMachine **aMachine)
    1310 {
     1308/** @note Locks this object for reading, then some machine objects for reading. */
     1309STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aNameOrId, IMachine **aMachine)
     1310{
     1311    LogFlowThisFuncEnter();
     1312    LogFlowThisFunc(("aName=\"%ls\", aMachine={%p}\n", aNameOrId, aMachine));
     1313
     1314    CheckComArgStrNotEmptyOrNull(aNameOrId);
    13111315    CheckComArgOutSafeArrayPointerValid(aMachine);
    13121316
     
    13141318    if (FAILED(autoCaller.rc())) return autoCaller.rc();
    13151319
    1316     ComObjPtr<Machine> machine;
    1317     HRESULT rc = findMachine(Guid(aId),
    1318                              true /* fPermitInaccessible */,
    1319                              true /* setError */,
    1320                              &machine);
    1321 
    1322     /* the below will set *aMachine to NULL if machine is null */
    1323     machine.queryInterfaceTo(aMachine);
    1324 
    1325     return rc;
    1326 }
    1327 
    1328 /** @note Locks this object for reading, then some machine objects for reading. */
    1329 STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aName, IMachine **aMachine)
    1330 {
    1331     LogFlowThisFuncEnter();
    1332     LogFlowThisFunc(("aName=\"%ls\", aMachine={%p}\n", aName, aMachine));
    1333 
    1334     CheckComArgStrNotEmptyOrNull(aName);
    1335     CheckComArgOutSafeArrayPointerValid(aMachine);
    1336 
    1337     AutoCaller autoCaller(this);
    1338     if (FAILED(autoCaller.rc())) return autoCaller.rc();
    1339 
    13401320    /* start with not found */
     1321    HRESULT rc = S_OK;
    13411322    ComObjPtr<Machine> pMachineFound;
    1342     Utf8Str strName(aName);
    1343 
    1344     AutoReadLock al(m->allMachines.getLockHandle() COMMA_LOCKVAL_SRC_POS);
    1345     for (MachinesOList::iterator it = m->allMachines.begin();
    1346          it != m->allMachines.end();
    1347          ++it)
    1348     {
    1349         ComObjPtr<Machine> &pMachine2 = *it;
    1350         AutoCaller machCaller(pMachine2);
    1351         /* skip inaccessible machines */
    1352         if (FAILED(machCaller.rc()))
    1353             continue;
    1354 
    1355         AutoReadLock machLock(pMachine2 COMMA_LOCKVAL_SRC_POS);
    1356         if (pMachine2->getName() == strName)
    1357         {
    1358             pMachineFound = pMachine2;
    1359             break;
    1360         }
     1323
     1324    Guid id(aNameOrId);
     1325    if (!id.isEmpty())
     1326        rc = findMachine(id,
     1327                         true /* fPermitInaccessible */,
     1328                         true /* setError */,
     1329                         &pMachineFound);
     1330                // returns VBOX_E_OBJECT_NOT_FOUND if not found and sets error
     1331    else
     1332    {
     1333        Utf8Str strName(aNameOrId);
     1334        AutoReadLock al(m->allMachines.getLockHandle() COMMA_LOCKVAL_SRC_POS);
     1335        for (MachinesOList::iterator it = m->allMachines.begin();
     1336             it != m->allMachines.end();
     1337             ++it)
     1338        {
     1339            ComObjPtr<Machine> &pMachine2 = *it;
     1340            AutoCaller machCaller(pMachine2);
     1341            if (machCaller.rc())
     1342                continue;       // we can't ask inaccessible machines for their names
     1343
     1344            AutoReadLock machLock(pMachine2 COMMA_LOCKVAL_SRC_POS);
     1345            if (pMachine2->getName() == strName)
     1346            {
     1347                pMachineFound = pMachine2;
     1348                break;
     1349            }
     1350        }
     1351
     1352        if (!pMachineFound)
     1353            rc = setError(VBOX_E_OBJECT_NOT_FOUND,
     1354                          tr("Could not find a registered machine named '%ls'"), aNameOrId);
    13611355    }
    13621356
     
    13641358    pMachineFound.queryInterfaceTo(aMachine);
    13651359
    1366     HRESULT rc = pMachineFound
    1367         ? S_OK
    1368         : setError(VBOX_E_OBJECT_NOT_FOUND,
    1369                    tr("Could not find a registered machine named '%ls'"), aName);
    1370 
    1371     LogFlowThisFunc(("aName=\"%ls\", aMachine=%p, rc=%08X\n", aName, *aMachine, rc));
     1360    LogFlowThisFunc(("aName=\"%ls\", aMachine=%p, rc=%08X\n", aNameOrId, *aMachine, rc));
    13721361    LogFlowThisFuncLeave();
    13731362
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