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 "RemoteStateOfferer.h"
25 #include "RemoteStateWrapper.h"
26 
27 namespace armarx
28 {
29  ////////////////////////////////////////////////////////////////////////////////
30  //////////// RemoteStateWrapper
31  ////////////////////////////////////////////////////////////////////////////////
32 
34  RemoteStateIceBasePrx const& callerStatePrx):
35  callerStatePrx(callerStatePrx),
36  realState(realState)
37  {
38  stateName = "remoteStateWrapper_of_" + realState->stateName;
39  activeSubstate = realState;
40 
41  if (callerStatePrx)
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)
68  : callerStatePrx(callerStatePrx)
69  , realState(realState)
70  {
71  stateName = "remoteStateWrapper_of_" + realState->stateName;
72  activeSubstate = realState;
73 
74  if (remoteParentStateLayout)
75  {
76  this->subStateList = remoteParentStateLayout->subStateList;
77  this->transitions = remoteParentStateLayout->transitions;
78  this->initState = remoteParentStateLayout->initState;
79  }
80  }
81 
83  Shared(),
84  Ice::Object(source),
85  StateIceBase(source),
86  Logging(source),
90  State(source)
91 
92  {
93  realState = StatePtr::dynamicCast(source.realState->clone());
94 
95  if (source.realState && !realState)
96  {
97  throw exceptions::local::eNullPointerException("Could not cast from StateBasePtr to StatePtr");
98  }
99 
100  callerStatePrx = source.callerStatePrx;
101  }
102 
104  {
105  subStateList.clear(); // clear this list here, so that RemoteStates are not removed in ~StateBase(). This sublist is just for information purposes
106  }
107 
108  void
110  {
111  ARMARX_DEBUG << "calling remoteprocessbufferedevets" << "" << flush;
112 
113  //call remoteProcessBufferedEvents over ice
114  if (callerStatePrx._ptr)
115  {
116  callerStatePrx->begin_remoteProcessBufferedEvents();
117  }
118  }
119 
120 
121 
122  void RemoteStateWrapper::__processEvent(const EventPtr ev, bool buffered)
123  {
124  // call substatesFinished over Ice
125  if (callerStatePrx)
126  {
127  callerStatePrx->remoteProcessEvent(ev, buffered);
128  }
129  else
130  {
131  ARMARX_INFO << "No remote state proxy was set - will not report back to remote state. In case this is a toplevel state this is not an issue (Event: " << ev->eventName << ")";
132  realState->_baseOnExit();
133  }
134  }
135 
137  {
138  if (callerStatePrx._ptr)
139  {
140  callerStatePrx->begin_remoteEnqueueEvent(event);
141  }
142 
143  }
144 
145  unsigned int
147  {
148 
149  if (callerStatePrx._ptr)
150  {
151  return callerStatePrx->getRemoteUnbreakableBufferSize();
152  }
153  else
154  {
155  return 0;
156  }
157  }
158 
160  {
161  if (callerStatePrx._ptr)
162  {
163  return callerStatePrx->getRemoteUnbreakableBufferStati();
164  }
165  else
166  {
167  return true;
168  }
169  }
170 
171 
173  {
174  //realState->baseOnExit();
175  ARMARX_INFO << "sending remote finalize " << realState._ptr << "";
176 
177  if (callerStatePrx._ptr)
178  {
179  callerStatePrx->begin_remoteFinalize(StateUtilFunctions::getSetValues(realState->getOutputParameters()), event);
180  }
181  }
182 
184  {
185  StateBasePtr result = new RemoteStateWrapper(*this);
186  return result;
187  }
188 
190  {
191  assert(0);
192  return new RemoteStateWrapper(nullptr, callerStatePrx);
193  }
194 }
armarx::RemoteStateWrapper::clone
StateBasePtr clone() const override
Pure virtual function to clone of the derived class type.
Definition: RemoteStateWrapper.cpp:183
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::RemoteStateWrapper
Definition: RemoteStateWrapper.h:50
armarx::StateController
Definition: StateController.h:55
RemoteStateWrapper.h
armarx::RemoteStateWrapper::__getUnbreakableBufferSize
unsigned int __getUnbreakableBufferSize() const override
Definition: RemoteStateWrapper.cpp:146
armarx::exceptions::local::eNullPointerException
Definition: Exception.h:42
armarx::RemoteStateWrapper::__processBufferedEvents
void __processBufferedEvents() override
Processes buffered events, that could not be processed immediately due to unbreakable substates.
Definition: RemoteStateWrapper.cpp:109
IceInternal::Handle< State >
armarx::RemoteStateWrapper::callerStatePrx
RemoteStateIceBasePrx callerStatePrx
Definition: RemoteStateWrapper.h:53
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::RemoteStateWrapper::~RemoteStateWrapper
~RemoteStateWrapper() override
Definition: RemoteStateWrapper.cpp:103
armarx::RemoteStateWrapper::__getUnbreakableBufferStati
bool __getUnbreakableBufferStati() const override
Before:Function to get the unbreakable-buffer status of all parent state - recursively.
Definition: RemoteStateWrapper.cpp:159
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::State
Definition: State.h:54
armarx::RemoteStateWrapper::__processEvent
void __processEvent(const EventPtr event, bool buffered=false) override
Main function to control the statemachine/state.
Definition: RemoteStateWrapper.cpp:122
armarx::StateBase
Definition: StateBase.h:61
armarx::RemoteStateWrapper::realState
StatePtr realState
Definition: RemoteStateWrapper.h:54
armarx::StateUtility
Definition: StateUtil.h:47
Ice
Definition: DBTypes.cpp:64
armarx::Logging
Base Class for all Logging classes.
Definition: Logging.h:232
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::RemoteStateWrapper::__finalize
void __finalize(const EventPtr event) override
Function that gets called, when a state enters a FinalSubstate. Virtual function, so that RemoteState...
Definition: RemoteStateWrapper.cpp:172
armarx::StateUtilFunctions::getSetValues
StringVariantContainerBaseMap getSetValues(const StateParameterMap &paramMap)
Definition: StateUtilFunctions.cpp:54
armarx::RemoteStateWrapper::createEmptyCopy
StateBasePtr createEmptyCopy() const override
Definition: RemoteStateWrapper.cpp:189
RemoteStateOfferer.h
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RemoteStateWrapper::__enqueueEvent
void __enqueueEvent(const EventPtr event) override
Definition: RemoteStateWrapper.cpp:136
armarx::RemoteStateWrapper::RemoteStateWrapper
RemoteStateWrapper(StatePtr const &realState, RemoteStateIceBasePrx const &callerStatePrx)
Definition: RemoteStateWrapper.cpp:33