LRAUV  revA
Slate.h
Go to the documentation of this file.
1 
17 #ifndef SLATE_H_
18 #define SLATE_H_
19 
20 #include "component/Component.h"
21 #include "data/DataAccess.h"
22 #include "data/DataAccessor.h"
23 #include "data/DataValue.h"
24 #include "data/ElementURI.h"
25 #include "data/SimpleDataElement.h"
26 #include "data/UniversalURI.h"
27 #include "logger/Logger.h"
28 #include "utils/Mutex.h"
29 #include "utils/Str.h"
30 
31 #ifdef ERROR // A workaround for wingdi.h
32 #undef ERROR
33 #endif
34 
35 class DataReader;
36 class DataValue;
37 class DataWriter;
38 class InStream;
39 class LogWriter;
40 class SimpleDataElement;
43 
44 template<typename S, typename T> class FastMap;
45 
49 
54 
55 template<typename T> class FlexArray;
56 
64 
73 class Slate
74 {
75 public:
76 
78  static void Construct();
79 
81  static DataAccess* GetDataAccess( const unsigned short& code );
82 
85  static DataAccess* GetDataAccess( const DataAccessor& dataAccessor, UniversalDataElement* universal = NULL );
86 
88  static unsigned short GetDataAccessCount()
89  {
90  return NextDataAccessCode_;
91  }
92 
94  static DataAccess* RegisterDataAccess( DataAccess* dataAccess );
95 
97  static DataElement* GetElement( const unsigned short& uriCode );
98 
100  static DataElement* GetElement( const ElementURI& elementURI );
101 
103  static ElementURI* GetElementURI( const unsigned short& code );
104 
106  static ElementURI* GetElementURI( const ElementURI& elementURI );
107 
109  static unsigned int GetElementURICount();
110 
113  static void CodifyElementURI( ElementURI& elementURI );
114 
116  static ElementURI* RegisterElementURI( ElementURI* elementURI );
117 
119  static void DeRegisterElementURI( ElementURI* elementURI );
120 
123  static ElementURI* FindElementURI( const Str& str );
124 
127  static unsigned short GetElementURICode( const char* chars );
128 
130  static CodedStr* GetName( const unsigned short& code );
131 
134  static CodedStr* FindCodedName( const Str& name );
135 
138  static CodedStr& GetCodedName( const Str& name );
139 
141  static void MapDataElement( ElementURI* elementURI, DataElement* dataElement );
142 
144  static CodedStr* RegisterCodedName( CodedStr* name );
145 
149  static DataReader* NewInputReader( const Str& uriPart,
150  Component* owner, const DataValue* defaultValue, bool deleteDefaultValue = true );
151  static DataReader* NewInputReader( const ElementURI &elementURI,
152  Component* owner, const DataValue* defaultValue, bool deleteDefaultValue = true );
153 
154  // Creates a writer for this component's output (and a dataElement)
155  static DataWriter* NewOutputWriter( const Str& uriPart,
156  Component* owner,
157  DataValue* initialValue );
158  static DataWriter* NewOutputWriter( const ElementURI &elementURI,
159  Component* owner,
160  DataValue* initialValue );
161 
162  // Creates a reader for some other component's declared output
163  static DataReader* NewReader( const Str &componentName, const Str& uriPart,
164  Component* owner, const DataValue* defaultValue, bool deleteDefaultValue = true ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newDataReader with DataURI arg instead.") ));
165  static DataReader* NewReader( const ElementURI &elementURI,
166  Component* owner, const DataValue* defaultValue, bool deleteDefaultValue = true ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newDataReader with DataURI arg instead.") ));
167 
168  // Creates a reader for any universal outputs
169  // Also creates a UniversalDataElement if a suitable one does not exist
170  static UniversalDataReader* NewUniversalReader( const UniversalURI &universalURI,
171  Component* owner, const DataValue* defaultValue, bool deleteDefaultValue = true ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newUniversalReader with UniversalURI arg instead.") ));
172 
173  // Creates a writer for this component's universal output (and a dataElement)
174  // Also creates a UniversalDataElement if a suitable one does not exist
175  static UniversalDataWriter* NewUniversalWriter( const UniversalURI &universalURI,
176  Component* owner, DataValue* initialValue,
177  const float accuracy = DataElement::NO_ACCURACY ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newUniversalWriter with UniversalURI arg instead.") ));
178 
179  // Creates a writer for some other component's declared input
180  static DataWriter* NewWriter( const Str &componentName, const Str& uriPart,
181  Component* owner ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newDataWriter with DataURI arg instead.") ));
182  static DataWriter* NewWriter( const ElementURI &elementURI,
183  Component* owner ); // TODO: __attribute__( ( deprecated ) ); // ("Use Component::newDataWriter with DataURI arg instead.") ));
184 
185  static DataElement* NewDataElement( const ElementURI &elementURI,
186  Component* owner,
187  const Unit& unit, BinaryDataType binaryType,
188  const float accuracy = DataElement::NO_ACCURACY );
189 
190  static UniversalDataElement *NewUniversalElement( const UniversalURI &universalURI,
191  Component* owner, const Unit& unit, BinaryDataType binaryType );
192 
193 
199  template<typename T>
200  inline static bool ReadOnce( const Str& componentName, const Str& uriPart,
201  const Unit& unit, T& readTo, Logger& logger,
203  {
204  return ReadOnce( ElementURI( componentName, uriPart ), unit, readTo,
205  logger, severity );
206  }
207  template<typename T> static bool ReadOnce( const ElementURI& elementURI,
208  const Unit& unit, T& readTo, Logger& logger,
209  Syslog::Severity severity = Syslog::CRITICAL );
210 
211  inline static bool ReadOnce( const Str& componentName, const Str& uriPart,
212  DataValue& readTo, Logger& logger, Syslog::Severity severity =
214  {
215  return ReadOnce( ElementURI( componentName, uriPart ), readTo, logger,
216  severity );
217  }
218 
219  static bool ReadOnce( const ElementURI& elementURI, DataValue& readTo,
220  Logger& logger, Syslog::Severity severity = Syslog::CRITICAL );
221  template<typename T> static bool ReadOnce( const unsigned short & uriCode,
222  const Unit& unit, T& readTo, Logger& logger,
223  Syslog::Severity severity = Syslog::CRITICAL );
229  template<typename T> static bool WriteOnce( const Str& uriPart,
230  Component* owner, const Unit& unit, const T& writeThis );
231  static bool WriteOnce( const Str& uriPart, Component* owner,
232  const DataValue& writeThis );
233  template<typename T> static bool WriteOnce( const unsigned short & uriCode,
234  Component* actor, const Unit& unit, const T& writeThis );
235  static bool WriteOnce( const unsigned short & uriCode, Component* actor,
236  const DataValue& writeThis );
237  // Called during initialization, to build up slate table entries based on
238  // previous outputs -- allowing continious logging across multiple
239  // runs and re-initialization of dataValues.
240  static void ReadDirectory( const Str& dirFilename );
241  // Called only by unserialize, to allow multiple directory scans.
242  static void ClearDirectory();
243 
244  static bool IsDirectoryRead()
245  {
246  return DirectoryRead_;
247  }
248 
249  // Enables logging of directory entries.
250  // Not called by unseriailize, for example.
251  static void EnableDirectoryWrites();
252  // Called by Unit Tests.
253  static void SimulateDirectoryWrites();
254  // Called by DirectoryWriter to log all the directory entries
255  static void WriteDirectory( LogWriter* rewriteTo = NULL, bool forceLog =
256  false );
257  static const unsigned short NO_LOG_FORMAT = 0x0000;
258 
259 private:
262  {
263  }
264 
265  ;
266  static DataElement* NewDataElement( const ElementURI& elementURI,
267  Component* owner, DataValue* initialValue, float accuracy =
270  const UniversalURI& universalURI, Component* owner,
271  const DataValue* testValue );
276  static bool ReadHeader( InStream& inStream );
278  static void WriteDataAccessEntry( DataAccess* dataAccess,
279  LogWriter* rewriteTo = NULL, bool forceWrite = false );
280  static void WriteElementURIEntry( ElementURI* elementURI,
281  LogWriter* rewriteTo = NULL, bool forceWrite = false );
282  static void WriteNameEntry( CodedStr* codeName, LogWriter* rewriteTo = NULL,
283  bool forceWrite = false );
286  static unsigned short NextDataAccessCode_;
287  static unsigned short NextElementURICode_;
288  static unsigned short NextNameCode_;
289  static bool DirectoryRead_;
290  static Logger* Logger_;
295  static NameMap* NameMap_;
300  static int ElementURICount_;
303  static Mutex DataAccessMutex_; // Makes DataAccess read/writes calls thread-sage
304  static Mutex ElementMutex_; // Makes ElementURI read/writes thread sage
308  {
309  public:
310  virtual ~StaticDestructor();
311  };
314 
315  static void ConfigureNewDataElement( Component* owner, const ElementURI& elementURI,
316  DataElement*& dataElement );
317 
319  friend class Supervisor;
320  friend class Unserialize;
321 
322  static void Uninitialize();
323 
324 };
325 
326 #endif /*SLATE_H_*/
Client-side interface for injecting log data into the log queue.
Definition: Logger.h:30
static bool WriteOnce(const Str &uriPart, Component *owner, const Unit &unit, const T &writeThis)
If the value is only going to be written once, it's probably not worth providing a DataWriter...
Definition: Slate.cpp:739
FlexArray< CodedStr * > NameArray
Definition: Slate.h:62
Simple class for providing key-pointer mappings.
Definition: Slate.h:44
Serializable representation of DataAccessor object.
Definition: DataAccess.h:30
FastMap< const ElementURI, UniversalDataElement * > UniversalMap
Definition: Slate.h:48
FastMap< const Str, ElementURI * > ElementURIMap
Definition: Slate.h:52
BinaryDataType
These are binary type identifiers for serializing and unserializing The syntax below handles up to 16...
Definition: BinaryDataType.h:39
static bool IsDirectoryRead()
Definition: Slate.h:244
static Mutex ElementMutex_
Definition: Slate.h:304
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: UniversalDataReader.h:26
Definition: Syslog.h:33
Implementation of a DataElement as a "UniversalDataElement".
Definition: UniversalDataElement.h:29
static void WriteNameEntry(CodedStr *codeName, LogWriter *rewriteTo=NULL, bool forceWrite=false)
Definition: Slate.cpp:1289
FlexArray< ElementURI * > ElementURIList
Definition: Slate.h:61
FlexArray< DataAccess * > DataAccessArray
Arrays for attaching codes to names.
Definition: Slate.h:55
static void MapDataElement(ElementURI *elementURI, DataElement *dataElement)
Maps the supplied DataElement to the suplied Uri.
Definition: Slate.cpp:436
FastMap< const ElementURI, DataElement * > DataElementMap
Maps for keeping track of actual data elements.
Definition: Slate.h:44
Base class for a generalized set of "log data destinations," including to files (text or binary)...
Definition: LogWriter.h:25
static bool DirectoryWritesEnabled_
Definition: Slate.h:284
static void WriteElementURIEntry(ElementURI *elementURI, LogWriter *rewriteTo=NULL, bool forceWrite=false)
Definition: Slate.cpp:1271
A DataAccessor that reads values from the Slate Contains a default dataValue that must not be NULL...
Definition: DataReader.h:30
static UniversalDataWriter * NewUniversalWriter(const UniversalURI &universalURI, Component *owner, DataValue *initialValue, const float accuracy=DataElement::NO_ACCURACY)
Definition: Slate.cpp:556
static bool DirectoryWritesSimulated_
Definition: Slate.h:285
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: UniversalDataWriter.h:24
static void CodifyElementURI(ElementURI &elementURI)
Adds a unique code to the elementURI.
Definition: Slate.cpp:258
virtual ~StaticDestructor()
static Destructor
Definition: Slate.cpp:105
static int ElementURICount_
Definition: Slate.h:300
static unsigned int GetElementURICount()
Returns the number of registered ElementURIs.
Definition: Slate.cpp:250
static Mutex DataAccessMutex_
Definition: Slate.h:303
Contains the DataAccess class definition.
Contains the Component class definition.
static void WriteDirectory(LogWriter *rewriteTo=NULL, bool forceLog=false)
Definition: Slate.cpp:1175
static CodedStr * RegisterCodedName(CodedStr *name)
Adds the supplied CodedStr to the registries.
Definition: Slate.cpp:407
A simple pthread Mutex abstraction.
Definition: Mutex.h:20
Contains the UniversalURI class definition.
static ElementURIArray * ElementURIArray_
Definition: Slate.h:298
static NameArray * NameArray_
Definition: Slate.h:301
FlexArray< CodedStr * > NameList
Definition: Slate.h:63
static StaticDestructor StaticDestructor_
Static instance of StaticDestructor.
Definition: Slate.h:313
FastMap< const Str, DataAccess * > DataAccessMap
Maps for keeping track of names only.
Definition: Slate.h:51
static DataReader * NewReader(const Str &componentName, const Str &uriPart, Component *owner, const DataValue *defaultValue, bool deleteDefaultValue=true)
Definition: Slate.cpp:507
static UniversalDataElement * NewUniversalElement(const UniversalURI &universalURI, Component *owner, const Unit &unit, BinaryDataType binaryType)
Definition: Slate.cpp:923
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
static CodedStr * FindCodedName(const Str &name)
Returns the CodedStr like the supplied string.
Definition: Slate.cpp:367
static const unsigned short NO_LOG_FORMAT
Definition: Slate.h:257
static DataWriter * NewOutputWriter(const Str &uriPart, Component *owner, DataValue *initialValue)
Definition: Slate.cpp:482
A DataAccessor that writes values to the Slate via its associated DataElement.
Definition: DataWriter.h:27
static ElementURI * FindElementURI(const Str &str)
Returns a ElementURI that matches the supplied str.
Definition: Slate.cpp:336
Code unit that represents a unique name for a measured quantity.
Definition: UniversalURI.h:29
This is a very abstract class that can be implemented by classes that want to receive stream input...
Definition: InStream.h:29
Extends the Str class, adding an unsigned short code (actually, the codes are limited to 14 bits...
Definition: CodedStr.h:23
static void WriteDataAccessEntry(DataAccess *dataAccess, LogWriter *rewriteTo=NULL, bool forceWrite=false)
Helper functions that write directory information.
Definition: Slate.cpp:1253
static unsigned short GetDataAccessCount()
Returns the number of DataAccess element currently registered.
Definition: Slate.h:88
static DataAccess * GetDataAccess(const unsigned short &code)
Returns the DataAccess with the code, or NULL if none.
Definition: Slate.cpp:140
static bool DirectoryRead_
Definition: Slate.h:289
static bool ReadHeader(InStream &inStream)
Read and process a header frame.
static unsigned short NextDataAccessCode_
Definition: Slate.h:286
static void ConfigureNewDataElement(Component *owner, const ElementURI &elementURI, DataElement *&dataElement)
Definition: Slate.cpp:942
static void SimulateDirectoryWrites()
Definition: Slate.cpp:893
static DataElement * NewDataElement(const ElementURI &elementURI, Component *owner, const Unit &unit, BinaryDataType binaryType, const float accuracy=DataElement::NO_ACCURACY)
Definition: Slate.cpp:904
static UniversalMap * UniversalMap_
Definition: Slate.h:292
static void ClearDirectory()
Definition: Slate.cpp:1094
FlexArray< DataAccess * > DataAccessList
Definition: Slate.h:59
static void Construct()
static Constructor
Definition: Slate.cpp:73
Abstact base class of all elements which can write to, or read from the slate.
Definition: DataAccessor.h:29
Replacement for standard template class string.
Definition: Str.h:12
static DataAccessMap * DataAccessMap_
Definition: Slate.h:293
Definition: unserialize.cpp:77
Abstract Base class for software components.
Definition: Component.h:53
static void DeRegisterElementURI(ElementURI *elementURI)
Removes the supplied ElementURI to the registries.
Definition: Slate.cpp:314
Contains the ElementURI class definition.
static ElementURI * GetElementURI(const unsigned short &code)
Returns the ElementURI with the code, or NULL if none.
Definition: Slate.cpp:234
FastMap< const Str, CodedStr * > NameMap
Definition: Slate.h:53
Contains the DataAccessor class definition.
Slate()
Private Constructor for static class.
Definition: Slate.h:261
Contains the Mutex, ThreadCondition, and MutexLocker class declarations.
static CodedStr * GetName(const unsigned short &code)
Returns the CodedStr with the code, or NULL if none.
Definition: Slate.cpp:358
static Mutex NameMutex_
Definition: Slate.h:305
static ElementURIList * ElementURIList_
Definition: Slate.h:299
Contains the Logger class definition.
static bool ReadOnce(const Str &componentName, const Str &uriPart, const Unit &unit, T &readTo, Logger &logger, Syslog::Severity severity=Syslog::CRITICAL)
If the value is only going to be read once, it's probably not worth providing a DataReader.
Definition: Slate.h:200
Code unit that represents the slate.
Definition: Slate.h:73
static Logger * Logger_
Definition: Slate.h:290
A "Simple" DataElement.
Definition: SimpleDataElement.h:24
static NameMap * NameMap_
Definition: Slate.h:295
static unsigned short NextNameCode_
Definition: Slate.h:288
Contains the DataValue class definition.
Simple class providing a flexible size array of pointers.
Definition: DataReader.h:19
static DataElementMap * DataElementMap_
Definition: Slate.h:291
Severity
An attempt to define different levels of syslog severity.
Definition: Syslog.h:28
Code unit that represents a unique name for a DataElement.
Definition: ElementURI.h:27
static DataAccess * RegisterDataAccess(DataAccess *dataAccess)
Adds the supplied DataAccess to the registries.
Definition: Slate.cpp:178
The supervisor is the "main" component in the vehicle software.
Definition: Supervisor.h:65
static unsigned short NextElementURICode_
Definition: Slate.h:287
static DataWriter * NewWriter(const Str &componentName, const Str &uriPart, Component *owner)
Definition: Slate.cpp:590
static void Uninitialize()
Definition: Slate.cpp:1135
FlexArray< ElementURI * > ElementURIArray
Definition: Slate.h:60
static unsigned short GetElementURICode(const char *chars)
Returns a ElementURI code for the ElementURI that matches the supplied chars.
Definition: Slate.cpp:345
Code that represents an engineering unit.
Definition: Unit.h:24
static DataAccessArray * DataAccessList_
Definition: Slate.h:297
Contains the SimpleDataElement class definition.
static ElementURIMap * ElementURIMap_
Definition: Slate.h:294
static DataAccessArray * DataAccessArray_
Definition: Slate.h:296
static UniversalDataReader * NewUniversalReader(const UniversalURI &universalURI, Component *owner, const DataValue *defaultValue, bool deleteDefaultValue=true)
Definition: Slate.cpp:540
static void EnableDirectoryWrites()
Definition: Slate.cpp:878
static DataElement * GetElement(const unsigned short &uriCode)
Returns the DataElement of the uriCode, or NULL.
Definition: Slate.cpp:208
static bool ReadOnce(const Str &componentName, const Str &uriPart, DataValue &readTo, Logger &logger, Syslog::Severity severity=Syslog::CRITICAL)
Definition: Slate.h:211
static CodedStr & GetCodedName(const Str &name)
Returns the CodedStr like the supplied string.
Definition: Slate.cpp:381
static const float NO_ACCURACY
Defines an accuracy quantity which means "no accuracy specified" typically means "don't use" i...
Definition: DataElement.h:73
Makes sure that static objects are deleted on shutdown.
Definition: Slate.h:307
static void ReadDirectory(const Str &dirFilename)
Definition: Slate.cpp:1083
Abstact base class for one "element" of the Slate.
Definition: DataElement.h:37
static NameList * NameList_
Definition: Slate.h:302
static DataReader * NewInputReader(const Str &uriPart, Component *owner, const DataValue *defaultValue, bool deleteDefaultValue=true)
Creates a reader for this component's input (and a dataElement) Doesn't take a ComponentName, assumes it's being created in the owner's namespace.
Definition: Slate.cpp:452
static ElementURI * RegisterElementURI(ElementURI *elementURI)
Adds the supplied ElementURI to the registries.
Definition: Slate.cpp:285