Skip to content
Snippets Groups Projects
Commit edcd90ce authored by PICHON's avatar PICHON
Browse files

Correction of a cyclique redondancy. Adding auto-imput capabilities to IONames.

parent f7e852de
Branches
Tags
No related merge requests found
Showing
with 447 additions and 41 deletions
...@@ -267,7 +267,7 @@ public abstract class AJepParser { ...@@ -267,7 +267,7 @@ public abstract class AJepParser {
return toStringBuilder.toString(); return toStringBuilder.toString();
} }
public abstract void initExpression() throws DevFailed; public abstract void initExpression() throws ParseException, DevFailed;
protected final void initExpression(String expression) throws ParseException, DevFailed { protected final void initExpression(String expression) throws ParseException, DevFailed {
List<String> missingSymbols = new ArrayList<>(); List<String> missingSymbols = new ArrayList<>();
...@@ -324,6 +324,10 @@ public abstract class AJepParser { ...@@ -324,6 +324,10 @@ public abstract class AJepParser {
} }
} }
public CaseInsensitiveMap<String> getAttributes() {
return attributes;
}
public Collection<AJepParser> getDependantJepParserList() { public Collection<AJepParser> getDependantJepParserList() {
return variablesJepToRead.values(); return variablesJepToRead.values();
} }
......
...@@ -53,12 +53,8 @@ public final class JepParserRead extends AJepParser { ...@@ -53,12 +53,8 @@ public final class JepParserRead extends AJepParser {
* @throws DevFailed * @throws DevFailed
*/ */
@Override @Override
public void initExpression() throws DevFailed { public void initExpression() throws ParseException, DevFailed {
try {
initExpression(expressionsR); initExpression(expressionsR);
} catch (final ParseException e) {
throw DevFailedUtils.newDevFailed(e);
}
} }
@Override @Override
......
...@@ -61,7 +61,7 @@ public final class JepParserWrite extends AJepParser { ...@@ -61,7 +61,7 @@ public final class JepParserWrite extends AJepParser {
* @throws DevFailed * @throws DevFailed
*/ */
@Override @Override
public void initExpression() throws DevFailed { public void initExpression() throws ParseException, DevFailed {
logger.debug("***building write expression - {} with variables {}", expression, variables); logger.debug("***building write expression - {} with variables {}", expression, variables);
// retrieve the result name result=expression // retrieve the result name result=expression
int equalIndex = expression.indexOf('='); int equalIndex = expression.indexOf('=');
...@@ -84,11 +84,7 @@ public final class JepParserWrite extends AJepParser { ...@@ -84,11 +84,7 @@ public final class JepParserWrite extends AJepParser {
} }
final String exp = expression.substring(equalIndex + 1).trim(); final String exp = expression.substring(equalIndex + 1).trim();
try {
initExpression(exp); initExpression(exp);
} catch (final ParseException e) {
throw DevFailedUtils.newDevFailed(e);
}
final SymbolTable symbols = jep.getSymbolTable(); final SymbolTable symbols = jep.getSymbolTable();
for (final Object entry : symbols.entrySet()) { for (final Object entry : symbols.entrySet()) {
......
package fr.soleil.tango.parser.autoinput;
import org.tango.server.StateMachineBehavior;
import org.tango.server.attribute.AttributeConfiguration;
import org.tango.server.attribute.AttributeValue;
import org.tango.server.attribute.IAttributeBehavior;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DispLevel;
import fr.esrf.TangoDs.TangoConst;
import fr.soleil.tango.clientapi.util.TypeConversionUtil;
public class AutoInputActivatorAttribute implements IAttributeBehavior {
private final AttributeValue value = new AttributeValue();
private final AttributeConfiguration config = new AttributeConfiguration();
private final AutoInputAttributeManager autoInputAttributeManager;
public AutoInputActivatorAttribute(String name, boolean activated, final AutoInputAttributeManager autoInputAttributeManager) throws DevFailed {
super();
config.setName(name);
config.setTangoType(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat.SCALAR);
config.setWritable(AttrWriteType.READ_WRITE);
config.setDispLevel(DispLevel.EXPERT);
value.setValue(TypeConversionUtil.castToType(config.getType(), activated));
this.autoInputAttributeManager = autoInputAttributeManager;
}
@Override
public AttributeConfiguration getConfiguration() throws DevFailed {
return config;
}
@Override
public AttributeValue getValue() throws DevFailed {
return value;
}
public boolean getBooleanValue() {
if (value.getValue() != null && value.getValue() instanceof Boolean) {
return ((Boolean) value.getValue()).booleanValue();
}
return false;
}
@Override
public void setValue(AttributeValue value) throws DevFailed {
boolean newValue = false;
if (value.getValue() != null && value.getValue() instanceof Boolean) {
newValue = ((Boolean) value.getValue()).booleanValue();
}
if( newValue != getBooleanValue() ) {
if( newValue ) {
autoInputAttributeManager.start();
} else {
autoInputAttributeManager.stop();
}
this.value.setValue(newValue);
}
}
@Override
public StateMachineBehavior getStateMachine() throws DevFailed {
return null;
}
}
package fr.soleil.tango.parser.autoinput;
import java.lang.reflect.Array;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tango.server.attribute.AttributeValue;
import org.tango.server.attribute.IAttributeBehavior;
import fr.esrf.Tango.DevFailed;
public class AutoInputAttributeManager {
private static final Logger logger = LoggerFactory.getLogger(AutoInputAttributeManager.class);
private class TaskRunner implements Runnable {
private Object prevValue = null;
private boolean numeric = false;
private boolean array = false;
@Override
public void run() {
Object newValue = readValue();
if (prevValue != null && newValue != null) {
boolean equal = false;
if (array) {
int length = Array.getLength(prevValue);
equal = length == Array.getLength(newValue);
for (int i = 0; i < length && equal; i++) {
Object newValueI = Array.get(newValue, i);
Object prevValueI = Array.get(prevValue, i);
equal = compareScalarValues(prevValueI, newValueI, numeric);
}
} else {
equal = compareScalarValues(prevValue, newValue, numeric);
}
if (!equal) {
writeValue(newValue);
}
} else if (newValue != null) {
// First value at start or after a shutdown.
array = newValue.getClass().isArray();
if (array) {
if (Array.getLength(newValue) > 0) {
numeric = Array.get(newValue, 0) instanceof Number;
} else {
newValue = null;
}
} else {
numeric = newValue instanceof Number;
}
if (newValue != null) {
writeValue(newValue);
}
}
prevValue = newValue;
}
}
private ScheduledThreadPoolExecutor executor;
private TaskRunner taskRunner;
private final IAttributeBehavior attribute;
private final AutoInputProperties properties;
public AutoInputAttributeManager(final IAttributeBehavior attribute, final AutoInputProperties properties) {
super();
this.attribute = attribute;
this.properties = properties;
this.executor = null;
this.taskRunner = null;
if (this.properties.isActivated()) {
start();
}
}
private boolean compareScalarValues(Object prevValue, Object newValue, boolean numeric) {
boolean equal = false;
if (numeric) {
double newValDbl = ((Number) newValue).doubleValue();
double prevValDbl = ((Number) prevValue).doubleValue();
double absDiff = Math.abs(newValDbl - prevValDbl);
equal = absDiff < properties.getPrecision();
} else {
// For boolean or strings, precision is useless.
equal = prevValue.equals(newValue);
}
return equal;
}
private Object readValue() {
Object value = null;
AttributeValue attrValue = null;
try {
attrValue = attribute.getValue();
if (attrValue != null) {
value = attrValue.getValue();
}
} catch (DevFailed e) {
logger.error("Error while reading attribute " + properties.getInputAttributeName(), e);
e.printStackTrace();
}
return value;
}
private void writeValue(Object value) {
try {
AttributeValue attrValue = new AttributeValue(value);
attribute.setValue(attrValue);
} catch (DevFailed e) {
logger.error("Error while writting attribute " + properties.getInputAttributeName(), e);
e.printStackTrace();
}
}
public void start() {
if (taskRunner == null) {
long periodMS = (long) (properties.getPoolingPeriod() * 1000.0 + 0.5);
taskRunner = new TaskRunner();
executor = new ScheduledThreadPoolExecutor(1);
executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
executor.scheduleAtFixedRate(taskRunner, 0, periodMS, TimeUnit.MILLISECONDS);
}
}
public void stop() {
if (executor != null) {
executor.shutdown();
executor = null;
taskRunner = null;
}
}
}
package fr.soleil.tango.parser.autoinput;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AutoInputProperties {
private static final Logger logger = LoggerFactory.getLogger(AutoInputProperties.class);
private String inputAttributeName;
private boolean activated;
private double poolingPeriod;
private double precision;
public static List<AutoInputProperties> parseProperty(String[] tangoParserProperty) {
List<AutoInputProperties> result = new ArrayList<>();
for (String propertyLine : tangoParserProperty) {
propertyLine = propertyLine.trim();
if (!propertyLine.isEmpty() && propertyLine.contains(";")) {
String[] splittedLine = propertyLine.split(";");
if (splittedLine.length > 2) {
String name = splittedLine[0].trim();
boolean error = name.isEmpty();
if (error) {
continue;
}
boolean activated = splittedLine[1].trim().toLowerCase().equals("true");
activated |= splittedLine[1].trim().toLowerCase().equals("on");
double pooling = 0.0;
try {
pooling = Double.parseDouble(splittedLine[2].trim());
} catch (NumberFormatException ex) {
logger.error("Bad format for polling period for attribute " + name, ex);
ex.printStackTrace();
error = true;
}
double precision = -1;
if (splittedLine.length > 3) {
try {
precision = Double.parseDouble(splittedLine[3].trim());
} catch (NumberFormatException ex) {
logger.error("Bad format for precision for attribute " + name, ex);
ex.printStackTrace();
error = true;
}
}
if (!error) {
AutoInputProperties autoInputProperties = new AutoInputProperties(name, activated, pooling,
precision);
result.add(autoInputProperties);
}
}
}
}
return result;
}
private AutoInputProperties(String inputAttributeName, boolean activated, double poolingPeriod, double precision) {
super();
this.inputAttributeName = inputAttributeName;
this.activated = activated;
this.poolingPeriod = poolingPeriod;
this.precision = precision;
}
public double getPoolingPeriod() {
return poolingPeriod;
}
public double getPrecision() {
return precision;
}
public String getInputAttributeName() {
return inputAttributeName;
}
public boolean isActivated() {
return activated;
}
}
package fr.soleil.tango.parser.datasource; package fr.soleil.tango.parser.datasource;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
...@@ -11,11 +13,14 @@ import org.lsmp.djep.vectorJep.values.MVector; ...@@ -11,11 +13,14 @@ import org.lsmp.djep.vectorJep.values.MVector;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tango.utils.DevFailedUtils; import org.tango.utils.DevFailedUtils;
import org.tango.utils.TangoUtil;
import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState; import fr.esrf.Tango.DevState;
import fr.esrf.TangoApi.CallBack;
import fr.esrf.TangoApi.DeviceAttribute; import fr.esrf.TangoApi.DeviceAttribute;
import fr.esrf.TangoApi.DeviceProxy;
import fr.esrf.TangoDs.TangoConst; import fr.esrf.TangoDs.TangoConst;
import fr.soleil.tango.clientapi.InsertExtractUtils; import fr.soleil.tango.clientapi.InsertExtractUtils;
import fr.soleil.tango.clientapi.TangoGroupAttribute; import fr.soleil.tango.clientapi.TangoGroupAttribute;
...@@ -34,6 +39,7 @@ public class TangoSource { ...@@ -34,6 +39,7 @@ public class TangoSource {
private final AttributeResults attributeData = new AttributeResults(); private final AttributeResults attributeData = new AttributeResults();
private final Map<String, TangoGroupAttribute> writeGroups = new TreeMap<String, TangoGroupAttribute>(); private final Map<String, TangoGroupAttribute> writeGroups = new TreeMap<String, TangoGroupAttribute>();
private final boolean isSynchronous; private final boolean isSynchronous;
private final Map<String, List<Integer>> suscribedEventIds = new TreeMap<>();
TangoSource(final String deviceName, final String name, final boolean isSynchronous) { TangoSource(final String deviceName, final String name, final boolean isSynchronous) {
this.deviceName = deviceName.toLowerCase(Locale.ENGLISH); this.deviceName = deviceName.toLowerCase(Locale.ENGLISH);
...@@ -91,6 +97,24 @@ public class TangoSource { ...@@ -91,6 +97,24 @@ public class TangoSource {
return attributeData.getAttributeResult(sourceName, variableName); return attributeData.getAttributeResult(sourceName, variableName);
} }
private void subscribeToAttribute(String fullAttributeName, CallBack callback) throws DevFailed {
String deviceAttribute = TangoUtil.getAttributeName(fullAttributeName);
String deviceName = TangoUtil.getfullDeviceNameForAttribute(fullAttributeName);
DeviceProxy deviceProxy = getDeviceProxy(fullAttributeName);
int eventId = deviceProxy.subscribe_event(deviceAttribute, TangoConst.CHANGE_EVENT, callback, null);
List<Integer> deviceEventList = suscribedEventIds.get(deviceProxy.get_name());
if( deviceEventList==null ) {
deviceEventList = new ArrayList<>();
suscribedEventIds.put(deviceProxy.get_name(), deviceEventList);
}
deviceEventList.add(eventId);
}
private DeviceProxy getDeviceProxy(String fullAttributeName) throws DevFailed {
DeviceProxy deviceProxy = readGroup.getGroup().getDevice(fullAttributeName);
return deviceProxy;
}
public void getResults() throws DevFailed { public void getResults() throws DevFailed {
// get results for tango attributes // get results for tango attributes
final DeviceAttribute[] results = readGroup.getReadAsyncReplies(); final DeviceAttribute[] results = readGroup.getReadAsyncReplies();
......
...@@ -5,6 +5,7 @@ import java.util.ArrayList; ...@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.nfunk.jep.ParseException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.tango.server.StateMachineBehavior; import org.tango.server.StateMachineBehavior;
...@@ -155,6 +156,10 @@ public final class DynamicAttributeParser implements IAttributeBehavior { ...@@ -155,6 +156,10 @@ public final class DynamicAttributeParser implements IAttributeBehavior {
jepParserWriterGroup.setValue(value.getValue(), true); jepParserWriterGroup.setValue(value.getValue(), true);
} }
public AJepParser getJepParserRead() {
return jepParserRead;
}
public void launchRefresh(final boolean lock) throws DevFailed { public void launchRefresh(final boolean lock) throws DevFailed {
if (jepParserRead != null) { if (jepParserRead != null) {
jepParserRead.refresh(lock); jepParserRead.refresh(lock);
...@@ -196,7 +201,7 @@ public final class DynamicAttributeParser implements IAttributeBehavior { ...@@ -196,7 +201,7 @@ public final class DynamicAttributeParser implements IAttributeBehavior {
logger.debug("read {} on {}", value.getValue(), config.getName()); logger.debug("read {} on {}", value.getValue(), config.getName());
} }
public void initExpression() throws DevFailed { public void initExpression() throws ParseException, DevFailed {
for (AJepParser jepParser : variablesJep) { for (AJepParser jepParser : variablesJep) {
jepParser.initExpression(); jepParser.initExpression();
} }
......
...@@ -12,6 +12,7 @@ import java.util.Map.Entry; ...@@ -12,6 +12,7 @@ import java.util.Map.Entry;
import java.util.Queue; import java.util.Queue;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Set; import java.util.Set;
import java.util.TreeMap;
import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceAlreadyExistsException;
import javax.management.MBeanRegistrationException; import javax.management.MBeanRegistrationException;
...@@ -57,6 +58,7 @@ import com.google.common.collect.HashBiMap; ...@@ -57,6 +58,7 @@ import com.google.common.collect.HashBiMap;
import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevError;
import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState; import fr.esrf.Tango.DevState;
import fr.esrf.Tango.DispLevel; import fr.esrf.Tango.DispLevel;
...@@ -66,6 +68,9 @@ import fr.soleil.tango.clientapi.TangoAttribute; ...@@ -66,6 +68,9 @@ import fr.soleil.tango.clientapi.TangoAttribute;
import fr.soleil.tango.clientapi.util.TypeConversionUtil; import fr.soleil.tango.clientapi.util.TypeConversionUtil;
import fr.soleil.tango.parser.AJepParser; import fr.soleil.tango.parser.AJepParser;
import fr.soleil.tango.parser.JepParserRead; import fr.soleil.tango.parser.JepParserRead;
import fr.soleil.tango.parser.autoinput.AutoInputActivatorAttribute;
import fr.soleil.tango.parser.autoinput.AutoInputAttributeManager;
import fr.soleil.tango.parser.autoinput.AutoInputProperties;
import fr.soleil.tango.parser.datasource.CacheRefresher; import fr.soleil.tango.parser.datasource.CacheRefresher;
import fr.soleil.tango.parser.datasource.SourceManager; import fr.soleil.tango.parser.datasource.SourceManager;
import fr.soleil.tango.parser.datasource.TangoSource; import fr.soleil.tango.parser.datasource.TangoSource;
...@@ -78,6 +83,7 @@ public final class TangoParser { ...@@ -78,6 +83,7 @@ public final class TangoParser {
private static final String STOP_COMMAND_NAME = "StopAll"; private static final String STOP_COMMAND_NAME = "StopAll";
private static final String FR_SOLEIL_MANAGEMENT_TYPE_TANGO_PARSER_STATS = "fr.soleil.management:type=TangoParserStats"; private static final String FR_SOLEIL_MANAGEMENT_TYPE_TANGO_PARSER_STATS = "fr.soleil.management:type=TangoParserStats";
private static final String autoInputActivatorTag = "AutoInputActivation";
private final Logger logger = LoggerFactory.getLogger(TangoParser.class); private final Logger logger = LoggerFactory.getLogger(TangoParser.class);
private final XLogger xlogger = XLoggerFactory.getXLogger(TangoParser.class); private final XLogger xlogger = XLoggerFactory.getXLogger(TangoParser.class);
private static volatile CacheRefresher CACHE_REFRESHER = null; private static volatile CacheRefresher CACHE_REFRESHER = null;
...@@ -123,6 +129,14 @@ public final class TangoParser { ...@@ -123,6 +129,14 @@ public final class TangoParser {
@DeviceProperty(description = "Property used by Scan server if ScanMode is set to true.") @DeviceProperty(description = "Property used by Scan server if ScanMode is set to true.")
private String movingState = ""; private String movingState = "";
/**
* Manage dynamic READ_WRITE attributes. format : type
* name;readExpression;writeExp1;...;writeExpN
*/
@DeviceProperty(description = "Manage automating of the writing part of READ_WRITE attributes.\n"
+ "Format : \n[IO_ATTRIBUTE_NAME]\nAUTO_INPUT_ACTIVATED=TRUE|FALSE\nIN_ATTR_NAME;POOLING_PERIOD;PRECISION\n\n[IO_ATTRIBUTE_NAME]\n...")
private String[] autoInputProperties = { "" };
/** /**
* Manage dynamic READ attributes. format : type name,attributeName=expression * Manage dynamic READ attributes. format : type name,attributeName=expression
*/ */
...@@ -317,7 +331,13 @@ public final class TangoParser { ...@@ -317,7 +331,13 @@ public final class TangoParser {
final String deviceName = device.getName(); final String deviceName = device.getName();
final JepParserRead jepParserRead = new JepParserRead(deviceName, "tmp", expression, attribMap, variablesJep, final JepParserRead jepParserRead = new JepParserRead(deviceName, "tmp", expression, attribMap, variablesJep,
srcManager.build(true, device.getName(), expression)); srcManager.build(true, device.getName(), expression));
try {
jepParserRead.initExpression(); jepParserRead.initExpression();
} catch (ParseException e) {
logger.error("expresion \"{}\" contains errors. {}", argin, e.getMessage());
e.printStackTrace();
throw DevFailedUtils.newDevFailed(e);
}
jepParserRead.refresh(true); jepParserRead.refresh(true);
final Object result = jepParserRead.getValue(true); final Object result = jepParserRead.getValue(true);
String[] argout; String[] argout;
...@@ -476,6 +496,42 @@ public final class TangoParser { ...@@ -476,6 +496,42 @@ public final class TangoParser {
dynMngt.addCommand(behavior); dynMngt.addCommand(behavior);
} }
} }
// Parsing the autoInputProperties property.
List<AutoInputProperties> autoInputPropertiesList = AutoInputProperties.parseProperty(autoInputProperties);
if (!autoInputPropertiesList.isEmpty()) {
Map<String, DynamicAttributeParser> dynAttributesMaps = new TreeMap<>();
for (IAttributeBehavior attr : dynMngt.getDynamicAttributes()) {
if (attr != null && attr instanceof DynamicAttributeParser) {
final AttrWriteType attrWryteType = attr.getConfiguration().getWritable();
if (attrWryteType.equals(AttrWriteType.READ_WRITE)) {
DynamicAttributeParser dynAttrParser = (DynamicAttributeParser) attr;
dynAttributesMaps.put(dynAttrParser.getName().toLowerCase(), dynAttrParser);
}
}
}
for (AutoInputProperties autoInputProperties : autoInputPropertiesList) {
DynamicAttributeParser dynAttrParser = dynAttributesMaps
.get(autoInputProperties.getInputAttributeName().toLowerCase());
if (dynAttrParser != null) {
// Creating the thread for pooling.
AutoInputAttributeManager autoInputAttributeManager = new AutoInputAttributeManager(dynAttrParser,
autoInputProperties);
// Creation of a dynamic boolean attribute for autoinput activation /
// deactivation
String attr_activator_name = autoInputProperties.getInputAttributeName() + autoInputActivatorTag;
AutoInputActivatorAttribute activatorAttribute = new AutoInputActivatorAttribute(
attr_activator_name, autoInputProperties.isActivated(), autoInputAttributeManager);
dynMngt.addAttribute(activatorAttribute);
} else {
logger.error("The auto input configuration '" + autoInputProperties.getInputAttributeName()
+ "' does not match any IONames.");
}
}
}
logger.info("init device done"); logger.info("init device done");
xlogger.exit(); xlogger.exit();
...@@ -595,8 +651,6 @@ public final class TangoParser { ...@@ -595,8 +651,6 @@ public final class TangoParser {
String[] oiNames = null; String[] oiNames = null;
// Expressions of READ-WRITE ATTRIBUTES // Expressions of READ-WRITE ATTRIBUTES
String[] inputOutputExpression = null; String[] inputOutputExpression = null;
// Input expressions of READ-WRITE ATTRIBUTES
String[][] ioExpression;
// Output expressions of READ-WRITE ATTRIBUTES // Output expressions of READ-WRITE ATTRIBUTES
String[] oiExpression = null; String[] oiExpression = null;
// Types of READ-WRITE ATTRIBUTES // Types of READ-WRITE ATTRIBUTES
...@@ -613,6 +667,8 @@ public final class TangoParser { ...@@ -613,6 +667,8 @@ public final class TangoParser {
Arrays.fill(ioTypes, TangoConst.Tango_DEV_DOUBLE); Arrays.fill(ioTypes, TangoConst.Tango_DEV_DOUBLE);
Arrays.fill(ioFormat, AttrDataFormat.SCALAR); Arrays.fill(ioFormat, AttrDataFormat.SCALAR);
for (int i = 0; i < iONames.length; i++) { for (int i = 0; i < iONames.length; i++) {
// Input expressions of READ-WRITE ATTRIBUTES
String[] ioExpression;
final String[] elements = iONames[i].split(";"); final String[] elements = iONames[i].split(";");
oiNames[i] = elements[0]; oiNames[i] = elements[0];
// try to get the type // try to get the type
...@@ -636,9 +692,9 @@ public final class TangoParser { ...@@ -636,9 +692,9 @@ public final class TangoParser {
System.arraycopy(elements, 1, inputOutputExpression, 0, elements.length - 1); System.arraycopy(elements, 1, inputOutputExpression, 0, elements.length - 1);
oiExpression[i] = inputOutputExpression[0]; oiExpression[i] = inputOutputExpression[0];
ioExpression = new String[iONames.length][inputOutputExpression.length - 1]; ioExpression = new String[inputOutputExpression.length - 1];
System.arraycopy(inputOutputExpression, 1, ioExpression[i], 0, inputOutputExpression.length - 1); System.arraycopy(inputOutputExpression, 1, ioExpression, 0, inputOutputExpression.length - 1);
final AttributeConfiguration config = new AttributeConfiguration(); final AttributeConfiguration config = new AttributeConfiguration();
try { try {
// srt configuration : name, type and write type (here : // srt configuration : name, type and write type (here :
...@@ -652,8 +708,8 @@ public final class TangoParser { ...@@ -652,8 +708,8 @@ public final class TangoParser {
// Create list for Write expression and put in write // Create list for Write expression and put in write
// expression(s). // expression(s).
final List<String> exprW = new ArrayList<String>(); final List<String> exprW = new ArrayList<String>();
for (int j = 0; j < ioExpression[i].length; j++) { for (int j = 0; j < ioExpression.length; j++) {
exprW.add(ioExpression[i][j]); exprW.add(ioExpression[j]);
} }
final String deviceName = device.getName(); final String deviceName = device.getName();
final DynamicAttributeParser attr = new DynamicAttributeParser(deviceName, config, oiExpression[i], final DynamicAttributeParser attr = new DynamicAttributeParser(deviceName, config, oiExpression[i],
...@@ -830,12 +886,13 @@ public final class TangoParser { ...@@ -830,12 +886,13 @@ public final class TangoParser {
logger.error("There is at least one cyclic reference between expressions."); logger.error("There is at least one cyclic reference between expressions.");
} }
logger.debug("init JEP done");
xlogger.exit(); xlogger.exit();
} }
private class DynamicAttributesInitializer implements CircuitBreakerCommand { private class DynamicAttributesInitializer implements CircuitBreakerCommand {
@Override @Override
public void execute() throws DevFailed { public void execute() throws DevFailed {
for (IAttributeBehavior attribute : TangoParser.this.dynMngt.getDynamicAttributes()) { for (IAttributeBehavior attribute : TangoParser.this.dynMngt.getDynamicAttributes()) {
...@@ -844,15 +901,29 @@ public final class TangoParser { ...@@ -844,15 +901,29 @@ public final class TangoParser {
try { try {
dynAttrParser.initExpression(); dynAttrParser.initExpression();
} catch (final DevFailed e) { } catch (final DevFailed e) {
if(e.getCause()!= null && e.getCause() instanceof ParseException ) { boolean parseError = e.getCause() != null && (e.getCause() instanceof ParseException);
if (!parseError && e.errors != null & e.errors.length > 0) {
for (DevError error : e.errors) {
parseError = error.desc != null
&& error.desc.equals(ParseException.class.getCanonicalName());
if (parseError) {
break;
}
}
}
if (parseError) {
// If it's a parsing exception, it's absorbed. It's useless to retry. // If it's a parsing exception, it's absorbed. It's useless to retry.
initFailed = true; initFailed = true;
e.printStackTrace(); e.printStackTrace();
logger.error("attribute \"{}\" not built. {}", dynAttrParser.getName(), DevFailedUtils.toString(e)); logger.error("attribute \"{}\" not built. {}", dynAttrParser.getName(),
} DevFailedUtils.toString(e));
else { } else {
throw e; throw e;
} }
} catch (ParseException e) {
initFailed = true;
e.printStackTrace();
logger.error("attribute \"{}\" not built. {}", dynAttrParser.getName(), e.getMessage());
} }
} }
} }
...@@ -979,7 +1050,13 @@ public final class TangoParser { ...@@ -979,7 +1050,13 @@ public final class TangoParser {
srcManager.build(scanMode, device.getName(), name)); srcManager.build(scanMode, device.getName(), name));
} }
if (attribute != null) { if (attribute != null) {
try {
attribute.initExpression(); attribute.initExpression();
} catch (ParseException e) {
logger.error("attribute \"{}\" not built. {}", name, e.getMessage());
e.printStackTrace();
throw DevFailedUtils.newDevFailed(e);
}
dynMngt.removeAttribute(name); dynMngt.removeAttribute(name);
dynMngt.addAttribute(attribute); dynMngt.addAttribute(attribute);
} }
...@@ -1032,6 +1109,12 @@ public final class TangoParser { ...@@ -1032,6 +1109,12 @@ public final class TangoParser {
checkProperty("IONames", true, TangoParserUtil.PATTERN_IO, TangoParserUtil.SYNTAX_IO_NAMES, iONames); checkProperty("IONames", true, TangoParserUtil.PATTERN_IO, TangoParserUtil.SYNTAX_IO_NAMES, iONames);
} }
public void setAutoInputProperties(final String[] autoInputProperties) throws DevFailed {
this.autoInputProperties = removeEmptyLineFromProperty("AutoInputProperties", autoInputProperties);
// checkProperty("AutoInputProperties", true, TangoParserUtil.PATTERN_IO,
// TangoParserUtil.SYNTAX_IO_NAMES, autoInputProperties);
}
public void setOutputNames(final String[] outputNames) throws DevFailed { public void setOutputNames(final String[] outputNames) throws DevFailed {
this.outputNames = removeEmptyLineFromProperty("OutputNames", outputNames); this.outputNames = removeEmptyLineFromProperty("OutputNames", outputNames);
checkProperty("OutputNames", true, TangoParserUtil.PATTERN_OUTPUT, TangoParserUtil.SYNTAX_OUTPUT_NAMES, checkProperty("OutputNames", true, TangoParserUtil.PATTERN_OUTPUT, TangoParserUtil.SYNTAX_OUTPUT_NAMES,
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
</appender> </appender>
<logger name="org.jacorb" level="ERROR" /> <logger name="org.jacorb" level="ERROR" />
<logger name="org.tango.server.events" level="DEBUG" />
<logger name="org.tango" level="ERROR" /> <logger name="org.tango" level="ERROR" />
<logger name="fr.soleil.tango.server" level="DEBUG" additivity="false"> <logger name="fr.soleil.tango.server" level="DEBUG" additivity="false">
<appender-ref ref="ATTRIBUTE" /> <appender-ref ref="ATTRIBUTE" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment