ADTF  3.18.3
target.h
Go to the documentation of this file.
1 
15 #ifndef DDL_MAPPING_RT_TARGET_HEADER
16 #define DDL_MAPPING_RT_TARGET_HEADER
17 
18 #include <a_util/concurrency.h>
19 #include <a_util/result.h>
20 #include <ddl/codec/static_codec.h>
26 
27 #include <memory>
28 #include <vector>
29 
30 namespace ddl {
31 namespace mapping {
32 namespace rt {
34 class Target {
35 public: // types
36 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
37 #pragma GCC diagnostic ignored \
38  "-Wattributes" // standard type attributes are ignored when used in templates
39 #endif
40 
42  typedef std::vector<std::pair<std::string, TargetElement*>> Assignments;
44  typedef std::vector<std::pair<uint64_t, TargetElement*>> TriggerCounters;
46  typedef std::vector<std::pair<std::string, TargetElement*>> Constants;
48  typedef std::vector<uint8_t> MemoryBuffer;
49 
50 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
51 #pragma GCC diagnostic warning \
52  "-Wattributes" // standard type attributes are ignored when used in templates
53 #endif
54 
55 public:
61 
66 
77  const MapTarget& map_target,
78  const std::string& target_description,
79  SourceMap& sources);
80 
87 
92  const std::string& getName() const;
93 
98  const std::string& getTypeName() const;
99 
105 
111  size_t getSize() const;
112 
121  a_util::result::Result getCurrentBuffer(void* target_buffer, size_t target_buffer_size);
122 
130  a_util::result::Result getBufferRef(const void*& buffer, size_t& target_buffer_size);
131 
137 
143 
144 private:
146  std::string _name;
147  std::string _type_name;
148  TargetElementList _target_elements;
149  std::vector<TargetElement*> _simulation_time_elements;
150  TriggerCounters _counter_elements;
151  Constants _constant_elements;
152  uint64_t _counter;
153  std::unique_ptr<ddl::codec::StaticCodec> _codec;
154  MemoryBuffer _buffer;
155  mutable a_util::concurrency::shared_mutex _buffer_mutex;
156  IMappingEnvironment& _env;
158 public:
160  inline void aquireWriteLock() const
161  {
162  _buffer_mutex.lock_shared();
163  }
164 
166  inline void releaseWriteLock() const
167  {
168  _buffer_mutex.unlock_shared();
169  }
170 
172  inline void aquireReadLock() const
173  {
174  _buffer_mutex.lock();
175  }
176 
178  inline void releaseReadLock() const
179  {
180  _buffer_mutex.unlock();
181  }
182 };
183 
185 typedef std::map<std::string, Target*> TargetMap;
187 typedef std::set<Target*> TargetSet;
188 
189 } // namespace rt
190 } // namespace mapping
191 } // namespace ddl
192 #endif // DDL_MAPPING_RT_TARGET_HEADER
A shared_mutex class as a workaround for std::shared_timed_mutex.
Definition: shared_mutex.h:26
void unlock_shared()
Unlock the mutex (shared ownership)
void lock_shared()
Lock the mutex for shared ownership, blocks if the mutex is not available.
void unlock()
Unlock the mutex.
void lock()
Lock the mutex, blocks if the mutex is not available.
A common result class usable as return value throughout.
MapConfiguration is the central class of the mapping::dd namespace.
MapTarget represents a mapped target from the mapping configuration.
Definition: map_target.h:31
Mapping environment interface class This in combination with ISignalListener forms the functionality ...
Target represents a mapped target signal in the runtime api.
Definition: target.h:34
void aquireReadLock() const
Lock the buffer for a buffer read.
Definition: target.h:172
std::vector< uint8_t > MemoryBuffer
Generic byte-buffer.
Definition: target.h:48
const std::string & getTypeName() const
Getter for the target type.
a_util::result::Result updateAccessFunctionValues()
Method to update all dynamic values that are to be updates during buffer access (i....
std::vector< std::pair< uint64_t, TargetElement * > > TriggerCounters
Trigger counter container.
Definition: target.h:44
Target(IMappingEnvironment &env)
CTOR.
a_util::result::Result getCurrentBuffer(void *target_buffer, size_t target_buffer_size)
Method to get a copy of the current target buffer.
void releaseReadLock() const
Unlock the buffer after a buffer read.
Definition: target.h:178
a_util::result::Result create(const MapConfiguration &map_config, const MapTarget &map_target, const std::string &target_description, SourceMap &sources)
Creation method to fill the object with data.
const std::string & getName() const
Getter for the target name.
void releaseWriteLock() const
Unlock the buffer after a source update.
Definition: target.h:166
size_t getSize() const
Method to get buffer size.
a_util::result::Result reset(const MapConfiguration &map_config)
Reset target Buffers.
void aquireWriteLock() const
Lock the buffer for a source update.
Definition: target.h:160
const TargetElementList & getElementList() const
Getter for the element list.
a_util::result::Result updateTriggerFunctionValues()
Method to update all dynamic values that are to be updates during a trigger (i.e.
a_util::result::Result getBufferRef(const void *&buffer, size_t &target_buffer_size)
Method to get access to the current buffer without copying it.
std::vector< std::pair< std::string, TargetElement * > > Constants
Constant container.
Definition: target.h:46
std::vector< std::pair< std::string, TargetElement * > > Assignments
Assignment container.
Definition: target.h:42
Common include for component a_util::concurrency.
std::map< std::string, Target * > TargetMap
Public composite types used in the mapping::rt namespace.
Definition: target.h:185
std::set< Target * > TargetSet
the targets pointer list
Definition: target.h:187
std::vector< TargetElement * > TargetElementList
the targets element list
Definition: element.h:133
std::map< std::string, Source * > SourceMap
Public composite types used in the mapping::rt namespace.
Definition: source.h:174
Common include for component a_util::result.