Changeset 33294 in vbox for trunk/src/VBox/Main/VirtualBoxImpl.cpp
- Timestamp:
- Oct 21, 2010 10:45:26 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 66862
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r33254 r33294 1306 1306 } 1307 1307 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. */ 1309 STDMETHODIMP VirtualBox::FindMachine(IN_BSTR aNameOrId, IMachine **aMachine) 1310 { 1311 LogFlowThisFuncEnter(); 1312 LogFlowThisFunc(("aName=\"%ls\", aMachine={%p}\n", aNameOrId, aMachine)); 1313 1314 CheckComArgStrNotEmptyOrNull(aNameOrId); 1311 1315 CheckComArgOutSafeArrayPointerValid(aMachine); 1312 1316 … … 1314 1318 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 1315 1319 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 1340 1320 /* start with not found */ 1321 HRESULT rc = S_OK; 1341 1322 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); 1361 1355 } 1362 1356 … … 1364 1358 pMachineFound.queryInterfaceTo(aMachine); 1365 1359 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)); 1372 1361 LogFlowThisFuncLeave(); 1373 1362
Note:
See TracChangeset
for help on using the changeset viewer.