use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class DataBrowserWidgetRuntime method stop.
@Override
public void stop() {
if (db_model_listener != null) {
widget.getDataBrowserModel().removeListener(db_model_listener);
db_model_listener = null;
}
final RuntimePV pv = selection_pv;
if (pv != null) {
removePV(pv);
PVFactory.releasePV(pv);
selection_pv = null;
}
super.stop();
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class ImageWidgetRuntime method bindPV.
/**
* @param pv_name Name of cursor related PV
* @return {@link RuntimePV} or <code>null</code>
*/
private RuntimePV bindPV(final String pv_name) {
if (!pv_name.isEmpty()) {
logger.log(Level.FINER, "Connecting {0} to {1}", new Object[] { widget, pv_name });
try {
final RuntimePV pv = PVFactory.getPV(pv_name);
addPV(pv);
return pv;
} catch (Exception ex) {
logger.log(Level.WARNING, "Error connecting PV " + pv_name, ex);
}
}
return null;
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class XYPlotWidgetRuntime method stop.
@Override
public void stop() {
// Disconnect Marker PVs and listeners
for (Map.Entry<WidgetProperty<?>, WidgetPropertyListener<?>> entry : marker_prop_listeners.entrySet()) entry.getKey().removePropertyListener(entry.getValue());
marker_prop_listeners.clear();
for (Map.Entry<RuntimePV, RuntimePVListener> entry : marker_pv_listeners.entrySet()) entry.getKey().removeListener(entry.getValue());
marker_pv_listeners.clear();
for (RuntimePV pv : marker_pvs) {
removePV(pv);
PVFactory.releasePV(pv);
}
marker_pvs.clear();
for (PVNameToValueBinding binding : bindings) binding.dispose();
super.stop();
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class WidgetRuntime method stop.
/**
* Stop: Disconnect PVs, ...
*/
public void stop() {
awaitStartup();
widget.propClass().removePropertyListener(update_widget_class);
final List<RuntimePV> safe_pvs = writable_pvs;
if (safe_pvs != null) {
for (final RuntimePV pv : safe_pvs) {
removePV(pv);
PVFactory.releasePV(pv);
}
writable_pvs = null;
}
final PVNameToValueBinding binding = pv_name_binding.getAndSet(null);
if (binding != null)
binding.dispose();
final Map<ExecuteScriptActionInfo, Script> actions = action_scripts;
if (actions != null) {
actions.clear();
action_scripts = null;
}
final List<RuntimeScriptHandler> handlers = script_handlers;
if (handlers != null) {
for (final RuntimeScriptHandler handler : handlers) handler.shutdown();
script_handlers = null;
}
if (runtime_pvs != null) {
final Collection<RuntimePV> pvs = runtime_pvs.getPVs();
if (!pvs.isEmpty())
logger.log(Level.SEVERE, widget + " has unreleased PVs: " + pvs);
}
// Close script support that might have been created
// by RuntimeScriptHandlers or action-invoked scripts
final ScriptSupport scripting = widget.getUserData(Widget.USER_DATA_SCRIPT_SUPPORT);
if (scripting != null)
scripting.close();
// Prepare for another start()
started = new CountDownLatch(1);
}
use of org.csstudio.display.builder.runtime.pv.RuntimePV in project org.csstudio.display.builder by kasemir.
the class ArrayPVDispatcherTest method testArrayPVDispatcher.
/**
* Test double-typed array PV
*/
@Test
public void testArrayPVDispatcher() throws Exception {
// Array PV. It's elements are to be dispatched into separate PVs
final RuntimePV array_pv = PVFactory.getPV("loc://an_array(1.0, 2.0, 3, 4)");
// The per-element PVs that will be bound to the array
final AtomicReference<List<RuntimePV>> element_pvs = new AtomicReference<>();
final CountDownLatch got_element_pvs = new CountDownLatch(1);
// Listener to the ArrayPVDispatcher
final Listener dispatch_listener = new Listener() {
@Override
public void arrayChanged(final List<RuntimePV> pvs) {
System.out.println("Per-element PVs: ");
element_pvs.set(pvs);
dump(pvs);
got_element_pvs.countDown();
}
};
final ArrayPVDispatcher dispatcher = new ArrayPVDispatcher(array_pv, "elementA247FE_", dispatch_listener);
// Await initial set of per-element PVs
got_element_pvs.await();
assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(0).read()).doubleValue(), equalTo(1.0));
assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(1).read()).doubleValue(), equalTo(2.0));
assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(2).read()).doubleValue(), equalTo(3.0));
assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(3).read()).doubleValue(), equalTo(4.0));
// Change array -> Observe update of per-element PV
System.out.println("Updating array");
array_pv.write(new double[] { 1.0, 22.5, 3, 4 });
dump(element_pvs.get());
// On one hand, this changed only one array element.
// On the other hand, it's a new array value with a new time stamp.
// Unclear if the array dispatcher should detect this and only update
// the per-element PVs that really have a new value, or all.
// Currently it updates all, but the test is satisfied with just one update:
assertThat(VTypeUtil.getValueNumber(element_pvs.get().get(1).read()).doubleValue(), equalTo(22.5));
// Change per-element PV -> Observe update of array
System.out.println("Updating per-element PV for element [2]");
element_pvs.get().get(2).write(30.7);
// Test assumes a local array PV which immediately reflects the change.
// A "real" PV can have a delay between writing a new value and receiving the update.
final ListNumber array_value = ((VNumberArray) array_pv.read()).getData();
System.out.println("Array: " + array_value);
assertThat(array_value.getDouble(2), equalTo(30.7));
// Close dispatcher
dispatcher.close();
// Close the array PV
PVFactory.releasePV(array_pv);
}
Aggregations