FairMQ  1.4.14
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 <fairlogger/Logger.h>
15 
16 #include <string>
17 #include <memory>
18 #include <functional>
19 #include <stdexcept>
20 
21 namespace fair
22 {
23 namespace mq
24 {
25 
27 {
28  public:
29  StateMachine();
30  virtual ~StateMachine();
31 
32  bool ChangeState(const 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 HandleStates(std::function<void(const State)> callback);
39  void StopHandlingStates();
40 
41  void SubscribeToNewTransition(const std::string& key, std::function<void(const Transition)> callback);
42  void UnsubscribeFromNewTransition(const std::string& key);
43 
44  bool NewStatePending() const;
45  void WaitForPendingState() const;
46  bool WaitForPendingStateFor(const int durationInMs) const;
47 
48  State GetCurrentState() const;
49  std::string GetCurrentStateName() const;
50 
51  void Start();
52 
53  void ProcessWork();
54 
55  struct ErrorStateException : std::runtime_error { using std::runtime_error::runtime_error; };
56 
57  private:
58  std::shared_ptr<void> fFsm;
59 };
60 
61 } // namespace mq
62 } // namespace fair
63 
64 #endif /* FAIRMQSTATEMACHINE_H_ */
Definition: StateMachine.h:55
Definition: StateMachine.h:26
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23

privacy