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

libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen