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 
26 #include <condition_variable>
27 #include <mutex>
28 
31 #include <ArmarXCore/interface/components/SimpleStatechartExecutorInterface.h>
32 #include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
34 
35 namespace armarx
36 {
37  /**
38  * @class SimpleStatechartExecutorPropertyDefinitions
39  * @brief
40  */
42  {
43  public:
46  {
47  defineOptionalProperty<std::string>(
48  "PackagesForVariantLibraries",
49  "ArmarXCore, ArmarXGui, RobotAPI",
50  "Comma-seperated list of packages that are used for loading nessecary libraries "
51  "for used variants");
52  };
53  };
54 
55  /**
56  * @defgroup Component-SimpleStatechartExecutor SimpleStatechartExecutor
57  * @ingroup ArmarXCore-Components
58  * This component provides an interface for executing and stopping statecharts without the need for
59  * the StatechartEditor. The proxy for the statechart-group containing the statechart to execute must already run.
60  *
61  * Only one state can run at any time from within this component, but it is possible
62  * to start more than one instance of this component.
63  *
64  * @class SimpleStatechartExecutor
65  * @ingroup Component-SimpleStatechartExecutor
66  * @brief This component provides interface functions to execute a statechart, stop the currently running
67  * statechart and provide the output-parameter of the statechart.
68  */
70  virtual public armarx::Component,
71  virtual public armarx::SimpleStatechartExecutorInterface
72  {
73 
74 
75  // SimpleStatechartExecutorInterface interface
76  public:
77  void ensureVariantLibrariesAreLoaded(const StateParameterMap& inputArguments,
78  const Ice::Current&) override;
79  bool startStatechart(const std::string& proxyName,
80  const std::string& stateName,
81  const StateParameterMap& inputArguments,
82  const Ice::Current&) override;
83  void stopImmediatly(const Ice::Current&) override;
84  bool hasExecutionFinished(const Ice::Current&) override;
85  StatechartExecutionResult
86  waitUntilStatechartExecutionIsFinished(const Ice::Current&) override;
87  StringVariantContainerBaseMap getSetOutputParameters(const Ice::Current&) override;
88  StateParameterMap getOutputParameters(const Ice::Current&) override;
89  void preloadLibrariesFromHumanNames(const StringList& typeNames,
90  const Ice::Current&) override;
91 
92  std::string
93  getDefaultName() const override
94  {
95  return "SimpleStatechartExecutor";
96  }
97 
98  protected:
99  void onInitComponent() override;
100  void onConnectComponent() override;
101  void onExitComponent() override;
103 
104  private:
105  void statechartTask();
106  ContainerTypePtr
107  checkIfLibraryNeedsToBeLoaded(const StateParameterIceBasePtr parameter) const;
108  bool isCurrentStateIdValid() const;
109 
110  bool _finished;
111  mutable std::mutex _finishedMutex;
112  mutable std::condition_variable _finishedCondition;
113  bool _aborted;
114 
115  StatechartExecutionResult _lastResult;
116  StateParameterMap _lastOutputParameters;
117 
119 
120  RemoteStateOffererInterfacePrx _prx;
121  int _currentStateId;
122 
123  Ice::StringSeq _packages;
124  VariantInfoPtr variantInfo;
125  std::map<std::string, DynamicLibraryPtr> _loadedDynamicLibraries;
126  };
127 } // namespace armarx
armarx::SimpleStatechartExecutor::getSetOutputParameters
StringVariantContainerBaseMap getSetOutputParameters(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:161
armarx::SimpleStatechartExecutor::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: SimpleStatechartExecutor.h:93
armarx::SimpleStatechartExecutor::ensureVariantLibrariesAreLoaded
void ensureVariantLibrariesAreLoaded(const StateParameterMap &inputArguments, const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:34
armarx::SimpleStatechartExecutor::hasExecutionFinished
bool hasExecutionFinished(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:142
armarx::SimpleStatechartExecutor::stopImmediatly
void stopImmediatly(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:123
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
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:52
armarx::SimpleStatechartExecutor::preloadLibrariesFromHumanNames
void preloadLibrariesFromHumanNames(const StringList &typeNames, const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:189
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::SimpleStatechartExecutor::waitUntilStatechartExecutionIsFinished
StatechartExecutionResult waitUntilStatechartExecutionIsFinished(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:148
armarx::SimpleStatechartExecutorPropertyDefinitions::SimpleStatechartExecutorPropertyDefinitions
SimpleStatechartExecutorPropertyDefinitions(std::string prefix)
Definition: SimpleStatechartExecutor.h:44
armarx::SimpleStatechartExecutor::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: SimpleStatechartExecutor.cpp:216
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:91
armarx::SimpleStatechartExecutor::getOutputParameters
StateParameterMap getOutputParameters(const Ice::Current &) override
Definition: SimpleStatechartExecutor.cpp:175
armarx::SimpleStatechartExecutor
This component provides interface functions to execute a statechart, stop the currently running state...
Definition: SimpleStatechartExecutor.h:69
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
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:210
armarx::SimpleStatechartExecutor::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: SimpleStatechartExecutor.cpp:201
armarx::SimpleStatechartExecutor::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Creates the property definition container.
Definition: SimpleStatechartExecutor.cpp:238
armarx::SimpleStatechartExecutorPropertyDefinitions
Definition: SimpleStatechartExecutor.h:41
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
ScenarioManager::Parser::StringList
std::vector< std::string > StringList
Definition: PackageBuilder.h:35
VariantInfo.h