StateWatcher.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package Mirko Waechter
17 * @author (waechter at kit dot edu)
18 * @date 2015
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 #pragma once
24 
28 #include <ArmarXCore/interface/observers/ProfilerObserverInterface.h>
30 
31 #include <mutex>
32 
33 namespace armarx
34 {
35 
36  class StateWatcher :
38  public ProfilerListener
39  // public EventListenerInterface
40  {
41  public:
43  {
44  StateIceBasePtr iceState;
45  std::set<statechartmodel::StatePtr> states;
46  std::set<StateItem*> stateItems;
47  std::map<std::string, ::armarx::StateParameterMap> parameters;
48 
49 
50  };
51 
52  using StateListenerDataMap = std::map<std::string, StateListenerData> ;
53 
54  StateWatcher();
55  bool subscribeToState(StateIceBasePtr iceState, StateItem* state);
56  bool subscribeToState(StateIceBasePtr iceState, statechartmodel::StatePtr state);
57  bool unsubscribeState(StateItem* state);
58  VariantPtr getStateParameter(statechartmodel::StatePtr state, const std::string paramMapType) const;
59  ::armarx::StateParameterMap getStateParameterMap(statechartmodel::StatePtr state, const std::string paramMapType) const;
60 
61  void clear();
62 
63  static std::string ExtractStateName(const std::string globalIdString);
64  // ManagedIceObject interface
65  std::string getDefaultName() const override;
66  protected:
67  void onInitComponent() override;
68  void onConnectComponent() override;
69  void onDisconnectComponent() override;
70 
71  void subscriptionFunction();
72 
74  mutable std::mutex mapMutex;
75  ConditionHandlerInterfacePrx conditionHandler;
76  ProfilerObserverInterfacePrx profilerObserver;
77  using SubscriptionMap = std::vector<std::pair<StateIceBasePtr, std::pair<statechartmodel::StatePtr, StateItem*>> >;
80 
81 
82  // ProfilerListener interface
83  public:
84  void reportNetworkTraffic(const std::string&, const std::string&, Ice::Int, Ice::Int, const Ice::Current&) override;
85  void reportEvent(const ProfilerEvent&, const Ice::Current&) override;
86  void reportStatechartTransition(const ProfilerStatechartTransition& event, const Ice::Current&) override;
87  void reportStatechartInputParameters(const ProfilerStatechartParameters& event, const Ice::Current&) override;
88  void reportStatechartLocalParameters(const ProfilerStatechartParameters& event, const Ice::Current&) override;
89  void reportStatechartOutputParameters(const ProfilerStatechartParameters&, const Ice::Current&) override;
90  void reportProcessCpuUsage(const ProfilerProcessCpuUsage&, const Ice::Current&) override;
91  void reportProcessMemoryUsage(const ProfilerProcessMemoryUsage&, const Ice::Current&) override;
92  void reportEventList(const ProfilerEventList&, const Ice::Current&) override;
93  void reportStatechartTransitionList(const ProfilerStatechartTransitionList&, const Ice::Current&) override;
94  void reportStatechartInputParametersList(const ProfilerStatechartParametersList& data, const Ice::Current&) override;
95  void reportStatechartLocalParametersList(const ProfilerStatechartParametersList&, const Ice::Current&) override;
96  void reportStatechartOutputParametersList(const ProfilerStatechartParametersList&, const Ice::Current&) override;
97  void reportProcessCpuUsageList(const ProfilerProcessCpuUsageList&, const Ice::Current&) override;
98  void reportProcessMemoryUsageList(const ProfilerProcessMemoryUsageList&, const Ice::Current&) override;
99 
100  void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters&, const Ice::Current&) override {}
101  void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList&, const Ice::Current&) override {}
102  };
104 }
105 
armarx::StateWatcher::ExtractStateName
static std::string ExtractStateName(const std::string globalIdString)
Definition: StateWatcher.cpp:250
armarx::StateWatcher::unsubscribeState
bool unsubscribeState(StateItem *state)
Definition: StateWatcher.cpp:147
armarx::StateWatcher::reportNetworkTraffic
void reportNetworkTraffic(const std::string &, const std::string &, Ice::Int, Ice::Int, const Ice::Current &) override
Definition: StateWatcher.cpp:266
armarx::StateWatcher::reportStatechartOutputParameters
void reportStatechartOutputParameters(const ProfilerStatechartParameters &, const Ice::Current &) override
Definition: StateWatcher.cpp:443
armarx::StateWatcher::subscribeToState
bool subscribeToState(StateIceBasePtr iceState, StateItem *state)
Definition: StateWatcher.cpp:164
armarx::StateWatcher::StateListenerData
Definition: StateWatcher.h:42
armarx::StateWatcher::SubscriptionMap
std::vector< std::pair< StateIceBasePtr, std::pair< statechartmodel::StatePtr, StateItem * > > > SubscriptionMap
Definition: StateWatcher.h:77
armarx::StateWatcher::mapMutex
std::mutex mapMutex
Definition: StateWatcher.h:74
armarx::StateWatcher::reportStatechartOutputParametersList
void reportStatechartOutputParametersList(const ProfilerStatechartParametersList &, const Ice::Current &) override
Definition: StateWatcher.cpp:487
armarx::StateWatcher::reportStatechartTransitionList
void reportStatechartTransitionList(const ProfilerStatechartTransitionList &, const Ice::Current &) override
Definition: StateWatcher.cpp:463
armarx::StateWatcher::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: StateWatcher.cpp:59
armarx::StateWatcher::getStateParameter
VariantPtr getStateParameter(statechartmodel::StatePtr state, const std::string paramMapType) const
Definition: StateWatcher.cpp:181
StateItem.h
armarx::StateWatcher
Definition: StateWatcher.h:36
PeriodicTask.h
armarx::StateWatcher::clear
void clear()
Definition: StateWatcher.cpp:243
armarx::StateWatcher::StateListenerData::states
std::set< statechartmodel::StatePtr > states
Definition: StateWatcher.h:45
armarx::StateWatcher::reportProcessMemoryUsageList
void reportProcessMemoryUsageList(const ProfilerProcessMemoryUsageList &, const Ice::Current &) override
Definition: StateWatcher.cpp:499
armarx::StateWatcher::subscriptionQueue
SubscriptionMap subscriptionQueue
Definition: StateWatcher.h:78
armarx::StateWatcher::reportProcessMemoryUsage
void reportProcessMemoryUsage(const ProfilerProcessMemoryUsage &, const Ice::Current &) override
Definition: StateWatcher.cpp:455
armarx::StateWatcher::reportEvent
void reportEvent(const ProfilerEvent &, const Ice::Current &) override
Definition: StateWatcher.cpp:270
armarx::StateWatcher::reportProcessCpuUsage
void reportProcessCpuUsage(const ProfilerProcessCpuUsage &, const Ice::Current &) override
Definition: StateWatcher.cpp:451
IceInternal::Handle< Variant >
DatafieldRef.h
armarx::StateWatcher::reportStatechartInputParameters
void reportStatechartInputParameters(const ProfilerStatechartParameters &event, const Ice::Current &) override
Definition: StateWatcher.cpp:429
armarx::StateWatcher::reportProcessCpuUsageList
void reportProcessCpuUsageList(const ProfilerProcessCpuUsageList &, const Ice::Current &) override
Definition: StateWatcher.cpp:495
armarx::StateWatcher::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: StateWatcher.cpp:45
ManagedIceObject.h
armarx::StateWatcher::subscriptionTask
PeriodicTask< StateWatcher >::pointer_type subscriptionTask
Definition: StateWatcher.h:79
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::StateWatcher::stateMap
StateListenerDataMap stateMap
Definition: StateWatcher.h:73
armarx::StateWatcher::subscriptionFunction
void subscriptionFunction()
Definition: StateWatcher.cpp:72
armarx::StateWatcher::reportEventList
void reportEventList(const ProfilerEventList &, const Ice::Current &) override
Definition: StateWatcher.cpp:459
armarx::StateWatcher::StateWatcher
StateWatcher()
Definition: StateWatcher.cpp:40
armarx::StateWatcher::conditionHandler
ConditionHandlerInterfacePrx conditionHandler
Definition: StateWatcher.h:75
armarx::StateWatcher::StateListenerData::parameters
std::map< std::string, ::armarx::StateParameterMap > parameters
Definition: StateWatcher.h:47
armarx::StateWatcher::reportStatechartTransitionWithParametersList
void reportStatechartTransitionWithParametersList(const ProfilerStatechartTransitionWithParametersList &, const Ice::Current &) override
Definition: StateWatcher.h:101
armarx::StateWatcher::StateListenerData::stateItems
std::set< StateItem * > stateItems
Definition: StateWatcher.h:46
armarx::StateWatcher::StateListenerData::iceState
StateIceBasePtr iceState
Definition: StateWatcher.h:44
armarx::StateWatcher::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: StateWatcher.cpp:260
armarx::ManagedIceObject
The ManagedIceObject is the base class for all ArmarX objects.
Definition: ManagedIceObject.h:163
armarx::StateWatcher::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: StateWatcher.cpp:50
armarx::StateWatcher::reportStatechartInputParametersList
void reportStatechartInputParametersList(const ProfilerStatechartParametersList &data, const Ice::Current &) override
Definition: StateWatcher.cpp:471
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx::StateWatcher::reportStatechartTransitionWithParameters
void reportStatechartTransitionWithParameters(const ProfilerStatechartTransitionWithParameters &, const Ice::Current &) override
Definition: StateWatcher.h:100
armarx::statechartmodel::StatePtr
std::shared_ptr< State > StatePtr
Definition: State.h:46
armarx::StateItem
Definition: StateItem.h:58
armarx::StateWatcher::reportStatechartTransition
void reportStatechartTransition(const ProfilerStatechartTransition &event, const Ice::Current &) override
Definition: StateWatcher.cpp:305
armarx::StateWatcher::getStateParameterMap
::armarx::StateParameterMap getStateParameterMap(statechartmodel::StatePtr state, const std::string paramMapType) const
Definition: StateWatcher.cpp:208
State.h
armarx::StateWatcher::reportStatechartLocalParameters
void reportStatechartLocalParameters(const ProfilerStatechartParameters &event, const Ice::Current &) override
Definition: StateWatcher.cpp:436
armarx::StateWatcher::StateListenerDataMap
std::map< std::string, StateListenerData > StateListenerDataMap
Definition: StateWatcher.h:52
armarx::StateWatcher::reportStatechartLocalParametersList
void reportStatechartLocalParametersList(const ProfilerStatechartParametersList &, const Ice::Current &) override
Definition: StateWatcher.cpp:479
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::StateWatcher::profilerObserver
ProfilerObserverInterfacePrx profilerObserver
Definition: StateWatcher.h:76