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