SerialPortImpl.cpp revision 8b5c19912f3e141c16afb49b7aeb9df38a309588
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2015 Oracle Corporation
*
* 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.
*/
#include "SerialPortImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include "GuestOSTypeImpl.h"
#include <VBox/settings.h>
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return BaseFinalConstruct();
}
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);
m = new Data();
/* m->pPeer 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);
m = new Data();
/* 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);
m = new Data();
/* pPeer 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;
delete m;
m = NULL;
}
// ISerialPort properties
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
{
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return S_OK;
}
{
return S_OK;
}
{
/* the machine needs to be mutable */
{
switch (aHostMode)
{
case PortMode_RawFile:
return setError(E_INVALIDARG,
tr("Cannot set the raw file mode of the serial port %d "
"because the file path is empty or null"),
break;
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;
}
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return S_OK;
}
{
return S_OK;
}
{
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])"),
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return S_OK;
}
{
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 */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return rc;
}
{
return S_OK;
}
{
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return S_OK;
}
{
return S_OK;
}
{
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->i_onSerialPortChange(this);
}
return S_OK;
}
// 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.
*/
{
AutoCaller autoCaller(this);
// simply copy
return S_OK;
}
/**
* Saves the port settings to the given port node.
*
* Note that the given Port node is completely empty on input.
*
* @param aPortNode <Port> node.
*
* @note Locks this object for reading.
*/
{
AutoCaller autoCaller(this);
// simply copy
return S_OK;
}
/**
* Returns true if any setter method has modified settings of this instance.
* @return
*/
bool SerialPort::i_isModified()
{
return m->fModified;
}
/**
* @note Locks this object for writing.
*/
void SerialPort::i_rollback()
{
/* sanity */
AutoCaller autoCaller(this);
}
/**
* @note Locks this object for writing, together with the peer object (also
* for writing) if there is one.
*/
void SerialPort::i_commit()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* lock both for writing since we modify both (pPeer is "master" so locked
* first) */
if (m->bd.isBackedUp())
{
if (m->pPeer)
{
/* 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 */
}
{
/* sanity */
AutoCaller autoCaller(this);
/* Set some more defaults.
* Note that the default value for COM1 (slot 0) is set in the constructor
* of bd. So slot 0 is correct already. */
{
case 1:
{
break;
}
case 2:
{
break;
}
case 3:
{
break;
}
default: break;
}
/* Enable port if requested */
{
}
}
/**
* 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;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */