ChimeraTK-ApplicationCore 04.06.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
18 class Application;
19 class ModuleGroup;
20 class ConfigReader;
21
22 /********************************************************************************************************************/
23
25 public:
38 ApplicationModule(ModuleGroup* owner, const std::string& name, const std::string& description,
39 const std::unordered_set<std::string>& tags = {});
40
42 ApplicationModule() = default;
43
45 ApplicationModule(ApplicationModule&& other) noexcept { operator=(std::move(other)); }
46
49
51 ~ApplicationModule() override;
52
55 virtual void mainLoop() = 0;
56
57 void run() override;
58
59 void terminate() override;
60
62
63 VersionNumber getCurrentVersionNumber() const override { return _currentVersionNumber; }
64
65 DataValidity getDataValidity() const override;
66
67 void incrementDataFaultCounter() override;
68 void decrementDataFaultCounter() override;
69
71 size_t getDataFaultCounter() const { return _dataFaultCounter; }
72
73 void setCurrentVersionNumber(VersionNumber versionNumber) override;
74
75 std::list<EntityOwner*> getInputModulesRecursively(std::list<EntityOwner*> startList) override;
76
77 size_t getCircularNetworkHash() const override;
78
82 void setCircularNetworkHash(size_t circularNetworkHash);
83
86
87 void unregisterModule(Module* module) override;
88
94
95 protected:
98 void mainLoopWrapper();
99
101 boost::thread _moduleThread;
102
105 VersionNumber _currentVersionNumber{nullptr};
106
111 std::atomic<size_t> _dataFaultCounter{0};
112
119
123 detail::CircularDependencyDetectionRecursionStopper _recursionStopper;
124
128 std::string className() {
129 auto name = boost::core::demangle(typeid(*this).name());
130 return name.substr(name.find_last_of(':') + 1);
131 }
132
135 };
136
137 /********************************************************************************************************************/
138
142
143 /********************************************************************************************************************/
144
145} /* namespace ChimeraTK */
boost::thread _moduleThread
The thread executing mainLoop()
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.
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.
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).
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.
ApplicationModule & operator=(ApplicationModule &&other) noexcept
Move assignment.
size_t getDataFaultCounter() const
Get the Number of inputs which report DataValidity::faulty.
Proxy for output stream, handed out to the log sources by the Logger::Module.
Definition Logger.h:39
Severity
Severity levels used by the Logger.
Definition Logger.h:27
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.
Logger::StreamProxy logger(Logger::Severity severity, std::string context)
Convenience function to obtain the logger stream.
Definition Logger.h:124