Detailed Description

Container of devices.

The xDevices is a container of vDevices. Input readings are combined in a union fashion over all participating devices, output writings are dispatched to the relevant device. Formally, the xDevice class is derived from the vDevice class to provide the same interaface to a simulator. Ie, the application does not need to know whether is acts on a single vDevice or an xDevice. This is also true for configuration from file, but of cause not for programatical configuration. An xDevice may not be configured to have individual outputs or inputs, but to hold particular vDevices.

Technical detail: the xDevice uses the vDevice interface to register a common event fifo buffer and a common condition variable. Thus, the xDevice only works with devices that support this configuration feature.

Definition at line 49 of file iop_xdevice.h.

#include <iop_xdevice.h>

Public Types

typedef std::vector< vDevice * >::const_iterator Iterator
 Iterator for const access to individual devices. More...
 
- Public Types inherited from faudes::vDevice
enum  DeviceState { Down , StartUp , Up , ShutDown }
 Enum for device stages. More...
 

Public Member Functions

 xDevice (void)
 Default constructor. More...
 
virtual ~xDevice (void)
 Explicit destructor. More...
 
Iterator Begin (void) const
 Set Iterator to first device. More...
 
Iterator End (void) const
 Set Iterator to last device. More...
 
Idx Size (void) const
 Get number of devices. More...
 
void Insert (vDevice *device)
 Insert a new device. More...
 
void Insert (const std::string &rFileName)
 Insert a new device by Filename. More...
 
void Configure (Idx event, const AttributeDeviceEvent &attr)
 Dummy. More...
 
void Configure (const EventSet &rEvents)
 An xDevice does not provide event based configuration. More...
 
void Compile (void)
 Build up internal data structures. More...
 
void Clear (void)
 Clear all configuarations and destroy existing devices. More...
 
void Reset (void)
 reset all dynamic state, i.e. More...
 
bool ResetRequest (void)
 Test for reset request. More...
 
void Start (void)
 Activate the devices. More...
 
void Stop (void)
 Deactivate the device. More...
 
DeviceState Status (void)
 Get status. More...
 
void WriteOutput (Idx output)
 Run output command on relevant device. More...
 
virtual void FlushOutputs (void)
 Flush any pending IO Operations. More...
 
Time::Type CurrentTime (void)
 Report global fauDES-time Note: per convention we take the time of the first device inserted in xDevice as global time. More...
 
long int CurrentTimeMs (void)
 Report global fauDES-time Note: per convention we take the time of the first device inserted in xDevice as global time. More...
 
virtual void CurrentTime (Time::Type now)
 Set physical time in ftu. More...
 
virtual void CurrentTimeMs (long int nowms)
 Set physical time in ms. More...
 
- Public Member Functions inherited from faudes::vDevice
 vDevice (void)
 Default constructor. More...
 
virtual ~vDevice (void)
 Explicit destructor. More...
 
void Name (const std::string &rName)
 Set the device name. More...
 
const std::string & Name (void) const
 Get device name. More...
 
void Tolerance (Time::Type maxgap)
 Set tolerance for time synchonisation. More...
 
Time::Type Tolerance (void)
 Get tolerance. More...
 
virtual void TimeScale (unsigned int scale)
 Set timescale. More...
 
virtual int TimeScale (void)
 Get timescale. More...
 
virtual const EventSetOutputs (void) const
 Get outputs as plain set. More...
 
virtual const EventSetInputs (void) const
 Get inputs as plain set. More...
 
virtual std::string StatusString (void)
 Get status as infromal string. More...
 
virtual Idx ReadInput (void)
 Read sensed input events. More...
 
virtual Idx PeekInput (void)
 Peek for sensed events. More...
 
virtual bool InputReady (void)
 Report whether a input-event is ready. More...
 
virtual bool WaitInputs (Time::Type duration)
 Wait for input trigger. More...
 
virtual bool WaitInputsMs (long int duration)
 Wait for input trigger. More...
 
virtual faudes_systime_t FtuToSystemTime (Time::Type duration)
 Convert faudes time unit duration to system time. More...
 
