CbmRoot
CbmMQDefs.h
Go to the documentation of this file.
1 //#ifdef HAVE_FAIRMQSTATEMACHINE
2 //#include "FairMQStateMachine.h"
3 //#endif
4 #include "FairMQDevice.h"
5 
6 namespace cbm {
7  namespace mq {
8  enum class Transition : int {
9  Idle,
11  Ready,
12  Stop,
13  End,
15  };
16 
17  enum class State : int { Running };
18 
19  void ChangeState(FairMQDevice* device, cbm::mq::Transition transition) {
20 #ifdef HAVE_FAIRMQSTATEMACHINE
21  if (transition == cbm::mq::Transition::ErrorFound) {
22  device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
23  } else if (transition == cbm::mq::Transition::End) {
24  device->ChangeState(FairMQStateMachine::Event::END);
25  } else if (transition == cbm::mq::Transition::Ready) {
26  device->ChangeState(FairMQStateMachine::Event::internal_READY);
27  } else if (transition == cbm::mq::Transition::DeviceReady) {
28  device->ChangeState(FairMQStateMachine::Event::internal_DEVICE_READY);
29  } else if (transition == cbm::mq::Transition::Idle) {
30  device->ChangeState(FairMQStateMachine::Event::internal_IDLE);
31  } else {
32  LOG(fatal) << "State Change not yet implemented";
33  device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
34  }
35 #else
36  if (transition == cbm::mq::Transition::ErrorFound) {
37  device->ChangeState(fair::mq::Transition::ErrorFound);
38  } else if (transition == cbm::mq::Transition::End) {
39  device->ChangeState(fair::mq::Transition::End);
40  } else if (transition == cbm::mq::Transition::Ready) {
41  device->ChangeState(fair::mq::Transition::ResetTask);
42  } else if (transition == cbm::mq::Transition::DeviceReady) {
43  device->ChangeState(fair::mq::Transition::ResetDevice);
44  } else if (transition == cbm::mq::Transition::Idle) {
45  device->ChangeState(fair::mq::Transition::Stop);
46  } else {
47  LOG(fatal) << "State Change not yet implemented";
48  device->ChangeState(fair::mq::Transition::ErrorFound);
49  }
50 #endif
51  }
52 
53  void LogState(FairMQDevice* device) {
54 #ifdef HAVE_FAIRMQSTATEMACHINE
55  // LOG(info) << "Current State: " << FairMQStateMachine::GetCurrentStateName();
56  LOG(info) << "Current State: " << device->GetCurrentStateName();
57 #else
58  LOG(info) << "Current State: " << device->GetCurrentStateName();
59 #endif
60  }
61 
62  bool CheckCurrentState(FairMQDevice* device, cbm::mq::State state) {
63 #ifdef HAVE_FAIRMQSTATEMACHINE
64  if (state == cbm::mq::State::Running) {
65  return device->CheckCurrentState(FairMQStateMachine::State::RUNNING);
66  } else {
67  LOG(fatal) << "State not yet implemented";
68  device->ChangeState(FairMQStateMachine::Event::ERROR_FOUND);
69  return 0;
70  }
71 #else
72  if (state == cbm::mq::State::Running) {
73  return !(device->NewStatePending());
74  } else {
75  LOG(fatal) << "State not yet implemented";
76  device->ChangeState(fair::mq::Transition::ErrorFound);
77  return 0;
78  }
79 #endif
80  }
81  } // namespace mq
82 } // namespace cbm
cbm::mq::Transition
Transition
Definition: CbmMQDefs.h:8
cbm
Definition: CbmMQDefs.h:6
cbm::mq::CheckCurrentState
bool CheckCurrentState(FairMQDevice *device, cbm::mq::State state)
Definition: CbmMQDefs.h:62
cbm::mq::Transition::Stop
@ Stop
cbm::mq::Transition::End
@ End
cbm::mq::Transition::ErrorFound
@ ErrorFound
cbm::mq::LogState
void LogState(FairMQDevice *device)
Definition: CbmMQDefs.h:53
cbm::mq::Transition::Ready
@ Ready
cbm::mq::State
State
Definition: CbmMQDefs.h:17
cbm::mq::State::Running
@ Running
cbm::mq::Transition::DeviceReady
@ DeviceReady
cbm::mq::ChangeState
void ChangeState(FairMQDevice *device, cbm::mq::Transition transition)
Definition: CbmMQDefs.h:19
cbm::mq::Transition::Idle
@ Idle