ArPiRobot-CoreLib C++
C++ library for ArPiRobot robots
ActionManager.hpp
1 /*
2  * Copyright 2021 Marcus Behel
3  *
4  * This file is part of ArPiRobot-CoreLib.
5  *
6  * ArPiRobot-CoreLib is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * ArPiRobot-CoreLib is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with ArPiRobot-CoreLib. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <arpirobot/core/action/Action.hpp>
23 #include <arpirobot/core/action/BaseActionTrigger.hpp>
24 
25 #include <vector>
26 #include <mutex>
27 
28 namespace arpirobot{
29 
30  class ActionSeries;
31 
38  public:
39 
47  static bool startAction(Action &action, bool doRestart = true);
48 
56  static bool startAction(std::shared_ptr<Action> action, bool doRestart = true);
57 
64  static bool stopAction(Action &action);
65 
72  static bool stopAction(std::shared_ptr<Action> action);
73 
78  static void addTrigger(BaseActionTrigger &trigger);
79 
84  static void addTrigger(std::shared_ptr<BaseActionTrigger> trigger);
85 
90  static void removeTrigger(BaseActionTrigger &trigger);
91 
96  static void removeTrigger(std::shared_ptr<BaseActionTrigger> trigger);
97 
98  private:
99 
100  static bool startActionInternal(std::shared_ptr<Action> action, bool doRestart, ActionSeries *owningActionSeries);
101 
102  static bool stopActionInternal(std::shared_ptr<Action> action, bool interrupted);
103 
104  static void checkTriggers();
105 
106  static std::mutex triggerLock;
107 
108  static std::vector<std::shared_ptr<BaseActionTrigger>> triggers;
109 
110  // Keep actions started with ActionManager::startAction(std::make_shared) in scope
111  static std::vector<std::shared_ptr<Action>> runningActions;
112  static std::mutex runningActionsLock;
113 
114  friend class BaseRobot; // BaseRobot needs to call checkTriggers on its scheduler
115  friend class Action; // Action needs to be able to call stopActionInternal
116  friend class ActionSeries; // ActionSeries needs to be able to call startActionInternal
117  };
118 
119 }
Definition: ActionManager.hpp:37
static bool startAction(std::shared_ptr< Action > action, bool doRestart=true)
static void removeTrigger(BaseActionTrigger &trigger)
static bool stopAction(Action &action)
static bool startAction(Action &action, bool doRestart=true)
static void addTrigger(std::shared_ptr< BaseActionTrigger > trigger)
static void addTrigger(BaseActionTrigger &trigger)
static void removeTrigger(std::shared_ptr< BaseActionTrigger > trigger)
static bool stopAction(std::shared_ptr< Action > action)
Definition: ActionSeries.hpp:34
Definition: Action.hpp:41
Definition: BaseActionTrigger.hpp:37
Definition: BaseRobot.hpp:40
Definition: ArduinoDevice.hpp:27