Search in sources :

Example 1 with RuntimePV

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();
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 2 with RuntimePV

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;
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV)

Example 3 with RuntimePV

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();
}
Also used : TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 4 with RuntimePV

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);
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) Script(org.csstudio.display.builder.runtime.script.internal.Script) RuntimeScriptHandler(org.csstudio.display.builder.runtime.script.internal.RuntimeScriptHandler) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport)

Example 5 with RuntimePV

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);
}
Also used : ArrayPVDispatcher(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher) VNumberArray(org.diirt.vtype.VNumberArray) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) ListNumber(org.diirt.util.array.ListNumber) Listener(org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener) List(java.util.List) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)21 CountDownLatch (java.util.concurrent.CountDownLatch)6 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)6 List (java.util.List)5 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)4 ArrayPVDispatcher (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher)4 VType (org.diirt.vtype.VType)4 Test (org.junit.Test)4 Listener (org.csstudio.display.builder.runtime.pv.ArrayPVDispatcher.Listener)3 Collection (java.util.Collection)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Level (java.util.logging.Level)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 VTypeUtil (org.csstudio.display.builder.model.util.VTypeUtil)2 ROIWidgetProperty (org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty)2