protected ServiceResult ValidateDataChangeFilter(
ISystemContext context,
NodeState source,
uint attributeId,
ExtensionObject requestedFilter,
out DataChangeFilter filter,
out Range range)
{
filter = null;
range = null;
// check for valid filter type.
filter = requestedFilter.Body as DataChangeFilter;
if (filter == null)
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
// only supported for value attributes.
if (attributeId != Attributes.Value)
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
// only supported for variables.
BaseVariableState variable = source as BaseVariableState;
if (variable == null)
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
// check the datatype.
if (filter.DeadbandType != (uint)DeadbandType.None)
{
BuiltInType builtInType = TypeInfo.GetBuiltInType(variable.DataType, Server.TypeTree);
if (!TypeInfo.IsNumericType(builtInType))
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
}
// validate filter.
ServiceResult error = filter.Validate();
if (ServiceResult.IsBad(error))
{
return error;
}
if (filter.DeadbandType ==(uint)DeadbandType.Percent)
{
BaseVariableState euRange = variable.FindChild(context, BrowseNames.EURange) as BaseVariableState;
if (euRange == null)
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
range = euRange.Value as Range;
if (range == null)
{
return StatusCodes.BadMonitoredItemFilterUnsupported;
}
}
// all good.
return ServiceResult.Good;
}