FairMQ  1.4.33
C++ Message Queuing Library and Framework
StateMachine.h
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 
19 namespace fair::mq
20 {
21 
22 class StateMachine
23 {
24  public:
25  StateMachine();
26  virtual ~StateMachine();
27 
28  bool ChangeState(const Transition transition);
29  bool ChangeState(const std::string& transition) { return ChangeState(GetTransition(transition)); }
30 
31  void SubscribeToStateChange(const std::string& key, std::function<void(const State)> callback);
32  void UnsubscribeFromStateChange(const std::string& key);
33 
34  void HandleStates(std::function<void(const State)> callback);
35  void StopHandlingStates();
36 
37  void SubscribeToNewTransition(const std::string& key, std::function<void(const Transition)> callback);
38  void UnsubscribeFromNewTransition(const std::string& key);
39 
40  bool NewStatePending() const;
41  void WaitForPendingState() const;
42  bool WaitForPendingStateFor(const int durationInMs) const;
43 
44  State GetCurrentState() const;
45  std::string GetCurrentStateName() const;
46 
47  void Start();
48 
49  void ProcessWork();
50 
51  struct ErrorStateException : std::runtime_error { using std::runtime_error::runtime_error; };
52 
53  private:
54  std::shared_ptr<void> fFsm;
55 };
56 
57 } // namespace fair::mq
58 
59 #endif /* FAIRMQSTATEMACHINE_H_ */
fair::mq
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy