RemoteState.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 
26 
27 // Statechart Includes
28 #include "StateBase.h"
29 #include "State.h"
30 #include "StateController.h"
31 #include "StatechartContext.h"
32 #include <ArmarXCore/interface/statechart/RemoteStateIce.h>
33 #include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
34 
35 
36 // ArmarX Includes
38 
39 
40 namespace armarx
41 {
42 
43  DEFINEEVENT(EvConnectionLost)
44 
45  class RemoteState;
46 
48 
49  /**
50  \class RemoteState
51  \ingroup StatechartGrp
52  \brief This Statetype is used to create a state instance that represents a state that is located in another application.
53  It is added in a parent state by calling State::addRemoteState(statename, proxyname).<br/>
54  If a RemoteState is entered for the <b>first</b> time, it creates automatically a new instance
55  at the remotely located RemoteStateOfferer that contains the real state. The RemoteState receives
56  upon creation of the new real-state instance an unique id of this state for further communication.<br/>
57  This id is automatically used in the onBreak- and onExit-functions, to communicate with the correct state.<br/>
58  Except the state creation-call (which should return immediately) all remote procedure calls are async calls.
59 
60  @see RemoteStateOfferer
61  */
62  class RemoteState :
63  virtual public RemoteStateIceBase,
64  virtual public State,
65  virtual public ManagedIceObject
66 
67  {
68  //! Proxy to this component that is sent to the state that this RemoteState is representing
69  RemoteStateIceBasePrx myProxy;
70 
71  //! Proxy to the state that this state is communicating with.
72  RemoteStateOffererIceBasePrx stateOffererPrx;
73  //! not used at the moment
74 
75  protected:
76  //! Overridden function to redirect this call to the real state in the other application.
77  bool __hasSubstates() override;
78  //! Overridden function to redirect this call to the real state in the other application.
79  bool __hasActiveSubstate() override;
80  //! Overridden function to redirect this call to the real state in the other application.
81  bool __breakActiveSubstate(const EventPtr event) override;
82  //! Overridden function to redirect this call to the real state in the other application.
83  void _baseOnEnter() override;
84  /*! \brief Called by processEvent()-function or parentstate. Must NOT be called by user.
85 
86  Calls OnBreak() in this hierarchylevel and all sub levels.
87  */
88  bool _baseOnBreak(const EventPtr evt) override;
89  //! Overridden function to redirect this call to the real state in the other application.
90  void _baseOnExit() override;
91  //void deepCopy(const StateBasePtr sourceState, bool reset = true);
92  //! Overridden function to redirect this call to the real state in the other application.
93  void __notifyEventBufferedDueToUnbreakableState(bool eventBuffered) override;
94 
95  void refetchSubstates() override;
96 
97  void __updateGlobalStateIdRecursive() override;
98 
99  public:
100  RemoteState();
103  ~RemoteState() override;
104 
105  void setStateName(const std::string& stateName);
106  void setProxyName(const std::string& proxyName);
107 
108  StateBasePtr clone() const override ;
109  StateBasePtr createEmptyCopy() const override;
110  // inherited from Component
111  std::string getDefaultName() const override;
112  void onInitComponent() override;
113  void onConnectComponent() override;
114  void onDisconnectComponent() override;
115 
116  void setOutput(const::armarx::StringVariantContainerBaseMap& properties, const::Ice::Current& c = Ice::emptyCurrent);
117  void remoteProcessBufferedEvents(const ::Ice::Current& c = Ice::emptyCurrent) override;
118  void remoteProcessEvent(const EventBasePtr& evt, bool buffered, const ::Ice::Current& c = Ice::emptyCurrent) override;
119  void remoteEnqueueEvent(const EventBasePtr& evt, const ::Ice::Current& c = Ice::emptyCurrent) override;
120  void remoteFinalize(const StringVariantContainerBaseMap& properties, const EventBasePtr& event, const ::Ice::Current& c = Ice::emptyCurrent) override;
121  void remoteRefetchSubstates(const ::Ice::Current& c = Ice::emptyCurrent);
122  ::Ice::Int getRemoteUnbreakableBufferSize(const ::Ice::Current& = Ice::emptyCurrent) const override;
123  bool getRemoteUnbreakableBufferStati(const ::Ice::Current& = Ice::emptyCurrent) const override;
124  StateIceBasePtr getParentStateLayout(const Ice::Current&) const override;
127 
128  //! Function that retrieves a copy of the remoteState. Calling functions or setting members on this instance won't have any effect.
130  friend class DynamicRemoteState;
131  bool waitForInitialization(int timeoutMS) const override;
132  bool isInitialized() const override;
133  };
134 
135 }
armarx::RemoteState::getOutputParameters
StateParameterMap & getOutputParameters() override
Definition: RemoteState.cpp:464
armarx::RemoteState::waitForInitialization
bool waitForInitialization(int timeoutMS) const override
Definition: RemoteState.cpp:495
armarx::RemoteState::getRemoteUnbreakableBufferSize
::Ice::Int getRemoteUnbreakableBufferSize(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteState.cpp:374
armarx::RemoteState::setStateName
void setStateName(const std::string &stateName)
Definition: RemoteState.cpp:99
armarx::RemoteState::remoteProcessEvent
void remoteProcessEvent(const EventBasePtr &evt, bool buffered, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: RemoteState.cpp:331
armarx::RemoteState::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: RemoteState.cpp:308
armarx::RemoteState::getRemoteStatePtr
StateBasePtr getRemoteStatePtr()
Function that retrieves a copy of the remoteState. Calling functions or setting members on this insta...
Definition: RemoteState.cpp:485
armarx::RemoteState::remoteFinalize
void remoteFinalize(const StringVariantContainerBaseMap &properties, const EventBasePtr &event, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: RemoteState.cpp:357
armarx::RemoteState::_baseOnEnter
void _baseOnEnter() override
Overridden function to redirect this call to the real state in the other application.
Definition: RemoteState.cpp:512
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::RemoteState::createEmptyCopy
StateBasePtr createEmptyCopy() const override
Definition: RemoteState.cpp:295
StatechartContext.h
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::RemoteState::getInputParameters
StateParameterMap getInputParameters() override
Not const because RemoteState implementation gets the current parameters via Ice and sets them.
Definition: RemoteState.cpp:446
armarx::RemoteState::getParentStateLayout
StateIceBasePtr getParentStateLayout(const Ice::Current &) const override
Definition: RemoteState.cpp:640
StateController.h
armarx::RemoteState::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: RemoteState.cpp:130
armarx::RemoteState::RemoteState
RemoteState()
Definition: RemoteState.cpp:39
armarx::RemoteState::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: RemoteState.cpp:120
armarx::RemoteState::getRemoteUnbreakableBufferStati
bool getRemoteUnbreakableBufferStati(const ::Ice::Current &=Ice::emptyCurrent) const override
Definition: RemoteState.cpp:392
ManagedIceObject.h
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::RemoteState::remoteRefetchSubstates
void remoteRefetchSubstates(const ::Ice::Current &c=Ice::emptyCurrent)
armarx::RemoteState::__updateGlobalStateIdRecursive
void __updateGlobalStateIdRecursive() override
Definition: RemoteState.cpp:618
State.h
armarx::RemoteState::clone
StateBasePtr clone() const override
Pure virtual function to clone of the derived class type.
Definition: RemoteState.cpp:279
armarx::RemoteState::~RemoteState
~RemoteState() override
Definition: RemoteState.cpp:82
armarx::RemoteState
This Statetype is used to create a state instance that represents a state that is located in another ...
Definition: RemoteState.h:62
armarx::DynamicRemoteState
DynamicRemoteStates can be used to connect to remote statecharts dynamically at runtime.
Definition: DynamicRemoteState.h:52
armarx::RemoteState::__breakActiveSubstate
bool __breakActiveSubstate(const EventPtr event) override
Overridden function to redirect this call to the real state in the other application.
Definition: RemoteState.cpp:634
armarx::RemoteState::__hasSubstates
bool __hasSubstates() override
not used at the moment
Definition: RemoteState.cpp:412
armarx::RemoteState::__hasActiveSubstate
bool __hasActiveSubstate() override
Overridden function to redirect this call to the real state in the other application.
Definition: RemoteState.cpp:429
armarx::RemoteState::isInitialized
bool isInitialized() const override
Returns the status of this state. Only if a state is initialized, it can be used.
Definition: RemoteState.cpp:506
armarx::RemoteState::refetchSubstates
void refetchSubstates() override
This functions updates the substates.
Definition: RemoteState.cpp:606
armarx::RemoteState::setProxyName
void setProxyName(const std::string &proxyName)
Definition: RemoteState.cpp:109
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
StateBase.h
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::RemoteState::__notifyEventBufferedDueToUnbreakableState
void __notifyEventBufferedDueToUnbreakableState(bool eventBuffered) override
Overridden function to redirect this call to the real state in the other application.
Definition: RemoteState.cpp:596
armarx::RemoteState::operator=
RemoteState & operator=(const RemoteState &source)
Definition: RemoteState.cpp:76
armarx::RemoteState::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: RemoteState.cpp:251
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::RemoteState::remoteProcessBufferedEvents
void remoteProcessBufferedEvents(const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: RemoteState.cpp:319
armarx::RemoteState::setOutput
void setOutput(const ::armarx::StringVariantContainerBaseMap &properties, const ::Ice::Current &c=Ice::emptyCurrent)
armarx::DEFINEEVENT
DEFINEEVENT(EvInit) struct StateRun
armarx::RemoteState::remoteEnqueueEvent
void remoteEnqueueEvent(const EventBasePtr &evt, const ::Ice::Current &c=Ice::emptyCurrent) override
Definition: RemoteState.cpp:345
armarx::RemoteState::_baseOnBreak
bool _baseOnBreak(const EventPtr evt) override
Called by processEvent()-function or parentstate. Must NOT be called by user.
Definition: RemoteState.cpp:553
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::RemoteState::_baseOnExit
void _baseOnExit() override
Overridden function to redirect this call to the real state in the other application.
Definition: RemoteState.cpp:578