ChimeraTK-ApplicationCore 04.07.01
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 class StatusAccessor : public ACCESSOR, public StatusAccessorBase {
27 public:
29 StatusAccessor(Module* owner, const std::string& name, const std::string& description,
30 const std::unordered_set<std::string>& tags = {})
31 : ACCESSOR(owner, name, "", description, tags) {}
32 StatusAccessor() = default;
33
34 using ACCESSOR::ACCESSOR;
35
37 // We want thhs to be implicit, disable the linting here, also need reinterpret cast for now
38 // NOLINTNEXTLINE(google-explicit-constructor,cppcoreguidelines-pro-type-reinterpret-cast)
39 operator Status&() { return *reinterpret_cast<Status*>(&ACCESSOR::get()->accessData(0, 0)); }
40
42 // We want this to be implicit, disable the linting here, also need reinterpret cast for now
43 // NOLINTNEXTLINE(google-explicit-constructor,cppcoreguidelines-pro-type-reinterpret-cast)
44 operator const Status&() const { return *reinterpret_cast<Status*>(&ACCESSOR::get()->accessData(0, 0)); }
45
47 StatusAccessor& operator=(Status rightHandSide) {
48 ACCESSOR::get()->accessData(0, 0) = static_cast<int32_t>(rightHandSide);
49 return *this;
50 }
51
52 /* Delete increment/decrement operators since they do not make much sense with a Status */
53 void operator++() = delete;
54 void operator++(int) = delete;
55 void operator--() = delete;
56 void operator--(int) = delete;
57 };
58
59 /********************************************************************************************************************/
60
66 class StatusOutput : public StatusAccessor<ScalarOutput<int32_t>> {
67 public:
69 StatusOutput(Module* owner, const std::string& name, const std::string& description,
70 const std::unordered_set<std::string>& tags = {})
71 : StatusAccessor<ScalarOutput<int32_t>>(owner, name, "", description, tags) {
72 addTag(ChimeraTK::SystemTags::statusOutput);
73 }
74 StatusOutput() = default;
75 using StatusAccessor<ScalarOutput<int32_t>>::operator=;
76
77 void writeIfDifferent(Status newValue) { ScalarOutput<int32_t>::writeIfDifferent(static_cast<int32_t>(newValue)); };
78 };
79
80 /********************************************************************************************************************/
81
83 class StatusPushInput : public StatusAccessor<ScalarPushInput<int32_t>> {
84 public:
87 };
88
89 /********************************************************************************************************************/
90
92 class StatusPollInput : public StatusAccessor<ScalarPollInput<int32_t>> {
93 public:
96 };
97
98 /********************************************************************************************************************/
99
100} // 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 output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::poll.
Convenience class for input scalar accessors with UpdateMode::push.
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.
InvalidityTracer application module.