VirtualBox

Changeset 5806 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Nov 20, 2007 6:20:00 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
26217
Message:

Main: Fixed: Always save values of unused attributes of serial ports to preserve user's settings for later use.

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

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

    r5659 r5806  
    275275}
    276276
     277/**
     278 *  Saves the port settings to the given <Port> node.
     279 *
     280 *  Note that the given node is always empty so it is not necessary to delete
     281 *  old values.
     282 *
     283 *  @param aNode Node to save the settings to.
     284 *
     285 *  @return
     286 */
    277287HRESULT ParallelPort::saveSettings (CFGNODE aNode)
    278288{
     
    292302    CFGLDRSetUInt32Ex (portNode, "IOBase",  mData->mIOBase, 16);
    293303    CFGLDRSetUInt32   (portNode, "IRQ",     mData->mIRQ);
    294     CFGLDRSetBSTR     (portNode, "path",    mData->mPath);
     304
     305    /* 'path' is optional in XML */
     306    if (!mData->mPath.isEmpty())
     307        CFGLDRSetBSTR (portNode, "path", mData->mPath);
    295308
    296309    return S_OK;
     
    378391    if (aIRQ > 255)
    379392        return setError (E_INVALIDARG,
    380             tr ("Invalid IRQ number: %lu (must be in range [0, %lu])"),
    381                 aIRQ, 255);
     393            tr ("Invalid IRQ number of the parallel port %d: "
     394                "%lu (must be in range [0, %lu])"),
     395            mData->mSlot, aIRQ, 255);
    382396
    383397    AutoCaller autoCaller (this);
     
    432446    if (aIOBase > 0xFFFF)
    433447        return setError (E_INVALIDARG,
    434             tr ("Invalid I/O port base address: %lu (must be in range [0, 0x%X])"),
    435                 aIOBase, 0, 0xFFFF);
     448            tr ("Invalid I/O port base address of the parallel port %d: "
     449                "%lu (must be in range [0, 0x%X])"),
     450            mData->mSlot, aIOBase, 0, 0xFFFF);
    436451
    437452    AutoCaller autoCaller (this);
     
    487502    if (!*aPath)
    488503        return setError (E_INVALIDARG,
    489             tr ("Parallel port path cannot be empty"));
     504            tr ("Path of the parallel port %d may not be empty"),
     505            mData->mSlot);
    490506
    491507    AutoCaller autoCaller (this);
  • trunk/src/VBox/Main/SerialPortImpl.cpp

    r5659 r5806  
    245245
    246246    AutoLock alock (this);
     247
     248    HRESULT rc = S_OK;
    247249
    248250    CFGNODE portNode = NULL;
     
    273275    /* pipe/device path */
    274276    Bstr path;
    275     CFGLDRQueryBSTR(portNode, "path", path.asOutParam());
     277    CFGLDRQueryBSTR (portNode, "path", path.asOutParam());
    276278    /* server mode */
    277279    bool fServer = true;
     
    282284    mData->mIOBase   = uIOBase;
    283285    mData->mIRQ      = uIRQ;
     286
     287    rc = checkSetPath (path);
     288    CheckComRCReturnRC (rc);
     289
    284290    mData->mPath     = path;
    285291    mData->mServer   = fServer;
    286292
    287     return S_OK;
    288 }
    289 
     293    return rc;
     294}
     295
     296/**
     297 *  Saves the port settings to the given <Port> node.
     298 *
     299 *  Note that the given node is always empty so it is not necessary to delete
     300 *  old values.
     301 *
     302 *  @param aNode Node to save the settings to.
     303 *
     304 *  @return
     305 */
    290306HRESULT SerialPort::saveSettings (CFGNODE aNode)
    291307{
     
    320336    CFGLDRSetUInt32   (portNode, "IRQ",      mData->mIRQ);
    321337    CFGLDRSetString   (portNode, "hostMode", mode);
    322     if (mData->mHostMode != PortMode_DisconnectedPort)
    323     {
    324         CFGLDRSetBSTR (portNode, "path",    mData->mPath);
    325         if (mData->mHostMode == PortMode_HostPipePort)
    326             CFGLDRSetBool (portNode, "server",  !!mData->mServer);
    327     }
     338
     339    /* Always save non-null mPath and mServer to preserve the user values for
     340     * later use. Note that 'server' is false by default in XML so we don't
     341     * save it when it's false. */
     342    if (!mData->mPath.isEmpty())
     343        CFGLDRSetBSTR (portNode, "path", mData->mPath);
     344    if (mData->mServer)
     345        CFGLDRSetBool (portNode, "server", !!mData->mServer);
    328346
    329347    return S_OK;
     
    406424    if (mData->mHostMode != aHostMode)
    407425    {
     426        switch (aHostMode)
     427        {
     428            case PortMode_HostPipePort:
     429                if (mData->mPath.isEmpty())
     430                    return setError (E_INVALIDARG,
     431                        tr ("Cannot set the host pipe mode of the serial port %d "
     432                            "because the pipe path is empty or null"),
     433                        mData->mSlot);
     434                break;
     435            case PortMode_HostDevicePort:
     436                if (mData->mPath.isEmpty())
     437                    return setError (E_INVALIDARG,
     438                        tr ("Cannot set the host device mode of the serial port %d "
     439                            "because the device path is empty or null"),
     440                        mData->mSlot);
     441                break;
     442            case PortMode_DisconnectedPort:
     443                break;
     444        }
     445
    408446        mData.backup();
    409447        mData->mHostMode = aHostMode;
    410         if (aHostMode == PortMode_DisconnectedPort)
    411         {
    412             mData->mPath.setNull();
    413             mData->mServer = false;
    414         }
     448
    415449        emitChangeEvent = true;
    416450    }
     
    463497    if (aIRQ > 255)
    464498        return setError (E_INVALIDARG,
    465             tr ("Invalid IRQ number: %lu (must be in range [0, %lu])"),
    466                 aIRQ, 255);
     499            tr ("Invalid IRQ number of the serial port %d: "
     500                "%lu (must be in range [0, %lu])"),
     501            mData->mSlot, aIRQ, 255);
    467502
    468503    AutoCaller autoCaller (this);
     
    517552    if (aIOBase > 0xFFFF)
    518553        return setError (E_INVALIDARG,
    519             tr ("Invalid I/O port base address: %lu (must be in range [0, 0x%X])"),
    520                 aIOBase, 0, 0xFFFF);
     554            tr ("Invalid I/O port base address of the serial port %d: "
     555                "%lu (must be in range [0, 0x%X])"),
     556            mData->mSlot, aIOBase, 0, 0xFFFF);
    521557
    522558    AutoCaller autoCaller (this);
     
    565601}
    566602
     603/**
     604 *  Validates COMSETTER(Path) arguments.
     605 */
     606HRESULT SerialPort::checkSetPath (BSTR aPath)
     607{
     608    AssertReturn (isLockedOnCurrentThread(), E_FAIL);
     609
     610    if ((mData->mHostMode == PortMode_HostDevicePort ||
     611         mData->mHostMode == PortMode_HostPipePort) &&
     612        (aPath == NULL || *aPath == '\0'))
     613        return setError (E_INVALIDARG,
     614            tr ("Path of the serial port %d may not be empty or null in "
     615                "host pipe or host device mode"),
     616            mData->mSlot);
     617
     618    return S_OK;
     619}
     620
    567621STDMETHODIMP SerialPort::COMSETTER(Path) (INPTR BSTR aPath)
    568622{
    569623    if (!aPath)
    570624        return E_POINTER;
    571 
    572     if (!*aPath)
    573         return setError (E_INVALIDARG,
    574             tr ("Serial port path cannot be empty"));
    575 
    576625
    577626    AutoCaller autoCaller (this);
     
    586635    if (mData->mPath != aPath)
    587636    {
     637        HRESULT rc = checkSetPath (aPath);
     638        CheckComRCReturnRC (rc);
     639
    588640        mData.backup();
    589641        mData->mPath = aPath;
  • trunk/src/VBox/Main/include/SerialPortImpl.h

    r4324 r5806  
    122122private:
    123123
     124    HRESULT checkSetPath (BSTR aPath);
     125
    124126    const ComObjPtr <Machine, ComWeakRef> mParent;
    125127    const ComObjPtr <SerialPort> mPeer;
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