StatechartEventDistributor.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 ArmarX::
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
25#pragma once
26
27#include <mutex>
28#include <queue>
29#include <string>
30
32#include <ArmarXCore/interface/statechart/StatechartIce.h>
33
34namespace armarx
35{
36 class StateController;
38
41
42 class StateBase;
44
45 class Event;
47
48 /**
49 * @brief The StatechartEventDistributor class is used to distribute
50 * incomming events (via Ice) to the correct states.<br/>
51 *
52 *
53 * The events must be registered before they can be distributed.
54 * The normal process is to register events here, when the condition or
55 * something else is registered on the observer. The registerEvent()-function
56 * returns a unique event-string that is to be passed to the observer.<br/>
57 * A pointer to this class is passed to the observer, so that the observer
58 * can call back.<br/>
59 *
60 * @note This class is an internal statechart-class and is used by the
61 * classes StatechartContext and StateUtility. There is usually only one
62 * instance per statechart (it is located in the StatechartContext).
63 */
65 virtual public EventListenerInterface,
66 virtual public ManagedIceObject
67 {
68 public:
77
79
80 void setStatechartManager(const StatechartManagerPtr& statechartManager);
81
82 void
84 {
85 this->statechartName = statechartName;
87 }
88
89 // inherited from Component
90 std::string
91 getDefaultName() const override
92 {
93 return statechartName + "s_EventDistributor";
94 }
95
96 using EventListenerMap = std::map<std::string, EventListenerMapEntry>;
97
98
99 std::string registerEvent(const EventPtr& event, StateBasePtr eventProcessor, long visitId);
100 void reportEvent(const EventBasePtr& event, const Ice::Current&) override;
101 std::string getUniqueEventIdentifier(const StateBasePtr& eventProcessor,
102 const EventPtr& event,
103 long visitId);
104 void clearEventMap();
105 EventListenerInterfacePrx getListener();
106
107 protected:
108 std::queue<std::pair<StateControllerPtr, EventPtr>> eventBuffer;
110 std::string statechartName;
111
112 private:
113 // inherited from Component
114 void onInitComponent() override;
115 void onConnectComponent() override;
116 EventListenerInterfacePrx myProxy;
117 StatechartManagerPtr statechartManager;
118
119 std::mutex eventMapMutex;
120 std::mutex eventBufferMutex;
121 };
122} // namespace armarx
An Event is used to communicate between e.g.
Definition Event.h:51
ManagedIceObject(ManagedIceObject const &other)
void setName(std::string name)
Override name of well-known object.
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.
void setStatechartName(std::string statechartName)
std::queue< std::pair< StateControllerPtr, EventPtr > > eventBuffer
std::string registerEvent(const EventPtr &event, StateBasePtr eventProcessor, long visitId)
std::string getUniqueEventIdentifier(const StateBasePtr &eventProcessor, const EventPtr &event, long visitId)
void setStatechartManager(const StatechartManagerPtr &statechartManager)
void reportEvent(const EventBasePtr &event, const Ice::Current &) override
std::map< std::string, EventListenerMapEntry > EventListenerMap
std::string getDefaultName() const override
Retrieve default name of component.
This file offers overloads of toIce() and fromIce() functions for STL container types.
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
IceUtil::Handle< StatechartManager > StatechartManagerPtr
IceInternal::Handle< StateController > StateControllerPtr