34 template class ::IceInternal::Handle<::armarx::ConditionCheck>;
38 ConditionCheck::ConditionCheck()
48 ChannelRegistry::const_iterator iterChannels = channelRegistry.find(dataFieldIdentifier->channelName);
50 if (iterChannels == channelRegistry.end())
52 throw InvalidConditionException(
"Invalid channel \"" + dataFieldIdentifier->channelName +
"\" in check " + configuration.checkName);
56 const DataFieldRegistry& dataFieldRegistry = iterChannels->second.dataFields;
57 DataFieldRegistry::const_iterator iterData = dataFieldRegistry.find(dataFieldIdentifier->datafieldName);
59 if (iterData == dataFieldRegistry.end())
61 throw InvalidConditionException(
"Invalid datafield \"" + dataFieldIdentifier->channelName +
"." + dataFieldIdentifier->datafieldName +
"\" in check " + configuration.checkName);
65 VariantPtr dataField = VariantPtr::dynamicCast(iterData->second.value);
66 assureTypeSupported(configuration, dataField->getType());
70 check->configuration = configuration;
75 void ConditionCheck::reset()
82 void ConditionCheck::evaluateCondition(
const DataFieldRegistry& dataFields)
103 auto iter = dataFields.find(configuration.dataFieldIdentifier->datafieldName);
104 if (iter != dataFields.end())
106 checkDataFields[iter->second.identifier->datafieldName] = *VariantPtr::dynamicCast(iter->second.value);
108 if (checkDataFields.size() == 0)
114 bool oldFulFilled = fulFilled;
115 fulFilled = evaluate(checkDataFields);
118 if (configuration.reportAlways || oldFulFilled != fulFilled || firstEval || configuration.reportDatafieldValues)
120 if (oldFulFilled != fulFilled)
122 ARMARX_DEBUG_S <<
"Evaluating check: '" << configuration.checkName <<
"' - status changed (" << oldFulFilled <<
" -> " << fulFilled <<
")" << std::endl;
126 ARMARX_DEBUG_S <<
"First evaluating of check: '" << configuration.checkName <<
"' is " << fulFilled;
130 ARMARX_DEBUG_S <<
"Unchanged value of check: '" << configuration.checkName <<
"' is " << fulFilled;
135 if (configuration.reportDatafieldValues)
137 configuration.listener->setValueAndData(fulFilled, configuration.dataFieldIdentifier, iter->second.value);
141 configuration.listener->setValue(fulFilled);
146 bool ConditionCheck::getFulFilled()
153 if (
index >= numberParameters)
155 throw LocalException(
"Illegal parameter requested\n");
158 VariantPtr var = VariantPtr::dynamicCast(configuration.checkParameters.at(
index));
164 var = dfr->getDataField();
170 void ConditionCheck::assureTypeSupported(
const CheckConfiguration& configuration,
VariantTypeId dataFieldType)
173 SupportedTypeList::iterator iter = supportedTypes.begin();
175 bool bValidType =
false;
177 while (iter != supportedTypes.end())
182 if (supportedType == 0)
187 else if (supportedType == dataFieldType)
189 if (configuration.checkParameters.size() != iter->parameterTypes.size())
191 throw InvalidConditionException(
"Wrong number of parameters for condition in check " + configuration.checkName);
194 ParameterTypeList::iterator iter_param = iter->parameterTypes.begin();
195 bool bParameterValid =
true;
198 while (iter_param != iter->parameterTypes.end())
202 VariantTypeId paramType = configuration.checkParameters.at(p)->getType();
206 VariantPtr var = VariantPtr::dynamicCast(configuration.checkParameters.at(p));
209 if (!dfr->validate())
211 bParameterValid =
false;
216 paramType = dfr->getDataField()->getType();
219 if (*iter_param != paramType)
221 bParameterValid =
false;
241 throw InvalidConditionException(
"Invalid types for check " + configuration.checkName +
" Type: " + Variant::typeToString(dataFieldType));
245 void ConditionCheck::setNumberParameters(
int numberParameters)
247 this->numberParameters = numberParameters;
250 void ConditionCheck::addSupportedType(
VariantTypeId dataFieldType, ParameterTypeList parameterTypes)
253 type.dataFieldType = dataFieldType;
254 type.parameterTypes = parameterTypes;
256 supportedTypes.push_back(type);
259 ParameterTypeList ConditionCheck::createParameterTypeList(
int numberTypes, ...)
262 va_start(ap, numberTypes);
264 ParameterTypeList params;
266 for (
int p = 0 ; p < numberTypes; p++)