Skip to content

Commit 98b8290

Browse files
committed
Solve write action on PV that named different from given name see
PR #3412
1 parent 413857c commit 98b8290

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

app/display/runtime/src/main/java/org/csstudio/display/builder/runtime/WidgetRuntime.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.epics.vtype.VType;
2727
import org.phoebus.framework.macros.MacroHandler;
2828
import org.phoebus.framework.macros.MacroValueProvider;
29-
import org.phoebus.pv.PVPool.TypedName;
3029

3130
import java.util.ArrayList;
3231
import java.util.Collection;
@@ -107,7 +106,8 @@ public class WidgetRuntime<MW extends Widget> {
107106
*/
108107
// This is empty for most widgets, or contains very few PVs,
109108
// so using List with linear lookup by name and not a HashMap
110-
private volatile List<RuntimePV> writable_pvs = null;
109+
// Set pv_name as Key to find the corresponding RuntimePV
110+
private volatile Map<String,RuntimePV> writable_pvs = null;
111111

112112
/**
113113
* Handlers for widget's behaviorScripts property,
@@ -230,16 +230,14 @@ public void start() {
230230
// Prepare action-related PVs
231231
final List<ActionInfo> actions = widget.propActions().getValue().getActions();
232232
if (actions.size() > 0) {
233-
final List<RuntimePV> action_pvs = new ArrayList<>();
233+
final Map<String, RuntimePV> action_pvs = new HashMap<>();
234234
for (final ActionInfo action : actions) {
235235
if (action instanceof WritePVAction) {
236236
final String pv_name = ((WritePVAction) action).getPV();
237237
try {
238238
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
239-
// Manage default datasource if not ca
240-
final TypedName type_name = TypedName.analyze(expanded);
241-
final RuntimePV pv = PVFactory.getPV(type_name.toString());
242-
action_pvs.add(pv);
239+
final RuntimePV pv = PVFactory.getPV(expanded);
240+
action_pvs.put(expanded, pv);
243241
addPV(pv, true);
244242
} catch (Exception ex) {
245243
logger.log(Level.WARNING, widget + " cannot start action to write PV '" + pv_name + "'", ex);
@@ -398,12 +396,8 @@ public void writePrimaryPV(final Object value) {
398396
public void writePV(final String pv_name, final Object value) throws Exception {
399397
final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
400398
String name_to_check = expanded;
401-
// Check for default datasource to manage custom datasource
402-
final TypedName type_name = TypedName.analyze(name_to_check);
403-
name_to_check = type_name != null ? type_name.toString() : name_to_check;
404-
String dataType = type_name != null ? type_name.type : null;
405399
// For local PV,
406-
if (dataType != null && dataType.equals("loc")) {
400+
if (name_to_check.startsWith("loc://")) {
407401
// strip optional data type ...
408402
int sep = name_to_check.indexOf('<');
409403
if (sep > 0)
@@ -414,18 +408,20 @@ public void writePV(final String pv_name, final Object value) throws Exception {
414408
name_to_check = name_to_check.substring(0, sep);
415409
}
416410
awaitStartup();
417-
final List<RuntimePV> safe_pvs = writable_pvs;
418-
if (safe_pvs != null)
419-
for (final RuntimePV pv : safe_pvs)
420-
if (pv.getName().equals(name_to_check)) {
411+
final Map<String, RuntimePV> safe_pvs = writable_pvs;
412+
if (safe_pvs != null) {
413+
final RuntimePV pv = safe_pvs.get(name_to_check);
414+
if(pv != null) {
421415
try {
422416
pv.write(value);
423417
} catch (final Exception ex) {
424418
throw new Exception("Failed to write " + value + " to PV " + name_to_check, ex);
425419
}
426-
return;
427420
}
428-
throw new Exception("Unknown PV '" + pv_name + "' (expanded: '" + name_to_check + "')");
421+
else {
422+
throw new Exception("Unknown PV '" + pv_name + "' (expanded: '" + name_to_check + "')");
423+
}
424+
}
429425
}
430426

431427
/**
@@ -448,13 +444,15 @@ public void stop() {
448444
awaitStartup();
449445
widget.propClass().removePropertyListener(update_widget_class);
450446

451-
final List<RuntimePV> safe_pvs = writable_pvs;
452-
if (safe_pvs != null) {
453-
for (final RuntimePV pv : safe_pvs) {
454-
removePV(pv);
455-
PVFactory.releasePV(pv);
447+
if(writable_pvs != null && !writable_pvs.isEmpty()) {
448+
final Collection<RuntimePV> safe_pvs = writable_pvs.values();
449+
if (safe_pvs != null) {
450+
for (final RuntimePV pv : safe_pvs) {
451+
removePV(pv);
452+
PVFactory.releasePV(pv);
453+
}
454+
writable_pvs = null;
456455
}
457-
writable_pvs = null;
458456
}
459457

460458
final PVNameToValueBinding binding = pv_name_binding.getAndSet(null);

app/display/runtime/src/test/java/org/csstudio/display/builder/runtime/test/WidgetRuntimeTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,13 @@ public void testWriteAction()
6666
//Test if the new value is ok
6767
assertThat(readValue, equalTo(newValue));
6868

69+
//Generate a stacktrace to fix in LocalPVFactory
70+
ofWidget.stop();
71+
6972
} catch (Exception e) {
7073
e.printStackTrace();
7174
fail(e);
7275
}
73-
74-
75-
76-
7776
}
7877

7978
}

0 commit comments

Comments
 (0)