mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 00:31:14 +00:00
Add backwards compatibility for removed ChangeState(int)
This commit is contained in:
parent
7dcd84dd93
commit
d9edcad845
|
@ -40,6 +40,21 @@ static map<fair::mq::Transition, fair::mq::State> backwardsCompatibilityWaitForE
|
|||
{ fair::mq::Transition::ResetDevice, fair::mq::State::Idle }
|
||||
};
|
||||
|
||||
static map<int, fair::mq::Transition> backwardsCompatibilityChangeStateHelper =
|
||||
{
|
||||
{ FairMQDevice::Event::INIT_DEVICE, fair::mq::Transition::InitDevice },
|
||||
{ FairMQDevice::Event::internal_DEVICE_READY, fair::mq::Transition::Auto },
|
||||
{ FairMQDevice::Event::INIT_TASK, fair::mq::Transition::InitTask },
|
||||
{ FairMQDevice::Event::internal_READY, fair::mq::Transition::Auto },
|
||||
{ FairMQDevice::Event::RUN, fair::mq::Transition::Run },
|
||||
{ FairMQDevice::Event::STOP, fair::mq::Transition::Stop },
|
||||
{ FairMQDevice::Event::RESET_TASK, fair::mq::Transition::ResetTask },
|
||||
{ FairMQDevice::Event::RESET_DEVICE, fair::mq::Transition::ResetDevice },
|
||||
{ FairMQDevice::Event::internal_IDLE, fair::mq::Transition::Auto },
|
||||
{ FairMQDevice::Event::END, fair::mq::Transition::End },
|
||||
{ FairMQDevice::Event::ERROR_FOUND, fair::mq::Transition::ErrorFound }
|
||||
};
|
||||
|
||||
FairMQDevice::FairMQDevice()
|
||||
: FairMQDevice(nullptr, {0, 0, 0})
|
||||
{
|
||||
|
@ -162,6 +177,11 @@ void FairMQDevice::WaitForState(fair::mq::State state)
|
|||
while (WaitForNextState() != state) {}
|
||||
}
|
||||
|
||||
bool FairMQDevice::ChangeState(const int transition)
|
||||
{
|
||||
return ChangeState(backwardsCompatibilityChangeStateHelper.at(transition));
|
||||
}
|
||||
|
||||
void FairMQDevice::WaitForEndOfState(fair::mq::Transition transition)
|
||||
{
|
||||
WaitForState(backwardsCompatibilityWaitForEndOfStateHelper.at(transition));
|
||||
|
|
|
@ -476,6 +476,8 @@ class FairMQDevice
|
|||
bool ChangeState(const fair::mq::Transition transition) { return fStateMachine.ChangeState(transition); }
|
||||
bool ChangeState(const std::string& transition) { return fStateMachine.ChangeState(fair::mq::StateMachine::GetTransition(transition)); }
|
||||
|
||||
bool ChangeState(const int transition) __attribute__((deprecated("Use ChangeState(const fair::mq::Transition transition).")));
|
||||
|
||||
void WaitForEndOfState(const fair::mq::Transition transition) __attribute__((deprecated("Use WaitForState(fair::mq::State expectedState).")));
|
||||
void WaitForEndOfState(const std::string& transition) __attribute__((deprecated("Use WaitForState(fair::mq::State expectedState)."))) { WaitForState(transition); }
|
||||
|
||||
|
|
|
@ -201,20 +201,6 @@ struct Machine_ : public state_machine_def<Machine_>
|
|||
}
|
||||
};
|
||||
|
||||
struct ErrorFct
|
||||
{
|
||||
template<typename EVT, typename FSM, typename SourceState, typename TargetState>
|
||||
void operator()(EVT const& e, FSM& fsm, SourceState& /* ss */, TargetState& ts)
|
||||
{
|
||||
fsm.fState = ts.Type();
|
||||
fsm.fLastTransitionResult = true;
|
||||
fsm.CallNewTransitionCallbacks(e.Type());
|
||||
fsm.CallStateChangeCallbacks(ts.Type());
|
||||
fsm.fNewStatePending = true;
|
||||
fsm.fNewStatePendingCV.notify_all();
|
||||
}
|
||||
};
|
||||
|
||||
struct transition_table : bmpl::vector<
|
||||
// Start Transition Next Action Guard
|
||||
Row<IDLE_S, END_E, EXITING_S, DefaultFct, none>,
|
||||
|
@ -242,7 +228,7 @@ struct Machine_ : public state_machine_def<Machine_>
|
|||
Row<RESETTING_TASK_S, AUTO_E, DEVICE_READY_S, DefaultFct, none>,
|
||||
Row<RESETTING_DEVICE_S, AUTO_E, IDLE_S, DefaultFct, none>,
|
||||
|
||||
Row<OK_S, ERROR_FOUND_E, ERROR_S, ErrorFct, none>> {};
|
||||
Row<OK_S, ERROR_FOUND_E, ERROR_S, DefaultFct, none>> {};
|
||||
|
||||
void CallStateChangeCallbacks(const State state) const
|
||||
{
|
||||
|
@ -480,6 +466,8 @@ void StateMachine::ProcessWork()
|
|||
} catch(...) {
|
||||
{
|
||||
lock_guard<mutex> lock(fsm->fStateMtx);
|
||||
fsm->fState = State::Error;
|
||||
fsm->CallStateChangeCallbacks(State::Error);
|
||||
fsm->fWorkOngoing = false;
|
||||
fsm->fWorkDoneCV.notify_one();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user