ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
StatusAccessor.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
14#include "Module.h"
15#include "ScalarAccessor.h"
16
17#include <ChimeraTK/ControlSystemAdapter/StatusAccessorBase.h>
18#include <ChimeraTK/SystemTags.h>
19
20namespace ChimeraTK {
21
22 /********************************************************************************************************************/
23
25 template<typename ACCESSOR>
26 struct StatusAccessor : ACCESSOR, StatusAccessorBase {
28 StatusAccessor(Module* owner, const std::string& name, const std::string& description,
29 const std::unordered_set<std::string>& tags = {})
30 : ACCESSOR(owner, name, "", description, tags) {}
31 StatusAccessor() = default;
32
33 using ACCESSOR::ACCESSOR;
34
36 // We want thhs to be implicit, disable the linting here, also need reinterpret cast for now
37 // NOLINTNEXTLINE(google-explicit-constructor,cppcoreguidelines-pro-type-reinterpret-cast)
38 operator Status&() { return *reinterpret_cast<Status*>(&ACCESSOR::get()->accessData(0, 0)); }
39
41 // We want this to be implicit, disable the linting here, also need reinterpret cast for now
42 // NOLINTNEXTLINE(google-explicit-constructor,cppcoreguidelines-pro-type-reinterpret-cast)
43 operator const Status&() const { return *reinterpret_cast<Status*>(&ACCESSOR::get()->accessData(0, 0)); }
44
46 StatusAccessor& operator=(Status rightHandSide) {
47 ACCESSOR::get()->accessData(0, 0) = static_cast<int32_t>(rightHandSide);
48 return *this;
49 }
50
51 /* Delete increment/decrement operators since they do not make much sense with a Status */
52 void operator++() = delete;
53 void operator++(int) = delete;
54 void operator--() = delete;
55 void operator--(int) = delete;
56 };
57
58 /********************************************************************************************************************/
59
65 struct StatusOutput : StatusAccessor<ScalarOutput<int32_t>> {
67 StatusOutput(Module* owner, const std::string& name, const std::string& description,
68 const std::unordered_set<std::string>& tags = {})
69 : StatusAccessor<ScalarOutput<int32_t>>(owner, name, "", description, tags) {
70 addTag(ChimeraTK::SystemTags::statusOutput);
72 }
73 StatusOutput() = default;
74 using StatusAccessor<ScalarOutput<int32_t>>::operator=;
75
76 void writeIfDifferent(Status newValue) { ScalarOutput<int32_t>::writeIfDifferent(static_cast<int32_t>(newValue)); };
77 };
78
79 /********************************************************************************************************************/
80
82 struct StatusPushInput : StatusAccessor<ScalarPushInput<int32_t>> {
85 };
86
87 /********************************************************************************************************************/
88
90 struct StatusPollInput : StatusAccessor<ScalarPollInput<int32_t>> {
93 };
94
95 /********************************************************************************************************************/
96
97} // namespace ChimeraTK
Base class for ApplicationModule and DeviceModule, to have a common interface for these module types.
Definition Module.h:21
void writeIfDifferent(UserType newValue, VersionNumber versionNumber, DataValidity validity)=delete
Convenience class for input scalar accessors with UpdateMode::push.
InvalidityTracer application module.
constexpr auto explicitDataValidityTag
Special tag to designate that a node should not automatically take over DataValidity of its owning mo...
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::poll.
Special StatusAccessor - used to avoid code duplication in StatusOutput, StatusPushInput and StatusPo...
void operator++(int)=delete
StatusAccessor & operator=(Status rightHandSide)
Assignment operator, assigns the first element.
void operator--(int)=delete
StatusAccessor(Module *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
Note: In contrast to normal ScalarInput accessors, this constructor omits the unit argument.
Special ScalarOutput which represents a status which can be aggregated by the StatusAggregator.
StatusOutput(Module *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
Note: In contrast to normal ScalarOutput accessors, this constructor omits the unit argument.
void writeIfDifferent(Status newValue)
Special StatusPollInput which reads from a StatusOutput and also handles the type conversion.
Special StatusPushInput which reads from a StatusOutput and also handles the type conversion.