Gazebo Sim

API Reference

7.7.0
GuardsImpl.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 /*
19  * \author Nick Lamprianidis <nlamprian@gmail.com>
20  * \date January 2021
21  */
22 
23 #include <mutex>
24 
25 namespace gz
26 {
27 namespace sim
28 {
29 // Inline bracket to help doxygen filtering
30 inline namespace GZ_SIM_VERSION_NAMESPACE {
31 namespace systems
32 {
33 namespace guards
34 {
37 template <typename TargetState>
38 struct IsInState
39 {
42  public: template <typename Fsm, typename State>
43  bool operator()(const Fsm &_fsm, const State &)
44  {
45  // NOTE Mind the inversion; the internal transition table needs
46  // the guard to return false in order to trigger a transition
47  return !_fsm.template is_in_state<TargetState()>();
48  }
49 };
50 
53 {
56  public: template <typename Fsm, typename State>
57  bool operator()(const Fsm &_fsm, const State &)
58  {
59  std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
60  return _fsm.dataPtr->targets.front() == _fsm.dataPtr->system->state;
61  }
62 };
63 
66 {
69  public: template <typename Fsm, typename State>
70  bool operator()(const Fsm &_fsm, const State &)
71  {
72  std::lock_guard<std::recursive_mutex> lock(_fsm.dataPtr->system->mutex);
73  return _fsm.dataPtr->targets.empty();
74  }
75 };
76 
77 } // namespace guards
78 } // namespace systems
79 } // namespace GZ_SIM_VERSION_NAMESPACE
80 } // namespace sim
81 } // namespace gz