Dev Essential
Loading...
Searching...
No Matches
mapping_engine.h
Go to the documentation of this file.
1
19
20#ifndef _MAPPING_ENGINE_HEADER
21#define _MAPPING_ENGINE_HEADER
22
23#include <ddl/mapping/mapper.h>
26
27#include <optional>
28#include <string_view>
29
30namespace ddl {
31namespace mapping {
32
37public:
42 void add(std::shared_ptr<const SourceFactory> source_factory);
47 void add(std::shared_ptr<const TargetFactory> target_factory);
52 void add(std::shared_ptr<const FunctionFactory> function_factory);
60 std::shared_ptr<Source> makeSource(const std::string& type,
61 std::string name,
62 Properties properties) const;
70 std::shared_ptr<Target> makeTarget(const std::string& type,
71 std::string name,
72 Properties properties) const;
80 std::shared_ptr<Function> makeFunction(const std::string& type,
81 std::string name,
82 Properties properties) const;
83
88 const std::unordered_map<std::string, std::shared_ptr<const SourceFactory>>&
94 const std::unordered_map<std::string, std::shared_ptr<const TargetFactory>>&
100 const std::unordered_map<std::string, std::shared_ptr<const FunctionFactory>>&
102
103private:
104 std::unordered_map<std::string, std::shared_ptr<const SourceFactory>> _source_factories;
105 std::unordered_map<std::string, std::shared_ptr<const TargetFactory>> _target_factories;
106 std::unordered_map<std::string, std::shared_ptr<const FunctionFactory>> _function_factories;
107};
108
122
126class Engine {
127public:
132 Engine(MapperFactories mapper_factories);
140 void create(const MappingConfiguration& configuration);
148 void create(const std::string& mapping_file);
164 void create(const std::string& mapping_file, const std::string& dd_file);
165
169 static constexpr auto property_time_strategy = "time_strategy";
170
171protected:
175 virtual void addSource(std::shared_ptr<Source> /*source*/, std::shared_ptr<Updateable> /*trigger_update*/){};
179 virtual void addTarget(std::shared_ptr<Target> /*target*/){};
180
189 std::chrono::nanoseconds _duration;
193 std::shared_ptr<Target> _target;
197 std::shared_ptr<AssignmentTrigger> _trigger;
201 std::unordered_map<std::string, std::string> _additional_properties;
202 };
203
207 virtual void addTimeTrigger(TargetTimeTrigger /*time_trigger*/){};
208
217 std::shared_ptr<Source> _source;
221 std::shared_ptr<Target> _target;
225 std::shared_ptr<AssignmentTrigger> _trigger;
229 std::unordered_map<std::string, std::string> _additional_properties;
230 };
231
235 virtual void addSourceTrigger(TargetSourceTrigger /*source_trigger*/){};
236
245 std::string strValueName;
257 std::string strOp;
261 std::string strValue;
265 std::shared_ptr<Source> _source;
269 std::shared_ptr<Target> _target;
273 std::shared_ptr<AssignmentTrigger> _trigger;
277 std::unordered_map<std::string, std::string> _additional_properties;
278 };
279
283 virtual void addDataTrigger(TargetDataTrigger /*data_trigger*/){};
284
285protected:
287 std::unique_ptr<Mapper> _mapper;
291 std::optional<ddl::DataDefinition> _global_dd;
292};
293
297class DefaultEngine final : public Engine {
298public:
308
314 public:
318 virtual ~ISourceTrigger() = default;
326 virtual bool update(std::chrono::nanoseconds time,
327 std::shared_ptr<const Memory> memory) = 0;
328 };
329
335 public:
339 virtual ~ITimeTrigger() = default;
347 virtual bool update(std::chrono::nanoseconds time) = 0;
348 };
349
355 public:
359 virtual ~ITargetTrigger() = default;
365 virtual std::shared_ptr<Memory> getMemory(size_t data_size) = 0;
381 virtual void update(std::chrono::nanoseconds target_time) = 0;
382 };
383
389 std::shared_ptr<ISourceTrigger> getSourceTrigger(const std::string_view& source_name);
394 std::shared_ptr<ITimeTrigger> getTimeTrigger();
395
401 void registerForTarget(const std::string_view& target_name,
402 std::shared_ptr<ITargetTrigger> target_trigger);
406 void reset();
407
408private:
409 void addSource(std::shared_ptr<Source> source, std::shared_ptr<Updateable> trigger_updateable) override;
410 void addTarget(std::shared_ptr<Target> target) override;
411 void addTimeTrigger(TargetTimeTrigger time_trigger) override;
412 void addSourceTrigger(TargetSourceTrigger source_trigger) override;
413 void addDataTrigger(TargetDataTrigger data_trigger) override;
414
415private:
416 std::shared_ptr<ITimeTrigger> _time_trigger;
417 std::unordered_map<std::string, std::shared_ptr<ISourceTrigger>> _source_triggers;
418 std::unordered_map<std::string, std::shared_ptr<AssignmentTrigger>> _target_triggers;
419};
420
421} // namespace mapping
422} // namespace ddl
423#endif // _MAPPING_ENGINE_HEADER
The Data Definiton class uses the validation model to keep a Data Definition datamodel (ddl::dd::data...
Definition dd.h:92
interface definition for source triggers.
Definition mapping_engine.h:313
virtual bool update(std::chrono::nanoseconds time, std::shared_ptr< const Memory > memory)=0
Update the source with current time and memory (if memory source)
interface definition for target triggers that must be implemented
Definition mapping_engine.h:354
virtual void update(std::chrono::nanoseconds target_time)=0
Update call for the target.
virtual std::shared_ptr< Memory > getMemory(size_t data_size)=0
Get a current memory buffer reference for the target.
interface definition for time triggers.
Definition mapping_engine.h:334
virtual bool update(std::chrono::nanoseconds time)=0
Periodic time update call.
std::shared_ptr< ITimeTrigger > getTimeTrigger()
Get the Time Trigger.
void registerForTarget(const std::string_view &target_name, std::shared_ptr< ITargetTrigger > target_trigger)
registers a target trigger
std::shared_ptr< ISourceTrigger > getSourceTrigger(const std::string_view &source_name)
Get the Source Trigger for the given name.
void reset()
resets the engine in time and memory
DefaultEngine(MapperFactories factories)
virtual void addTarget(std::shared_ptr< Target >)
Callback function to inform about a target that is about to be added to the engine.
Definition mapping_engine.h:179
Engine(MapperFactories mapper_factories)
virtual void addDataTrigger(TargetDataTrigger)
Callback function to inform about a source data trigger that is about to be added to the engine.
Definition mapping_engine.h:283
MapperFactories _factories
the factories to use for creating source, target, function instances
Definition mapping_engine.h:289
static constexpr auto property_time_strategy
Definition mapping_engine.h:169
virtual void addSourceTrigger(TargetSourceTrigger)
Callback function to inform about a source trigger that is about to be added to the engine.
Definition mapping_engine.h:235
void create(const std::string &mapping_file, const std::string &dd_file)
Creates an engine with the given configuration file path and data definition. This method is there fo...
virtual void addSource(std::shared_ptr< Source >, std::shared_ptr< Updateable >)
Callback function to inform about a source that is about to be added to the engine.
Definition mapping_engine.h:175
virtual void addTimeTrigger(TargetTimeTrigger)
Callback function to inform about a time trigger that is about to be added to the engine.
Definition mapping_engine.h:207
std::unique_ptr< Mapper > _mapper
the mapper to initialize
Definition mapping_engine.h:287
void create(const MappingConfiguration &configuration, ddl::DataDefinition dd)
Creates an engine with the given configuration. This method is there for legacy reasons to load mappi...
std::optional< ddl::DataDefinition > _global_dd
the mapping 1.0 global legacy data definition
Definition mapping_engine.h:291
void create(const MappingConfiguration &configuration)
Creates an engine with the given configuration.
void create(const std::string &mapping_file)
Creates an engine with the given configuration file path.
Mapping factory collection class registry.
Definition mapping_engine.h:36
void add(std::shared_ptr< const SourceFactory > source_factory)
Adds a Source factory to the collection.
const std::unordered_map< std::string, std::shared_ptr< const SourceFactory > > & getSourceFactories() const
Get all current registered source factories.
const std::unordered_map< std::string, std::shared_ptr< const FunctionFactory > > & getFunctionFactories() const
Get all current registered function factories.
std::shared_ptr< Source > makeSource(const std::string &type, std::string name, Properties properties) const
Creates a source of given type.
const std::unordered_map< std::string, std::shared_ptr< const TargetFactory > > & getTargetFactories() const
Get all current registered target factories.
std::shared_ptr< Function > makeFunction(const std::string &type, std::string name, Properties properties) const
Creates a function of given type.
void add(std::shared_ptr< const FunctionFactory > function_factory)
Adds a Function factory to the collection.
void add(std::shared_ptr< const TargetFactory > target_factory)
Adds a Target factory to the collection.
std::shared_ptr< Target > makeTarget(const std::string &type, std::string name, Properties properties) const
Creates a target of given type.
Mapping Configuration model with validation and requirements management.
Definition mapping_configuration.h:34
definition of the dd namespace
Definition datamodel_base.h:26
definition of the mapping namespace
Definition ddl.h:50
MapperFactories getDefaultMapperFactories()
Retrieves the default mapper factories This contains:
std::unordered_map< std::string, Property > Properties
Properties class as set of key - property value pairs This proerties are used to adjust the readers a...
Definition mapper_interfaces.h:331
definition of the ddl namespace
Definition codec.h:21
Target data trigger definitions.
Definition mapping_engine.h:241
std::shared_ptr< Source > _source
The source reference to retrieve the strValueName from.
Definition mapping_engine.h:265
std::shared_ptr< AssignmentTrigger > _trigger
assignemnt to trigger
Definition mapping_engine.h:273
std::unordered_map< std::string, std::string > _additional_properties
additional properties (i.e. "time_strategy")
Definition mapping_engine.h:277
std::string strValueName
source value name to execute the conditional operation on.
Definition mapping_engine.h:245
std::string strValue
The value to ececute the operation with as string.
Definition mapping_engine.h:261
std::string strOp
Operation to execute. Possible conditional operation values within ddl::mapping::DefaultEngine :
Definition mapping_engine.h:257
std::shared_ptr< Target > _target
target to update
Definition mapping_engine.h:269
Target source trigger definitions.
Definition mapping_engine.h:213
std::shared_ptr< AssignmentTrigger > _trigger
assignment to trigger
Definition mapping_engine.h:225
std::unordered_map< std::string, std::string > _additional_properties
additional properties (i.e. "time_strategy")
Definition mapping_engine.h:229
std::shared_ptr< Target > _target
target to update
Definition mapping_engine.h:221
std::shared_ptr< Source > _source
source reference
Definition mapping_engine.h:217
Target time trigger definitions.
Definition mapping_engine.h:185
std::shared_ptr< AssignmentTrigger > _trigger
assignment to trigger
Definition mapping_engine.h:197
std::chrono::nanoseconds _duration
time trigger period
Definition mapping_engine.h:189
std::unordered_map< std::string, std::string > _additional_properties
additional properties
Definition mapping_engine.h:201
std::shared_ptr< Target > _target
target to update
Definition mapping_engine.h:193