VirtualBox

Changeset 44039 in vbox for trunk


Ignore:
Timestamp:
Dec 5, 2012 12:08:52 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82492
Message:

Main: renavation com::Guid class. PR5744

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/Guid.h

    r34071 r44039  
    4848{
    4949
     50typedef enum
     51    {
     52        ZERO_GUID,
     53        NORMAL_GUID,
     54        INVALID_GUID
     55    }GuidState_t;
     56
    5057/**
    5158 *  Helper class that represents the UUID type and hides platform-specific
     
    6067        ::RTUuidClear(&mUuid);
    6168        refresh();
     69        mGuidState = ZERO_GUID;
    6270    }
    6371
     
    6674        mUuid = that.mUuid;
    6775        refresh();
     76        if (isEmpty())
     77            mGuidState = ZERO_GUID;
     78        else
     79            mGuidState = NORMAL_GUID;
    6880    }
    6981
     
    7284        mUuid = that;
    7385        refresh();
     86        if (isEmpty())
     87            mGuidState = ZERO_GUID;
     88        else
     89            mGuidState = NORMAL_GUID;
    7490    }
    7591
     
    7995        ::memcpy(&mUuid, &that, sizeof(GUID));
    8096        refresh();
     97        if (isEmpty())
     98            mGuidState = ZERO_GUID;
     99        else
     100            mGuidState = NORMAL_GUID;
    81101    }
    82102
     
    92112    Guid(const char *that)
    93113    {
     114        mGuidState = NORMAL_GUID;
     115
    94116        int rc = ::RTUuidFromStr(&mUuid, that);
     117
    95118        if (RT_FAILURE(rc))
     119        {
    96120            ::RTUuidClear(&mUuid);
     121            mGuidState = INVALID_GUID;
     122        }
     123        else if(isEmpty())
     124            mGuidState = ZERO_GUID;
    97125        refresh();
    98126    }
     
    109137    Guid(const Bstr &that)
    110138    {
    111         int rc = !that.isEmpty()
    112                ? ::RTUuidFromUtf16(&mUuid, that.raw())
    113                : VERR_INVALID_UUID_FORMAT;
     139        mGuidState = NORMAL_GUID;
     140
     141        if (that.isEmpty())
     142        {
     143            ::RTUuidClear(&mUuid);
     144            mGuidState = ZERO_GUID;
     145        }
     146        else
     147        {
     148            int rc = ::RTUuidFromUtf16(&mUuid, that.raw());
     149            if (RT_FAILURE(rc))
     150            {
     151                ::RTUuidClear(&mUuid);
     152                mGuidState = INVALID_GUID;
     153            }
     154        }
     155
     156        refresh();
     157    }
     158
     159    Guid& operator=(const Guid &that)
     160    {
     161        mGuidState = NORMAL_GUID;
     162        ::memcpy(&mUuid, &that.mUuid, sizeof (RTUUID));
     163        if (isEmpty())
     164            mGuidState = ZERO_GUID;
     165        refresh();
     166        return *this;
     167    }
     168    Guid& operator=(const GUID &guid)
     169    {
     170        mGuidState = NORMAL_GUID;
     171        ::memcpy(&mUuid, &guid, sizeof (GUID));
     172        if (isEmpty())
     173            mGuidState = ZERO_GUID;
     174        refresh();
     175        return *this;
     176    }
     177    Guid& operator=(const RTUUID &guid)
     178    {
     179        mGuidState = NORMAL_GUID;
     180        ::memcpy(&mUuid, &guid, sizeof (RTUUID));
     181        if (isEmpty())
     182            mGuidState = ZERO_GUID;
     183        refresh();
     184        return *this;
     185    }
     186    Guid& operator=(const char *str)
     187    {
     188        mGuidState = NORMAL_GUID;
     189        int rc = ::RTUuidFromStr(&mUuid, str);
     190
    114191        if (RT_FAILURE(rc))
     192        {
    115193            ::RTUuidClear(&mUuid);
    116         refresh();
    117     }
    118 
    119     Guid& operator=(const Guid &that)
    120     {
    121         ::memcpy(&mUuid, &that.mUuid, sizeof (RTUUID));
    122         refresh();
    123         return *this;
    124     }
    125     Guid& operator=(const GUID &guid)
    126     {
    127         ::memcpy(&mUuid, &guid, sizeof (GUID));
    128         refresh();
    129         return *this;
    130     }
    131     Guid& operator=(const RTUUID &guid)
    132     {
    133         ::memcpy(&mUuid, &guid, sizeof (RTUUID));
    134         refresh();
    135         return *this;
    136     }
    137     Guid& operator=(const char *str)
    138     {
    139         int rc = ::RTUuidFromStr(&mUuid, str);
    140         if (RT_FAILURE(rc))
    141             ::RTUuidClear(&mUuid);
    142         refresh();
     194            mGuidState = INVALID_GUID;
     195        }
     196        else
     197        {
     198            if (isEmpty())
     199            mGuidState = ZERO_GUID;
     200        }
     201
     202        refresh();
     203
    143204        return *this;
    144205    }
     
    147208    {
    148209        ::RTUuidCreate(&mUuid);
     210        mGuidState = NORMAL_GUID;
    149211        refresh();
    150212    }
     
    152214    {
    153215        ::RTUuidClear(&mUuid);
     216        mGuidState = ZERO_GUID;
    154217        refresh();
    155218    }
     
    164227    {
    165228        char buf[RTUUID_STR_LENGTH];
     229
     230        ::memset(buf,0,RTUUID_STR_LENGTH);
     231
     232        if (mGuidState == INVALID_GUID)
     233        {
     234            /* What to return in case of wrong Guid */
     235            return Utf8Str("00000000-0000-0000-0000-00000000000");
     236        }
     237
    166238        ::RTUuidToStr(&mUuid, buf, RTUUID_STR_LENGTH);
     239
     240
    167241        return Utf8Str(buf);
    168242    }
     
    176250    Utf8Str toStringCurly() const
    177251    {
     252
     253        if (mGuidState == INVALID_GUID)
     254        {
     255            /* What to return in case of wrong Guid */
     256            return Utf8Str("{00000000-0000-0000-0000-00000000000}");
     257        }
     258
    178259        char buf[RTUUID_STR_LENGTH + 2] = "{";
     260
    179261        ::RTUuidToStr(&mUuid, buf + 1, RTUUID_STR_LENGTH);
    180262        buf[sizeof(buf) - 2] = '}';
    181263        buf[sizeof(buf) - 1] = '\0';
     264
    182265        return Utf8Str(buf);
    183266    }
     
    191274    Bstr toUtf16() const
    192275    {
    193         if (isEmpty())
    194           return Bstr();
     276        if (mGuidState == INVALID_GUID)
     277          return Bstr("00000000-0000-0000-0000-00000000000");
    195278
    196279        RTUTF16 buf[RTUUID_STR_LENGTH];
     
    199282    }
    200283
    201     bool isEmpty() const
    202     {
    203         return ::RTUuidIsNull(&mUuid);
    204     }
    205 
    206     bool isNotEmpty() const
    207     {
    208         return !::RTUuidIsNull(&mUuid);
     284    bool isValid() const
     285    {
     286        bool res = true;
     287        if (mGuidState == INVALID_GUID)
     288            res = false;
     289
     290        return res;
     291    }
     292
     293    bool isZero() const
     294    {
     295        return (::RTUuidIsNull(&mUuid) && mGuidState == ZERO_GUID);
    209296    }
    210297
     
    257344        if (ppGuid)
    258345            *ppGuid = (nsID *)nsMemory::Clone(&mUuid, sizeof(nsID));
     346
    259347        return *this;
    260348    }
     
    309397    static const Guid Empty;
    310398
     399protected:
     400
     401    bool isEmpty() const
     402    {
     403        return ::RTUuidIsNull(&mUuid);
     404    }
     405
     406    bool isNotEmpty() const
     407    {
     408        return !::RTUuidIsNull(&mUuid);
     409    }
     410
    311411private:
    312412    /**
     
    327427    /** The UUID. */
    328428    RTUUID mUuid;
     429
     430    GuidState_t mGuidState;
    329431
    330432#ifdef DEBUG
     
    335437#endif
    336438};
    337 
     439/*
    338440inline Bstr asGuidStr(const Bstr& str)
    339441{
     
    341443   return guid.isEmpty() ? Bstr() : guid.toUtf16();
    342444}
    343 
     445*/
    344446inline bool isValidGuid(const Bstr& str)
    345447{
    346448   Guid guid(str);
    347    return !guid.isEmpty();
     449   return guid.isValid();
     450//   return !guid.isEmpty();
    348451}
    349452
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageControlVM.cpp

    r42551 r44039  
    874874
    875875            Bstr usbId = a->argv[2];
    876             if (Guid(usbId).isEmpty())
     876
     877            Guid guid(usbId);
     878            if (!guid.isValid())
    877879            {
    878880                // assume address
     
    897899                    CHECK_ERROR_BREAK(dev, COMGETTER(Id)(usbId.asOutParam()));
    898900                }
     901            }
     902            else if (guid.isZero())
     903            {
     904                errorArgument("Zero UUID argument '%s'", a->argv[2]);
     905                rc = E_FAIL;
     906                break;
    899907            }
    900908
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp

    r44028 r44039  
    159159
    160160    /* If it is no UUID, convert the filename to an absolute one. */
    161     if (id.isEmpty())
     161    if (!id.isValid())
    162162    {
    163163        int irc = RTPathAbs(pszFilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r42472 r44039  
    950950            // first check if a UUID was supplied
    951951            uuidVM = argv[curArg];
    952             if (uuidVM.isEmpty())
     952
     953            if (!uuidVM.isValid())
    953954            {
    954955                LogFlow(("invalid UUID format, assuming it's a VM name\n"));
    955956                vmName = argv[curArg];
     957            }
     958            else if (uuidVM.isZero())
     959            {
     960                RTPrintf("Error: UUID argument is zero!\n");
     961                return 1;
    956962            }
    957963        }
     
    14171423     * Do we have a UUID?
    14181424     */
    1419     if (!uuidVM.isEmpty())
     1425    if (uuidVM.isValid())
    14201426    {
    14211427        rc = pVirtualBox->FindMachine(uuidVM.toUtf16().raw(), pMachine.asOutParam());
     
    14431449            goto leave;
    14441450        }
    1445     }
    1446     else if (uuidVM.isEmpty())
    1447     {
    1448         RTPrintf("Error: no machine specified!\n");
    1449         goto leave;
    14501451    }
    14511452
  • trunk/src/VBox/Main/include/VirtualBoxBase.h

    r42129 r44039  
    384384        Guid tmpGuid(a_Arg); \
    385385        (a_GuidVar) = tmpGuid; \
    386         if (RT_UNLIKELY((a_GuidVar).isEmpty())) \
     386        if (RT_UNLIKELY((a_GuidVar).isValid() == false)) \
    387387            return setError(E_INVALIDARG, \
    388388                tr("GUID argument %s is not valid (\"%ls\")"), #a_Arg, Bstr(a_Arg).raw()); \
  • trunk/src/VBox/Main/src-all/ProgressImpl.cpp

    r41184 r44039  
    200200    {
    201201        /* remove the added progress on failure to complete the initialization */
    202         if (aAutoUninitSpan.initFailed() && !mId.isEmpty())
     202        if (aAutoUninitSpan.initFailed() && mId.isValid() && !mId.isZero())
    203203            mParent->removeProgress(mId.ref());
    204204
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r43952 r44039  
    31773177{
    31783178#ifdef VBOX_WITH_USB
    3179     CheckComArgExpr(aId, Guid(aId).isEmpty() == false);
     3179    CheckComArgExpr(aId, Guid(aId).isValid() == true);
    31803180    CheckComArgOutPointerValid(aDevice);
    31813181
     
    34893489STDMETHODIMP Console::DeleteSnapshot(IN_BSTR aId, IProgress **aProgress)
    34903490{
    3491     CheckComArgExpr(aId, Guid(aId).isEmpty() == false);
     3491    CheckComArgExpr(aId, Guid(aId).isValid() == true);
    34923492    CheckComArgOutPointerValid(aProgress);
    34933493
     
    35123512STDMETHODIMP Console::DeleteSnapshotAndAllChildren(IN_BSTR aId, IProgress **aProgress)
    35133513{
    3514     CheckComArgExpr(aId, Guid(aId).isEmpty() == false);
     3514    CheckComArgExpr(aId, Guid(aId).isValid() == true);
    35153515    CheckComArgOutPointerValid(aProgress);
    35163516
     
    35353535STDMETHODIMP Console::DeleteSnapshotRange(IN_BSTR aStartId, IN_BSTR aEndId, IProgress **aProgress)
    35363536{
    3537     CheckComArgExpr(aStartId, Guid(aStartId).isEmpty() == false);
    3538     CheckComArgExpr(aEndId, Guid(aEndId).isEmpty() == false);
     3537    CheckComArgExpr(aStartId, Guid(aStartId).isValid() == true);
     3538    CheckComArgExpr(aEndId, Guid(aEndId).isValid() == true);
    35393539    CheckComArgOutPointerValid(aProgress);
    35403540
  • trunk/src/VBox/Main/src-client/RemoteUSBBackend.cpp

    r38986 r44039  
    901901    for (i = 0; i < RT_ELEMENTS(aGuids); i++)
    902902    {
    903         if (aGuids[i].isEmpty ())
     903        if (aGuids[i].isZero())
    904904        {
    905905            aGuids[i] = *pUuid;
  • trunk/src/VBox/Main/src-server/ApplianceImplImport.cpp

    r43041 r44039  
    26402640                if (cHardDisks == 1)
    26412641                {
    2642                     if (hdUuid.isEmpty())
     2642                    if (hdUuid.isZero())
    26432643                        hdUuid = thisUuid;
    26442644                    else
     
    26472647                else
    26482648                {
    2649                     if (thisUuid.isEmpty())
     2649                   if (thisUuid.isZero())
    26502650                        fInconsistent = true;
    26512651                    else if (thisUuid == hdUuid)
     
    27002700            settings::AttachedDevice &d = *dit;
    27012701
    2702             if (d.uuid.isEmpty())
     2702            if (d.uuid.isZero())
    27032703                // empty DVD and floppy media
    27042704                continue;
  • trunk/src/VBox/Main/src-server/HostImpl.cpp

    r43958 r44039  
    14341434    return E_NOTIMPL;
    14351435#else
    1436     if (Guid(id).isEmpty())
     1436    if (!Guid(id).isValid())
    14371437        return E_INVALIDARG;
    14381438    if (!networkInterface)
     
    15381538{
    15391539#ifdef VBOX_WITH_USB
    1540     CheckComArgExpr(aId, Guid (aId).isEmpty() == false);
     1540    CheckComArgExpr(aId, Guid (aId).isValid() == true);
    15411541    CheckComArgOutPointerValid(aDevice);
    15421542
     
    18691869
    18701870    Guid uuid(strNameOrId);
    1871     if (!uuid.isEmpty())
     1871    if (uuid.isValid() && !uuid.isZero())
    18721872        return findHostDriveById(mediumType, uuid, true /* fRefresh */, pMedium);
    18731873
  • trunk/src/VBox/Main/src-server/HostNetworkInterfaceImpl.cpp

    r43933 r44039  
    7070
    7171    ComAssertRet(!aInterfaceName.isEmpty(), E_INVALIDARG);
    72     ComAssertRet(!aGuid.isEmpty(), E_INVALIDARG);
     72    ComAssertRet(!aGuid.isValid(), E_INVALIDARG);
    7373
    7474    /* Enclose the state transition NotReady->InInit->Ready */
     
    185185
    186186//    ComAssertRet(aInterfaceName, E_INVALIDARG);
    187 //    ComAssertRet(!aGuid.isEmpty(), E_INVALIDARG);
     187//    ComAssertRet(aGuid.isValid(), E_INVALIDARG);
    188188    ComAssertRet(pIf, E_INVALIDARG);
    189189
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r43949 r44039  
    685685    AssertReturn(!isSessionMachine(), E_FAIL);
    686686    AssertReturn(!isSnapshotMachine(), E_FAIL);
    687     AssertReturn(!mData->mUuid.isEmpty(), E_FAIL);
     687    AssertReturn(mData->mUuid.isValid(), E_FAIL);
    688688    AssertReturn(!mData->mAccessible, E_FAIL);
    689689
     
    854854     * because at this point we did not call uninitDataAndChildObjects() yet
    855855     * and therefore also removeBackReference() for all these mediums was not called! */
    856     if (!uuidMachine.isEmpty())     // can be empty if we're called from a failure of Machine::init
     856
     857    if (uuidMachine.isValid() && !uuidMachine.isZero())     // can be empty if we're called from a failure of Machine::init
    857858        mParent->unregisterMachineMedia(uuidMachine);
    858859
     
    10001001    // never be found by findMachine()
    10011002    Guid test(aName);
    1002     if (test.isNotEmpty())
     1003    //if (test.isNotEmpty())
     1004    if (test.isValid())
    10031005        return setError(E_INVALIDARG,  tr("A machine cannot have a UUID as its name"));
    10041006
     
    13381340    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    13391341
    1340     if (!mHWData->mHardwareUUID.isEmpty())
     1342    if (mHWData->mHardwareUUID.isValid())
    13411343        mHWData->mHardwareUUID.toUtf16().cloneTo(aUUID);
    13421344    else
     
    13491351{
    13501352    Guid hardwareUUID(aUUID);
    1351     if (hardwareUUID.isEmpty())
     1353    if (!hardwareUUID.isValid())
    13521354        return E_INVALIDARG;
    13531355
     
    52935295    {
    52945296        Guid uuid(aNameOrId);
    5295         if (!uuid.isEmpty())
     5297        if (uuid.isValid())
    52965298            rc = findSnapshotById(uuid, pSnapshot, true /* aSetError */);
    52975299        else
     
    90299031    }
    90309032
    9031     if (aId.isEmpty())
     9033    if (aId.isZero())
    90329034        aSnapshot = mData->mFirstSnapshot;
    90339035    else
  • trunk/src/VBox/Main/src-server/MachineImplCloneVM.cpp

    r42109 r44039  
    951951         * with the stuff from the snapshot. */
    952952        settings::Snapshot sn;
    953         if (!d->snapshotId.isEmpty())
     953
     954        if (d->snapshotId.isValid() && !d->snapshotId.isZero())
    954955            if (!d->findSnapshot(trgMCF.llFirstSnapshot, d->snapshotId, sn))
    955956                throw p->setError(E_FAIL,
     
    960961        if (d->mode == CloneMode_MachineState)
    961962        {
    962             if (!sn.uuid.isEmpty())
     963            if (sn.uuid.isValid() && !sn.uuid.isZero())
    963964            {
    964965                trgMCF.hardwareMachine = sn.hardware;
     
    971972        }
    972973        else if (   d->mode == CloneMode_MachineAndChildStates
    973                  && !sn.uuid.isEmpty())
     974                    && sn.uuid.isValid()
     975                    && !sn.uuid.isZero())
    974976        {
    975977            if (!d->pOldMachineState.isNull())
     
    13231325            /* Update the path in the configuration either for the current
    13241326             * machine state or the snapshots. */
    1325             if (sst.snapshotUuid.isEmpty())
     1327            if (!sst.snapshotUuid.isValid() || sst.snapshotUuid.isZero())
    13261328                trgMCF.strStateFile = strTrgSaveState;
    13271329            else
  • trunk/src/VBox/Main/src-server/MediumImpl.cpp

    r44029 r44039  
    6969            const Guid &aSnapshotId = Guid::Empty)
    7070        : machineId(aMachineId),
    71           fInCurState(aSnapshotId.isEmpty())
    72     {
    73         if (!aSnapshotId.isEmpty())
     71          fInCurState(aSnapshotId.isZero())
     72    {
     73        if (aSnapshotId.isValid() && !aSnapshotId.isZero())
    7474            llSnapshotIds.push_back(aSnapshotId);
    7575    }
     
    942942    unconst(m->pVirtualBox) = aVirtualBox;
    943943
    944     if (!uuidMachineRegistry.isEmpty())
     944    if (uuidMachineRegistry.isValid() && !uuidMachineRegistry.isZero())
    945945        m->llRegistryIDs.push_back(uuidMachineRegistry);
    946946
     
    10871087        else
    10881088        {
    1089             AssertStmt(!m->id.isEmpty(),
     1089            AssertStmt(!m->id.isZero(),
    10901090                       alock.release(); autoCaller.release(); uninit(); return E_FAIL);
    10911091
     
    11421142    unconst(m->pVirtualBox) = aVirtualBox;
    11431143
    1144     if (!uuidMachineRegistry.isEmpty())
     1144    if (uuidMachineRegistry.isValid() && !uuidMachineRegistry.isZero())
    11451145        m->llRegistryIDs.push_back(uuidMachineRegistry);
    11461146
     
    20002000        {
    20012001            imageId = Guid(aImageId);
    2002             if (imageId.isEmpty())
    2003                 return setError(E_INVALIDARG, tr("Argument %s is empty"), "aImageId");
     2002            if (!imageId.isValid())
     2003                return setError(E_INVALIDARG, tr("Argument %s is invalid"), "aImageId");
    20042004        }
    20052005    }
     
    20612061                                    ComSafeArrayOut(BSTR, aSnapshotIds))
    20622062{
    2063     CheckComArgExpr(aMachineId, Guid(aMachineId).isEmpty() == false);
     2063    CheckComArgExpr(aMachineId, Guid(aMachineId).isValid() == true);
    20642064    CheckComArgOutSafeArrayPointerValid(aSnapshotIds);
    20652065
     
    34013401                                 const Guid &aSnapshotId /*= Guid::Empty*/)
    34023402{
    3403     AssertReturn(!aMachineId.isEmpty(), E_FAIL);
     3403    AssertReturn(aMachineId.isValid(), E_FAIL);
    34043404
    34053405    LogFlowThisFunc(("ENTER, aMachineId: {%RTuuid}, aSnapshotId: {%RTuuid}\n", aMachineId.raw(), aSnapshotId.raw()));
     
    34433443    // to a machine a medium which represents the machine's current state,
    34443444    // so set the flag
    3445     if (aSnapshotId.isEmpty())
     3445
     3446    if (aSnapshotId.isZero())
    34463447    {
    34473448        /* sanity: no duplicate attachments */
     
    34993500                                    const Guid &aSnapshotId /*= Guid::Empty*/)
    35003501{
    3501     AssertReturn(!aMachineId.isEmpty(), E_FAIL);
     3502    AssertReturn(aMachineId.isValid(), E_FAIL);
    35023503
    35033504    AutoCaller autoCaller(this);
     
    35113512    AssertReturn(it != m->backRefs.end(), E_FAIL);
    35123513
    3513     if (aSnapshotId.isEmpty())
     3514    if (aSnapshotId.isZero())
    35143515    {
    35153516        /* remove the current state attachment */
     
    45894590                && (   !aMachineId
    45904591                    || m->backRefs.size() != 1
    4591                     || aMachineId->isEmpty()
     4592                    || aMachineId->isZero()
    45924593                    || *getFirstMachineBackrefId() != *aMachineId
    4593                     || (   (!aSnapshotId || !aSnapshotId->isEmpty())
     4594                    || (   (!aSnapshotId || !aSnapshotId->isZero())
    45944595                        && *getFirstMachineBackrefSnapshotId() != *aSnapshotId)))
    45954596                throw setError(VBOX_E_OBJECT_IN_USE,
     
    54355436    /* are we dealing with a new medium constructed using the existing
    54365437     * location? */
    5437     bool isImport = m->id.isEmpty();
     5438    bool isImport = m->id.isZero();
    54385439    unsigned uOpenFlags = VD_OPEN_FLAGS_INFO;
    54395440
     
    55605561                    mediumId = uuid;
    55615562
    5562                     if (mediumId.isEmpty() && (m->hddOpenMode == OpenReadOnly))
     5563                    if (mediumId.isZero() && (m->hddOpenMode == OpenReadOnly))
    55635564                        // only when importing a VDMK that has no UUID, create one in memory
    55645565                        mediumId.create();
     
    55665567                else
    55675568                {
    5568                     Assert(!mediumId.isEmpty());
     5569                     Assert(!mediumId.isZero());
    55695570
    55705571                    if (mediumId != uuid)
     
    60346035                  || (    autoCaller.state() == InInit
    60356036                       && m->state != MediumState_NotCreated
    6036                        && m->id.isEmpty()
     6037                       && m->id.isZero()
    60376038                       && m->strFormat.isEmpty()
    60386039                       && m->formatObj.isNull()),
     
    65936594        * the setLocation() argument). Otherwise we have to generate it */
    65946595        Guid id = m->id;
    6595         fGenerateUuid = id.isEmpty();
     6596
     6597        fGenerateUuid = id.isZero();
    65966598        if (fGenerateUuid)
    65976599        {
     
    67306732         * the setLocation() argument). Otherwise we have to generate it */
    67316733        Guid targetId = pTarget->m->id;
    6732         fGenerateUuid = targetId.isEmpty();
     6734
     6735        fGenerateUuid = targetId.isZero();
    67336736        if (fGenerateUuid)
    67346737        {
     
    72347237         * the setLocation() argument). Otherwise we have to generate it */
    72357238        Guid targetId = pTarget->m->id;
    7236         fGenerateUuid = targetId.isEmpty();
     7239
     7240        fGenerateUuid = targetId.isZero();
    72377241        if (fGenerateUuid)
    72387242        {
     
    80528056         * the setLocation() argument). Otherwise we have to generate it */
    80538057        Guid targetId = m->id;
    8054         fGenerateUuid = targetId.isEmpty();
     8058
     8059        fGenerateUuid = targetId.isZero();
    80558060        if (fGenerateUuid)
    80568061        {
  • trunk/src/VBox/Main/src-server/SnapshotImpl.cpp

    r43915 r44039  
    115115    LogFlowThisFunc(("uuid=%s aParent->uuid=%s\n", aId.toString().c_str(), (aParent) ? aParent->m->uuid.toString().c_str() : ""));
    116116
    117     ComAssertRet(!aId.isEmpty() && !aName.isEmpty() && aMachine, E_INVALIDARG);
     117    ComAssertRet(!aId.isZero() && aId.isValid() && !aName.isEmpty() && aMachine, E_INVALIDARG);
    118118
    119119    /* Enclose the state transition NotReady->InInit->Ready */
     
    329329    // never be found by findMachine()
    330330    Guid test(aName);
    331     if (test.isNotEmpty())
     331
     332    if (!test.isZero() && test.isValid())
    332333        return setError(E_INVALIDARG,  tr("A machine cannot have a UUID as its name"));
    333334
     
    956957    LogFlowThisFunc(("mName={%s}\n", aSessionMachine->mUserData->s.strName.c_str()));
    957958
    958     AssertReturn(aSessionMachine && !Guid(aSnapshotId).isEmpty(), E_INVALIDARG);
     959    Guid l_guid(aSnapshotId);
     960    AssertReturn(aSessionMachine && (!l_guid.isZero() && l_guid.isValid()), E_INVALIDARG);
    959961
    960962    /* Enclose the state transition NotReady->InInit->Ready */
     
    10971099    LogFlowThisFunc(("mName={%s}\n", aMachine->mUserData->s.strName.c_str()));
    10981100
    1099     AssertReturn(aMachine && !Guid(aSnapshotId).isEmpty(), E_INVALIDARG);
     1101    Guid l_guid(aSnapshotId);
     1102    AssertReturn(aMachine && (!l_guid.isZero() && l_guid.isValid()), E_INVALIDARG);
    11001103
    11011104    /* Enclose the state transition NotReady->InInit->Ready */
     
    20622065    Guid startId(aStartId);
    20632066    Guid endId(aEndId);
    2064     AssertReturn(aInitiator && !startId.isEmpty() && !endId.isEmpty(), E_INVALIDARG);
     2067
     2068    AssertReturn(aInitiator && !startId.isZero() && !endId.isZero() && startId.isValid() && endId.isValid(), E_INVALIDARG);
     2069
    20652070    AssertReturn(aMachineState && aProgress, E_POINTER);
    20662071
     
    24632468                replaceSnapshotId = *pSnapshotId;
    24642469
    2465             if (!replaceMachineId.isEmpty())
     2470            if (replaceMachineId.isValid() && !replaceMachineId.isZero())
    24662471            {
    24672472                // Adjust the backreferences, otherwise merging will assert.
     
    32403245    }
    32413246
    3242     if (!aMachineId.isEmpty())
     3247    if (aMachineId.isValid() && !aMachineId.isZero())
    32433248    {
    32443249        // reattach the source media to the snapshot
  • trunk/src/VBox/Main/src-server/VirtualBoxImpl.cpp

    r44029 r44039  
    14531453        }
    14541454    }
    1455     if (id.isEmpty())
     1455
     1456    if (id.isZero())
    14561457        fDirectoryIncludesUUID = false;
     1458    else if (!id.isValid())
     1459    {
     1460        /* do something else */
     1461        return setError(E_INVALIDARG,
     1462                 tr("'%ls' is not a valid Guid"),
     1463                 id.toStringCurly().c_str());
     1464    }
    14571465
    14581466    Utf8Str strGroup(aGroup);
     
    16491657    }
    16501658    /* Create UUID if none was specified. */
    1651     if (id.isEmpty())
     1659    if (id.isZero())
    16521660        id.create();
     1661    else if (!id.isValid())
     1662    {
     1663        /* do something else */
     1664        return setError(E_INVALIDARG,
     1665                 tr("'%ls' is not a valid Guid"),
     1666                 id.toStringCurly().c_str());
     1667    }
    16531668
    16541669    /* NULL settings file means compose automatically */
     
    17801795
    17811796    Guid id(aNameOrId);
    1782     if (!id.isEmpty())
     1797    if (id.isValid() && !id.isZero())
     1798
    17831799        rc = findMachine(id,
    17841800                         true /* fPermitInaccessible */,
     
    19531969    {
    19541970        case DeviceType_HardDisk:
    1955             if (!id.isEmpty())
     1971            if (id.isValid() && !id.isZero())
    19561972                rc = findHardDiskById(id, false /* setError */, &pMedium);
    19571973            else
     
    19631979        case DeviceType_Floppy:
    19641980        case DeviceType_DVD:
    1965             if (!id.isEmpty())
     1981            if (id.isValid() && !id.isZero())
    19661982                rc = findDVDOrFloppyImage(deviceType, &id, Utf8Str::Empty,
    19671983                                          false /* setError */, &pMedium);
     
    34073423                                     ComObjPtr<Medium> *aHardDisk /*= NULL*/)
    34083424{
    3409     AssertReturn(!id.isEmpty(), E_INVALIDARG);
     3425    AssertReturn(!id.isZero(), E_INVALIDARG);
    34103426
    34113427    // we use the hard disks map, but it is protected by the
     
    36143630                                         ComObjPtr<Medium> &pMedium)
    36153631{
    3616     if (uuid.isEmpty())
     3632    if (uuid.isZero())
    36173633    {
    36183634        // that's easy
    36193635        pMedium.setNull();
    36203636        return S_OK;
     3637    }
     3638    else if (!uuid.isValid())
     3639    {
     3640        /* handling of case invalid GUID */
     3641        return setError(VBOX_E_OBJECT_NOT_FOUND,
     3642                            tr("Guid '%ls' is invalid"),
     3643                            uuid.toString().c_str());
    36213644    }
    36223645
     
    38213844                                           ComObjPtr<Medium> *ppMedium)
    38223845{
    3823     AssertReturn(!aId.isEmpty() && !aLocation.isEmpty(), E_FAIL);
     3846    AssertReturn(!aId.isZero() && !aLocation.isEmpty(), E_FAIL);
    38243847    AssertReturn(ppMedium, E_INVALIDARG);
    38253848
     
    38343857    const char *pcszType = NULL;
    38353858
    3836     if (!aId.isEmpty())
     3859    if (aId.isValid() && !aId.isZero())
    38373860        rc = findHardDiskById(aId, false /* aSetError */, &pMediumFound);
    38383861    if (FAILED(rc) && !aLocation.isEmpty())
     
    44234446HRESULT VirtualBox::unregisterMachineMedia(const Guid &uuidMachine)
    44244447{
    4425     Assert(!uuidMachine.isEmpty());
     4448    Assert(!uuidMachine.isZero() && uuidMachine.isValid());
    44264449
    44274450    LogFlowFuncEnter();
  • trunk/src/VBox/Main/xml/Settings.cpp

    r43041 r44039  
    383383{
    384384    guid = strUUID.c_str();
    385     if (guid.isEmpty())
     385    if (guid.isZero())
     386        throw ConfigFileError(this, NULL, N_("UUID \"%s\" has zero format"), strUUID.c_str());
     387    else if (!guid.isValid())
    386388        throw ConfigFileError(this, NULL, N_("UUID \"%s\" has invalid format"), strUUID.c_str());
    387389}
     
    35453547    if (m->sv >= SettingsVersion_v1_4)
    35463548        pelmHardware->setAttribute("version", hw.strVersion);
    3547     if (    (m->sv >= SettingsVersion_v1_9)
    3548          && (!hw.uuid.isEmpty())
     3549
     3550    if ((m->sv >= SettingsVersion_v1_9)
     3551         && !hw.uuid.isZero()
     3552         && hw.uuid.isValid()
    35493553       )
    35503554        pelmHardware->setAttribute("uuid", hw.uuid.toStringCurly());
     
    38623866                        if (att.fTempEject)
    38633867                            pelmDVD->setAttribute("tempeject", att.fTempEject);
    3864                         if (!att.uuid.isEmpty())
     3868
     3869                        if (!att.uuid.isZero() && att.uuid.isValid())
    38653870                            pelmDVD->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
    38663871                        else if (att.strHostDriveSrc.length())
     
    38783883                    const AttachedDevice &att = sctl.llAttachedDevices.front();
    38793884                    pelmFloppy->setAttribute("enabled", true);
    3880                     if (!att.uuid.isEmpty())
     3885
     3886                    if (!att.uuid.isZero() && att.uuid.isValid())
    38813887                        pelmFloppy->createChild("Image")->setAttribute("uuid", att.uuid.toStringCurly());
    38823888                    else if (att.strHostDriveSrc.length())
     
    44514457
    44524458            // attached image, if any
    4453             if (    !att.uuid.isEmpty()
    4454                  && (    att.deviceType == DeviceType_HardDisk
     4459            if (!att.uuid.isZero()
     4460                 && att.uuid.isValid()
     4461                 && (att.deviceType == DeviceType_HardDisk
    44554462                      || !fSkipRemovableMedia
    44564463                    )
     
    46554662       )
    46564663        elmMachine.setAttributePath("stateFile", strStateFile);
    4657     if (    (fl & BuildMachineXML_IncludeSnapshots)
    4658          && !uuidCurrentSnapshot.isEmpty())
     4664
     4665    if ((fl & BuildMachineXML_IncludeSnapshots)
     4666         && !uuidCurrentSnapshot.isZero()
     4667         && uuidCurrentSnapshot.isValid())
    46594668        elmMachine.setAttribute("currentSnapshot", uuidCurrentSnapshot.toStringCurly());
    46604669
     
    51745183              || !machineUserData.strTeleporterAddress.isEmpty()
    51755184              || !machineUserData.strTeleporterPassword.isEmpty()
    5176               || !hardwareMachine.uuid.isEmpty()
     5185              || (!hardwareMachine.uuid.isZero() && hardwareMachine.uuid.isValid())
    51775186            )
    51785187        )
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