RemoteStateWrapper.cpp
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#include "RemoteStateWrapper.h"
25
26#include "RemoteStateOfferer.h"
27
28namespace armarx
29{
30 ////////////////////////////////////////////////////////////////////////////////
31 //////////// RemoteStateWrapper
32 ////////////////////////////////////////////////////////////////////////////////
33
35 RemoteStateIceBasePrx const& callerStatePrx) :
37 {
38 stateName = "remoteStateWrapper_of_" + realState->stateName;
39 activeSubstate = realState;
40
42 {
43 ARMARX_IMPORTANT << "Calling callerStatePrx->getParentStateLayout() in " << stateName;
44 StateIceBasePtr remoteParentStateLayout;
45 try
46 {
47 remoteParentStateLayout = callerStatePrx->getParentStateLayout();
48 }
49 catch (Ice::ConnectFailedException const& e)
50 {
51 ARMARX_WARNING << "Ice connect failed, trying again in a little bit";
52 ::usleep(1000000);
53 remoteParentStateLayout = callerStatePrx->getParentStateLayout();
54 }
55
56 if (remoteParentStateLayout)
57 {
58 this->subStateList = remoteParentStateLayout->subStateList;
59 this->transitions = remoteParentStateLayout->transitions;
60 this->initState = remoteParentStateLayout->initState;
61 }
62 }
63 }
64
66 RemoteStateIceBasePrx const& callerStatePrx,
67 StateIceBasePtr const& remoteParentStateLayout) :
69 {
70 stateName = "remoteStateWrapper_of_" + realState->stateName;
71 activeSubstate = realState;
72
73 if (remoteParentStateLayout)
74 {
75 this->subStateList = remoteParentStateLayout->subStateList;
76 this->transitions = remoteParentStateLayout->transitions;
77 this->initState = remoteParentStateLayout->initState;
78 }
79 }
80
82 Shared(),
83 Ice::Object(source),
84 StateIceBase(source),
85 Logging(source),
86 StateBase(source),
87 StateController(source),
88 StateUtility(source),
89 State(source)
90
91 {
92 realState = StatePtr::dynamicCast(source.realState->clone());
93
94 if (source.realState && !realState)
95 {
97 "Could not cast from StateBasePtr to StatePtr");
98 }
99
100 callerStatePrx = source.callerStatePrx;
101 }
102
104 {
105 subStateList
106 .clear(); // clear this list here, so that RemoteStates are not removed in ~StateBase(). This sublist is just for information purposes
107 }
108
109 void
111 {
112 ARMARX_DEBUG << "calling remoteprocessbufferedevets"
113 << "" << flush;
114
115 //call remoteProcessBufferedEvents over ice
116 if (callerStatePrx._ptr)
117 {
118 callerStatePrx->begin_remoteProcessBufferedEvents();
119 }
120 }
121
122 void
124 {
125 // call substatesFinished over Ice
126 if (callerStatePrx)
127 {
128 callerStatePrx->remoteProcessEvent(ev, buffered);
129 }
130 else
131 {
132 ARMARX_INFO << "No remote state proxy was set - will not report back to remote state. "
133 "In case this is a toplevel state this is not an issue (Event: "
134 << ev->eventName << ")";
135 realState->_baseOnExit();
136 }
137 }
138
139 void
141 {
142 if (callerStatePrx._ptr)
143 {
144 callerStatePrx->begin_remoteEnqueueEvent(event);
145 }
146 }
147
148 unsigned int
150 {
151
152 if (callerStatePrx._ptr)
153 {
154 return callerStatePrx->getRemoteUnbreakableBufferSize();
155 }
156 else
157 {
158 return 0;
159 }
160 }
161
162 bool
164 {
165 if (callerStatePrx._ptr)
166 {
167 return callerStatePrx->getRemoteUnbreakableBufferStati();
168 }
169 else
170 {
171 return true;
172 }
173 }
174
175 void
177 {
178 //realState->baseOnExit();
179 ARMARX_INFO << "sending remote finalize " << realState._ptr << "";
180
181 if (callerStatePrx._ptr)
182 {
183 callerStatePrx->begin_remoteFinalize(
184 StateUtilFunctions::getSetValues(realState->getOutputParameters()), event);
185 }
186 }
187
190 {
191 StateBasePtr result = new RemoteStateWrapper(*this);
192 return result;
193 }
194
197 {
198 assert(0);
199 return new RemoteStateWrapper(nullptr, callerStatePrx);
200 }
201} // namespace armarx
Base Class for all Logging classes.
Definition Logging.h:240
This class is the implementation of the Slice Definition of a state.
Definition StateBase.h:60
The StateController class processes events and controls the statechart flow.
This class provides utility functions for statechart-implementing-users to communicate with other dis...
Definition StateUtil.h:47
friend class RemoteStateWrapper
Definition State.h:522
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
StringVariantContainerBaseMap getSetValues(const StateParameterMap &paramMap)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< State > StatePtr
Definition State.h:44
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< Event > EventPtr
Typedef of EventPtr as IceInternal::Handle<Event> for convenience.
Definition Event.h:40
IceInternal::Handle< StateBase > StateBasePtr
Definition StateBase.h:49
RemoteStateWrapper(StatePtr const &realState, RemoteStateIceBasePrx const &callerStatePrx)
void __enqueueEvent(const EventPtr event) override
StateBasePtr clone() const override
Pure virtual function to clone of the derived class type.
unsigned int __getUnbreakableBufferSize() const override
bool __getUnbreakableBufferStati() const override
Before:Function to get the unbreakable-buffer status of all parent state - recursively.
StateBasePtr createEmptyCopy() const override
RemoteStateIceBasePrx callerStatePrx
void __processEvent(const EventPtr event, bool buffered=false) override
Main function to control the statemachine/state.
void __processBufferedEvents() override
Processes buffered events, that could not be processed immediately due to unbreakable substates.
void __finalize(const EventPtr event) override
Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteState...