VirtualBox

Changeset 59926 in vbox for trunk


Ignore:
Timestamp:
Mar 4, 2016 2:01:54 PM (9 years ago)
Author:
vboxsync
Message:

Main/Machine+SerialPort+ParallelPort: only write the non-default serial/parallel port config lines to the settings file, plus some other minor cleanups, including whitespace

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/ParallelPortImpl.h

    r57979 r59926  
    66
    77/*
    8  * Copyright (C) 2006-2013 Oracle Corporation
     8 * Copyright (C) 2006-2016 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3838
    3939    // public initializer/uninitializer for internal purposes only
    40     HRESULT init (Machine *aParent, ULONG aSlot);
    41     HRESULT init (Machine *aParent, ParallelPort *aThat);
    42     HRESULT initCopy (Machine *parent, ParallelPort *aThat);
     40    HRESULT init(Machine *aParent, ULONG aSlot);
     41    HRESULT init(Machine *aParent, ParallelPort *aThat);
     42    HRESULT initCopy(Machine *parent, ParallelPort *aThat);
    4343    void uninit();
    4444
     
    5252    void i_copyFrom(ParallelPort *aThat);
    5353    void i_applyDefaults();
     54    bool i_hasDefaults();
    5455
    5556private:
  • trunk/src/VBox/Main/include/SerialPortImpl.h

    r49644 r59926  
    77
    88/*
    9  * Copyright (C) 2006-2013 Oracle Corporation
     9 * Copyright (C) 2006-2016 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4141
    4242    // public initializer/uninitializer for internal purposes only
    43     HRESULT init (Machine *aParent, ULONG aSlot);
    44     HRESULT init (Machine *aParent, SerialPort *aThat);
    45     HRESULT initCopy (Machine *parent, SerialPort *aThat);
     43    HRESULT init(Machine *aParent, ULONG aSlot);
     44    HRESULT init(Machine *aParent, SerialPort *aThat);
     45    HRESULT initCopy(Machine *parent, SerialPort *aThat);
    4646    void uninit();
    4747
     
    5555    void i_copyFrom(SerialPort *aThat);
    5656
    57     void i_applyDefaults (GuestOSType *aOsType);
     57    void i_applyDefaults(GuestOSType *aOsType);
     58    bool i_hasDefaults();
    5859
    5960    // public methods for internal purposes only
     
    7980    HRESULT setPath(const com::Utf8Str &aPath);
    8081
    81     ////////////////////////////////////////////////////////////////////////////////
    82     ////
    83     //// SerialPort private data definition
    84     ////
    85     //////////////////////////////////////////////////////////////////////////////////
    86     //
    87     struct Data
    88     {
    89       Data()
    90            : fModified(false),
    91              pMachine(NULL)
    92         { }
    93 
    94        bool                                fModified;
    95        Machine * const                     pMachine;
    96        const ComObjPtr<SerialPort>         pPeer;
    97        Backupable<settings::SerialPort>    bd;
    98     };
    99 
     82    struct Data;
    10083    Data *m;
    10184};
  • trunk/src/VBox/Main/src-server/MachineImpl.cpp

    r59464 r59926  
    1030510305        for (ULONG slot = 0; slot < RT_ELEMENTS(mSerialPorts); ++slot)
    1030610306        {
     10307            if (mSerialPorts[slot]->i_hasDefaults())
     10308                continue;
     10309
    1030710310            settings::SerialPort s;
    1030810311            s.ulSlot = slot;
     
    1031710320        for (ULONG slot = 0; slot < RT_ELEMENTS(mParallelPorts); ++slot)
    1031810321        {
     10322            if (mParallelPorts[slot]->i_hasDefaults())
     10323                continue;
     10324
    1031910325            settings::ParallelPort p;
    1032010326            p.ulSlot = slot;
  • trunk/src/VBox/Main/src-server/ParallelPortImpl.cpp

    r57979 r59926  
    55
    66/*
    7  * Copyright (C) 2006-2015 Oracle Corporation
     7 * Copyright (C) 2006-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    124124    unconst(m->pPeer) = aThat;
    125125
    126     AutoCaller thatCaller (aThat);
     126    AutoCaller thatCaller(aThat);
    127127    AssertComRCReturnRC(thatCaller.rc());
    128128
     
    442442    /* sanity */
    443443    AutoCaller autoCaller(this);
    444     AssertComRCReturnVoid (autoCaller.rc());
     444    AssertComRCReturnVoid(autoCaller.rc());
    445445
    446446    /* sanity too */
    447     AutoCaller peerCaller (m->pPeer);
    448     AssertComRCReturnVoid (peerCaller.rc());
     447    AutoCaller peerCaller(m->pPeer);
     448    AssertComRCReturnVoid(peerCaller.rc());
    449449
    450450    /* lock both for writing since we modify both (m->pPeer is "master" so locked
     
    469469void ParallelPort::i_copyFrom(ParallelPort *aThat)
    470470{
    471     AssertReturnVoid (aThat != NULL);
     471    AssertReturnVoid(aThat != NULL);
    472472
    473473    /* sanity */
    474474    AutoCaller autoCaller(this);
    475     AssertComRCReturnVoid (autoCaller.rc());
     475    AssertComRCReturnVoid(autoCaller.rc());
    476476
    477477    /* sanity too */
    478     AutoCaller thatCaller (aThat);
    479     AssertComRCReturnVoid (thatCaller.rc());
     478    AutoCaller thatCaller(aThat);
     479    AssertComRCReturnVoid(thatCaller.rc());
    480480
    481481    /* peer is not modified, lock it for reading (aThat is "master" so locked
     
    495495    /* sanity */
    496496    AutoCaller autoCaller(this);
    497     AssertComRCReturnVoid (autoCaller.rc());
     497    AssertComRCReturnVoid(autoCaller.rc());
    498498
    499499    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    514514            break;
    515515        }
    516         default: break;
    517     }
     516        default:
     517            AssertMsgFailed(("Parallel port slot %u exceeds limit\n", m->bd->ulSlot));
     518            break;
     519    }
     520}
     521
     522bool ParallelPort::i_hasDefaults()
     523{
     524    /* sanity */
     525    AutoCaller autoCaller(this);
     526    AssertComRCReturn(autoCaller.rc(), true);
     527
     528    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     529
     530    if (!m->bd->fEnabled)
     531    {
     532        /* Could be default, check the IO base and IRQ. */
     533        switch (m->bd->ulSlot)
     534        {
     535            case 0:
     536                if (m->bd->ulIOBase == 0x378 && m->bd->ulIRQ == 7)
     537                    return true;
     538                break;
     539            case 1:
     540                if (m->bd->ulIOBase == 0x278 && m->bd->ulIRQ == 5)
     541                    return true;
     542                break;
     543            default:
     544                AssertMsgFailed(("Parallel port slot %u exceeds limit\n", m->bd->ulSlot));
     545                break;
     546        }
     547
     548        /* Detect old-style defaults (0x378, irq 4) in any slot, they are still
     549         * in place for many VMs created by old VirtualBox versions. */
     550        if (m->bd->ulIOBase == 0x378 && m->bd->ulIRQ == 4)
     551            return true;
     552    }
     553
     554    return false;
    518555}
    519556
  • trunk/src/VBox/Main/src-server/SerialPortImpl.cpp

    r55401 r59926  
    66
    77/*
    8  * Copyright (C) 2006-2015 Oracle Corporation
     8 * Copyright (C) 2006-2016 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222#include "GuestOSTypeImpl.h"
    2323
     24#include <iprt/assert.h>
    2425#include <iprt/string.h>
    2526#include <iprt/cpp/utils.h>
     
    3132#include "Logging.h"
    3233
     34//////////////////////////////////////////////////////////////////////////////////
     35//
     36// SerialPort private data definition
     37//
     38//////////////////////////////////////////////////////////////////////////////////
     39
     40struct SerialPort::Data
     41{
     42    Data()
     43        : fModified(false),
     44          pMachine(NULL)
     45    { }
     46
     47    bool                                fModified;
     48    Machine * const                     pMachine;
     49    const ComObjPtr<SerialPort>         pPeer;
     50    Backupable<settings::SerialPort>    bd;
     51};
     52
    3353// constructor / destructor
    3454/////////////////////////////////////////////////////////////////////////////
    3555
    36 DEFINE_EMPTY_CTOR_DTOR (SerialPort)
     56DEFINE_EMPTY_CTOR_DTOR(SerialPort)
    3757
    3858HRESULT SerialPort::FinalConstruct()
     
    106126    unconst(m->pPeer) = aThat;
    107127
    108     AutoCaller thatCaller (aThat);
     128    AutoCaller thatCaller(aThat);
    109129    AssertComRCReturnRC(thatCaller.rc());
    110130
    111131    AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
    112     m->bd.share (aThat->m->bd);
     132    m->bd.share(aThat->m->bd);
    113133
    114134    /* Confirm a successful initialization */
     
    140160    /* pPeer is left null */
    141161
    142     AutoCaller thatCaller (aThat);
     162    AutoCaller thatCaller(aThat);
    143163    AssertComRCReturnRC(thatCaller.rc());
    144164
    145165    AutoReadLock thatLock(aThat COMMA_LOCKVAL_SRC_POS);
    146     m->bd.attachCopy (aThat->m->bd);
     166    m->bd.attachCopy(aThat->m->bd);
    147167
    148168    /* Confirm a successful initialization */
     
    545565    /* sanity */
    546566    AutoCaller autoCaller(this);
    547     AssertComRCReturnVoid (autoCaller.rc());
     567    AssertComRCReturnVoid(autoCaller.rc());
    548568
    549569    /* sanity too */
     
    570590 *  represented by @a aThat (locked for reading).
    571591 */
    572 void SerialPort::i_copyFrom (SerialPort *aThat)
    573 {
    574     AssertReturnVoid (aThat != NULL);
     592void SerialPort::i_copyFrom(SerialPort *aThat)
     593{
     594    AssertReturnVoid(aThat != NULL);
    575595
    576596    /* sanity */
    577597    AutoCaller autoCaller(this);
    578     AssertComRCReturnVoid (autoCaller.rc());
     598    AssertComRCReturnVoid(autoCaller.rc());
    579599
    580600    /* sanity too */
    581     AutoCaller thatCaller (aThat);
    582     AssertComRCReturnVoid (thatCaller.rc());
     601    AutoCaller thatCaller(aThat);
     602    AssertComRCReturnVoid(thatCaller.rc());
    583603
    584604    /* peer is not modified, lock it for reading (aThat is "master" so locked
     
    588608
    589609    /* this will back up current data */
    590     m->bd.assignCopy (aThat->m->bd);
    591 }
    592 
    593 void SerialPort::i_applyDefaults (GuestOSType *aOsType)
    594 {
    595     AssertReturnVoid (aOsType != NULL);
     610    m->bd.assignCopy(aThat->m->bd);
     611}
     612
     613void SerialPort::i_applyDefaults(GuestOSType *aOsType)
     614{
     615    AssertReturnVoid(aOsType != NULL);
    596616
    597617    /* sanity */
    598618    AutoCaller autoCaller(this);
    599     AssertComRCReturnVoid (autoCaller.rc());
     619    AssertComRCReturnVoid(autoCaller.rc());
    600620
    601621    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    608628        case 1:
    609629        {
    610             m->bd->ulIOBase = 0x2F8;
     630            m->bd->ulIOBase = 0x2f8;
    611631            m->bd->ulIRQ = 3;
    612632            break;
     
    624644            break;
    625645        }
    626         default: break;
     646        default:
     647            AssertMsgFailed(("Serial port slot %u exceeds limit\n", m->bd->ulSlot));
     648            break;
    627649    }
    628650
     
    634656        m->bd->fEnabled = true;
    635657    }
     658}
     659
     660bool SerialPort::i_hasDefaults()
     661{
     662    /* sanity */
     663    AutoCaller autoCaller(this);
     664    AssertComRCReturn(autoCaller.rc(), true);
     665
     666    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     667
     668    if (   !m->bd->fEnabled
     669        && m->bd->portMode == PortMode_Disconnected
     670        && !m->bd->fServer)
     671    {
     672        /* Could be default, check the IO base and IRQ. */
     673        switch (m->bd->ulSlot)
     674        {
     675            case 0:
     676                if (m->bd->ulIOBase == 0x3f8 && m->bd->ulIRQ == 4)
     677                    return true;
     678                break;
     679            case 1:
     680                if (m->bd->ulIOBase == 0x2f8 && m->bd->ulIRQ == 3)
     681                    return true;
     682                break;
     683            case 2:
     684                if (m->bd->ulIOBase == 0x3e8 && m->bd->ulIRQ == 4)
     685                    return true;
     686                break;
     687            case 3:
     688                if (m->bd->ulIOBase == 0x2e8 && m->bd->ulIRQ == 3)
     689                    return true;
     690                break;
     691            default:
     692                AssertMsgFailed(("Serial port slot %u exceeds limit\n", m->bd->ulSlot));
     693                break;
     694        }
     695
     696        /* Detect old-style defaults (0x3f8, irq 4) in any slot, they are still
     697         * in place for many VMs created by old VirtualBox versions. */
     698        if (m->bd->ulIOBase == 0x3f8 && m->bd->ulIRQ == 4)
     699            return true;
     700    }
     701
     702    return false;
    636703}
    637704
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