libFAUDES
Sections
Index
|
iop_xdevice.hGo to the documentation of this file.00001 /** @file iop_xdevice.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_XDEVICE_H 00014 #define FAUDES_XDEVICE_H 00015 00016 #include "corefaudes.h" 00017 #include "tp_include.h" 00018 #include "iop_vdevice.h" 00019 00020 00021 00022 00023 00024 namespace faudes { 00025 00026 00027 00028 00029 /** 00030 * Container of devices. 00031 * 00032 * The xDevices is a container of vDevices. Input readings are 00033 * combined in a union fashion over all participating devices, 00034 * output writings are dispatched to the relevant device. Formally, 00035 * the xDevice class is derived from the vDevice class to provide the 00036 * same interaface to a simulator. Ie, the application does not 00037 * need to know whether is acts on a single vDevice or an xDevice. This 00038 * is also true for configuration from file, but of cause not for programatical 00039 * configuration. An xDevice may not be configureb to have individual 00040 * outputs or inputs, but to hold particular vDevices. 00041 * 00042 * Technical detail: the xDevice uses the vDevice interface to register a 00043 * common event fifo buffer and a pthread condition. Thus, the xDevice only works 00044 * with devices that support this configuration feature. 00045 * 00046 * @ingroup IODevicePlugin 00047 */ 00048 00049 class xDevice : public vDevice { 00050 00051 FAUDES_TYPE_DECLARATION(DeviceContainer,xDevice,vDevice) 00052 00053 00054 public: 00055 00056 00057 /** Iterator for const access to individual devices*/ 00058 typedef std::vector<vDevice*>::const_iterator Iterator; 00059 00060 00061 /** 00062 * Default constructor 00063 */ 00064 xDevice(void); 00065 00066 /** 00067 * Construct on heap from token reader. 00068 * 00069 * This constructor examines the token strean, determines the coressponding 00070 * class and constructs the device on the heap. Todo: the implementation 00071 * of this function is a hack, there must be proper 00072 * solution to this issue. 00073 * 00074 * @param rTr 00075 * TokenReader to read from 00076 * @return 00077 * vDevice pointer 00078 * 00079 * @exception Exception 00080 * - token mismatch (id 552) 00081 * - IO errors (id 1) 00082 */ 00083 static xDevice* FromTokenReader(TokenReader& rTr); 00084 00085 /** 00086 * Construct on heap from file. 00087 * 00088 * This constructor examines the file, determines the coressponding 00089 * class and constructs the device on the heap. 00090 * 00091 * @param rFileName 00092 * Filename 00093 * @return 00094 * vDevice pointer 00095 * 00096 * @exception Exception 00097 * - token mismatch (id 552) 00098 * - IO errors (id 1) 00099 */ 00100 static xDevice* FromFile(const std::string& rFileName); 00101 00102 /** 00103 * Explicit destructor. 00104 */ 00105 virtual ~xDevice(void); 00106 00107 00108 /** 00109 * Set Iterator to first device 00110 * 00111 * @return 00112 * Iterator to first device 00113 */ 00114 Iterator Begin(void) const { return mDevices.begin() ; }; 00115 00116 /** 00117 * Set Iterator to last device 00118 * 00119 * @return 00120 * Iterator to last device 00121 */ 00122 Iterator End(void) const { return mDevices.end() ; }; 00123 00124 /** 00125 * 00126 * Get number of devices 00127 */ 00128 Idx Size(void) const { return mDevices.size(); }; 00129 00130 00131 /** 00132 * Insert a new device. 00133 * An xDevice is configured by inserting vDevices. An xDevice cannot be 00134 * configured by individual output/sensro events. 00135 * 00136 * Note: by inserting a device into an xdevice its ownership 00137 * will be assumed by the xdevice and therewith the right to destoy 00138 * it. 00139 * 00140 * @param device 00141 * Pointer to vDevice 00142 */ 00143 void Insert(vDevice* device); 00144 00145 /** 00146 * Insert a new device by Filename 00147 * 00148 * An xDevice is configured by inserting vDevices. An xDevice cannot be 00149 * configured by individual output/sensro events. 00150 * 00151 * Note: by inserting a device into an xdevice its ownership 00152 * will be assumed by the xdevice and therewith the right to destoy 00153 * 00154 * For information on how to write such a file see the "iodevice" - tutorial 00155 * 00156 * @param rFileName 00157 * Configuration-file to build up device 00158 */ 00159 00160 void Insert(const std::string& rFileName); 00161 00162 00163 00164 /** 00165 * Dummy. An xDevice does not provide event based configuration. Use Insert instead. This function 00166 * will throw an execption 00167 */ 00168 void Configure(Idx event, const AttributeDeviceEvent& attr); 00169 00170 /** 00171 * An xDevice does not provide event based configuration. Use Insert instead. 00172 * This function will throw an execption 00173 */ 00174 void Configure(const EventSet& rEvents); 00175 00176 /** 00177 * 00178 * Build up internal data structures. I.e. (event-idx,int) - map 00179 */ 00180 void Compile(void) ; 00181 00182 00183 /** 00184 * Clear all configuarations and destroy existing devices 00185 * 00186 */ 00187 void Clear(void); 00188 00189 00190 /** reset all dynamic state, iw call reset on each device */ 00191 void Reset(void); 00192 00193 /** Test for reset request */ 00194 bool ResetRequest(void); 00195 00196 /** 00197 * Activate the devices. xxx This function enables output execution and input reading. 00198 * 00199 * @exception Exception 00200 * - Not yet configured (id 551) 00201 */ 00202 void Start(void); 00203 00204 /** 00205 * Deactivate the device. This function disables output execution and input reading. 00206 * 00207 */ 00208 void Stop(void); 00209 00210 /** 00211 * Get status. This function returns the current status of the device. 00212 * In derived classes that use background threads for input reading etc, 00213 * a device may change its status without notice. Dont forget to reimplement 00214 * this method with an appropriate mutex. 00215 * 00216 */ 00217 DeviceState Status(void); 00218 00219 /** 00220 * Run output command. 00221 * 00222 * @exception Exception 00223 * - unknown output event (id 65) 00224 * 00225 */ 00226 void WriteOutput(Idx output); 00227 00228 /** 00229 * Report global fauDES-time 00230 * Note: per convention we take the time of the first 00231 * device inserted in xDevice as global time 00232 * 00233 * @return 00234 * fauDES-time 00235 */ 00236 tpTime::Type CurrentTime(void); 00237 00238 /** 00239 * Report global fauDES-time 00240 * Note: per convention we take the time of the first 00241 * device inserted in xDevice as global time 00242 * 00243 * @return 00244 * fauDES-time 00245 */ 00246 long int CurrentTimeMs(void); 00247 00248 /** 00249 * Set physical time in ftu. 00250 * 00251 * @param now 00252 * now in faudes time units (ftu). 00253 */ 00254 virtual void CurrentTime(tpTime::Type now); 00255 00256 /** 00257 * Set physical time in ms. 00258 * 00259 * @param nowms 00260 * now in msec 00261 */ 00262 virtual void CurrentTimeMs(long int nowms); 00263 00264 00265 00266 protected: 00267 00268 // internal iterator type 00269 typedef std::vector<vDevice*>::iterator iterator; 00270 00271 00272 /** 00273 * Actual method to read device configuration from tokenreader. 00274 * 00275 * DoRead basically calls the DoWrite-function of all devices which are part of xDevice 00276 * 00277 * @param rTr 00278 * TokenReader to read from 00279 * @param rLabel 00280 * Section to read 00281 * @param pContext 00282 * Read context to provide contextual information 00283 * 00284 * @exception Exception 00285 * - IO error (id 1) 00286 */ 00287 virtual void DoReadConfiguration(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00288 00289 /** 00290 * Write the device patrameters to a TokenWriter. 00291 * 00292 * 00293 * @param rTw 00294 * Reference to TokenWriter 00295 * @param rLabel 00296 * Label of section to write 00297 * @param pContext 00298 * Read context to provide contextual information 00299 * @exception Exception 00300 * - IO errors (id 2) 00301 */ 00302 virtual void DoWriteConfiguration(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const; 00303 00304 /** Return first Device */ 00305 iterator Begin(void) { return mDevices.begin() ; }; 00306 00307 /** Return last Device */ 00308 iterator End(void) { return mDevices.end() ; }; 00309 00310 /** Vector of member-devices */ 00311 std::vector<vDevice*> mDevices; 00312 00313 /** Vector of member-device-names*/ 00314 std::vector<std::string> mDeviceNames; 00315 00316 /** Compiled data: Input map to map input idx to device no */ 00317 std::map<Idx,int> mInputToDevice; 00318 00319 /** Compiled data: Output Map to map input idx to device no */ 00320 std::map<Idx,int> mOutputToDevice; 00321 00322 /** Current device state: remember last stop/down command */ 00323 bool lastCommandWasStart; 00324 00325 00326 }; 00327 00328 00329 00330 } 00331 00332 00333 #endif 00334 |
libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen