Changeset 107241 in vbox for trunk/src/VBox/Frontends/VBoxManage
- Timestamp:
- Dec 6, 2024 11:13:51 AM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageObjectTracker.cpp
r107155 r107241 30 30 #include <map> 31 31 #include <vector> 32 #include <iprt/time.h> 32 33 33 34 using namespace com; 34 35 using namespace std; 35 36 //std::vector <com::Utf8Str> supportedIfaceList= {"IProgress", "ISession", "IMedium", "IMachine"};37 36 38 37 enum supIfaces_T … … 52 51 }; 53 52 53 static void makeTimeStr(char *s, int cb, int64_t millies) 54 { 55 RTTIME t; 56 RTTIMESPEC ts; 57 58 RTTimeSpecSetMilli(&ts, millies); 59 60 RTTimeExplode(&t, &ts); 61 62 RTStrPrintf(s, cb, "%04d/%02d/%02d %02d:%02d:%02d UTC", 63 t.i32Year, t.u8Month, t.u8MonthDay, 64 t.u8Hour, t.u8Minute, t.u8Second); 65 } 66 67 static Utf8Str trackedObjectStateToStr(TrackedObjectState_T aState) 68 { 69 Utf8Str strState("None"); 70 switch (aState) 71 { 72 case TrackedObjectState_Alive: 73 strState = "Alive"; 74 break; 75 case TrackedObjectState_Deleted: 76 strState = "Deleted"; 77 break; 78 case TrackedObjectState_Invalid: 79 strState = "Invalid"; 80 break; 81 case TrackedObjectState_None: 82 default: 83 strState = "None"; 84 break; 85 } 86 87 return strState; 88 } 89 90 struct TrackedObjInfo_T 91 { 92 ComPtr<IUnknown> pIUnknown; 93 TrackedObjectState_T enmState; 94 LONG64 creationTime; 95 LONG64 deletionTime; 96 }; 54 97 55 98 void printProgressObjectInfo(const ComPtr<IProgress>& pObj) … … 221 264 } 222 265 223 void printTrackedObjectInfo(supIfaces_T aIface, const map < Bstr, ComPtr<IUnknown>>& aObjMap)266 void printTrackedObjectInfo(supIfaces_T aIface, const map < Bstr, TrackedObjInfo_T >& aObjMap) 224 267 { 225 268 switch (aIface) 226 269 { 227 270 case kProgress: 228 for (const pair< const Bstr, ComPtr<IUnknown>>& item : aObjMap)271 for (const pair< const Bstr, TrackedObjInfo_T >& item : aObjMap) 229 272 { 230 273 ComPtr<IProgress> pObj; 231 item.second->QueryInterface(IID_IProgress, (void **)pObj.asOutParam()); 232 233 if (pObj.isNotNull()) 274 item.second.pIUnknown->QueryInterface(IID_IProgress, (void **)pObj.asOutParam()); 275 276 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 277 278 Utf8Str strState = trackedObjectStateToStr(item.second.enmState); 279 RTPrintf((" State %s\n"), strState.c_str()); 280 281 char szTimeValue[128]; 282 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.creationTime); 283 RTPrintf((" Creation time %s\n"), szTimeValue); 284 285 if (item.second.deletionTime != 0) 234 286 { 235 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 287 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.deletionTime); 288 RTPrintf((" Deletion time %s\n"), szTimeValue); 289 } 290 291 if (item.second.enmState != TrackedObjectState_Invalid && pObj.isNotNull()) 236 292 printProgressObjectInfo(pObj); 293 } 294 295 break; 296 297 case kSession: 298 for (const pair< const Bstr, TrackedObjInfo_T >& item : aObjMap) 299 { 300 ComPtr<ISession> pObj; 301 item.second.pIUnknown->QueryInterface(IID_ISession, (void **)pObj.asOutParam()); 302 303 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 304 305 Utf8Str strState = trackedObjectStateToStr(item.second.enmState); 306 RTPrintf((" State %s\n"), strState.c_str()); 307 308 char szTimeValue[128]; 309 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.creationTime); 310 RTPrintf((" Creation time %s\n"), szTimeValue); 311 312 if (item.second.deletionTime != 0) 313 { 314 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.deletionTime); 315 RTPrintf((" Deletion time %s\n"), szTimeValue); 237 316 } 238 } 239 240 break; 241 242 case kSession: 243 for (const pair< const Bstr, ComPtr<IUnknown> >& item : aObjMap) 244 { 245 ComPtr<ISession> pObj; 246 item.second->QueryInterface(IID_ISession, (void **)pObj.asOutParam()); 247 248 if (pObj.isNotNull()) 317 318 if (item.second.enmState != TrackedObjectState_Invalid && pObj.isNotNull()) 319 printSessionObjectInfo(pObj); 320 } 321 322 break; 323 324 case kMedium: 325 for (const pair< const Bstr, TrackedObjInfo_T >& item : aObjMap) 326 { 327 ComPtr<IMedium> pObj; 328 item.second.pIUnknown->QueryInterface(IID_IMedium, (void **)pObj.asOutParam()); 329 330 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 331 332 Utf8Str strState = trackedObjectStateToStr(item.second.enmState); 333 RTPrintf((" State %s\n"), strState.c_str()); 334 335 char szTimeValue[128]; 336 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.creationTime); 337 RTPrintf((" Creation time %s\n"), szTimeValue); 338 339 if (item.second.deletionTime != 0) 249 340 { 250 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str());251 printSessionObjectInfo(pObj);341 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.deletionTime); 342 RTPrintf((" Deletion time %s\n"), szTimeValue); 252 343 } 253 } 254 255 break; 256 257 case kMedium: 258 for (const pair< const Bstr, ComPtr<IUnknown> >& item : aObjMap) 259 { 260 ComPtr<IMedium> pObj; 261 item.second->QueryInterface(IID_IMedium, (void **)pObj.asOutParam()); 262 263 if (pObj.isNotNull()) 344 345 if (item.second.enmState != TrackedObjectState_Invalid && pObj.isNotNull()) 346 printMediumObjectInfo(pObj); 347 } 348 349 break; 350 351 case kMachine: 352 for (const pair< const Bstr, TrackedObjInfo_T >& item : aObjMap) 353 { 354 ComPtr<IMachine> pObj; 355 item.second.pIUnknown->QueryInterface(IID_IMachine, (void **)pObj.asOutParam()); 356 357 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 358 359 Utf8Str strState = trackedObjectStateToStr(item.second.enmState); 360 RTPrintf((" State %s\n"), strState.c_str()); 361 362 char szTimeValue[128]; 363 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.creationTime); 364 RTPrintf((" Creation time %s\n"), szTimeValue); 365 366 if (item.second.deletionTime != 0) 264 367 { 265 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str());266 printMediumObjectInfo(pObj);368 makeTimeStr(szTimeValue, sizeof(szTimeValue), item.second.deletionTime); 369 RTPrintf((" Deletion time %s\n"), szTimeValue); 267 370 } 268 } 269 270 break; 271 272 case kMachine: 273 for (const pair< const Bstr, ComPtr<IUnknown> >& item : aObjMap) 274 { 275 ComPtr<IMachine> pObj; 276 item.second->QueryInterface(IID_IMachine, (void **)pObj.asOutParam()); 277 278 if (pObj.isNotNull()) 279 { 280 RTPrintf(("\nTracked object id: %s\n"), Utf8Str(item.first).c_str()); 371 372 if (item.second.enmState != TrackedObjectState_Invalid && pObj.isNotNull()) 281 373 printMachineObjectInfo(pObj); 282 }283 374 } 284 375 … … 364 455 if (SUCCEEDED(hrc)) 365 456 { 366 map < Bstr, ComPtr<IUnknown> > lObjMap; 457 map < Bstr, TrackedObjInfo_T > lObjInfoMap; 458 367 459 if (strObjUuid.isNotEmpty()) 368 460 { … … 372 464 if (bstrObjId.equals(strObjUuid.c_str())) 373 465 { 374 ComPtr<IUnknown> pIUnknown; 375 hrc = pVirtualBox->GetTrackedObject(bstrObjId.raw(), pIUnknown.asOutParam()); 376 lObjMap[bstrObjId] = pIUnknown; 466 TrackedObjInfo_T objInfo; 467 hrc = pVirtualBox->GetTrackedObject(bstrObjId.raw(), 468 objInfo.pIUnknown.asOutParam(), 469 &objInfo.enmState, 470 &objInfo.creationTime, 471 &objInfo.deletionTime); 472 lObjInfoMap[bstrObjId] = objInfo; 377 473 break; 378 474 } … … 384 480 { 385 481 Bstr bstrObjId = ObjIDsList[i]; 386 ComPtr<IUnknown> pIUnknown; 387 hrc = pVirtualBox->GetTrackedObject(bstrObjId.raw(), pIUnknown.asOutParam()); 388 lObjMap[bstrObjId] = pIUnknown; 482 TrackedObjInfo_T objInfo; 483 hrc = pVirtualBox->GetTrackedObject(bstrObjId.raw(), 484 objInfo.pIUnknown.asOutParam(), 485 &objInfo.enmState, 486 &objInfo.creationTime, 487 &objInfo.deletionTime); 488 if (SUCCEEDED(hrc)) 489 lObjInfoMap[bstrObjId] = objInfo; 490 else 491 RTPrintf(("VirtualBox::getTrackedObject() returned the error 0x%LX\n"), hrc); 389 492 } 390 493 } 391 494 392 if (!lObj Map.empty())393 printTrackedObjectInfo(foundIface, lObj Map);495 if (!lObjInfoMap.empty()) 496 printTrackedObjectInfo(foundIface, lObjInfoMap); 394 497 else 395 RTPrintf(("Object with Id %s wasn't found or has \"invalid\" state\n"), strObjUuid.c_str());498 RTPrintf(("Object with Id %s wasn't found\n"), strObjUuid.c_str()); 396 499 } 500 else 501 RTPrintf(("VirtualBox::getTrackedObjectIds() returned the error 0x%LX\n"), hrc); 397 502 } 398 503 else
Note:
See TracChangeset
for help on using the changeset viewer.