/******************************************************************************** * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ #ifndef FAIRMQSTATEMACHINE_H_ #define FAIRMQSTATEMACHINE_H_ #include #include #include #include #include namespace fair::mq { class StateMachine { public: StateMachine(); StateMachine(const StateMachine&) = delete; StateMachine(StateMachine&&) = delete; StateMachine& operator=(const StateMachine&) = delete; StateMachine& operator=(StateMachine&&) = delete; ~StateMachine(); bool ChangeState(Transition transition); bool ChangeState(const std::string& transition) { return ChangeState(GetTransition(transition)); } void SubscribeToStateChange(const std::string& key, std::function callback); void UnsubscribeFromStateChange(const std::string& key); void PrepareState(std::function callback); void HandleStates(std::function callback); void StopHandlingStates(); void SubscribeToNewTransition(const std::string& key, std::function callback); void UnsubscribeFromNewTransition(const std::string& key); bool NewStatePending() const; void WaitForPendingState() const; bool WaitForPendingStateFor(int durationInMs) const; State GetCurrentState() const; std::string GetCurrentStateName() const; void Start(); void ProcessWork(); struct ErrorStateException : std::runtime_error { using std::runtime_error::runtime_error; }; private: std::shared_ptr fFsm; }; } // namespace fair::mq #endif /* FAIRMQSTATEMACHINE_H_ */