ConditionHandler.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::Core
19 * @author Kai Welke (welke _at_ kit _dot_ edu)
20 * @date 2011
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
29 
31 #include <ArmarXCore/interface/observers/ObserverInterface.h>
32 #include <ArmarXCore/interface/observers/ConditionHandlerInterface.h>
34 
35 #include <vector>
36 #include <string>
37 #include <mutex>
38 
39 
40 namespace armarx
41 {
42  /**
43  * @class ConditionHandlerPropertyDefinitions
44  * @brief
45  */
48  {
49  public:
51  };
52 
53  /**
54  * @defgroup Component-ConditionHandler ConditionHandler
55  * @ingroup ArmarXCore-Components
56  * @brief This component allows installing distributed \ref armarx::Condition "conditions" on sensor data on multiple \ref armarx::Observer "Observers".
57  *
58  * The ConditionHandler manages the status of complex condition trees and distributes complex conditions \ref armarx::Literal "literals" to their designated observers.
59  * Upon fulfillment of conditions an associated event the send to the given EventListenerInterfacePrx.
60  * @see \ref Observers, armarx::ConditionCheck, armarx::ConditionRoot, armarx::Literal, armarx::Term
61  *
62  * @class ConditionHandler
63  * @ingroup Component-ConditionHandler
64  */
66  virtual public ConditionHandlerInterface,
67  virtual public Component
68  {
69  public:
70  /**
71  * Installs a condition
72  *
73  * @param listener Event listener
74  * @param expression Expression to test for
75  * @param e Event to generate when condition is fulfilled
76  *
77  * @throw InvalidConditionException
78  *
79  * @return Identifier of installed condition as required for removal (see removeCondition)
80  */
81  ConditionIdentifier installCondition(const EventListenerInterfacePrx& listener, const TermImplBasePtr& expression, const EventBasePtr& e, bool onlyFireOnce, bool reportDatafields, const DatafieldRefList& refs, const Ice::Current& c = Ice::emptyCurrent) override;
82 
83  /**
84  * Installs a condition
85  *
86  * @param listener Event listener
87  * @param expression Expression to test for
88  * @param e Event to generate when condition is fulfilled
89  * @param desc Description of the condition for debugging and visualization purpose
90  *
91  * @throw InvalidConditionException
92  *
93  * @return Identifier of installed condition as required for removal (see removeCondition)
94  */
95  ConditionIdentifier installConditionWithDescription(const EventListenerInterfacePrx& listener, const TermImplBasePtr& expression, const EventBasePtr& e, const std::string& desc, bool onlyFireOnce, bool reportDatafields, const DatafieldRefList& refs, const Ice::Current& c = Ice::emptyCurrent) override;
96 
97  /**
98  * Removes a condition. If the condition has already been removed, the function immediately returns.
99  *
100  * @param id Identifier of the condition to remove
101  */
102  void removeCondition(const ConditionIdentifier& id, const Ice::Current& c = Ice::emptyCurrent) override;
103 
104  /**
105  * Removes all conditions.
106  *
107  */
108  void removeAllConditions(const Ice::Current& c = Ice::emptyCurrent) override;
109 
110  /**
111  * Retrieve the list of known observers as provided in the config file
112  *
113  * @return List of observer names
114  */
115  Ice::StringSeq getObserverNames(const Ice::Current& c = Ice::emptyCurrent) override;
116 
117  /**
118  * Retrieve the list of active conditions.
119  *
120  * @return The condition registry
121  */
122  ConditionRegistry getActiveConditions(const Ice::Current& c = Ice::emptyCurrent) override;
123 
124  /**
125  * Retrieve the list of conditions that have been registered in the past.
126  * The length limit of the list can be controlled with the config file parameter HistoryLength.
127  *
128  * @return The condition registry for past conditions
129  */
130  ConditionRegistry getPastConditions(const Ice::Current& c = Ice::emptyCurrent) override;
131 
132  ConditionRootBasePtr getCondition(Ice::Int id, const Ice::Current& c = Ice::emptyCurrent) override;
133 
134  std::string getDefaultName() const override;
135 
136  protected:
137  /**
138  * Framework hook. Called once on initialization of the ConditionInstaller.
139  */
140  virtual void onInitConditionHandler() { }
141 
142  /**
143  * Framework hook. Called on first run, after ice setup.
144  */
145  virtual void onStartConditionHandler() { }
146 
147  /**
148  * @see PropertyUser::createPropertyDefinitions()
149  */
150  PropertyDefinitionsPtr createPropertyDefinitions() override;
151 
152  // inherited from Component
153  void onInitComponent() override;
154  void onConnectComponent() override;
155 
156  private:
157  // active checks and associated events
158  std::mutex idMutex;
159  std::mutex iceManagerMutex;
160  std::mutex conditionRegistryMutex;
161  ConditionRegistry conditionRegistry;
162  std::mutex conditionHistoryMutex;
163  ConditionRegistry conditionHistory;
164  int historyLength;
165 
166  // utility methods for observers
167  void useObservers(std::vector<std::string>& names);
168  void preCacheObservers(std::vector<std::string>& names);
169  ObserverInterfacePrx getObserver(std::string observerName);
170 
171  // utility methods for check handling
172  void installChecks(std::vector<LiteralImplPtr>& literals, const Ice::Current& c);
173  void removeChecks(std::vector<LiteralImplPtr>& literals, const Ice::Current& c);
174 
175  Ice::StringSeq observerNames;
176 
177  int generateId();
178  int currentId;
179  };
180 }
181 
LiteralImpl.h
Properties.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::ConditionHandler
Definition: ConditionHandler.h:65
armarx::ConditionHandler::onStartConditionHandler
virtual void onStartConditionHandler()
Framework hook.
Definition: ConditionHandler.h:145
armarx::ConditionHandlerPropertyDefinitions::ConditionHandlerPropertyDefinitions
ConditionHandlerPropertyDefinitions(std::string prefix)
Definition: ConditionHandler.cpp:36
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
armarx::viz::data::ElementFlags::names
const simox::meta::IntEnumNames names
Definition: json_elements.cpp:14
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
ImportExport.h
ARMARXCORE_IMPORT_EXPORT
#define ARMARXCORE_IMPORT_EXPORT
Definition: ImportExport.h:38
armarx::ConditionHandler::onInitConditionHandler
virtual void onInitConditionHandler()
Framework hook.
Definition: ConditionHandler.h:140
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::ConditionHandlerPropertyDefinitions
Definition: ConditionHandler.h:46