Skip to content

Source · fairmq/

StateMachine.hpublic header

Defines class fair::mq::StateMachine, struct fair::mq::StateMachine::ErrorStateException.

Described in Device states, Threads in a device, Control a device from code, States and transitions, Your first device, Logging.

fairmq/StateMachine.h64 lines · C++API: StateMachineAPI: ErrorStateExceptionGitHub ↗
1/********************************************************************************2 *    Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH    *3 *                                                                              *4 *              This software is distributed under the terms of the             *5 *              GNU Lesser General Public Licence (LGPL) version 3,             *6 *                  copied verbatim in the file "LICENSE"                       *7 ********************************************************************************/8 9#ifndef FAIRMQSTATEMACHINE_H_10#define FAIRMQSTATEMACHINE_H_11 12#include <fairmq/States.h>13 14#include <string>15#include <memory>16#include <functional>17#include <stdexcept>18 19namespace fair::mq20{21 22class StateMachine23{24  public:25    StateMachine();26    StateMachine(const StateMachine&) = delete;27    StateMachine(StateMachine&&) = delete;28    StateMachine& operator=(const StateMachine&) = delete;29    StateMachine& operator=(StateMachine&&) = delete;30    ~StateMachine();31 32    bool ChangeState(Transition transition);33    bool ChangeState(const std::string& transition) { return ChangeState(GetTransition(transition)); }34 35    void SubscribeToStateChange(const std::string& key, std::function<void(const State)> callback);36    void UnsubscribeFromStateChange(const std::string& key);37 38    void PrepareState(std::function<void(const State)> callback);39    void HandleStates(std::function<void(const State)> callback);40    void StopHandlingStates();41 42    void SubscribeToNewTransition(const std::string& key, std::function<void(const Transition)> callback);43    void UnsubscribeFromNewTransition(const std::string& key);44 45    bool NewStatePending() const;46    void WaitForPendingState() const;47    bool WaitForPendingStateFor(int durationInMs) const;48 49    State GetCurrentState() const;50    std::string GetCurrentStateName() const;51 52    void Start();53 54    void ProcessWork();55 56    struct ErrorStateException : std::runtime_error { using std::runtime_error::runtime_error; };57 58  private:59    std::shared_ptr<void> fFsm;60};61 62} // namespace fair::mq63 64#endif /* FAIRMQSTATEMACHINE_H_ */