2 * Copyright (C) 2017 EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 package org
.lttng
.scope
.tmf2
.views
.core
.context
;
12 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
13 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignal
;
14 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
15 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalManager
;
16 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalThrottler
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceRangeUpdatedSignal
;
19 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfWindowRangeUpdatedSignal
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
26 import org
.lttng
.scope
.tmf2
.views
.core
.TimeRange
;
29 * Bridge between a {@link ViewGroupContext} and the {@link TmfSignalManager}.
30 * It sends equivalent "signals" back-and-forth between the two APIs.
32 * Note: Needs to be public because of the way TmfSignalManager works.
34 * @author Alexandre Montplaisir
36 public class SignalBridge
{
38 private static final int SIGNAL_DELAY_MS
= 200;
40 private final TmfSignalThrottler fVisibleRangeSignalThrottler
= new TmfSignalThrottler(null, SIGNAL_DELAY_MS
);
42 private final ViewGroupContext fViewContext
;
48 * The view context this bridge will connect to
50 public SignalBridge(ViewGroupContext viewContext
) {
51 TmfSignalManager
.register(this);
52 fViewContext
= viewContext
;
54 viewContext
.currentTraceProperty().addListener((obs
, oldTrace
, newTrace
) -> {
55 if (newTrace
== null) {
58 TmfSignal newTraceSignal
= new TmfTraceSelectedSignal(SignalBridge
.this, newTrace
);
59 TmfSignalManager
.dispatchSignal(newTraceSignal
);
61 viewContext
.currentTraceFullRangeProperty().addListener((observable
, oldRange
, newRange
) -> {
62 TmfTimeRange tmfTimeRange
= newRange
.toTmfTimeRange();
63 TmfSignal signal
= new TmfTraceRangeUpdatedSignal(SignalBridge
.this, viewContext
.getCurrentTrace(), tmfTimeRange
);
64 TmfSignalManager
.dispatchSignal(signal
);
67 viewContext
.currentVisibleTimeRangeProperty().addListener((observable
, oldRange
, newRange
) -> {
68 TmfTimeRange tmfTimeRange
= newRange
.toTmfTimeRange();
69 TmfSignal signal
= new TmfWindowRangeUpdatedSignal(SignalBridge
.this, tmfTimeRange
);
70 fVisibleRangeSignalThrottler
.queue(signal
);
73 viewContext
.currentSelectionTimeRangeProperty().addListener((observable
, oldRange
, newRange
) -> {
75 if (newRange
.isSingleTimestamp()) {
76 ITmfTimestamp ts
= TmfTimestamp
.fromNanos(newRange
.getStart());
77 signal
= new TmfSelectionRangeUpdatedSignal(SignalBridge
.this, ts
);
79 ITmfTimestamp startTs
= TmfTimestamp
.fromNanos(newRange
.getStart());
80 ITmfTimestamp endTs
= TmfTimestamp
.fromNanos(newRange
.getEnd());
81 signal
= new TmfSelectionRangeUpdatedSignal(SignalBridge
.this, startTs
, endTs
);
83 TmfSignalManager
.dispatchSignal(signal
);
90 * Dispose of this bridge, deregistering it from the signal manager.
92 public void dispose() {
93 TmfSignalManager
.deregister(this);
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
101 * Handler for the trace selected signal
107 public void traceSelected(final TmfTraceSelectedSignal signal
) {
108 if (signal
.getSource() == this) {
111 ITmfTrace trace
= signal
.getTrace();
112 fViewContext
.setCurrentTrace(trace
);
116 * Handler for the trace closed signal
122 public void traceClosed(final TmfTraceClosedSignal signal
) {
123 if (signal
.getSource() == this) {
126 if (TmfTraceManager
.getInstance().getActiveTrace() == null) {
127 fViewContext
.setCurrentTrace(null);
132 * Handler for the trace range updated signal
138 public void traceRangeUpdated(TmfTraceRangeUpdatedSignal signal
) {
139 if (signal
.getSource() == this) {
143 * This signal is a disaster, it's very inconsistent, has no guarantee
144 * of even showing up and sometimes gives values outside of the trace's
145 * own range. Best to ignore its contents completely.
148 ITmfTrace trace
= fViewContext
.getCurrentTrace();
152 long traceStart
= trace
.getStartTime().toNanos();
153 long traceEnd
= trace
.getEndTime().toNanos();
154 fViewContext
.setCurrentTraceFullRange(TimeRange
.of(traceStart
, traceEnd
));
158 * Handler for the selection range updated signal
164 public void selectionRangeUpdated(final TmfSelectionRangeUpdatedSignal signal
) {
165 if (signal
.getSource() == this) {
168 long rangeStart
= signal
.getBeginTime().toNanos();
169 long rangeEnd
= signal
.getEndTime().toNanos();
171 /* Sometimes the range is weird... */
172 if (rangeStart
== Long
.MAX_VALUE
|| rangeEnd
== Long
.MAX_VALUE
) {
177 * This signal's end can be before its start time, against all logic.
180 if (rangeStart
> rangeEnd
) {
181 range
= TimeRange
.of(rangeEnd
, rangeStart
);
183 range
= TimeRange
.of(rangeStart
, rangeEnd
);
186 ITmfTrace trace
= fViewContext
.getCurrentTrace();
190 fViewContext
.setCurrentSelectionTimeRange(range
);
194 * Handler for the window range updated signal
200 public void windowRangeUpdated(final TmfWindowRangeUpdatedSignal signal
) {
201 if (signal
.getSource() == this) {
204 TmfTimeRange windowRange
= signal
.getCurrentRange();
205 ITmfTrace trace
= fViewContext
.getCurrentTrace();
206 if (windowRange
== null || trace
== null) {
209 fViewContext
.setCurrentVisibleTimeRange(TimeRange
.fromTmfTimeRange(windowRange
));