void UseCondition (faudes_mutex_t *wmutex, faudes_cond_t *wcond)
 Tell the device which condition to use for waiting. More...
 
void UseBuffer (faudes_mutex_t *bmutex, std::deque< Idx > *bbuffer)
 Tell the device which buffer to use for inputs. More...
 
virtual std::string EStr (Idx ev)
 Convenience method. More...
 
SampledDensityFunction Performance (void)
 Get performance (need compiletime option) More...
 
void ResetPerformance (void)
 Clear performance (need compiletime option) More...
 
void WritePerformance (void)
 Convenience method. More...
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 Constructor. More...
 
 Type (const Type &rType)
 Copy constructor. More...
 
virtual ~Type (void)
 Destructor. More...
 
virtual TypeNew (void) const
 Construct on heap. More...
 
virtual TypeCopy (void) const
 Construct on heap. More...
 
virtual const TypeCast (const Type *pOther) const
 Cast other object to this type. More...
 
virtual TypeAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
virtual Typeoperator= (const Type &rSrc)
 Assign configurationdata from other object. More...
 
virtual bool Equal (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator== (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual bool operator!= (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual const std::string & TypeName (void) const
 Get objects's type name. More...
 
void Write (const Type *pContext=0) const
 Write configuration data to console. More...
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file. More...
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 Write configuration data to a file. More...
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to TokenWriter. More...
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to an XML file. More...
 
void XWrite (const Type *pContext=0) const
 Write configuration data in XML format to concole Note: this write function uses the virtual function DoXWrite(), to be reimplemented by derived classes. More...
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in XML format to TokenWriter. More...
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a string. More...
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data to a formated string. More...
 
void DWrite (const Type *pContext=0) const
 Write configuration data to console, debugging format. More...
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 Write configuration data to a file, debugging format. More...
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debug format to TokenWriter. More...
 
void SWrite (TokenWriter &rTw) const
 Write statistics comment to TokenWriter. More...
 
void SWrite (void) const
 Write statistics comment to console. More...
 
std::string ToSText (void) const
 Write statistics to a string. More...
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from file with label specified. More...
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from a string. More...
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Read configuration data from TokenReader with label sepcified. More...
 

Static Public Member Functions

static xDeviceFromTokenReader (TokenReader &rTr)
 Construct on heap from token reader. More...
 
static xDeviceFromFile (const std::string &rFileName)
 Construct on heap from file. More...
 
- Static Public Member Functions inherited from faudes::vDevice
static vDeviceFromTokenReader (TokenReader &rTr)
 Construct on heap from token reader. More...
 
static vDeviceFromFile (const std::string &rFileName)
 Construct on heap from file. More...
 
static void StopAll (void)
 Stop all devices. More...
 

Protected Types

typedef std::vector< vDevice * >::iterator iterator
 

Protected Member Functions

virtual void DoReadConfiguration (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Actual method to read device configuration from tokenreader. More...
 
virtual void DoWriteConfiguration (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write the device patrameters to a TokenWriter. More...
 
iterator Begin (void)
 Return first Device. More...
 
iterator End (void)
 Return last Device. More...
 
- Protected Member Functions inherited from faudes::vDevice
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Token output, see Type::Write for public wrappers. More...
 
virtual void DoWritePreface (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Writes non-event-configuration data from TokenWriter. More...
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Token input, see Type::DRead for public wrappers. More...
 
virtual void DoReadPreface (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 Reads non-event-configuration data from TokenReader. More...
 
virtual long int FtuToMs (Time::Type faudes_time)
 convert duration from fauDES-time units to ms More...
 
virtual Time::Type MsToFtu (long int real_time)
 convert duration in ms to faudes-time units More...
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 Assign configuration data from other object. More...
 
bool DoEqual (const Type &rOther) const
 Test equality of configuration data. More...
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data of this object to TokenWriter in XML format. More...
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 Write configuration data in debugging format to TokenWriter. More...
 
virtual void DoSWrite (TokenWriter &rTw) const
 Write statistical data as a comment to TokenWriter. More...
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 Get objects's type definition. More...
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

std::vector< vDevice * > mDevices
 Vector of member-devices. More...
 
std::vector< std::string > mDeviceNames
 Vector of member-device-names. More...
 
std::map< Idx, int > mInputToDevice
 Compiled data: Input map to map input idx to device no. More...
 
std::map< Idx, int > mOutputToDevice
 Compiled data: Output Map to map input idx to device no. More...
 
bool lastCommandWasStart
 Current device state: remember last stop/down command. More...
 
- Protected Attributes inherited from faudes::vDevice
std::string mDefaultLabel
 Default label for token io. More...
 
std::string mName
 Name. More...
 
EventSetmpConfiguration
 Overall event configuration (uses cast for type) More...
 
EventSet mInputs
 All inputs. More...
 
EventSet mOutputs
 All outputs. More...
 
DeviceState mState
 Status: running, starting etc. More...
 
faudes_mutex_t mWaitMutex
 Default Wait Condition Mutex. More...
 
faudes_cond_t mWaitCondition
 Default Wait Condition. More...
 
faudes_mutex_t * pWaitMutex
 Actual Wait Condition Mutex. More...
 
faudes_cond_t * pWaitCondition
 Actual Wait Condition. More...
 
faudes_systime_t mTimeZero
 physical timepoint zero
More...
 
int mTimeScale
 FauDES-time: scaling factor in ms/ftu. More...
 
Time::Type mMaxSyncGap
 Toleance for time sync. More...
 
std::deque< IdxmInputBuffer
 Default Fifo buffer for input readings. More...
 
std::deque< Idx > * pInputBuffer
 Actual Fifo buffer for input readings. More...
 
faudes_mutex_t mBufferMutex
 Default mutex for input buffer (mutexted) More...
 
faudes_mutex_t * pBufferMutex
 Actual mutex for input buffer (mutexted) More...
 
bool mResetRequest
 Reset request marker (mutexed) More...
 
faudes_systime_t * mpPerformanceWaitEnter
 Structures to store time-samples in. More...
 
faudes_systime_t * mpPerformanceWaitExit
 
int mPerformanceEndIterator
 Global iterator. More...
 
int mPerformanceBeginIterator
 

Member Typedef Documentation

◆ Iterator

typedef std::vector<vDevice*>::const_iterator faudes::xDevice::Iterator

Iterator for const access to individual devices.

Definition at line 58 of file iop_xdevice.h.

◆ iterator

typedef std::vector<vDevice*>::iterator faudes::xDevice::iterator
protected

Definition at line 278 of file iop_xdevice.h.

Constructor & Destructor Documentation

◆ xDevice()

faudes::xDevice::xDevice ( void  )

Default constructor.

Definition at line 44 of file iop_xdevice.cpp.

◆ ~xDevice()

faudes::xDevice::~xDevice ( void  )
virtual

Explicit destructor.

Definition at line 80 of file iop_xdevice.cpp.

Member Function Documentation

◆ Begin() [1/2]

iterator faudes::xDevice::Begin ( void  )
inlineprotected

Return first Device.

Definition at line 314 of file iop_xdevice.h.

◆ Begin() [2/2]

Iterator faudes::xDevice::Begin ( void  ) const
inline

Set Iterator to first device.

Returns
Iterator to first device

Definition at line 114 of file iop_xdevice.h.

◆ Clear()

void faudes::xDevice::Clear ( void  )
virtual

Clear all configuarations and destroy existing devices.

Reimplemented from faudes::vDevice.

Definition at line 197 of file iop_xdevice.cpp.

◆ Compile()

void faudes::xDevice::Compile ( void  )
virtual

Build up internal data structures.

I.e. (event-idx,int) - map

Reimplemented from faudes::vDevice.

Definition at line 247 of file iop_xdevice.cpp.

◆ Configure() [1/2]

void faudes::xDevice::Configure ( const EventSet rEvents)
virtual

An xDevice does not provide event based configuration.

Use Insert instead. This function will throw an execption

Reimplemented from faudes::vDevice.

Definition at line 307 of file iop_xdevice.cpp.

◆ Configure() [2/2]

void faudes::xDevice::Configure ( Idx  event,
const AttributeDeviceEvent attr 
)
virtual

Dummy.

An xDevice does not provide event based configuration. Use Insert instead. This function will throw an execption

Reimplemented from faudes::vDevice.

Definition at line 296 of file iop_xdevice.cpp.

◆ CurrentTime() [1/2]

void faudes::xDevice::CurrentTime ( Time::Type  now)
virtual

Set physical time in ftu.

Parameters
nownow in faudes time units (ftu).

Reimplemented from faudes::vDevice.

Definition at line 348 of file iop_xdevice.cpp.

◆ CurrentTime() [2/2]

Time::Type faudes::xDevice::CurrentTime ( void  )
virtual

Report global fauDES-time Note: per convention we take the time of the first device inserted in xDevice as global time.

Returns
fauDES-time

Reimplemented from faudes::vDevice.

Definition at line 319 of file iop_xdevice.cpp.

◆ CurrentTimeMs() [1/2]

void faudes::xDevice::CurrentTimeMs ( long int  nowms)
virtual

Set physical time in ms.

Parameters
nowmsnow in msec

Reimplemented from faudes::vDevice.

Definition at line 356 of file iop_xdevice.cpp.

◆ CurrentTimeMs() [2/2]

long int faudes::xDevice::CurrentTimeMs ( void  )
virtual

Report global fauDES-time Note: per convention we take the time of the first device inserted in xDevice as global time.

Returns
fauDES-time

Reimplemented from faudes::vDevice.

Definition at line 334 of file iop_xdevice.cpp.

◆ DoReadConfiguration()

void faudes::xDevice::DoReadConfiguration ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
)
protectedvirtual

Actual method to read device configuration from tokenreader.

DoRead basically calls the DoWrite-function of all devices which are part of xDevice

Parameters
rTrTokenReader to read from
rLabelSection to read
pContextRead context to provide contextual information
Exceptions
Exception
  • IO error (id 1)

Reimplemented from faudes::vDevice.

Definition at line 403 of file iop_xdevice.cpp.

◆ DoWriteConfiguration()

void faudes::xDevice::DoWriteConfiguration ( TokenWriter rTw,
const std::string &  rLabel = "",
const Type pContext = 0 
) const
protectedvirtual

Write the device patrameters to a TokenWriter.

Parameters
rTwReference to TokenWriter
rLabelLabel of section to write
pContextRead context to provide contextual information
Exceptions
Exception
  • IO errors (id 2)

Reimplemented from faudes::vDevice.

Definition at line 365 of file iop_xdevice.cpp.

◆ End() [1/2]

iterator faudes::xDevice::End ( void  )
inlineprotected

Return last Device.

Definition at line 317 of file iop_xdevice.h.

◆ End() [2/2]

Iterator faudes::xDevice::End ( void  ) const
inline

Set Iterator to last device.

Returns
Iterator to last device

Definition at line 122 of file iop_xdevice.h.

◆ FlushOutputs()

void faudes::xDevice::FlushOutputs ( void  )
virtual

Flush any pending IO Operations.

Pass on flush output buffers to participating devices.

Reimplemented from faudes::vDevice.

Definition at line 461 of file iop_xdevice.cpp.

◆ FromFile()

xDevice * faudes::xDevice::FromFile ( const std::string &  rFileName)
static

Construct on heap from file.

This constructor examines the file, determines the coressponding class and constructs the device on the heap.

Parameters
rFileNameFilename
Returns
vDevice pointer
Exceptions
Exception
  • token mismatch (id 552)
  • IO errors (id 1)

Definition at line 101 of file iop_xdevice.cpp.

◆ FromTokenReader()

xDevice * faudes::xDevice::FromTokenReader ( TokenReader rTr)
static

Construct on heap from token reader.

This constructor examines the token strean, determines the coressponding class and constructs the device on the heap. Todo: the implementation of this function is a hack, there must be proper solution to this issue.

Parameters
rTrTokenReader to read from
Returns
vDevice pointer
Exceptions
Exception
  • token mismatch (id 552)
  • IO errors (id 1)

Definition at line 90 of file iop_xdevice.cpp.

◆ Insert() [1/2]

void faudes::xDevice::Insert ( const std::string &  rFileName)

Insert a new device by Filename.

An xDevice is configured by inserting vDevices. An xDevice cannot be configured by individual output/sensro events.

Note: by inserting a device into an xdevice its ownership will be assumed by the xdevice and therewith the right to destoy

For information on how to write such a file see the "iodevice" - tutorial

Parameters
rFileNameConfiguration-file to build up device

Definition at line 234 of file iop_xdevice.cpp.

◆ Insert() [2/2]

void faudes::xDevice::Insert ( vDevice device)

Insert a new device.

An xDevice is configured by inserting vDevices. An xDevice cannot be configured by individual output/sensro events.

Note: by inserting a device into an xdevice its ownership will be assumed by the xdevice and therewith the right to destoy it.

Parameters
devicePointer to vDevice

Definition at line 218 of file iop_xdevice.cpp.

◆ Reset()

void faudes::xDevice::Reset ( void  )
virtual

reset all dynamic state, i.e.

call reset on each device

Reimplemented from faudes::vDevice.

Definition at line 183 of file iop_xdevice.cpp.

◆ ResetRequest()

bool faudes::xDevice::ResetRequest ( void  )
virtual

Test for reset request.

Reimplemented from faudes::vDevice.

Definition at line 393 of file iop_xdevice.cpp.

◆ Size()

Idx faudes::xDevice::Size ( void  ) const
inline

Get number of devices.

Definition at line 128 of file iop_xdevice.h.

◆ Start()

void faudes::xDevice::Start ( void  )
virtual

Activate the devices.

This function enables output execution and input reading.

Exceptions
Exception
  • Not yet configured (id 551)

Reimplemented from faudes::vDevice.

Definition at line 153 of file iop_xdevice.cpp.

◆ Status()

xDevice::DeviceState faudes::xDevice::Status ( void  )
virtual

Get status.

This function returns the current status of the device. In derived classes that use background threads for input reading etc, a device may change its status without notice. Dont forget to reimplement this method with an appropriate mutex.

Reimplemented from faudes::vDevice.

Definition at line 111 of file iop_xdevice.cpp.

◆ Stop()

void faudes::xDevice::Stop ( void  )
virtual

Deactivate the device.

This function disables output execution and input reading.

Reimplemented from faudes::vDevice.

Definition at line 168 of file iop_xdevice.cpp.

◆ WriteOutput()

void faudes::xDevice::WriteOutput ( Idx  output)
virtual

Run output command on relevant device.

Exceptions
Exception
  • unknown output event (id 65)

Implements faudes::vDevice.

Definition at line 451 of file iop_xdevice.cpp.

Member Data Documentation

◆ lastCommandWasStart

bool faudes::xDevice::lastCommandWasStart
protected

Current device state: remember last stop/down command.

Definition at line 332 of file iop_xdevice.h.

◆ mDeviceNames

std::vector<std::string> faudes::xDevice::mDeviceNames
protected

Vector of member-device-names.

Definition at line 323 of file iop_xdevice.h.

◆ mDevices

std::vector<vDevice*> faudes::xDevice::mDevices
protected

Vector of member-devices.

Definition at line 320 of file iop_xdevice.h.

◆ mInputToDevice

std::map<Idx,int> faudes::xDevice::mInputToDevice
protected

Compiled data: Input map to map input idx to device no.

Definition at line 326 of file iop_xdevice.h.

◆ mOutputToDevice

std::map<Idx,int> faudes::xDevice::mOutputToDevice
protected

Compiled data: Output Map to map input idx to device no.

Definition at line 329 of file iop_xdevice.h.


The documentation for this class was generated from the following files:

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen