ParallelPortImpl.cpp revision 9e27b031131a40ba8403de216d5dbd704b89f011
/* $Id$ */
/** @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 "ParallelPortImpl.h"
#include "MachineImpl.h"
#include "VirtualBoxImpl.h"
#include <VBox/settings.h>
#include "AutoStateDep.h"
#include "AutoCaller.h"
#include "Logging.h"
////////////////////////////////////////////////////////////////////////////////
//
// ParallelPort private data definition
//
////////////////////////////////////////////////////////////////////////////////
struct ParallelPort::Data
{
Data()
: fModified(false)
{ }
bool fModified;
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return S_OK;
}
void ParallelPort::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the Parallel 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 Parallel 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;
/* m->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 ParallelPort::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
delete m;
m = NULL;
}
// IParallelPort properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
if (aEnabled &&
return setError (E_INVALIDARG,
tr ("Cannot enable the parallel port %d "
"because the port path is empty or null"),
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->onParallelPortChange(this);
}
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(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 parallel port %d: "
"%lu (must be in range [0, %lu])"),
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
m->pMachine->onParallelPortChange(this);
}
return S_OK;
}
{
AutoCaller autoCaller(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 parallel 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->onParallelPortChange(this);
}
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
/* the machine needs to be mutable */
{
m->fModified = true;
// leave the lock before informing callbacks
return m->pMachine->onParallelPortChange(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 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.
*/
{
AutoCaller autoCaller(this);
// simply copy
return S_OK;
}
/**
* @note Locks this object for writing.
*/
bool ParallelPort::rollback()
{
/* sanity */
AutoCaller autoCaller(this);
bool changed = false;
if (m->bd.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 ParallelPort::commit()
{
/* sanity */
AutoCaller autoCaller(this);
/* sanity too */
/* lock both for writing since we modify both (m->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 */
}
/**
* Validates COMSETTER(Path) arguments.
*/
{
)
return setError(E_INVALIDARG,
tr("Path of the parallel port %d may not be empty or null "
"when the port is enabled"),
return S_OK;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */