StatechartContext.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::Statechart
19* @author Mirko Waechter( mirko.waechter at kit dot edu)
20* @date 2012
21* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22* GNU General Public License
23*/
24#pragma once
25#ifndef _ARMARX_CORE_STATECHARTCONTEXT_H
26#define _ARMARX_CORE_STATECHARTCONTEXT_H
27
28
29#include <unordered_map>
30
31#include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
32#include <ArmarXCore/interface/observers/SystemObserverInterface.h>
33
34#include "../core/Component.h"
37
38namespace armarx
39{
40 class StatechartEventDistributor;
42
43 class State;
45
47
50
51 using StatechartProfilePtr = std::shared_ptr<class StatechartProfile>;
52
53 /**
54 * @brief The StatechartContextPropertyDefinitions class contains properties associated with all statecharts
55 */
61
62 /**
63 \class StatechartContext
64 \ingroup StatechartGrp
65 \brief This class contains a statechart and provides the interfaces to distributed components.
66
67 This class inherits from armarx::Component and should be the entry point for applications containing a statechart.
68 This class contains all the proxies to distributed components like the ConditionHandler
69 or the KinematicUnit.\n
70 This class should only be created once per application and the top-level state of this StatechartContext
71 should be set via armarx::StatechartContext::setToplevelState().
72
73 The StatechartContext is available from the State-implementations with
74 StateBase::getContext<StatechartContextType>().
75
76 If a statechart needs other proxies to Ice objects (\see armarx::ManagedIceObject), this class
77 needs to be subclassed and armarx::StatechartContext::onInitStatechartContext()
78 and armarx::StatechartContext::onConnectStatechartContext() reimplemented.
79 But keep in mind to call armarx::StatechartContext::onInitStatechartContext() and
80 armarx::StatechartContext::onConnectStatechartContext() (or the intermediate statechart context, from
81 which you are deriving) in your reimplentation.
82
83 \snippet
84 */
86 {
87 private:
88 // inherited from Component
89 void onInitComponent() override;
90 void onConnectComponent() override;
91 void onDisconnectComponent() override;
92 void onExitComponent() override;
93
94 protected:
95 /**
96 * @brief onInitStatechartonInitStatechartContext can be implemented by subclasses
97 *
98 * Override this method to specify required proxies and topics via armarx::Component::usingProxy(),
99 * armarx::Component::usingTopic() and armarx::Component::offeringTopic().
100 *
101 * This method is calle by armarx::StatechartContext::onInitComponent().
102 */
103 virtual void
107
108 /**
109 * @brief onConnectStatechartContext can be implemented by subclasses
110 *
111 * Override this method to retrieve the proxies and topics specified in armarx::StatechartContext::onInitStatechart()
112 * via armarx::Component::getProxy() and armarx::Component::getTopic().
113 *
114 * This method is called by armarx::StatechartContext::onConnectComponent().
115 */
116 virtual void
120
121 public:
123 ~StatechartContext() override;
124
125 /**
126 * @see PropertyUser::createPropertyDefinitions()
127 */
129
130 TimedVariantBaseList
131 getDataListFromObserver(std::string observerName,
132 const DataFieldIdentifierBaseList& identifierList) override;
134 ChannelRefPtr getChannelRef(const std::string& observerName,
135 const std::string& channelName) override;
136 DatafieldRefPtr getDatafieldRef(const DataFieldIdentifier& datafieldIdentifier) override;
138 const std::string& datafieldName) override;
139
140 //! use the Component::getIceManager() method in this object class
142
143 /**
144 * @brief setToplevelState initializes \p newToplevelState with the current StatechartContext and the current StatechartContext::statechartManager
145 * and sets \p newToplevelState as top-level state on the current StatechartContext::statechartManager.
146 * @param newToplevelState
147 * @param startParameters
148 * @return
149 */
150 bool setToplevelState(
151 const armarx::StatePtr& newToplevelState,
152 StringVariantContainerBaseMap startParameters = StringVariantContainerBaseMap());
153
154 /**
155 * @brief setAutoStartStatechart controls whether the toplevelstate is
156 * automatically entered, when the statechart manager is started,
157 * @param autostart
158 */
159 void setAutoEnterToplevelState(bool autoEnter);
160
161 void setReportingTopic(std::string reportingTopic);
162
163 /**
164 * @brief startStatechart actives both, the toplevel startchart stored
165 * in the variable statechart and the StatechartManager for handling
166 * eventprocessing.
167 */
168 void startStatechart();
169
170 /**
171 * @brief onInitStatechart this method is called when the statechart is started. \see armarx::RemoteStateOfferer
172 */
173 virtual void onInitStatechart() = 0;
174
175 /**
176 * @brief onConnectStatechart is called before armarx::StatechartContext::startStatechart() and after armarx::StatechartContext::onConnectStatechartContext()
177 */
178 virtual void onConnectStatechart() = 0;
179
180 /**
181 * @brief onExitStatechart can be implemented by subclasses
182 *
183 * Override this method to perform cleanup tasks when the statechart is left.
184 */
185 virtual void
187 {
188 }
189
190 std::unordered_map<std::string, ObserverInterfacePrx> observerMap;
191
192 /**
193 * The EventListenerInterface instance, that receives events from observers and redirects them to the correct states
194 */
197 ConditionHandlerInterfacePrx conditionHandlerPrx;
198 SystemObserverInterfacePrx systemObserverPrx;
199
200 protected:
203 std::string reportingTopic;
204 };
205
207
209 {
210 public:
212
213
214 protected:
216
217 private:
218 StatechartProfilePtr selectedStatechartProfile;
219 friend class XMLStateComponent;
220 };
221
222} // namespace armarx
223
224#endif
Default component property definition container.
Definition Component.h:70
Component()
Protected default constructor. Used for virtual inheritance. Use createManagedIceObject() instead.
Definition Component.cpp:66
DataFieldIdentifier provide the basis to identify data field within a distributed ArmarX scenario.
IceManagerPtr getIceManager() const
Returns the IceManager.
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Class that offers the main functionality needed to create a statechart.
Definition State.h:54
TimedVariantBaseList getDataListFromObserver(std::string observerName, const DataFieldIdentifierBaseList &identifierList) override
void startStatechart()
startStatechart actives both, the toplevel startchart stored in the variable statechart and the State...
VariantBasePtr getDataFromObserver(const DataFieldIdentifierBasePtr &identifier) override
void setAutoEnterToplevelState(bool autoEnter)
setAutoStartStatechart controls whether the toplevelstate is automatically entered,...
DatafieldRefPtr getDatafieldRef(const DataFieldIdentifier &datafieldIdentifier) override
std::unordered_map< std::string, ObserverInterfacePrx > observerMap
StatechartEventDistributorPtr eventDistributor
The EventListenerInterface instance, that receives events from observers and redirects them to the co...
bool setToplevelState(const armarx::StatePtr &newToplevelState, StringVariantContainerBaseMap startParameters=StringVariantContainerBaseMap())
setToplevelState initializes newToplevelState with the current StatechartContext and the current Stat...
virtual void onExitStatechart()
onExitStatechart can be implemented by subclasses
SystemObserverInterfacePrx systemObserverPrx
StatechartManagerPtr statechartManager
ConditionHandlerInterfacePrx conditionHandlerPrx
virtual void onInitStatechart()=0
onInitStatechart this method is called when the statechart is started.
PropertyDefinitionsPtr createPropertyDefinitions() override
virtual void onConnectStatechart()=0
onConnectStatechart is called before armarx::StatechartContext::startStatechart() and after armarx::S...
virtual void onInitStatechartContext()
onInitStatechartonInitStatechartContext can be implemented by subclasses
Profiler::ProfilerPtr stateReporter
ChannelRefPtr getChannelRef(const std::string &observerName, const std::string &channelName) override
void setReportingTopic(std::string reportingTopic)
virtual void onConnectStatechartContext()
onConnectStatechartContext can be implemented by subclasses
const StatechartProfilePtr & getSelectedStatechartProfile() const
void setSelectedStatechartProfile(const StatechartProfilePtr &value)
std::shared_ptr< Profiler > ProfilerPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< StatechartContext > StatechartContextPtr
IceInternal::Handle< DataFieldIdentifierBase > DataFieldIdentifierBasePtr
IceInternal::Handle< State > StatePtr
Definition State.h:44
IceInternal::Handle< ChannelRef > ChannelRefPtr
Definition ChannelRef.h:40
::std::vector<::armarx::DataFieldIdentifierBasePtr > DataFieldIdentifierBaseList
IceInternal::Handle< DatafieldRef > DatafieldRefPtr
Definition Observer.h:43
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
std::shared_ptr< class StatechartProfile > StatechartProfilePtr
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr
IceUtil::Handle< StatechartManager > StatechartManagerPtr
IceInternal::Handle< StatechartEventDistributor > StatechartEventDistributorPtr