ChimeraTK-ApplicationCore 04.08.00
Loading...
Searching...
No Matches
ApplicationModule.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
6#include "Logger.h"
7#include "Model.h"
8#include "VariableGroup.h"
9
10#include <boost/thread.hpp>
11
12#include <list>
13
14namespace ChimeraTK {
15
16 /********************************************************************************************************************/
17
23 // NOLINTNEXTLINE(modernize-avoid-c-arrays)
24 constexpr char noInitialValueReadTag[]{"_ChimeraTK_ApplicationCore_noInitialValueRead"};
25
26 /********************************************************************************************************************/
27
28 class Application;
29 class ModuleGroup;
30 class ConfigReader;
31
32 /********************************************************************************************************************/
33
35 public:
48 ApplicationModule(ModuleGroup* owner, const std::string& name, const std::string& description,
49 const std::unordered_set<std::string>& tags = {});
50
52 ApplicationModule() = default;
53
55 ApplicationModule(ApplicationModule&& other) noexcept { operator=(std::move(other)); }
56
59
61 ~ApplicationModule() override;
62
65 virtual void mainLoop() = 0;
66
67 void run() override;
68
69 void terminate() override;
70
72
73 VersionNumber getCurrentVersionNumber() const override { return _currentVersionNumber; }
74
75 DataValidity getDataValidity() const override;
76
77 void incrementDataFaultCounter() override;
78 void decrementDataFaultCounter() override;
79
81 size_t getDataFaultCounter() const { return _dataFaultCounter; }
82
83 void setCurrentVersionNumber(VersionNumber versionNumber) override;
84
85 std::list<EntityOwner*> getInputModulesRecursively(std::list<EntityOwner*> startList) override;
86
87 size_t getCircularNetworkHash() const override;
88
92 void setCircularNetworkHash(size_t circularNetworkHash);
93
96
97 void unregisterModule(Module* module) override;
98
104
109
114
119
124
129
130 protected:
133 void mainLoopWrapper();
134
136 boost::thread _moduleThread;
137
140 VersionNumber _currentVersionNumber{nullptr};
141
146 std::atomic<size_t> _dataFaultCounter{0};
147
154
158 detail::CircularDependencyDetectionRecursionStopper _recursionStopper;
159
163 std::string className() {
164 auto name = boost::core::demangle(typeid(*this).name());
165 return name.substr(name.find_last_of(':') + 1);
166 }
167
170 };
171
172 /********************************************************************************************************************/
173
177
178 /********************************************************************************************************************/
179
183
184 /********************************************************************************************************************/
185
189
190 /********************************************************************************************************************/
191
195 /********************************************************************************************************************/
196
200
201 /********************************************************************************************************************/
202
206} /* namespace ChimeraTK */
boost::thread _moduleThread
The thread executing mainLoop()
Logger::StreamProxy warning()
Convenicene function to obtain a warning logger stream, with the current class name as context.
DataValidity getDataValidity() const override
Return the data validity flag.
virtual void mainLoop()=0
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
VersionNumber _currentVersionNumber
Version number of last push-type read operation - will be passed on to any write operations.
void unregisterModule(Module *module) override
Unregister another module as a sub-module.
ChimeraTK::Model::ApplicationModuleProxy _model
void run() override
Execute the module.
detail::CircularDependencyDetectionRecursionStopper _recursionStopper
Helper needed to stop the recursion when detecting circular dependency networks.
std::string className()
Name of the module class, used for logging and debugging purposes.
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
Logger::StreamProxy info()
Convenicene function to obtain a info logger stream, with the current class name as context.
void terminate() override
Terminate the module.
ModuleType getModuleType() const override
Return the module type of this module, or in case of a VirtualModule the module type this VirtualModu...
Logger::StreamProxy logger(Logger::Severity severity)
Convenicene function to obtain a logger stream with the given Severity.
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
void setCircularNetworkHash(size_t circularNetworkHash)
Set the ID of the circular dependency network.
~ApplicationModule() override
Destructor.
void setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
std::atomic< size_t > _dataFaultCounter
Number of inputs which report DataValidity::faulty.
std::list< EntityOwner * > getInputModulesRecursively(std::list< EntityOwner * > startList) override
Use pointer to the module as unique identifier.
size_t _circularNetworkHash
Unique ID for the circular dependency network.
void mainLoopWrapper()
Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop.
Logger::StreamProxy debug()
Convenicene function to obtain a debug logger stream, with the current class name as context.
VersionNumber getCurrentVersionNumber() const override
Return the current version number which has been received with the last push-type read operation.
size_t getCircularNetworkHash() const override
Get the ID of the circular dependency network (0 if none).
Logger::StreamProxy trace()
Convenicene function to obtain a trace logger stream, with the current class name as context.
ChimeraTK::Model::ApplicationModuleProxy getModel()
Return the application model proxy representing this module.
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
ApplicationModule(ApplicationModule &&other) noexcept
Move operation with the move constructor.
Logger::StreamProxy error()
Convenicene function to obtain a error logger stream, with the current class name as context.
ApplicationModule & operator=(ApplicationModule &&other) noexcept
Move assignment.
size_t getDataFaultCounter() const
Get the Number of inputs which report DataValidity::faulty.
Severity levels used by the Logger.
Definition Logger.h:29
Proxy for output stream, handed out to the log sources by the Logger::Module.
Definition Logger.h:65
Implementation class for the model.
Definition Model.h:1360
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
InvalidityTracer application module.
constexpr char noInitialValueReadTag[]
System tag to mark an accessor which should be excluded from the initial value read during applicatio...
Logger::StreamProxy logger(Logger::Severity severity, std::string context)
Convenience function to obtain the logger stream.
Definition Logger.h:156