VirtualBox

Ignore:
Timestamp:
Dec 9, 2008 8:41:26 AM (16 years ago)
Author:
vboxsync
Message:

#3285: Improve error handling API to include unique error numbers
Document IMachine interface, part II.

File:
1 edited

Legend:

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

    r15051 r15140  
    22842284STDMETHODIMP Machine::GetSerialPort (ULONG slot, ISerialPort **port)
    22852285{
    2286     if (!port)
    2287         return E_POINTER;
    2288     if (slot >= RT_ELEMENTS (mSerialPorts))
    2289         return setError (E_INVALIDARG, tr ("Invalid slot number: %d"), slot);
     2286    CheckComArgOutPointerValid(port);
     2287    CheckComArgExpr(slot, slot < RT_ELEMENTS (mSerialPorts));
    22902288
    22912289    AutoCaller autoCaller (this);
     
    23012299STDMETHODIMP Machine::GetParallelPort (ULONG slot, IParallelPort **port)
    23022300{
    2303     if (!port)
    2304         return E_POINTER;
    2305     if (slot >= RT_ELEMENTS (mParallelPorts))
    2306         return setError (E_INVALIDARG, tr ("Invalid slot number: %d"), slot);
     2301    CheckComArgOutPointerValid(port);
     2302    CheckComArgExpr(slot, slot < RT_ELEMENTS (mParallelPorts));
    23072303
    23082304    AutoCaller autoCaller (this);
     
    23182314STDMETHODIMP Machine::GetNetworkAdapter (ULONG slot, INetworkAdapter **adapter)
    23192315{
    2320     if (!adapter)
    2321         return E_POINTER;
    2322     if (slot >= RT_ELEMENTS (mNetworkAdapters))
    2323         return setError (E_INVALIDARG, tr ("Invalid slot number: %d"), slot);
     2316    CheckComArgOutPointerValid(adapter);
     2317    CheckComArgExpr(slot, slot < RT_ELEMENTS (mNetworkAdapters));
    23242318
    23252319    AutoCaller autoCaller (this);
     
    24192413
    24202414        /* Here we are when a) there are no items at all or b) there are items
    2421          * but none of them equals to the requested non-NULL key. b) is an
     2415         * but none of them equals the requested non-NULL key. b) is an
    24222416         * error as well as a) if the key is non-NULL. When the key is NULL
    24232417         * (which is the case only when there are no items), we just fall
     
    24252419
    24262420        if (aKey != NULL)
    2427             return setError (E_FAIL,
     2421            return setError (VBOX_E_OBJECT_NOT_FOUND,
    24282422                tr ("Could not find the extra data key '%ls'"), aKey);
    24292423    }
     
    27122706
    27132707    if (mData->mRegistered)
    2714         return setError (E_FAIL,
     2708        return setError (VBOX_E_INVALID_VM_STATE,
    27152709            tr ("Cannot delete settings of a registered machine"));
    27162710
     
    27212715        int vrc = RTFileDelete (Utf8Str (mData->mConfigFileFull));
    27222716        if (RT_FAILURE (vrc))
    2723             return setError (E_FAIL,
     2717            return setError (VBOX_E_IPRT_ERROR,
    27242718                tr ("Could not delete the settings file '%ls' (%Rrc)"),
    27252719                mData->mConfigFileFull.raw(), vrc);
     
    28342828    rc = findSharedFolder (aName, sharedFolder, false /* aSetError */);
    28352829    if (SUCCEEDED (rc))
    2836         return setError (E_FAIL,
     2830        return setError (VBOX_E_OBJECT_IN_USE,
    28372831            tr ("Shared folder named '%ls' already exists"), aName);
    28382832
     
    28462840
    28472841    if (!accessible)
    2848         return setWarning (E_FAIL,
     2842        return setWarning (VBOX_E_FILE_ERROR,
    28492843            tr ("Shared folder host path '%ls' is not accessible"), aHostPath);
    28502844
     
    28942888    AutoCaller autoCaller (this);
    28952889    AssertComRCReturnRC (autoCaller.rc());
     2890
     2891    ComPtr <IInternalSessionControl> directControl;
     2892    {
     2893        AutoReadLock alock (this);
     2894
     2895        if (mData->mSession.mState != SessionState_Open)
     2896            return setError (VBOX_E_INVALID_VM_STATE,
     2897                tr ("Machine session is not open (session state: %d)"),
     2898                mData->mSession.mState);
     2899
     2900        directControl = mData->mSession.mDirectControl;
     2901    }
     2902
     2903    /* ignore calls made after #OnSessionEnd() is called */
     2904    if (!directControl)
     2905        return S_OK;
     2906
     2907    ULONG64 dummy;
     2908    return directControl->OnShowWindow (TRUE /* aCheck */, aCanShow, &dummy);
     2909}
     2910
     2911STDMETHODIMP Machine::ShowConsoleWindow (ULONG64 *aWinId)
     2912{
     2913    CheckComArgOutPointerValid(aWinId);
     2914
     2915    AutoCaller autoCaller (this);
     2916    AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
    28962917
    28972918    ComPtr <IInternalSessionControl> directControl;
     
    29112932        return S_OK;
    29122933
    2913     ULONG64 dummy;
    2914     return directControl->OnShowWindow (TRUE /* aCheck */, aCanShow, &dummy);
    2915 }
    2916 
    2917 STDMETHODIMP Machine::ShowConsoleWindow (ULONG64 *aWinId)
    2918 {
    2919     CheckComArgOutPointerValid(aWinId);
    2920 
    2921     AutoCaller autoCaller (this);
    2922     AssertComRCReturn (autoCaller.rc(), autoCaller.rc());
    2923 
    2924     ComPtr <IInternalSessionControl> directControl;
    2925     {
    2926         AutoReadLock alock (this);
    2927 
    2928         if (mData->mSession.mState != SessionState_Open)
    2929             return setError (E_FAIL,
    2930                 tr ("Machine session is not open (session state: %d)"),
    2931                 mData->mSession.mState);
    2932 
    2933         directControl = mData->mSession.mDirectControl;
    2934     }
    2935 
    2936     /* ignore calls made after #OnSessionEnd() is called */
    2937     if (!directControl)
    2938         return S_OK;
    2939 
    29402934    BOOL dummy;
    29412935    return directControl->OnShowWindow (FALSE /* aCheck */, &dummy, aWinId);
     
    29472941    ReturnComNotImplemented();
    29482942#else
    2949     if (!VALID_PTR (aName))
    2950         return E_INVALIDARG;
    2951     if (!VALID_PTR (aValue))
    2952         return E_POINTER;
    2953     if (!VALID_PTR (aTimestamp))
    2954         return E_POINTER;
    2955     if (!VALID_PTR (aFlags))
    2956         return E_POINTER;
     2943    CheckComArgNotNull(aName);
     2944    CheckComArgOutPointerValid(aValue);
     2945    CheckComArgOutPointerValid(aTimestamp);
     2946    CheckComArgOutPointerValid(aFlags);
    29572947
    29582948    AutoCaller autoCaller (this);
     
    30193009    using namespace guestProp;
    30203010
    3021     if (!VALID_PTR (aName))
    3022         return E_INVALIDARG;
     3011    CheckComArgNotNull(aName);
    30233012    if ((aValue != NULL) && !VALID_PTR (aValue))
    30243013        return E_INVALIDARG;
     
    30603049        property.mFlags = NILFLAG;
    30613050        if (fFlags & TRANSIENT)
    3062             rc = setError (E_INVALIDARG, tr ("Cannot set a transient property when the machine is not running"));
     3051            rc = setError (VBOX_E_INVALID_OBJECT_STATE, tr ("Cannot set a transient property when the machine is not running"));
    30633052        if (SUCCEEDED (rc))
    30643053        {
     
    31433132    if (!VALID_PTR (aPatterns) && (aPatterns != NULL))
    31443133        return E_POINTER;
    3145     if (ComSafeArrayOutIsNull (aNames))
    3146         return E_POINTER;
    3147     if (ComSafeArrayOutIsNull (aValues))
    3148         return E_POINTER;
    3149     if (ComSafeArrayOutIsNull (aTimestamps))
    3150         return E_POINTER;
    3151     if (ComSafeArrayOutIsNull (aFlags))
    3152         return E_POINTER;
     3134    CheckComArgSafeArrayNotNull(aNames);
     3135    CheckComArgSafeArrayNotNull(aValues);
     3136    CheckComArgSafeArrayNotNull(aTimestamps);
     3137    CheckComArgSafeArrayNotNull(aFlags);
    31533138
    31543139    AutoCaller autoCaller (this);
     
    43034288                 mData->mMachineState > MachineState_Paused ||
    43044289                 mData->mMachineState == MachineState_Saved))
    4305                 return setError (E_ACCESSDENIED,
     4290                return setError (VBOX_E_INVALID_VM_STATE,
    43064291                    tr ("The machine is not mutable (state is %d)"),
    43074292                    mData->mMachineState);
     
    43134298                (mType != IsSessionMachine ||
    43144299                 mData->mMachineState > MachineState_Paused))
    4315                 return setError (E_ACCESSDENIED,
     4300                return setError (VBOX_E_INVALID_VM_STATE,
    43164301                    tr ("The machine is not mutable (state is %d)"),
    43174302                    mData->mMachineState);
     
    46214606 *                          not found
    46224607 *  @return
    4623  *      S_OK when found or E_INVALIDARG when not found
     4608 *      S_OK when found or VBOX_E_OBJECT_NOT_FOUND when not found
    46244609 *
    46254610 *  @note
     
    46414626    }
    46424627
    4643     HRESULT rc = found ? S_OK : E_INVALIDARG;
     4628    HRESULT rc = found ? S_OK : VBOX_E_OBJECT_NOT_FOUND;
    46444629
    46454630    if (aSetError && !found)
     
    55185503    {
    55195504        if (aSetError)
    5520             return setError (E_FAIL,
     5505            return setError (VBOX_E_OBJECT_NOT_FOUND,
    55215506                tr ("This machine does not have any snapshots"));
    5522         return E_FAIL;
     5507        return VBOX_E_OBJECT_NOT_FOUND;
    55235508    }
    55245509
     
    55285513    {
    55295514        if (aSetError)
    5530             return setError (E_FAIL,
     5515            return setError (VBOX_E_OBJECT_NOT_FOUND,
    55315516                tr ("Could not find a snapshot named '%ls'"), aName);
    5532         return E_FAIL;
     5517        return VBOX_E_OBJECT_NOT_FOUND;
    55335518    }
    55345519
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette