#include <basicdevice.h>
Inheritance diagram for simth::Device:
Public Member Functions | |
Device (int deviceID, DeviceSystemIntf *system, const PropertyList &pl) | |
virtual | ~Device () |
Device information | |
virtual int | ID () const |
template<class T> | |
const T & | getProperty (const std::string &name) const |
bool | hasProperty (const std::string &name) const |
bool | propertyIsSet (const std::string &name) const |
virtual void | print (std::ostream &os) const |
Simulation setup and end | |
void | connect (int fromInterfaceID, Device *toDev, int toInterfaceID) |
void | connectControlInterface (int interfaceNr, const std::string &globalName) |
InputInterface *const | acceptConnection (int interfaceID) |
virtual void | startOfSimulation () |
virtual void | endOfSimulation () |
Running the simulation | |
virtual void | refresh () |
void | invokeProcess () |
virtual void | process ()=0 |
virtual void | acceptNewData (int interfaceID) |
void | resetDevice () |
void | resetInterfaces () |
virtual void | reset () |
Input sequence length | |
void | setInputLength (size_t newLength, int interfaceID, bool enableUpdate=true) |
void | setInputLength (size_t newLength, bool enableUpdate=true) |
size_t | inputLength (int interfaceID) const |
size_t | inputLength () const |
bool | isInputLengthUndefined (int interfaceID) const |
Output sequence length | |
void | setOutputLength (size_t newLength, int interfaceID, bool enableUpdate=true) |
void | setOutputLength (size_t newLength, bool enableUpdate=true) |
size_t | outputLength (int interfaceID) const |
size_t | outputLength () const |
bool | isOutputLengthUndefined (int interfaceID) const |
void | reserveOutputLength (size_t newCapacity, int interfaceID) |
void | reserveOutputLength (size_t newCapacity) |
size_t | outputCapacity (int interfaceID) const |
size_t | outputCapacity () const |
Protected Member Functions | |
Protected device information | |
template<class T> | |
void | setProperty (const std::string &name, const T &value) |
DeviceSystemIntf * | systemPtr () |
Input interfaces and sequences | |
template<class T> | |
size_t | insertInputInterface (int number=1, const typename T::value_type &default_val=typename T::value_type()) |
virtual InputInterface * | inputInterface (int interfaceID) |
virtual const InputInterface * | inputInterface (int interfaceID) const |
bool | isInputInterface (int interfaceID) const |
bool | isInputInterfaceConnected (int interfaceID) const |
bool | isInputSequence (int interfaceID) const |
template<class T> | |
T * | getInputSequence (int interfaceID) |
Output interfaces and sequences | |
template<class T> | |
size_t | insertOutputInterface (int number=1) |
virtual OutputInterface * | outputInterface (int interfaceID) |
virtual const OutputInterface * | outputInterface (int interfaceID) const |
bool | isOutputInterface (int interfaceID) const |
bool | isOutputInterfaceConnected (int interfaceID) const |
template<class T> | |
T * | getOutputSequence (int interfaceID) |
Sequence length update | |
virtual void | updateInputLengths ()=0 |
virtual void | updateOutputLengths ()=0 |
End of processing | |
void | flushProcessedSequences () |
void | flushProcessedInputSequences () |
void | flushProcessedOutputSequences () |
void | flushProcessedInputSequence (int interface) |
void | flushProcessedOutputSequence (int interface) |
void | releaseProcessedInputSequence (int interface) |
Control interface | |
template<class D> | |
size_t | insertControlInterface (D *dev, void(D::*helpFuncPtr)()) |
template<class T, class D> | |
size_t | insertControlInterface (D *dev, void(D::*helpFuncPtr)(T)) |
template<class D> | |
size_t | insertAndConnectControlInterface (D *dev, void(D::*helpFuncPtr)(), const std::string &globalName) |
template<class T, class D> | |
size_t | insertAndConnectControlInterface (D *dev, void(D::*helpFuncPtr)(T), const std::string &globalName) |
bool | isControlInterface (int interfaceID) const |
virtual ControlInterface * | controlInterface (int interfaceNr) |
Signal handling | |
These functions send different signals to the simulation system. | |
void | sendReadyToProcessSignal () |
void | sendStopIterationSignal () |
void | sendStopSimulationPrematureSignal () |
Stop watch | |
void | startStopWatch () |
void | stopStopWatch () |
Friends | |
class | CompatibleDevice |
This class is the base class for all devices (blocks) that are used in a FreeConnectionSystem.
The configuration of each Device for a concrete simulation is done through a list of simth::Propertys. These lists of Properties are created from the devicelist XML files (not from the C++ source code!) by means of the simth::DeviceManager class. See also Migration of Parameter files to the XML format
The main functionality of a Device is defined in its function process(). To get the current input data, this function needs to call the function getInputSequence<T>(interfaceID)
where T is the type of the input sequence of that device an interfaceID is the number of the used interface. The sequence types are instantiations of the simth::SignalSequence template classes, e.g. simth::BitSeq or simth::ModSeq.
See also Sequence diagram of Device::Process with output and Sequence diagram of Device::Process with input .
A new or additional interface can be inserted by a constructor of a device by using the function insertInputInterface<T>()
.
New blocks should inheritance this class. The pure virtual functions process(), updateInputLengths() and updateOutputLengths() have to be defined in the derived classes.
|
Constructor with identification number, pointer to the simulation environment and PropertyList of this device. Some (old) devices need a constructor without these arguments. For that old code, the class CompatibleDevice exists. But that class is deprecated! Do not use it for new code; instead, rather try to change the existing code so that devices are directly derived from simth::Device instead through this class. In that old code, you must not forget to call the functions CompatibleDevice::setID(int ID) and CompatibleDevice::setSystemPtr(system* sPtr)! In both cases the pointer to the simulation system is used by the device to send signals to the simulation system. |
|
Virtual destructor of that device. |
|
Set a property to the given value of type T. This will only work if this property already exists (created by addProperty()), otherwise it will throw an error. Also, if the type in the template function does not match the type of this property.
|
|
Returns a pointer to the Simulation-Device interface. |
|
Inserts one or more new input interfaces. The type of the input interfaces' data sequence type is determined by the template argument T. Note: This sequence type needs to have a constructor for explicit reference copies with pointer to the master sequence! This constructor is already implemented in e.g. StdSignalSequence, or llvSeq, or TimeSignalEVC, but *not* (yet) in Sequence. The first inserted interface gets the interfaceID 0, the second the interfaceID 1 and so on. The argument number can be used to insert more interfaces with same time while calling this function just once. However, if input interfaces with different types are needed, this function has to be called several times with different template arguments.
|
|
Returns a pointer to the InputInterface specified by interfaceID. Note that the interfaceID starts by zero. If interfaceID-1 is bigger than the number of input interfaces of the device, an error is thrown. |
|
Returns a pointer to the InputInterface specified by interfaceID. Note that the interfaceID starts by zero. If interfaceID-1 is bigger than the number of input interfaces of the device, an error is thrown. |
|
Returns true if the specified input interface exists. |
|
Returns true if the specified input interface exists and is connected with another interface. |
|
Returns true if the specified input interface exists, is connected and is filled (see also inputInterface::isFilled()) |
|
Returns a pointer to the received input sequence. Additionally, a reference counter for this sequence will be incremented, which will only be decremented when flushProcessedSequences() (or one of its more specialized versions) is called. The sequence type of the input interface's data sequence is determined by the template argument T. If the input buffer contains not enough data (less then the length specified by setInputLenght()) an error will be thrown. You need to check for this condition beforehand by calling isInputSequence(). |
|
Inserts one or more new output interfaces. The type of the output interfaces' data sequence type is determined by the template argument T. The same restrictions apply as for insertInputInterface.
|
|
Returns a pointer to the OutputInterface specified by interfaceID. Note that the interfaceID starts by zero. If interfaceID-1 is bigger than the number of output interfaces of the device, an error is thrown. |
|
Returns a pointer to the OutputInterface specified by interfaceID. Note that the interfaceID starts by zero. If interfaceID-1 is bigger than the number of output interfaces of the device, an error is thrown. |
|
Returns true if the specified interface exists. |
|
Returns true if the specified interface is connected with another interface. |
|
Returns a pointer to the output sequence. This output sequence must be used to store the processed data. Additionally, a reference counter for this sequence will be incremented, which will only be decremented when flushProcessedSequences() (or one of its more specialized versions) is called. The sequence type of the output interface's data sequence is determined by the template argument T. |
|
This method must be implemented by a derived class, and it must compute and update the input lengths of the interfaces and set them by setInputLength(). This method is called either from your own initialization code, or if the method setOutputLength() has been called from the successor device (i. e. setOutputLength() has been called "from the output side"). Also see the sequence diagram at setOutputLength(). If your derived class does not want to allow the computation and update of the input lengths to be set by the method call "from the output side", then you can implement this method as a call of the base class implementation:
That implementation will simply throw an exception. But in any case this method must be implemented. To repeat: The method setOutputLength() will set the new length and then call this updateInputLengths(). The method setInputLength() will set the new length and then call the method updateOutputLengths(). |
|
This method must be implemented by a derived class, and it must compute and update the output lengths of the interfaces and set them by setOutputLength(). This method is called either from your own initialization code, or if the method setInputLength() has been called from the predecessor device (i. e. setInputLength() has been called "from the input side"). Also see the sequence diagram at setInputLength(). If your derived class does not want to allow the computation and update of the output lengths to be set by the method call "from the input side", then you can implement this method as a call of the base class implementation:
That implementation will simply throw an exception. But in any case this method must be implemented. To repeat: The method setInputLength() will set the new length and then call this updateOutputLengths(). The method setOutputLength() will set the new length and then call the method updateInputLengths(). |
|
Flushes all input and output sequences, i.e. all reference counters will be decremented and released again. WATCH OUT: This will decrement the reference counters of *all* sequences regardless of whether you actually referenced them by getInputSequence and getOutputSequence! If you intend to use only some sequences but not others, you *have* to use the specialized flushProcessedInputSequence(nr) and flushProcessedOutputSequence(nr) instead of this function! One way to look at this is that this function will signal from your Device to the simulation system: "The sequences retrieved by getInputSequence and getOutputSequence have been processed now." This function is the counter-part to getInputSequence() and getOutputSequence(). This function must be called in the function process() after input and output sequences have been retrieved by getInputSequence() and getOutputSequence(), respectivley.
|
|
Flushes all input sequences, i.e. all reference counters will be decremented and released again. In contrast to flushProcessedSequences, this function only works on all input sequences. WATCH OUT: This will decrement the reference counters of *all* sequences regardless of whether you actually referenced them by getInputSequence! If you intend to use only some sequences but not others, you *have* to use the specialized flushProcessedInputSequence(nr) instead of this function! This function is the counter-part to getInputSequence(). This function must be called in the function process() after input sequences have been retrieved by getInputSequence().
|
|
Flushes all output sequences, i.e. all reference counters will be decremented and released again. In contrast to flushProcessedSequences, this function only works on all output sequences. WATCH OUT: This will decrement the reference counters of *all* sequences regardless of whether you actually referenced them by getOutputSequence! If you intend to use only some sequences but not others, you *have* to use the specialized and flushProcessedOutputSequence(nr) instead of this function! This function is the counter-part to getOutputSequence(). This function must be called in the function process() after output sequences have been retrieved by getOutputSequence().
|
|
Flushes one specific input sequence, i.e. all reference counters will be decremented and released again. In contrast to flushProcessedSequences, this function only works on one specific input sequence. This function is the counter-part to getInputSequence(). This function must be called in the function process() after input sequences have been retrieved by getInputSequence().
|
|
Flushes one specific output sequence, i.e. all reference counters will be decremented and released again. In contrast to flushProcessedSequences, this function only works on one specific output sequence. This function is the counter-part to getOutputSequence(). This function must be called in the function process() after output sequences have been retrieved by getOutputSequence().
|
|
"Releases" one specific input sequence, i.e. the reference counters will be decremented and released again. In contrast to any of the flush functions, this function is meant for the case when none of the data has been processed this time, but the data should still be left in the input interface for next time. This function is the counter-part to getInputSequence(). Unlike the function flushProcessedInputSequence(), the data is kept in the input interface.
|
|
Inserts a new ControlInterface. The ControlInterface wrapps a member function of the device that takes no argument. With connectControlInterface() the controlInterface is connected to a loop variable of the FreeConnectionSystem. Each time the loop variable enters a new iteration the wrap function is called by the control interface.
|
|
Inserts a new ControlInterface. A ControlInterface wrapps a member function of the device that takes one argument. With connectControlInterface() the controlInterface is connected to a loop variable of the FreeConnectionSystem. Each time the loop variable enters a new iteration the wrap function is called by the control interface. The template argument T determines the argument type of the function.
|
|
Inserts a new ControlInterface and connect it once with a loop variable of the FreeConnectionSystem. See insertControlInterface() and connectControlInterface() for more explanation.
|
|
Inserts a new ControlInterface and connect it once with a loop variable of the FreeConnectionSystem. The template argument T determines the argument type of the function. See insertControlInterface() and connectControlInterface() for more explanation.
|
|
Returns true if the specified control interface exists. |
|
Returns a pointer to the specified control interface. |
|
I am ready to process!
|
|
Stop this iteration, start next iteration (see loop_variables). |
|
Stop this iteration and finish the simulation. |
|
This function starts the stop watch. This can be used to time the simulation run of this device. |
|
This function stops the stop watch. This can be used to time the simulation run of this device. |
|
Returns the ID of the device. The ID is an unique integer value that addresses this devices in the FreeConnectionSystem. |
|
Returns the value of the specified property, of type T. Throws an error if the property doesn't exist, or if the type in the template function does not match the type of this property.
|
|
Returns true when a property with the specified name exists.
|
|
Returns true when a property with the specified name has been set to some value. Returns false if that property is still set to its default value. Throws an error if the property doesn't exist.
|
|
This function prints its device information (e.g. type of device, parameter, ...) to the ostream passed as argument. |
|
The function connects the specified OutputInterface of this device with the specified InputInterface of the device pointed to by toDev.
|
|
The function connects an already existing ControlInterface of this device with a loop variable of the FreeConnectionSystem.
|
|
The function signalizes the device (FIXME: what does this mean?), that its input interface with the number interfaceID is connected with another device. If the connection is possible, the function returns a pointer to the input interface, otherwise the function throws a connection_error exception. |
|
This function can be overriden by a derived class to do something when the simulation is going to be started, e.g. write a parameter to the system wide parameter list using the function FreeConnectionSystem::writeParameter(). (Note for this example, devices that takes a pointer to the system in its constructor argument list can do this in its constructor and doesn't need this function for that example. But the class CompatibleDevices does not take a pointer to the system and hence it needs this function to write at the beginning of a simulation run to the system.)
|
|
This function can be overriden by a derived class to do something after the simulation has been finished and before the destructor can do this, e.g. write stored error information to a file before displaying the results. |
|
A derived device can overwrite this function to do some specific refresh actions, otherwise nothing is happens when the function is called. In a StreamDrivenSystem this function is called by the system when the device has sent a refresh signal to the system. |
|
The function calls the procedure startProcess(), then the main functionality function process() (see below) and finally the function stopProcess(). Basically this function only calls the virtual function process() and nothing else happens here.
|
|
This pure virtual function has to be overwritten by derived devices. It is called by the function invokeProcess(). In a StreamDrivenSystem invokeProcess() is called when the interfaces contain enough data for processing. Then the function get data from the input interfaces (use getInputSequence(interfaceID)), process this data and put the result to the output interfaces (use getOutputSequence(interfaceID)). This is repeated until the device contains not enough data to proceed processing.
|
|
Tells the devices to accept new data at the specified input interface. The standard implementation will check whether the stored input data of all input interfaces exceeds the input length set by setInputLength(), and if it does, it will call sendReadyToProcessSignal() to the FreeConnectionSystem to let this device be queued for process().
|
|
Resets the device by calling resetInterfaces() and reset(). In the StreamDrivenSimulationSystem this fucntion is called at the beginning of each iteration step. Do *NOT* override this function in derived classes since it is not declared as virtual function. The virtual function reset() that will be called by this function can be used in derived classes to specify some specific actions.
|
|
Flushes the sequences stored in the interfaces. |
|
This function is called by resetDevice(). It will be called in all devices at each innermost iteration step, right before Device::process() of the first device will be called to start a new iteration step. A derived class can overwrite this function to do some device specific reset actions. In a StreamDrivenSystem resetDevice() (and within reset()) is called at the beginning of each new iteration step, i.e. when a loop variable is set to a new value. The implementation in this class does nothing, i.e. the definition body of reset() is empty.
|
|
Sets the sequence length of the specified input interface and calls updateOutputLengths() if (and only if) the new length differs from the current sequence length of that interface and 'enableUpdate' equals true.
|
|
Sets the sequence length of all input interfaces and calls updateOutputLengths() if (and only if) the new length differs from the current sequence length of at least one input interface and 'enableUpdate' equals true.
|
|
Returns the sequence length of the specified input interface.
|
|
Returns the sequence length of the input interfaces. The sequence lengths of all input interfaces have to be equal. Otherwise an error is thrown.
|
|
Returns true if the sequence length of the specified input interface is undefined. |
|
Sets the sequence length of the specified output interface and calls updateInputLengths() if (and only if) the new length differs from the current sequence length of that interface. and 'enableUpdate' equals true.
|
|
Sets the sequence length of all output interfaces and calls updateInputLengths() if (and only if) the new length differs from the current sequence length of at least one output interface.
|
|
Returns the sequence length of the specified output interface.
|
|
Returns the sequence length of the output interfaces. The sequence lengths of all output interfaces have to be equal. Otherwise an error is thrown.
|
|
Returns true if the sequence length of the specified output interface is undefined. |
|
Sets the sequence capacity of the specified output interface (see The C++ Programming Language, S. 485 for explanation of the capacity of a vector). This could be useful, if a device needs for example an output length of 100, but for internal computation the length growth intermediate to 102. In this case the capacity should had been set to 102. This enables resizing the sequence intermediate to 102 - avoid an extra buffer - and resize it finally to the output length of 100. Note, if the new capacity is smaller than the output length this function has no effect.
|
|
Sets the sequence capacity of each output interface (see The C++ Programming Language, S. 485 for explanation of the capacity of a vector). This could be useful, if a device needs for example an output length of 100, but for internal computation the length growth intermediate to 102. In this case the capacity should had been set to 102. This enables resizing the sequence intermediate to 102 - avoid an extra buffer - and resize it finally to the output length of 100. Note, if the new capacity is smaller than the output length this function has no effect.
|
|
Returns the capacity of the specified output interface. (see The C++ Programming Language, S. 485 for explanation of the capacity of a vector)
|
|
Returns the capacity of the output interfaces. The cpacity of all input interfaces have to be equal. Otherwise an error is thrown. (see The C++ Programming Language, S. 485 for explanation of the capacity of a vector) |
|
|