Ejemplo n.º 1
0
/**
 * List media information.
 *
 * @returns See produceList.
 * @param   pVirtualBox         Reference to the IVirtualBox smart pointer.
 * @param   aMedia              Medium objects to list information for.
 * @param   pszParentUUIDStr    String with the parent UUID string (or "base").
 * @param   fOptLong            Long (@c true) or short list format.
 */
static HRESULT listMedia(const ComPtr<IVirtualBox> pVirtualBox,
                         const com::SafeIfaceArray<IMedium> &aMedia,
                         const char *pszParentUUIDStr,
                         bool fOptLong)
{
    HRESULT rc = S_OK;
    for (size_t i = 0; i < aMedia.size(); ++i)
    {
        ComPtr<IMedium> pMedium = aMedia[i];

        rc = showMediumInfo(pVirtualBox, pMedium, pszParentUUIDStr, fOptLong);

        RTPrintf("\n");

        com::SafeIfaceArray<IMedium> children;
        CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
        if (children.size() > 0)
        {
            Bstr uuid;
            pMedium->COMGETTER(Id)(uuid.asOutParam());

            // depth first listing of child media
            rc = listMedia(pVirtualBox, children, Utf8Str(uuid).c_str(), fOptLong);
        }
    }

    return rc;
}
Ejemplo n.º 2
0
static void listMedia(const ComPtr<IVirtualBox> aVirtualBox,
                      const com::SafeIfaceArray<IMedium> &aMedia,
                      const char *pszParentUUIDStr)
{
    HRESULT rc;
    for (size_t i = 0; i < aMedia.size(); ++i)
    {
        ComPtr<IMedium> pMedium = aMedia[i];
        Bstr uuid;
        pMedium->COMGETTER(Id)(uuid.asOutParam());
        RTPrintf("UUID:        %s\n", Utf8Str(uuid).c_str());
        if (pszParentUUIDStr)
            RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
        Bstr format;
        pMedium->COMGETTER(Format)(format.asOutParam());
        RTPrintf("Format:      %ls\n", format.raw());
        Bstr filepath;
        pMedium->COMGETTER(Location)(filepath.asOutParam());
        RTPrintf("Location:    %ls\n", filepath.raw());

        MediumState_T enmState;
        pMedium->RefreshState(&enmState);
        const char *stateStr = "unknown";
        switch (enmState)
        {
            case MediumState_NotCreated:
                stateStr = "not created";
                break;
            case MediumState_Created:
                stateStr = "created";
                break;
            case MediumState_LockedRead:
                stateStr = "locked read";
                break;
            case MediumState_LockedWrite:
                stateStr = "locked write";
                break;
            case MediumState_Inaccessible:
                stateStr = "inaccessible";
                break;
            case MediumState_Creating:
                stateStr = "creating";
                break;
            case MediumState_Deleting:
                stateStr = "deleting";
                break;
        }
        RTPrintf("State:       %s\n", stateStr);

        MediumType_T type;
        pMedium->COMGETTER(Type)(&type);
        const char *typeStr = "unknown";
        switch (type)
        {
            case MediumType_Normal:
                typeStr = "normal";
                break;
            case MediumType_Immutable:
                typeStr = "immutable";
                break;
            case MediumType_Writethrough:
                typeStr = "writethrough";
                break;
            case MediumType_Shareable:
                typeStr = "shareable";
                break;
            case MediumType_Readonly:
                typeStr = "readonly";
                break;
            case MediumType_MultiAttach:
                typeStr = "multiattach";
                break;
        }
        RTPrintf("Type:        %s\n", typeStr);

        com::SafeArray<BSTR> machineIds;
        pMedium->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
        for (size_t j = 0; j < machineIds.size(); ++j)
        {
            ComPtr<IMachine> machine;
            CHECK_ERROR(aVirtualBox, FindMachine(machineIds[j], machine.asOutParam()));
            ASSERT(machine);
            Bstr name;
            machine->COMGETTER(Name)(name.asOutParam());
            RTPrintf("%s%ls (UUID: %ls)",
                    j == 0 ? "Usage:       " : "             ",
                    name.raw(), machineIds[j]);
            com::SafeArray<BSTR> snapshotIds;
            pMedium->GetSnapshotIds(machineIds[j],
                                    ComSafeArrayAsOutParam(snapshotIds));
            for (size_t k = 0; k < snapshotIds.size(); ++k)
            {
                ComPtr<ISnapshot> snapshot;
                machine->FindSnapshot(snapshotIds[k], snapshot.asOutParam());
                if (snapshot)
                {
                    Bstr snapshotName;
                    snapshot->COMGETTER(Name)(snapshotName.asOutParam());
                    RTPrintf(" [%ls (UUID: %ls)]", snapshotName.raw(), snapshotIds[k]);
                }
            }
            RTPrintf("\n");
        }
        RTPrintf("\n");

        com::SafeIfaceArray<IMedium> children;
        CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
        if (children.size() > 0)
        {
            // depth first listing of child media
            listMedia(aVirtualBox, children, Utf8Str(uuid).c_str());
        }
    }
}