ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
StatusWithMessage.cc
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#include "StatusWithMessage.h"
4
5namespace ChimeraTK {
6
7 /********************************************************************************************************************/
8
9 StatusWithMessage::StatusWithMessage(VariableGroup* owner, const std::string& qualifiedStatusVariableName,
10 const std::string& description, const std::unordered_set<std::string>& tags)
11 : VariableGroup(owner, Utilities::getPathName(qualifiedStatusVariableName), description, tags),
12 _status(this, Utilities::getUnqualifiedName(qualifiedStatusVariableName), description, {tagStatusHasMessage}),
13 _message(this, Utilities::getUnqualifiedName(qualifiedStatusVariableName) + "_message", "", "status message") {
15 }
16
17 /********************************************************************************************************************/
18
19 void StatusWithMessage::write(StatusOutput::Status status, std::string message) {
20 set(status, std::move(message));
21 writeAll();
22 }
23
24 /********************************************************************************************************************/
25
26 void StatusWithMessage::writeIfDifferent(StatusOutput::Status status, std::string message) {
27 if(status != _status || message != std::string(_message) || _status.getVersionNumber() == VersionNumber{nullptr}) {
28 write(status, std::move(message));
29 }
30 }
31
32 /********************************************************************************************************************/
33
35 setOk();
36 writeAll();
37 }
38
39 /********************************************************************************************************************/
40
42 if(_status != StatusOutput::Status::OK || _status.getVersionNumber() == VersionNumber{nullptr}) {
43 setOk();
44 writeAll();
45 }
46 // This assert makes sure the above "if" condition is sufficient. There is no way to set the status to OK and have
47 // a non-empty message string.
48 assert(std::string(_message).empty());
49 }
50
51 /********************************************************************************************************************/
52
53 void StatusWithMessage::set(StatusOutput::Status status, std::string message) {
54 assert(status != StatusOutput::Status::OK);
55 _status = status;
56 _message = std::move(message);
57 }
58
59 /********************************************************************************************************************/
60
62 _status = StatusOutput::Status::OK;
63 _message = "";
64 }
65
66 /********************************************************************************************************************/
67 /********************************************************************************************************************/
68
69 StatusWithMessageInput::StatusWithMessageInput(VariableGroup* owner, const std::string& qualifiedName,
70 const std::string& description, const std::unordered_set<std::string>& tags)
71 : VariableGroup(owner, Utilities::getPathName(qualifiedName), "", tags),
72 _status(this, Utilities::getUnqualifiedName(qualifiedName), description) {
73 hasMessageSource = false;
74 _statusNameLong = description;
75 }
76
77 /********************************************************************************************************************/
78
79 void StatusWithMessageInput::setMessageSource(std::string msgInputName) {
80 // at the time this function is called, TransferElement impl is not yet set, so don't look there for name
81 if(msgInputName.empty()) {
82 msgInputName = ((VariableNetworkNode)_status).getName() + "_message";
83 }
84 // late initialization of _message
85 _message = ScalarPushInput<std::string>(this, msgInputName, "", "");
86 hasMessageSource = true;
87 }
88
89 /********************************************************************************************************************/
90
91} // namespace ChimeraTK
const std::string & getName() const
Get the name of the module instance.
Definition EntityOwner.h:59
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Definition Module.cc:157
Convenience class for input scalar accessors with UpdateMode::push.
Class describing a node of a variable network.
std::string getUnqualifiedName(const std::string &qualifiedName)
Return the last component of the given qualified path name.
Definition Utilities.cc:19
InvalidityTracer application module.
constexpr auto explicitDataValidityTag
Special tag to designate that a node should not automatically take over DataValidity of its owning mo...
void writeOk()
Set status to OK, clear the message and write the outputs.
static constexpr auto tagStatusHasMessage
Reserved tag which is used to mark presense of the message output.
void setOk()
Set status to OK and clear the message, but to not write.
void set(StatusOutput::Status status, std::string message)
Set status and message but to not write.
void writeIfDifferent(StatusOutput::Status status, std::string message)
ScalarOutput< std::string > _message
void write(StatusOutput::Status status, std::string message)
Set the status and the message and write the outputs.
StatusWithMessageInput(VariableGroup *owner, const std::string &qualifiedName, const std::string &description, const std::unordered_set< std::string > &tags={})
Construct StatusWithMessageInput which reads only status, not message.
void setMessageSource(std::string msgInputName="")
read associated status message from given (fully qualified) msgInputName.
ScalarPushInput< std::string > _message