SerialPortImpl.cpp revision 16ab6cda9bc53bc791284d26da448bbccb11b7ff
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "SerialPortImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "Logging.h"
#include <iprt/cpputils.h>
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void SerialPort::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the Serial Port object.
*
* @param aParent Handle of the parent object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* initialize data */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the Serial Port object given another serial port object
* (a kind of copy constructor). This object shares data with
* the object passed as an argument.
*
* @note This object must be destroyed before the original object
* it shares data with is destroyed.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Initializes the guest object given another guest object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*
* @note Locks @a aThat object for reading.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* mPeer is left null */
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void SerialPort::uninit()
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
}
// public methods only for internal purposes
////////////////////////////////////////////////////////////////////////////////
/**
* Loads settings from the given port node.
* May be called once right after this object creation.
*
* @param aPortNode <Port> node.
*
* @note Locks this object for writing.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* Note: we assume that the default values for attributes of optional
* nodes are assigned in the Data::Data() constructor and don't do it
* here. It implies that this method may only be called after constructing
* a new BIOSSettings object while all its data fields are in the default
* values. Exceptions are fields whose creation time defaults don't match
* values that should be applied when these fields are not explicitly set
* in the settings file (for backwards compatibility reasons). This takes
* place when a setting of a newly created object must default to A while
* the same setting of an object loaded from the old settings file must
* default to B. */
/* enabled (required) */
/* I/O base (required) */
/* IRQ (required) */
/* host mode (required) */
else
/* server mode (optional, defaults to false) */
return S_OK;
}
/**
* Saves the port settings to the given port node.
*
* Note that the given Port node is comletely empty on input.
*
* @param aPortNode <Port> node.
*
* @note Locks this object for reading.
*/
{
using namespace settings;
AutoCaller autoCaller (this);
AutoReadLock alock (this);
{
case PortMode_Disconnected:
mode = "Disconnected";
break;
case PortMode_HostPipe:
mode = "HostPipe";
break;
case PortMode_HostDevice:
mode = "HostDevice";
break;
default:
ComAssertMsgFailedRet (("Invalid serial port mode: %d",
E_FAIL);
}
/* Always save non-null mPath and mServer to preserve the user values for
* later use. Note that 'server' is false by default in XML so we don't
* save it when it's false. */
return S_OK;
}
/**
* @note Locks this object for writing.
*/
bool SerialPort::rollback()
{
/* sanity */
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
bool changed = false;
if (mData.isBackedUp())
{
/* we need to check all data to see whether anything will be changed
* after rollback */
}
return changed;
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void SerialPort::commit()
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* lock both for writing since we modify both (mPeer is "master" so locked
* first) */
if (mData.isBackedUp())
{
if (mPeer)
{
/* attach new data to the peer and reshare it */
}
}
}
/**
* @note Locks this object for writing, together with the peer object
* represented by @a aThat (locked for reading).
*/
{
/* sanity */
AutoCaller autoCaller (this);
/* sanity too */
/* peer is not modified, lock it for reading (aThat is "master" so locked
* first) */
/* this will back up current data */
}
// ISerialPort properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
/* leave the lock before informing callbacks */
mParent->onSerialPortChange (this);
}
return S_OK;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
bool emitChangeEvent = false;
{
switch (aHostMode)
{
case PortMode_HostPipe:
return setError (E_INVALIDARG,
tr ("Cannot set the host pipe mode of the serial port %d "
"because the pipe path is empty or null"),
break;
case PortMode_HostDevice:
return setError (E_INVALIDARG,
tr ("Cannot set the host device mode of the serial port %d "
"because the device path is empty or null"),
break;
case PortMode_Disconnected:
break;
}
emitChangeEvent = true;
}
if (emitChangeEvent)
{
/* leave the lock before informing callbacks */
mParent->onSerialPortChange (this);
}
return rc;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
/* check IRQ limits
* (when changing this, make sure it corresponds to XML schema */
if (aIRQ > 255)
return setError (E_INVALIDARG,
tr ("Invalid IRQ number of the serial port %d: "
"%lu (must be in range [0, %lu])"),
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
bool emitChangeEvent = false;
{
emitChangeEvent = true;
}
if (emitChangeEvent)
{
/* leave the lock before informing callbacks */
mParent->onSerialPortChange (this);
}
return rc;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
/* check IOBase limits
* (when changing this, make sure it corresponds to XML schema */
if (aIOBase > 0xFFFF)
return setError (E_INVALIDARG,
tr ("Invalid I/O port base address of the serial port %d: "
"%lu (must be in range [0, 0x%X])"),
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
bool emitChangeEvent = false;
{
emitChangeEvent = true;
}
if (emitChangeEvent)
{
/* leave the lock before informing callbacks */
mParent->onSerialPortChange (this);
}
return rc;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
/**
* Validates COMSETTER(Path) arguments.
*/
{
return setError (E_INVALIDARG,
tr ("Path of the serial port %d may not be empty or null in "
"host pipe or host device mode"),
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
/* we treat empty as null when e.g. saving to XML, do the same here */
{
/* leave the lock before informing callbacks */
return mParent->onSerialPortChange (this);
}
return S_OK;
}
{
AutoCaller autoCaller (this);
AutoReadLock alock (this);
return S_OK;
}
{
AutoCaller autoCaller (this);
/* the machine needs to be mutable */
AutoWriteLock alock (this);
{
/* leave the lock before informing callbacks */
mParent->onSerialPortChange (this);
}
return S_OK;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */