Executor.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Nicola Miskowiec
20 * @date 2016
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
26#pragma once
27
28#include <future>
29#include <map>
30#include <memory>
31
35#include "ApplicationStarter.h"
36#include "StopStrategy.h"
37
38namespace ScenarioManager
39{
40 class StatusManager;
41}
42
44{
45 class StopStrategy;
46 using StopStrategyPtr = std::shared_ptr<StopStrategy>;
47
48 /**
49 * @class Executor
50 * @ingroup exec
51 * @brief Starts, stops and restarts applications and scenarios.
52 * Can also be used to request the status of an application. The proper system-specific stopstrategy and starter have to be set in the constructor.
53 */
55 {
56
57 private:
58 StopStrategyPtr defaultStopStrategy;
59 ApplicationStarterPtr defaultStartStrategy;
60 std::map<Data_Structure::ScenarioPtr, StopStrategyPtr> stopStrategy;
61 std::map<Data_Structure::ScenarioPtr, ApplicationStarterPtr> starter;
62 StatusManager statusManager;
63
64
65 void asyncApplicationRestart(Data_Structure::ApplicationInstancePtr application,
66 bool printOnly);
67
68 void asyncScenarioStop(Data_Structure::ScenarioPtr scenario);
69 std::string asyncGetScenarioStatus(Data_Structure::ScenarioPtr scenario);
70 void asyncScenarioRestart(Data_Structure::ScenarioPtr scenario, bool printOnly);
71
72 public:
73 /**
74 * Constructor that sets StopStrategy and ApplicationStarter.
75 * @param strategy Strategy used to stop applications.
76 * @param starter Starter used to start applications and request their status.
77 */
79
80 /**
81 * Starts an application.
82 * @param application application to be started.
83 * @return {@code true} if the application was successfully started
84 */
85 std::future<void> startApplication(Data_Structure::ApplicationInstancePtr application,
86 bool printOnly = false,
87 const std::string& commandLineParameters = "");
88
89 /**
90 * Stops an application
91 * @param application application to be stopped
92 * @return {@code true} if the application was successfully stopped
93 */
94 std::future<void> stopApplication(Data_Structure::ApplicationInstancePtr application);
95
96 /**
97 * Restarts an application. Stops and starts an application.
98 * @param application application to be restarted
99 * @return {@code true} if the application was successfully restarted. Successfull restart requires successfull stop and successfull start.
100 * An already stopped application also counts as successfully restarted, if successfully started.
101 */
103 bool printOnly = false);
104
105 /**
106 * Returns the status of an application. Uses the ApplicationStarter to request the status, therefore the proper
107 * system-specific starter has to be set, even to use this method.
108 * @param application application whose status is returned
109 * @return status of the application
110 */
112
113 /**
114 * Starts a scenario. Iterates over the applications in the scenario and starts them.
115 * @param scenario scenario to be started
116 * @return {@code true} if all applications were successfully started
117 */
118 std::future<void> startScenario(Data_Structure::ScenarioPtr scenario,
119 bool printOnly = false,
120 const std::string& commandLineParameters = "");
121
122 /**
123 * Stops a scenario. Iterates over the applications in the scenario and stops them.
124 * @param scenario scenario to be stopped
125 * @return {@code true} if all applications were successfully stopped
126 */
127 std::future<void> stopScenario(Data_Structure::ScenarioPtr scenario);
128
129 /**
130 * Restarts a scenario. Iterates over the applications in the scenario and restarts them.
131 * @param scenario scenario to be restarted
132 * @return {@code true} if all applications were successfully restarted
133 */
134 std::future<void> restartScenario(Data_Structure::ScenarioPtr scenario,
135 bool printOnly = false);
136
137 /**
138 * Generates an XML file of the given application and saves it in the specified path.
139 * If there already is an XML file at that location it only reloads the file if the executable is more recently changed
140 * than the Xml file
141 * @param application Application whose XML file is to be generate
142 * @param path location to save the XML, must be a folder
143 * @param reload forces to reload the cached XML
144 * @param set if true the newly Cached Xml gets loaded into the Application (Warning: If you load an ApplicationInstance the cfg parameter have to be reloaded)
145 */
147 std::string path,
148 bool reload = false,
149 bool set = true);
150
151 /**
152 * Sets the strategy this Executor uses to stop applications. Needs to be system specific.
153 * Use the Factory-Classes to get the proper strategy for your system.
154 * @param strategy strategy to be set
155 * @see StopStrategyFactory
156 */
159
160 /**
161 * Sets the appStarter this Executor uses to start applications and request statuses. Needs to be system specific.
162 * Use the Factory-Classes to get the proper appStarter for your system.
163 * @param appStarter appStarter to be set
164 * @see StarterFactory
165 * @see StarterFactoryLinux
166 */
169
173 };
174
175 using ExecutorPtr = std::shared_ptr<Executor>;
176} // namespace ScenarioManager::Exec
StopStrategyPtr getStopStrategy(Data_Structure::ScenarioPtr scenario)
Definition Executor.cpp:326
std::future< void > startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false, const std::string &commandLineParameters="")
Starts a scenario.
Definition Executor.cpp:155
void setDefaultStarter(ApplicationStarterPtr appStarter)
Sets the appStarter this Executor uses to start applications and request statuses.
Definition Executor.cpp:298
void loadAndSetCachedProperties(Data_Structure::ApplicationPtr application, std::string path, bool reload=false, bool set=true)
Generates an XML file of the given application and saves it in the specified path.
Definition Executor.cpp:240
std::future< void > restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false)
Restarts an application.
Definition Executor.cpp:126
std::future< void > stopScenario(Data_Structure::ScenarioPtr scenario)
Stops a scenario.
Definition Executor.cpp:203
std::string getApplicationStatus(Data_Structure::ApplicationInstancePtr application)
Returns the status of an application.
Definition Executor.cpp:145
std::future< void > restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false)
Restarts a scenario.
Definition Executor.cpp:229
std::future< void > startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false, const std::string &commandLineParameters="")
Starts an application.
Definition Executor.cpp:49
Executor(StopStrategyPtr strategy, ApplicationStarterPtr starter)
Constructor that sets StopStrategy and ApplicationStarter.
Definition Executor.cpp:42
std::future< void > stopApplication(Data_Structure::ApplicationInstancePtr application)
Stops an application.
Definition Executor.cpp:80
void setDefaultStopStrategy(StopStrategyPtr strategy)
Sets the strategy this Executor uses to stop applications.
Definition Executor.cpp:292
StopStrategyPtr getDefaultStopStrategy()
Definition Executor.cpp:336
void setStarter(ApplicationStarterPtr appStarter, Data_Structure::ScenarioPtr scenario)
Definition Executor.cpp:310
ApplicationStarterPtr getStarter(Data_Structure::ScenarioPtr scenario)
Definition Executor.cpp:316
void setStopStrategy(StopStrategyPtr strategy, Data_Structure::ScenarioPtr scenario)
Definition Executor.cpp:304
Interface for classes that define how an application get stopped.
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< Application > ApplicationPtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< Executor > ExecutorPtr
Definition Executor.h:175
std::shared_ptr< StopStrategy > StopStrategyPtr
Definition Executor.h:46
std::shared_ptr< ApplicationStarter > ApplicationStarterPtr