Belle II Software development
RCCommand.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8#include "daq/slc/runcontrol/RCCommand.h"
9
10#include "daq/slc/runcontrol/RCState.h"
11
12using namespace Belle2;
13
14const RCCommand RCCommand::CONFIGURE(101, "RC_CONFIGURE");
15const RCCommand RCCommand::LOAD(102, "RC_LOAD");
16const RCCommand RCCommand::START(103, "RC_START");
17const RCCommand RCCommand::STOP(104, "RC_STOP");
18const RCCommand RCCommand::RESUME(105, "RC_RESUME");
19const RCCommand RCCommand::PAUSE(106, "RC_PAUSE");
20const RCCommand RCCommand::RECOVER(107, "RC_RECOVER");
21const RCCommand RCCommand::ABORT(108, "RC_ABORT");
22const RCCommand RCCommand::BOOT(109, "RC_BOOT");
23const RCCommand RCCommand::STATUS(110, "RC_STATUS");
24
25const RCCommand& RCCommand::operator=(const RCCommand& command)
26{
27 NSMCommand::operator=(command);
28 return *this;
29}
30
31// cppcheck-suppress duplInheritedMember ; the derived class deliberately provides its own
32const RCCommand& RCCommand::operator=(const std::string& label)
33{
34 if (NSMCommand::operator=(label) != Enum::UNKNOWN) return *this;
35 else if (label == CONFIGURE.getLabel()) *this = CONFIGURE;
36 else if (label == LOAD.getLabel()) *this = LOAD;
37 else if (label == START.getLabel()) *this = START;
38 else if (label == STOP.getLabel()) *this = STOP;
39 else if (label == RECOVER.getLabel()) *this = RECOVER;
40 else if (label == RESUME.getLabel()) *this = RESUME;
41 else if (label == PAUSE.getLabel()) *this = PAUSE;
42 else if (label == ABORT.getLabel()) *this = ABORT;
43 else if (label == BOOT.getLabel()) *this = BOOT;
44 else if (label == STATUS.getLabel()) *this = STATUS;
45 else *this = Enum::UNKNOWN;
46 return *this;
47}
48
49// cppcheck-suppress duplInheritedMember ; the derived class deliberately provides its own
51{
52 if (NSMCommand::operator=(id) != Enum::UNKNOWN) return *this;
53 else if (id == CONFIGURE.getId()) *this = CONFIGURE;
54 else if (id == LOAD.getId()) *this = LOAD;
55 else if (id == START.getId()) *this = START;
56 else if (id == STOP.getId()) *this = STOP;
57 else if (id == RECOVER.getId()) *this = RECOVER;
58 else if (id == RESUME.getId()) *this = RESUME;
59 else if (id == PAUSE.getId()) *this = PAUSE;
60 else if (id == ABORT.getId()) *this = ABORT;
61 else if (id == BOOT.getId()) *this = BOOT;
62 else if (id == STATUS.getId()) *this = STATUS;
63 else *this = Enum::UNKNOWN;
64 return *this;
65}
66
67// cppcheck-suppress duplInheritedMember ; the derived class deliberately provides its own
68const RCCommand& RCCommand::operator=(const char* label)
69{
70 if (label != NULL) *this = std::string(label);
71 else *this = Enum::UNKNOWN;
72 return *this;
73}
74
75int RCCommand::isAvailable(const RCState& state) const
76{
77 const RCCommand& cmd(*this);
78 if ((cmd == LOAD || cmd == CONFIGURE) &&
79 state == RCState::NOTREADY_S) {
80 return SUGGESTED;
81 /* } else if ((cmd == LOAD || cmd == CONFIGURE) &&
82 state == RCState::READY_S) {
83 return ENABLED;
84 */
85 } else if (cmd == START && state == RCState::READY_S) {
86 return SUGGESTED;
87 } else if (cmd == STOP && (state == RCState::RUNNING_S ||
88 state == RCState::PAUSED_S)) {
89 return SUGGESTED;
90 } else if (cmd == PAUSE && state == RCState::RUNNING_S) {
91 return ENABLED;
92 } else if (cmd == RESUME && state == RCState::PAUSED_S) {
93 return ENABLED;
94 } else if (cmd == ABORT) {
95 return ENABLED;
96 } else if (cmd == RECOVER && state == RCState::ERROR_ES) {
97 return ENABLED;
98 } else if (cmd == BOOT && state == RCState::NOTREADY_S) {
99 return ENABLED;
100 } else {
101 return DISABLED;
102 }
103}
104
105RCState RCCommand::nextState() const
106{
107 const RCCommand& cmd(*this);
108 if (cmd == LOAD) return RCState::READY_S;
109 else if (cmd == START) return RCState::RUNNING_S;
110 else if (cmd == STOP) return RCState::READY_S;
111 else if (cmd == RESUME) return RCState::RUNNING_S;
112 else if (cmd == PAUSE) return RCState::PAUSED_S;
113 else if (cmd == RECOVER) return RCState::READY_S;
114 else if (cmd == ABORT) return RCState::NOTREADY_S;
115 else if (cmd == BOOT) return RCState::NOTREADY_S;
116 else if (cmd == CONFIGURE) return RCState::NOTREADY_S;
117 else return Enum::UNKNOWN;
118}
119
120RCState RCCommand::nextTState() const
121{
122 const RCCommand& cmd(*this);
123 if (cmd == CONFIGURE) return RCState::CONFIGURING_TS;
124 else if (cmd == LOAD) return RCState::LOADING_TS;
125 else if (cmd == START) return RCState::STARTING_TS;
126 else if (cmd == STOP) return RCState::STOPPING_TS;
127 else if (cmd == RESUME) return RCState::RUNNING_S;
128 else if (cmd == PAUSE) return RCState::PAUSED_S;
129 else if (cmd == RECOVER) return RCState::RECOVERING_RS;
130 else if (cmd == ABORT) return RCState::ABORTING_RS;
131 else if (cmd == BOOT) return RCState::BOOTING_RS;
132 else return Enum::UNKNOWN;
133}
const NSMCommand & operator=(const NSMCommand &command)
Operator =.
Definition NSMCommand.cc:32
const RCCommand & operator=(const RCCommand &command)
Operator =.
Definition RCCommand.cc:25
Abstract base class for different kinds of events.