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 <ArmarXCore/interface/statechart/RemoteStateIce.h>
29#include <ArmarXCore/interface/statechart/RemoteStateOffererIce.h>
30
31#include "State.h"
32#include "StateBase.h"
33#include "StateController.h"
34#include "StatechartContext.h"
35
36
37// ArmarX Includes
39
40namespace 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 */
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();
101 RemoteState(const RemoteState& source);
102 RemoteState& operator=(const RemoteState& source);
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,
117 const ::Ice::Current& c = Ice::emptyCurrent);
118 void remoteProcessBufferedEvents(const ::Ice::Current& c = Ice::emptyCurrent) override;
119 void remoteProcessEvent(const EventBasePtr& evt,
120 bool buffered,
121 const ::Ice::Current& c = Ice::emptyCurrent) override;
122 void remoteEnqueueEvent(const EventBasePtr& evt,
123 const ::Ice::Current& c = Ice::emptyCurrent) override;
124 void remoteFinalize(const StringVariantContainerBaseMap& properties,
125 const EventBasePtr& event,
126 const ::Ice::Current& c = Ice::emptyCurrent) override;
127 void remoteRefetchSubstates(const ::Ice::Current& c = Ice::emptyCurrent);
128 ::Ice::Int
129 getRemoteUnbreakableBufferSize(const ::Ice::Current& = Ice::emptyCurrent) const override;
130 bool
131 getRemoteUnbreakableBufferStati(const ::Ice::Current& = Ice::emptyCurrent) const override;
132 StateIceBasePtr getParentStateLayout(const Ice::Current&) const override;
133 StateParameterMap getInputParameters() override;
134 StateParameterMap& getOutputParameters() override;
135
136 //! Function that retrieves a copy of the remoteState. Calling functions or setting members on this instance won't have any effect.
138 friend class DynamicRemoteState;
139 bool waitForInitialization(int timeoutMS) const override;
140 bool isInitialized() const override;
141 };
142
143} // namespace armarx
#define DEFINEEVENT(NEWEVENT)
this macro declares a new event-class derived vom Event, to have a compiletime check for typos in eve...
constexpr T c
ManagedIceObject(ManagedIceObject const &other)
This Statetype is used to create a state instance that represents a state that is located in another ...
Definition RemoteState.h:67
void onInitComponent() override
Pure virtual hook for the subclass.
StateParameterMap getInputParameters() override
Not const because RemoteState implementation gets the current parameters via Ice and sets them.
bool waitForInitialization(int timeoutMS) const override
void remoteRefetchSubstates(const ::Ice::Current &c=Ice::emptyCurrent)
RemoteState & operator=(const RemoteState &source)
void setProxyName(const std::string &proxyName)
void __updateGlobalStateIdRecursive() override
StateBasePtr clone() const override
Pure virtual function to clone of the derived class type.
void onDisconnectComponent() override
Hook for subclass.
bool isInitialized() const override
Returns the status of this state. Only if a state is initialized, it can be used.
bool _baseOnBreak(const EventPtr evt) override
Called by processEvent()-function or parentstate. Must NOT be called by user.
void refetchSubstates() override
This functions updates the substates.
void remoteFinalize(const StringVariantContainerBaseMap &properties, const EventBasePtr &event, const ::Ice::Current &c=Ice::emptyCurrent) override
~RemoteState() override
bool __breakActiveSubstate(const EventPtr event) override
Overridden function to redirect this call to the real state in the other application.
StateBasePtr createEmptyCopy() const override
bool getRemoteUnbreakableBufferStati(const ::Ice::Current &=Ice::emptyCurrent) const override
void setOutput(const ::armarx::StringVariantContainerBaseMap &properties, const ::Ice::Current &c=Ice::emptyCurrent)
void setStateName(const std::string &stateName)
StateIceBasePtr getParentStateLayout(const Ice::Current &) const override
void onConnectComponent() override
Pure virtual hook for the subclass.
void remoteProcessEvent(const EventBasePtr &evt, bool buffered, const ::Ice::Current &c=Ice::emptyCurrent) override
void _baseOnExit() override
Overridden function to redirect this call to the real state in the other application.
void remoteEnqueueEvent(const EventBasePtr &evt, const ::Ice::Current &c=Ice::emptyCurrent) override
::Ice::Int getRemoteUnbreakableBufferSize(const ::Ice::Current &=Ice::emptyCurrent) const override
void __notifyEventBufferedDueToUnbreakableState(bool eventBuffered) override
Overridden function to redirect this call to the real state in the other application.
bool __hasSubstates() override
not used at the moment
StateBasePtr getRemoteStatePtr()
Function that retrieves a copy of the remoteState. Calling functions or setting members on this insta...
void remoteProcessBufferedEvents(const ::Ice::Current &c=Ice::emptyCurrent) override
friend class DynamicRemoteState
void _baseOnEnter() override
Overridden function to redirect this call to the real state in the other application.
std::string getDefaultName() const override
Retrieve default name of component.
bool __hasActiveSubstate() override
Overridden function to redirect this call to the real state in the other application.
StateParameterMap & getOutputParameters() override
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< RemoteState > RemoteStatePtr
Definition RemoteState.h:47
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