SimpleStatechartExecutor.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package ArmarXCore::ArmarXObjects::SimpleSimpleStatechartExecutor
17  * @author Stefan Reither ( stefan dot reither at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 
27 #include <ArmarXCore/interface/components/SimpleStatechartExecutorInterface.h>
28 
29 #include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
32 
33 #include <condition_variable>
34 #include <mutex>
35 
36 
37 namespace armarx
38 {
39  /**
40  * @class SimpleStatechartExecutorPropertyDefinitions
41  * @brief
42  */
45  {
46  public:
49  {
50  defineOptionalProperty<std::string>("PackagesForVariantLibraries", "ArmarXCore, ArmarXGui, RobotAPI",
51  "Comma-seperated list of packages that are used for loading nessecary libraries for used variants");
52  };
53  };
54 
55 
56 
57  /**
58  * @defgroup Component-SimpleStatechartExecutor SimpleStatechartExecutor
59  * @ingroup ArmarXCore-Components
60  * This component provides an interface for executing and stopping statecharts without the need for
61  * the StatechartEditor. The proxy for the statechart-group containing the statechart to execute must already run.
62  *
63  * Only one state can run at any time from within this component, but it is possible
64  * to start more than one instance of this component.
65  *
66  * @class SimpleStatechartExecutor
67  * @ingroup Component-SimpleStatechartExecutor
68  * @brief This component provides interface functions to execute a statechart, stop the currently running
69  * statechart and provide the output-parameter of the statechart.
70  */
72  virtual public armarx::Component,
73  virtual public armarx::SimpleStatechartExecutorInterface
74  {
75 
76 
77  // SimpleStatechartExecutorInterface interface
78  public:
79  void ensureVariantLibrariesAreLoaded(const StateParameterMap& inputArguments, const Ice::Current&) override;
80  bool startStatechart(const std::string& proxyName, const std::string& stateName, const StateParameterMap& inputArguments, const Ice::Current&) override;
81  void stopImmediatly(const Ice::Current&) override;
82  bool hasExecutionFinished(const Ice::Current&) override;
83  StatechartExecutionResult waitUntilStatechartExecutionIsFinished(const Ice::Current&) override;
84  StringVariantContainerBaseMap getSetOutputParameters(const Ice::Current&) override;
85  StateParameterMap getOutputParameters(const Ice::Current&) override;
86  void preloadLibrariesFromHumanNames(const StringList& typeNames, const Ice::Current&) override;
87 
88  std::string getDefaultName() const override
89  {
90  return "SimpleStatechartExecutor";
91  }
92 
93  protected:
94  void onInitComponent() override;
95  void onConnectComponent() override;
96  void onExitComponent() override;
98 
99  private:
100  void statechartTask();
101  ContainerTypePtr checkIfLibraryNeedsToBeLoaded(const StateParameterIceBasePtr parameter) const;
102  bool isCurrentStateIdValid() const;
103 
104  bool _finished;
105  mutable std::mutex _finishedMutex;
106  mutable std::condition_variable _finishedCondition;
107  bool _aborted;
108 
109  StatechartExecutionResult _lastResult;
110  StateParameterMap _lastOutputParameters;
111 
113 
114  RemoteStateOffererInterfacePrx _prx;
115  int _currentStateId;
116 
117  Ice::StringSeq _packages;
118  VariantInfoPtr variantInfo;
119  std::map<std::string, DynamicLibraryPtr> _loadedDynamicLibraries;
120  };
121 }
armarx::SimpleStatechartExecutor::getSetOutputParameters
StringVariantContainerBaseMap getSetOutputParameters(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:143
armarx::SimpleStatechartExecutor::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: SimpleStatechartExecutor.h:88
armarx::SimpleStatechartExecutor::ensureVariantLibrariesAreLoaded
void ensureVariantLibrariesAreLoaded(const StateParameterMap &inputArguments, const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:32
armarx::SimpleStatechartExecutor::hasExecutionFinished
bool hasExecutionFinished(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:126
armarx::SimpleStatechartExecutor::stopImmediatly
void stopImmediatly(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:108
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
RunningTask.h
armarx::SimpleStatechartExecutor::startStatechart
bool startStatechart(const std::string &proxyName, const std::string &stateName, const StateParameterMap &inputArguments, const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:46
armarx::SimpleStatechartExecutor::preloadLibrariesFromHumanNames
void preloadLibrariesFromHumanNames(const StringList &typeNames, const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:169
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::SimpleStatechartExecutor::waitUntilStatechartExecutionIsFinished
StatechartExecutionResult waitUntilStatechartExecutionIsFinished(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:131
armarx::SimpleStatechartExecutorPropertyDefinitions::SimpleStatechartExecutorPropertyDefinitions
SimpleStatechartExecutorPropertyDefinitions(std::string prefix)
Definition: SimpleStatechartExecutor.h:47
armarx::SimpleStatechartExecutor::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: SimpleStatechartExecutor.cpp:191
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::SimpleStatechartExecutor::getOutputParameters
StateParameterMap getOutputParameters(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:156
armarx::SimpleStatechartExecutor
This component provides interface functions to execute a statechart, stop the currently running state...
Definition: SimpleStatechartExecutor.h:71
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
armarx::SimpleStatechartExecutor::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: SimpleStatechartExecutor.cpp:186
armarx::SimpleStatechartExecutor::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: SimpleStatechartExecutor.cpp:179
armarx::SimpleStatechartExecutor::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
Definition: SimpleStatechartExecutor.cpp:212
armarx::SimpleStatechartExecutorPropertyDefinitions
Definition: SimpleStatechartExecutor.h:43
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
ScenarioManager::Parser::StringList
std::vector< std::string > StringList
Definition: PackageBuilder.h:34
VariantInfo.h