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
35namespace armarx
36{
37 /**
38 * @class SimpleStatechartExecutorPropertyDefinitions
39 * @brief
40 */
42 {
43 public:
46 {
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
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
This component provides interface functions to execute a statechart, stop the currently running state...
void onInitComponent() override
Pure virtual hook for the subclass.
StringVariantContainerBaseMap getSetOutputParameters(const Ice::Current &) override
bool hasExecutionFinished(const Ice::Current &) override
StateParameterMap getOutputParameters(const Ice::Current &) override
void ensureVariantLibrariesAreLoaded(const StateParameterMap &inputArguments, const Ice::Current &) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
bool startStatechart(const std::string &proxyName, const std::string &stateName, const StateParameterMap &inputArguments, const Ice::Current &) override
void onConnectComponent() override
Pure virtual hook for the subclass.
StatechartExecutionResult waitUntilStatechartExecutionIsFinished(const Ice::Current &) override
void preloadLibrariesFromHumanNames(const StringList &typeNames, const Ice::Current &) override
void onExitComponent() override
Hook for subclass.
std::string getDefaultName() const override
Retrieve default name of component.
void stopImmediatly(const Ice::Current &) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition VariantInfo.h:39