About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

iop_vdevice.h

Go to the documentation of this file.
00001 /** @file iop_vdevice.h Virtual device for interface definition  */
00002 
00003 /*
00004   FAU Discrete Event Systems Library (libfaudes)
00005 
00006   Copyright (C) 2008, Thomas Moor
00007   Exclusive copyright is granted to Klaus Schmidt
00008 
00009 */
00010 
00011 
00012 
00013 #ifndef FAUDES_VDEVICE_H
00014 #define FAUDES_VDEVICE_H
00015 
00016 #include "corefaudes.h"
00017 #include "tp_include.h"
00018 #include "sp_densityfnct.h"
00019 
00020 // Windows needs this
00021 #include <pthread.h>
00022 
00023 // Debugging: io level
00024 #ifdef FAUDES_DEBUG_IODEVICE
00025 #define FD_DH(message) FAUDES_WRITE_CONSOLE("FAUDES_IODEVICE: " << message)
00026 #else
00027 #define FD_DH(message)
00028 #endif
00029 
00030 
00031 // Debugging: io level
00032 #ifdef FAUDES_DEBUG_IOVERBOSE
00033 #define FD_DHV(message) FAUDES_WRITE_CONSOLE("FAUDES_IODEVICE: " << message)
00034 #else
00035 #define FD_DHV(message)
00036 #endif
00037 
00038 
00039 // Debugging: io performance  
00040 #ifdef FAUDES_DEBUG_IOPERF
00041 #define FD_DHT(message) FAUDES_WRITE_CONSOLE("FAUDES_IOTIMING: " << message)
00042 #else
00043 #define FD_DHT(message)
00044 #endif
00045 
00046 
00047 // Max number of time stamps for performance monitor
00048 #define FAUDES_DEBUG_IOPERF_SAMPLES 10000
00049 
00050 
00051 
00052 namespace faudes {
00053 
00054 
00055 
00056 /**
00057  * Attribute for the configuration of a input or output mapping
00058  *
00059  * The base class for all device event attributes only distinguishes between
00060  * output and input events. The actual attribute is of type AttributeVoid.
00061  * Derived classes are meant to override this type in order to provide the
00062  * defining data for the actual mapping of physical and logical events.
00063  *
00064  */
00065 
00066 class AttributeDeviceEvent : public AttributeVoid {
00067 
00068   FAUDES_TYPE_DECLARATION(Void,AttributeDeviceEvent,AttributeVoid)
00069 
00070     public:
00071 
00072   /** Default constructor (no attributes, aka undefined) */
00073 
00074   AttributeDeviceEvent(void);
00075 
00076   /** Copy constructor */
00077   AttributeDeviceEvent(const AttributeDeviceEvent& rOtherAttr);
00078 
00079   /** Destructor */
00080   virtual ~AttributeDeviceEvent(void);
00081 
00082   /** Clear */
00083   virtual void Clear(void);
00084 
00085   /** Test for default value (undefined) */
00086   virtual bool IsDefault(void) const {return (!mpOutputAttribute &&  !mpInputAttribute); };
00087 
00088   /** Does this attribute define an output mapping? */
00089   bool IsOutput(void) const {return mpOutputAttribute!=0; };
00090 
00091   /** Does this attribute define a input mapping? */
00092   bool IsInput(void) const {return mpInputAttribute!=0; };
00093 
00094   /** Set to default output attribute */
00095   void DefaultOutput(void) {
00096     Clear();
00097     mpOutputAttribute= pOutputPrototype->New();
00098   };
00099 
00100   /** Set to default input attribute */
00101   void DefaultInput(void) {
00102     Clear();
00103     mpInputAttribute= pInputPrototype->New();
00104   };
00105 
00106   /** Set output attribute */
00107   virtual void Output(const AttributeVoid&  rOutputAttribute) {
00108     DefaultOutput();
00109     mpOutputAttribute->Assign(rOutputAttribute);
00110   };
00111 
00112   /** Set input attribute */
00113   virtual void Input(const AttributeVoid&  rInputAttribute) {
00114     DefaultInput();
00115     mpInputAttribute->Assign(rInputAttribute);
00116   };
00117 
00118   /** Read output attribute */
00119   virtual void ReadOutput(TokenReader&  rTr) {
00120     DefaultOutput();
00121     mpOutputAttribute->Read(rTr);
00122   };
00123 
00124   /** Read input attribute */
00125   virtual void ReadInput(TokenReader&  rTr) {
00126     DefaultInput();
00127     mpInputAttribute->Read(rTr);
00128   };
00129 
00130   /**  Get output mapping (return 0 if its not an output) */
00131   const AttributeVoid*  Outputp(void) const {return mpOutputAttribute; };
00132 
00133   /**  Get input mapping (return 0 if its not a input) */
00134   const AttributeVoid*  Inputp(void) const {return mpInputAttribute; };
00135 
00136 
00137 protected:
00138 
00139   /** Output Attribute (use cast in derived classes) */
00140   AttributeVoid* mpOutputAttribute;
00141 
00142   /** Input Attribute (use cast in derived classes) */
00143   AttributeVoid* mpInputAttribute;
00144 
00145   /** Output Prototype (set to nontrivial attribute in derived classes) */
00146   const AttributeVoid* pOutputPrototype;
00147 
00148   /** Input Prototype (set to nontrivial attribute in derived classes) */
00149   const AttributeVoid* pInputPrototype;
00150 
00151   /** Fallback attribute type (initialize on first use static construct)*/
00152   static const AttributeVoid* FallbackAttributep(void);
00153 
00154   /**
00155    * Assignment 
00156    *
00157    * @param rSrcAttr
00158    *   Source to copy from
00159    * @return
00160    *   Ref to this attribute
00161    */
00162   virtual void DoAssign(const AttributeDeviceEvent& rSrcAttr);
00163 
00164 
00165   /**
00166    * Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
00167    *
00168    * If the current token indicates an "Input" or "Output" section, the method reads that
00169    * section. Else it does nothing. Exceptions may only be thrown
00170    * on invalid data within the section. The label argument is ignored.
00171    * The context argument is ignored.
00172    *
00173    * @param rTr
00174    *   TokenReader to read from
00175    * @param rLabel
00176    *   Section to read
00177    * @param pContext
00178    *   Read context to provide contextual information
00179    *
00180    * @exception Exception
00181    *   - IO error (id 1)
00182    */
00183   virtual void DoRead(TokenReader& rTr,const std::string& rLabel="", const Type* pContext=0);
00184 
00185   /**
00186    * Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
00187    *
00188    * Writes all present device event attributes to include the defining data.
00189    * The label argument is ignored, we use hardcoded labels "Input" or "Output".
00190    * The context argument is ignored.
00191    *
00192    * @param rTw
00193    *   TokenWriter to write to
00194    * @param rLabel
00195    *   Section to write
00196    * @param pContext
00197    *   Read context to provide contextual information
00198    *
00199    * @exception Exception
00200    *   - IO error (id 2)
00201    */
00202   virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=0) const;
00203 
00204 
00205 
00206 }; // class AttributeDeviceEvent
00207 
00208 
00209 
00210 /**
00211  * Virtual base class to define the interface for event io.
00212  *
00213  * @section IOPvdeviceA Input and Output event IO
00214  *
00215  * A vDevice provides an virtual interface to execute output events and sense
00216  * input events, ie ReadInput() and WriteOutput(). The latter is prepared to
00217  * be organized as a background thread that accumulates events in an internal fifo buffer.
00218  * Once a input event has been read by the application, the buffer is cleared.
00219  * A device is configured by passing an event set with device event attributes. The virtual
00220  * base class formalls takes void attributes, and uses a dynamic cast to the actual attribute 
00221  * type that is provided by any derived class.
00222  *
00223  * @section IOPvdeviceB Physical Time
00224  *
00225  * The vDevice defines an interface to access the current physical time. The default
00226  * implementation has msec resolution and is based on the system clock. Time may be queried
00227  * in ms by CurrentTimeMs() or in faudes time unis (ftu) by CurrentTime(). Faudes time units
00228  * refer to defining data in eg guards and invariants of timed automata or stochastical
00229  * execution properties. Conversion to physical time is by the factor mTimeScale given in
00230  * msecs per ftu. There is also a default implementation WaitInputs() for timed waiting
00231  * for events based on pthread conditions.
00232  * This requires a derived class to send the according pthread signal. Both, physical
00233  * time and waiting for events, may be overwritten in derived classes.
00234  *
00235  * @section IOPvdeviceC Operating Status
00236  *
00237  * The device may be in one of four operating states Down, StartUp, Up or ShutDown. Once configured
00238  * you may Start() the device. The device will assychonously allocate required resources
00239  * and if successful eventually be in state Up. While the device is Up, you can write
00240  * outputs and read events. You can request the device to release resources by calling
00241  * Stop(). While Up, you may also Reset() the device, to set outputs in passive state,
00242  * to reset physical time to zero and tu flush the input fifo buffer.
00243  *
00244  * @section IOPvdeviceD File IO
00245  *
00246  * The vDevice provides std faudes token io interface via faudes::Type. In addition,
00247  * there is a static constructor FromTokenreader() to construct a vDevice
00248  * object of specific type as indentifiesd by the token section.
00249  * 
00250  * @section Techical Note
00251  *
00252  * The vDevice derived classes implement std faudes type semantics for 
00253  * token IO plus the New() factory function to support type registration required for 
00254  * XML formated files. Assignment and comparison are, however, not implemented.
00255  *
00256  * @ingroup IODevicePlugin
00257  */
00258 
00259 class vDevice : public Type {
00260 
00261 
00262   friend class xDevice;
00263 
00264 
00265  public:
00266 
00267   /** Enum for device stages */
00268   typedef enum { Down, StartUp, Up , ShutDown } DeviceState;
00269 
00270   /**
00271    * Default constructor
00272    */
00273   vDevice(void);
00274 
00275   /**
00276    * Construct on heap from token reader.
00277    *
00278    * This constructor examines the token strean, determines the coressponding
00279    * class and constructs the device on the heap. Todo: the implementation
00280    * of this function is a hack, there must be proper
00281    * solution to this issue.
00282    *
00283    * @param rTr
00284    *   TokenReader to read from
00285    * @return
00286    *  vDevice pointer
00287    *
00288    * @exception Exception
00289    *   - token mismatch (id 552)
00290    *   - IO errors (id 1)
00291    */
00292   static vDevice* FromTokenReader(TokenReader& rTr);
00293 
00294   /**
00295    * Construct on heap from file.
00296    *
00297    * This constructor examines the file, determines the coressponding
00298    * class and constructs the device on the heap.
00299    *
00300    * @param rFileName
00301    *   Filename
00302    * @return
00303    *  vDevice pointer
00304    *
00305    * @exception Exception
00306    *   - token mismatch (id 552)
00307    *   - IO errors (id 1)
00308    */
00309   static vDevice* FromFile(const std::string& rFileName);
00310 
00311 
00312   /**
00313    * Explicit destructor.
00314    */
00315   virtual ~vDevice(void);
00316 
00317 
00318   /**
00319    * Set the device name
00320    *
00321    * @param rName
00322    *   Generator name
00323    */
00324   void Name(const std::string& rName);
00325 
00326   /**
00327    * Get device name
00328    *
00329    * @return
00330    *   Name of generator
00331    */
00332   const std::string& Name(void) const;
00333 
00334 
00335   /**
00336    * Set tolerance for time synchonisation.
00337    *
00338    * @param maxgap
00339    *   Max acceptable amount of time by which the generator may be behind device time.
00340    *
00341    */
00342   void Tolerance(tpTime::Type maxgap) {mMaxSyncGap=maxgap;};
00343 
00344 
00345   /**
00346    * Get tolerance.
00347    *
00348    * @return
00349    *   Max acceptable amount of time by which the generator may be behind device time
00350    *
00351    */
00352   tpTime::Type Tolerance(void) {return mMaxSyncGap;};
00353 
00354 
00355   /**
00356    * Set timescale.
00357    *
00358    * @param scale
00359    *   Conversion factor in msecs/ftu  (faudes time units)
00360    *
00361    */
00362   virtual void TimeScale(unsigned int scale) {mTimeScale=scale; CurrentTime(0); };
00363 
00364 
00365   /**
00366    * Get timescale.
00367    *
00368    * @return
00369    *   Conversion factor in msecs/ftu  (faudes time units)
00370    *
00371    */
00372   virtual int TimeScale(void) {return mTimeScale;};
00373 
00374 
00375   /**
00376    * Clear all configuration.
00377    * This implies Stop().
00378    */
00379   virtual void Clear(void);
00380 
00381   /**
00382    * Insert/edit input or output configuration
00383    *
00384    * For a nontrivial device, a dynamic cast is used to
00385    * access the attribute parameter.
00386    *
00387    * @param event
00388    *   Input or output event by faudes index
00389    * @param attr
00390    *   Configuration attribute
00391    * @exception Exception
00392    *   - unknown event (id 65)
00393    *   - Cannot cast attribute (id 550)
00394    */
00395   virtual void Configure(Idx event, const AttributeDeviceEvent& attr);
00396 
00397   /**
00398    * Configure by alphabet
00399    *
00400    * For a nontrivial device, a dynamic cast is used to
00401    * access atributes of the alphabet parameter.
00402    *
00403    * @param rPhysicalEvents
00404    *   Event set with configuration attributes
00405    * @exception Exception
00406    *   - Cannot cast argument (id 550)
00407    */
00408   virtual void Configure(const EventSet& rPhysicalEvents);
00409 
00410 
00411   /**
00412    * Compile inner data-structures. 
00413    *
00414    * As every derived class may have its own individual inner data-structures to
00415    * set up, it has to reimplement its own Compile()-function if needed.
00416    *
00417    * In the base class Compile() builds up the input- and output event set.
00418    * 
00419    */
00420   virtual void Compile(void);
00421 
00422 
00423   /**
00424    * Get outputs as plain set.
00425    *
00426    * @return
00427    *   Set of all configured outputs
00428    */
00429   virtual const EventSet& Outputs(void) const;
00430 
00431   /**
00432    * Get inputs as plain set.
00433    *
00434    * @return
00435    *   Set of all configured inputs
00436    */
00437   virtual const EventSet& Inputs(void) const;
00438 
00439 
00440   /**
00441    * Reset device. Resets any dynamic state such as edge detection.
00442    * Since the vDevice only provides timing, it only resets the current faudes
00443    * time to zero. A reset does not stop the device.
00444    *
00445    */
00446   virtual void Reset(void);
00447 
00448   /**
00449    * A device may ask for a reset by returning true for ResetRequest(). A well behaved
00450    * simulator application will perform a Reset() and initialise any faudes::Executors,
00451    * and stop the simulation. The device is meant to cancel any pending WaitInputs() 
00452    * or WaitInputsMs() when it requests a reset. The defult implementation returns 
00453    * false;
00454    *
00455    * @return 
00456    *   True, if a reset is requested
00457    *
00458    */
00459   virtual bool ResetRequest(void);
00460 
00461   /**
00462    * Activate the device. This function enables output execution and input reading.
00463    * It will allocate device specific necessary resources eg start a background thread,
00464    * initialise operating system device drivers etc.
00465    *
00466    * @exception Exception
00467    *   - Not yet configured (id 551)
00468    */
00469   virtual void Start(void);
00470 
00471   /**
00472    * Deactivate the device. This function disables output execution and input reading.
00473    * Stop also runs Reset.
00474    *
00475    */
00476   virtual void Stop(void);
00477 
00478   /**
00479    * Get status. This function returns the current status of the device.
00480    * In derived classes that use background threads for input reading etc,
00481    * a device may change its status without notice. Stop runs Reset()
00482    *
00483    */
00484   virtual DeviceState Status(void) { return mState;};
00485 
00486   /**
00487    * Get status as infromal string.
00488    *
00489    */
00490   virtual std::string StatusString(void);
00491 
00492 
00493   /**
00494    * Run output command.
00495    *
00496    * @exception Exception
00497    *   - unknown output event (id 65)
00498    *
00499    */
00500   virtual void WriteOutput(Idx output)=0;
00501 
00502   /**
00503    * Read sensed input events.
00504    * Report the oldest event from the internal input buffer.
00505    * The event is removed from the buffer. The function returns
00506    * 0 if the buffer is empty.
00507    *
00508    */
00509   virtual Idx ReadInput(void);
00510 
00511   /**
00512    * Peek for sensed events.
00513    * Report the oldest input-event from the buffer. However,
00514    * dont remove the event.
00515    *
00516    * @return
00517    *   Input-event index or 0 if no such available.
00518    */
00519   virtual Idx PeekInput(void);
00520 
00521 
00522   /**
00523    * Report whether a input-event is ready
00524    */
00525   virtual bool InputReady(void);
00526 
00527 
00528   /**
00529    * Wait for input trigger.
00530    *
00531    * The default implementation assumes that inputs events are
00532    * notified via the pthread condition signal. The duration to wait
00533    * is specified in faudes time units (ftu) and is converted to a pthraed
00534    * time spec by the scaling factor mTimeScale (ms/ftu).
00535    *
00536    * @return
00537    *   True, if events are available for read.
00538    */
00539   virtual bool WaitInputs(tpTime::Type duration);
00540 
00541   /**
00542    * Wait for input trigger.
00543    *
00544    * Same as WaitInputs, but with the maximum time to wait given in
00545    * msecs.
00546    *
00547    * @return
00548    *   True, if events are available for read.
00549    */
00550   virtual bool WaitInputsMs(long int duration);
00551 
00552 
00553   /**
00554    * Report physical time in ftu.
00555    *
00556    * The time elapsed since the last reset is retunred
00557    * in faudes time units (ftu).
00558    *
00559    * @return
00560    *   Physical time.
00561    */
00562   virtual tpTime::Type CurrentTime(void);
00563 
00564   /**
00565    * Report physical time in ms
00566    *
00567    * The time elapsed since the last reset is returned
00568    * in msecs.
00569    *
00570    * @return
00571    *   Physical time.
00572    */
00573   virtual long int CurrentTimeMs(void);
00574 
00575   /**
00576    * Set physical time in ftu.
00577    * @param now
00578    *   physical time in faudes time units (ftu).
00579    */
00580   virtual void CurrentTime(tpTime::Type now);
00581 
00582 
00583   /**
00584    * Set physical time in ms.
00585    * @param nowms
00586    *   physical time in msec
00587    */
00588   virtual void CurrentTimeMs(long int nowms);
00589 
00590 
00591   /**
00592    * Compute time difference
00593    *
00594    * @return
00595    *   time difference
00596    * @param end
00597    *   end of time measurement
00598    * @param start
00599    *   begin of time measurement
00600    */
00601   static timeval DiffTime(timeval end, timeval start);
00602 
00603   /**
00604    * Compute time sum
00605    *
00606    * @return
00607    *   time sum
00608    * @param start
00609    *   Summand 1
00610    * @param duration
00611    *   Summand 2
00612    */
00613   static timeval SumTime(timeval start, timeval duration);
00614 
00615   /**
00616    * Convert faudes time unit duration to a pthread time spec
00617    *
00618    * Note: this helper function is not static since it refers to
00619    * the parameter mTimeScale.
00620    *
00621    * @return
00622    *  Absolut system-time form now + duration in the future
00623    * @param duration
00624    *  Time in fauDes-time
00625    */
00626   virtual timespec FtuToTimeSpec(tpTime::Type duration);
00627 
00628   /**
00629    * Convert msec duration to pthread timespec
00630    *
00631    * @return
00632    *  Absolut system-time form now + duration in the future
00633    * @param duration
00634    *  Time in msec
00635    */
00636   static timespec MsToTimeSpec(long int duration);
00637 
00638 
00639   /** Tell the device which condition to use for waiting*/
00640   void UseCondition(pthread_mutex_t* wmutex, pthread_cond_t* wcond);
00641 
00642   /** Tell the device which buffer to use for inputs */
00643   void UseBuffer(pthread_mutex_t* bmutex, std::deque<Idx>* bbuffer);
00644 
00645   /** Convenience method */
00646   virtual std::string EStr(Idx ev) {return Inputs().Str(ev);};
00647 
00648   /** Get performance (need compiletime option) */
00649   SampledDensityFunction Performance(void);
00650 
00651   /** Clear performance (need compiletime option) */
00652   void ResetPerformance(void);
00653 
00654   /** Convenience method */
00655   void WritePerformance(void);
00656 
00657   /** 
00658    * Stop all devices.
00659    * This function is intended to be called on ungraceful termination of a
00660    * simulater application. It uses a global variable that tracks all device 
00661    * instances. 
00662    *
00663    */
00664   static void StopAll(void);
00665 
00666  protected:
00667 
00668   /**
00669    * Token output, see Type::Write for public wrappers.
00670    * The vDevice inplements token writing to consist of  DoWritePreface (device name and time scale).
00671    * and DoWriteConfiguration (device specific event attributes). The default label is taken from the 
00672    * member variable mDefaultLabel. Derived classes are meant to set mDefaultLabel in their constructor
00673    * and to reimplement DoWritePreface to add additional data eg cycle time or network address.
00674    * The parameter pContext is ignored and passed on.
00675    *
00676    * @param rTw
00677    *   Reference to TokenWriter
00678    * @param rLabel
00679    *   Label of section to write, defaults to name of set
00680    * @param pContext
00681    *   Write context to provide contextual information
00682    */
00683   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00684 
00685   /**  Writes non-event-configuration data from TokenWriter
00686    *
00687    * This function is part of the non-event-configuration token-output mechanism. The vDevice will write
00688    * its name and the time scale, derived classes are meant to first call the base class method and then
00689    * add additional configuration parameter. 
00690    *
00691    * Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate
00692    * this data-section. Never the less a default-label ("Device") is specified.
00693    *
00694    * @param rTw
00695    *   TokenWriter to write to
00696    * @param rLabel
00697    *   Section to read
00698    * @param pContext
00699    *   Provide contextual information
00700    *
00701    * */
00702   virtual void DoWritePreface(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00703 
00704 
00705   /** Writes event-configuration to TokenWriter
00706    *
00707    * This function is part of the event-configuration token-output mechanism. It writes the device-specific
00708    * event-configuration to provided TokenWriter. It uses the virtual interface of TBaseSet to figure the
00709    * actual attribute type.
00710    *
00711    * Note: the event-configuration will be labeled by "EventConfiguration"
00712    *
00713    * @param rTw
00714    *   TokenWriter to write to
00715    * @param rLabel
00716    *   Section to write
00717    * @param pContext
00718    *   Provide contextual information
00719    *
00720    */
00721   virtual void DoWriteConfiguration(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00722 
00723   /**
00724    * Token input, see Type::DRead for public wrappers.
00725    * The vDevice implkements token input to consist of DoReadPreface (name, time scale etc) and DoReadConfiguration
00726    * (events attributes), followed by Compile (set up internal data structures). The default label is given by
00727    * the member variable mDefaultLabel. Derived classes arte meant to set mDefaultLabel in their constructor and
00728    * to reimplement DoReadPreface to cover additional parameters. The pContext parameter is ignored.
00729    *
00730    * @param rTr
00731    *   Reference to TokenReader
00732    * @param rLabel
00733    *   Label of section to write, defaults to name of set
00734    * @param pContext
00735    *   Write context to provide contextual information
00736    */
00737   virtual void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
00738 
00739   /** Default label for token io */
00740   std::string mDefaultLabel;
00741 
00742   /**  Reads non-event-configuration data from TokenReader
00743    *
00744    * This function is part of the non-event-configuration token-input mechanism and located at the top
00745    * of the class hierarchy. The vDevice will read its name and the time scale, derived classes are meant 
00746    * to first call the base class method and then read add additional configuration parameters. 
00747    *
00748    * Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate
00749    *     this data-section. Never the less a default-label ("Device") is specified.
00750    *
00751    * @param rTr
00752    *   TokenReader to write
00753    * @param rLabel
00754    *   Section to read
00755    * @param pContext
00756    *   Provide contextual information
00757    *
00758    */
00759   virtual void DoReadPreface(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
00760 
00761   /** Reads event-configuration data from TokenReader
00762    *
00763    * This function is part of the token-input mechanism and reads the device-specific event-configuration.
00764    * It uses the virtual interface of TBaseSet to figure the actual attribute type. The section defaults to
00765    * "EventConfiguration".
00766    *
00767    * @param rTr
00768    *   TokenReader to read
00769    * @param rLabel
00770    *   Section to read
00771    * @param pContext
00772    Provide contextual information
00773    * */
00774   virtual void DoReadConfiguration(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
00775 
00776   /** Name */
00777   std::string mName;
00778 
00779   /** Overall event configuration (uses cast for type) */
00780   EventSet* mpConfiguration;
00781 
00782   /** All inputs */
00783   EventSet mInputs;
00784 
00785   /** All outputs */
00786   EventSet mOutputs;
00787 
00788   /** Status: running, starting etc */
00789   DeviceState mState;
00790 
00791   /** Default Wait Condition Mutex */
00792   pthread_mutex_t mWaitMutex;
00793 
00794   /** Default Wait Condition */
00795   pthread_cond_t mWaitCondition;
00796 
00797   /** Actual  Wait Condition Mutex*/
00798   pthread_mutex_t* pWaitMutex;
00799 
00800   /** Actual Wait Condition */
00801   pthread_cond_t* pWaitCondition;
00802 
00803   /** physical timepoint zero  */
00804   timeval mTimeZero;
00805 
00806   /** FauDES-time: scaling factor in ms/ftu */
00807   int mTimeScale;
00808 
00809   /** Toleance for time sync */
00810   tpTime::Type mMaxSyncGap;
00811 
00812   /** Default Fifo buffer for input readings */
00813   std::deque<Idx> mInputBuffer;
00814 
00815   /** Actual Fifo buffer for input readings */
00816   std::deque<Idx>* pInputBuffer;
00817 
00818   /** Default mutex for input buffer (mutexted) */
00819   pthread_mutex_t mBufferMutex;
00820 
00821   /** Actual mutex for input buffer (mutexted) */
00822   pthread_mutex_t* pBufferMutex;
00823 
00824   /** Reset request marker (mutexed) */
00825   bool mResetRequest; 
00826   
00827   /**
00828    * convert duration from fauDES-time units to ms
00829    *
00830    */
00831   virtual long int FtuToMs(tpTime::Type faudes_time);
00832 
00833   /**
00834    * convert duration in ms to faudes-time units
00835    *
00836    */
00837   virtual tpTime::Type MsToFtu(long int real_time);
00838 
00839 
00840 #ifdef FAUDES_DEBUG_IOPERF
00841 
00842   /** Filename for performance log */
00843 #define FAUDES_DEBUG_IOPERF_LOG "tmp_ioperformance.txt"
00844 
00845   /** Structures to store time-samples in */
00846   timeval* mpPerformanceWaitEnter;
00847   timeval* mpPerformanceWaitExit;
00848 
00849   /** Global iterator */
00850   int mPerformanceEndIterator;
00851   int mPerformanceBeginIterator;
00852 
00853 #endif
00854 
00855  private:
00856 
00857   // track all devices (initialize on first use construct)
00858   static std::set<vDevice*>& AllDevices(void);
00859 
00860 }; // end class vDevice
00861 
00862 
00863 
00864 } // namespace faudes
00865 
00866 
00867 #endif
00868 

libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen