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 "ApplicationStarter.h"
29 #include "../parser/StatusManager.h"
30 #include "../data_structure/ApplicationInstance.h"
31 #include "../data_structure/Scenario.h"
32 #include "StopStrategy.h"
33 #include "ApplicationStarter.h"
34 #include <memory>
35 #include <future>
36 #include <map>
37 
38 namespace ScenarioManager
39 {
40  class StatusManager;
41 }
42 
43 namespace ScenarioManager::Exec
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  */
54  class Executor
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, bool printOnly);
66 
67  void asyncScenarioStop(Data_Structure::ScenarioPtr scenario);
68  std::string asyncGetScenarioStatus(Data_Structure::ScenarioPtr scenario);
69  void asyncScenarioRestart(Data_Structure::ScenarioPtr scenario, bool printOnly);
70 
71  public:
72  /**
73  * Constructor that sets StopStrategy and ApplicationStarter.
74  * @param strategy Strategy used to stop applications.
75  * @param starter Starter used to start applications and request their status.
76  */
78 
79  /**
80  * Starts an application.
81  * @param application application to be started.
82  * @return {@code true} if the application was successfully started
83  */
84  std::future<void> startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly = false, const std::string& commandLineParameters = "");
85 
86  /**
87  * Stops an application
88  * @param application application to be stopped
89  * @return {@code true} if the application was successfully stopped
90  */
91  std::future<void> stopApplication(Data_Structure::ApplicationInstancePtr application);
92 
93  /**
94  * Restarts an application. Stops and starts an application.
95  * @param application application to be restarted
96  * @return {@code true} if the application was successfully restarted. Successfull restart requires successfull stop and successfull start.
97  * An already stopped application also counts as successfully restarted, if successfully started.
98  */
99  std::future<void> restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly = false);
100 
101  /**
102  * Returns the status of an application. Uses the ApplicationStarter to request the status, therefore the proper
103  * system-specific starter has to be set, even to use this method.
104  * @param application application whose status is returned
105  * @return status of the application
106  */
108 
109  /**
110  * Starts a scenario. Iterates over the applications in the scenario and starts them.
111  * @param scenario scenario to be started
112  * @return {@code true} if all applications were successfully started
113  */
114  std::future<void> startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly = false, const std::string& commandLineParameters = "");
115 
116  /**
117  * Stops a scenario. Iterates over the applications in the scenario and stops them.
118  * @param scenario scenario to be stopped
119  * @return {@code true} if all applications were successfully stopped
120  */
121  std::future<void> stopScenario(Data_Structure::ScenarioPtr scenario);
122 
123  /**
124  * Restarts a scenario. Iterates over the applications in the scenario and restarts them.
125  * @param scenario scenario to be restarted
126  * @return {@code true} if all applications were successfully restarted
127  */
128  std::future<void> restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly = false);
129 
130  /**
131  * Generates an XML file of the given application and saves it in the specified path.
132  * If there already is an XML file at that location it only reloads the file if the executable is more recently changed
133  * than the Xml file
134  * @param application Application whose XML file is to be generate
135  * @param path location to save the XML, must be a folder
136  * @param reload forces to reload the cached XML
137  * @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)
138  */
139  void loadAndSetCachedProperties(Data_Structure::ApplicationPtr application, std::string path, bool reload = false, bool set = true);
140 
141  /**
142  * Sets the strategy this Executor uses to stop applications. Needs to be system specific.
143  * Use the Factory-Classes to get the proper strategy for your system.
144  * @param strategy strategy to be set
145  * @see StopStrategyFactory
146  */
149 
150  /**
151  * Sets the appStarter this Executor uses to start applications and request statuses. Needs to be system specific.
152  * Use the Factory-Classes to get the proper appStarter for your system.
153  * @param appStarter appStarter to be set
154  * @see StarterFactory
155  * @see StarterFactoryLinux
156  */
157  void setDefaultStarter(ApplicationStarterPtr appStarter);
159 
163  };
164  using ExecutorPtr = std::shared_ptr<Executor>;
165 }
ScenarioManager::Exec::Executor::setStopStrategy
void setStopStrategy(StopStrategyPtr strategy, Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:255
ScenarioManager::Exec::Executor::setDefaultStopStrategy
void setDefaultStopStrategy(StopStrategyPtr strategy)
Sets the strategy this Executor uses to stop applications.
Definition: Executor.cpp:246
ScenarioManager::Exec::Executor
Starts, stops and restarts applications and scenarios. Can also be used to request the status of an a...
Definition: Executor.h:54
ScenarioManager::Data_Structure::ApplicationInstancePtr
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
Definition: ApplicationInstance.h:33
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
ScenarioManager::Exec::Executor::getStarter
ApplicationStarterPtr getStarter(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:265
ScenarioManager::Exec::Executor::restartApplication
std::future< void > restartApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false)
Restarts an application.
Definition: Executor.cpp:108
ScenarioManager::Exec
Definition: ApplicationStarter.h:35
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:119
ScenarioManager::Exec::Executor::stopApplication
std::future< void > stopApplication(Data_Structure::ApplicationInstancePtr application)
Stops an application.
Definition: Executor.cpp:68
ScenarioManager::Exec::StopStrategyPtr
std::shared_ptr< StopStrategy > StopStrategyPtr
Definition: Executor.h:46
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:164
ScenarioManager::Exec::Executor::startApplication
std::future< void > startApplication(Data_Structure::ApplicationInstancePtr application, bool printOnly=false, const std::string &commandLineParameters="")
Starts an application.
Definition: Executor.cpp:45
ScenarioManager::Exec::Executor::getApplicationStatus
std::string getApplicationStatus(Data_Structure::ApplicationInstancePtr application)
Returns the status of an application.
Definition: Executor.cpp:125
ScenarioManager::Exec::Executor::stopScenario
std::future< void > stopScenario(Data_Structure::ScenarioPtr scenario)
Stops a scenario.
Definition: Executor.cpp:173
StopStrategy.h
ScenarioManager::Exec::Executor::getStopStrategy
StopStrategyPtr getStopStrategy(Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:274
ScenarioManager::Exec::Executor::setDefaultStarter
void setDefaultStarter(ApplicationStarterPtr appStarter)
Sets the appStarter this Executor uses to start applications and request statuses.
Definition: Executor.cpp:250
ScenarioManager::StatusManager
Definition: StatusManager.h:7
ScenarioManager::Exec::ApplicationStarterPtr
std::shared_ptr< ApplicationStarter > ApplicationStarterPtr
Definition: ApplicationStarter.h:64
ScenarioManager
Definition: Application.cpp:166
set
set(LIBS ArmarXCoreInterfaces ${CMAKE_THREAD_LIBS_INIT} ${dl_LIBRARIES} ${rt_LIBRARIES} ${QT_LIBRARIES} ${Boost_LIBRARIES} BoostAssertionHandler ArmarXCPPUtility SimoxUtility) set(LIB_FILES ArmarXManager.cpp ArmarXMultipleObjectsScheduler.cpp ArmarXObjectScheduler.cpp ManagedIceObject.cpp ManagedIceObjectPlugin.cpp Component.cpp ComponentPlugin.cpp IceGridAdmin.cpp ArmarXObjectObserver.cpp IceManager.cpp PackagePath.cpp RemoteReferenceCount.cpp logging/LoggingUtil.cpp logging/Logging.cpp logging/LogSender.cpp logging/ArmarXLogBuf.cpp system/ArmarXDataPath.cpp system/DynamicLibrary.cpp system/ProcessWatcher.cpp system/FactoryCollectionBase.cpp system/cmake/CMakePackageFinder.cpp system/cmake/CMakePackageFinderCache.cpp system/cmake/ArmarXPackageToolInterface.cpp system/RemoteObjectNode.cpp services/sharedmemory/HardwareId.cpp services/tasks/RunningTask.cpp services/tasks/ThreadList.cpp services/tasks/ThreadPool.cpp services/profiler/Profiler.cpp services/profiler/FileLoggingStrategy.cpp services/profiler/IceLoggingStrategy.cpp application/Application.cpp application/ApplicationOptions.cpp application/ApplicationProcessFacet.cpp application/ApplicationNetworkStats.cpp application/properties/PropertyUser.cpp application/properties/Property.cpp application/properties/PropertyDefinition.cpp application/properties/PropertyDefinitionContainer.cpp application/properties/PropertyDefinitionHelpFormatter.cpp application/properties/PropertyDefinitionConfigFormatter.cpp application/properties/PropertyDefinitionBriefHelpFormatter.cpp application/properties/PropertyDefinitionXmlFormatter.cpp application/properties/PropertyDefinitionDoxygenFormatter.cpp application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.cpp application/properties/PropertyDefinitionContainerBriefHelpFormatter.cpp application/properties/IceProperties.cpp exceptions/Exception.cpp exceptions/local/UnexpectedEnumValueException.cpp util/FileSystemPathBuilder.cpp util/StringHelpers.cpp util/IceReportSkipper.cpp util/Throttler.cpp util/distributed/AMDCallbackCollection.cpp util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.cpp util/distributed/RemoteHandle/RemoteHandle.cpp util/distributed/RemoteHandle/RemoteHandleControlBlock.cpp time/ice_conversions.cpp time/json_conversions.cpp time/CallbackWaitLock.cpp time/Clock.cpp time/ClockType.cpp time/ClockTypeNames.cpp time/CycleUtil.cpp time/DateTime.cpp time/Duration.cpp time/Frequency.cpp time/LocalTimeServer.cpp time/Metronome.cpp time/ScopedStopWatch.cpp time/StopWatch.cpp time/Timer.cpp time/TimeKeeper.cpp time/TimeUtil.cpp csv/CsvWriter.cpp csv/CsvReader.cpp eigen/conversions.cpp eigen/ice_conversions.cpp) set(LIB_HEADERS ArmarXManager.h ArmarXDummyManager.h ArmarXMultipleObjectsScheduler.h ArmarXObjectObserver.h ArmarXObjectScheduler.h ArmarXFwd.h Component.h ComponentPlugin.h ComponentFactories.h CoreObjectFactories.h IceGridAdmin.h IceManager.h IceManagerImpl.h json_conversions.h ManagedIceObject.h ManagedIceObjectPlugin.h ManagedIceObjectImpl.h ManagedIceObjectDependency.h ManagedIceObjectRegistryInterface.h PackagePath.h RemoteReferenceCount.h system/ImportExport.h system/ImportExportComponent.h system/AbstractFactoryMethod.h system/FactoryCollectionBase.h system/Synchronization.h system/ArmarXDataPath.h system/DynamicLibrary.h system/ProcessWatcher.h system/ConditionSynchronization.h system/cmake/CMakePackageFinder.h system/cmake/CMakePackageFinderCache.h system/cmake/FindPackageX.cmake system/cmake/ArmarXPackageToolInterface.h system/RemoteObjectNode.h logging/LoggingUtil.h logging/LogSender.h logging/Logging.h logging/ArmarXLogBuf.h logging/SpamFilterData.h services/tasks/RunningTask.h services/tasks/PeriodicTask.h services/tasks/ThreadList.h services/tasks/TaskUtil.h services/tasks/ThreadPool.h services/sharedmemory/SharedMemoryProvider.h services/sharedmemory/SharedMemoryConsumer.h services/sharedmemory/IceSharedMemoryProvider.h services/sharedmemory/IceSharedMemoryConsumer.h services/sharedmemory/HardwareIdentifierProvider.h services/sharedmemory/HardwareId.h services/sharedmemory/exceptions/SharedMemoryExceptions.h services/profiler/Profiler.h services/profiler/LoggingStrategy.h services/profiler/FileLoggingStrategy.h services/profiler/IceLoggingStrategy.h application/Application.h application/ApplicationOptions.h application/ApplicationProcessFacet.h application/ApplicationNetworkStats.h application/properties/forward_declarations.h application/properties/Properties.h application/properties/Property.h application/properties/PluginEigen.h application/properties/PluginEnumNames.h application/properties/PluginCfgStruct.h application/properties/PluginAll.h application/properties/PropertyUser.h application/properties/PropertyDefinition.h application/properties/PropertyDefinition.hpp application/properties/PropertyDefinitionInterface.h application/properties/PropertyDefinitionContainer.h application/properties/PropertyDefinitionFormatter.h application/properties/PropertyDefinitionContainerFormatter.h application/properties/PropertyDefinitionConfigFormatter.h application/properties/PropertyDefinitionHelpFormatter.h application/properties/PropertyDefinitionBriefHelpFormatter.h application/properties/PropertyDefinitionXmlFormatter.h application/properties/PropertyDefinitionDoxygenFormatter.h application/properties/PropertyDefinitionDoxygenComponentPagesFormatter.h application/properties/PropertyDefinitionContainerBriefHelpFormatter.h application/properties/ProxyPropertyDefinition.h application/properties/IceProperties.h exceptions/Exception.h exceptions/LocalException.h exceptions/local/DynamicLibraryException.h exceptions/local/ExpressionException.h exceptions/local/FileIOException.h exceptions/local/InvalidPropertyValueException.h exceptions/local/MissingRequiredPropertyException.h exceptions/local/PropertyInheritanceCycleException.h exceptions/local/ProxyNotInitializedException.h exceptions/local/UnexpectedEnumValueException.h exceptions/local/UnmappedValueException.h exceptions/local/ValueRangeExceededException.h exceptions/user/NotImplementedYetException.h rapidxml/rapidxml.hpp rapidxml/rapidxml_print.hpp rapidxml/rapidxml_iterators.hpp rapidxml/rapidxml_utils.hpp rapidxml/wrapper/RapidXmlReader.h rapidxml/wrapper/RapidXmlWriter.h rapidxml/wrapper/DefaultRapidXmlReader.h rapidxml/wrapper/MultiNodeRapidXMLReader.h util/IceBlobToObject.h util/ObjectToIceBlob.h util/FileSystemPathBuilder.h util/FiniteStateMachine.h util/StringHelpers.h util/StringHelperTemplates.h util/algorithm.h util/OnScopeExit.h util/Predicates.h util/Preprocessor.h util/PropagateConst.h util/Registrar.h util/TemplateMetaProgramming.h util/TripleBuffer.h util/IceReportSkipper.h util/Throttler.h util/distributed/AMDCallbackCollection.h util/distributed/RemoteHandle/ClientSideRemoteHandleControlBlock.h util/distributed/RemoteHandle/RemoteHandle.h util/distributed/RemoteHandle/RemoteHandleControlBlock.h util/SimpleStatemachine.h time.h time_minimal.h time/forward_declarations.h time/ice_conversions.h time/json_conversions.h time/CallbackWaitLock.h time/Clock.h time/ClockType.h time/ClockTypeNames.h time/CycleUtil.h time/DateTime.h time/Duration.h time/Frequency.h time/LocalTimeServer.h time/Metronome.h time/ScopedStopWatch.h time/StopWatch.h time/Timer.h time/TimeUtil.h time/TimeKeeper.h csv/CsvWriter.h csv/CsvReader.h eigen/conversions.h eigen/ice_conversions.h ice_conversions.h ice_conversions/ice_conversions_boost_templates.h ice_conversions/ice_conversions_templates.h ice_conversions/ice_conversions_templates.tpp $
Definition: CMakeLists.txt:12
ApplicationStarter.h
ScenarioManager::Exec::Executor::setStarter
void setStarter(ApplicationStarterPtr appStarter, Data_Structure::ScenarioPtr scenario)
Definition: Executor.cpp:260
ScenarioManager::Exec::Executor::Executor
Executor(StopStrategyPtr strategy, ApplicationStarterPtr starter)
Constructor that sets StopStrategy and ApplicationStarter.
Definition: Executor.cpp:39
ScenarioManager::Exec::Executor::getDefaultStopStrategy
StopStrategyPtr getDefaultStopStrategy()
Definition: Executor.cpp:283
ScenarioManager::Exec::Executor::restartScenario
std::future< void > restartScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false)
Restarts a scenario.
Definition: Executor.cpp:196
ScenarioManager::Exec::Executor::loadAndSetCachedProperties
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:205
ScenarioManager::Exec::Executor::startScenario
std::future< void > startScenario(Data_Structure::ScenarioPtr scenario, bool printOnly=false, const std::string &commandLineParameters="")
Starts a scenario.
Definition: Executor.cpp:134