Fix for missing end event in CFV/RV processing.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / common / ParamsUpdater.java
CommitLineData
6e512b93
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.common;
13
14import org.eclipse.linuxtools.lttng.event.LttngTimestamp;
15import org.eclipse.linuxtools.lttng.ui.TraceDebug;
16import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
63eecb47 17import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
6e512b93
ASL
18import org.eclipse.linuxtools.tmf.ui.viewers.timeAnalysis.TmfTimeScaleSelectionEvent;
19
20/**
21 *
22 * Preserve the time and space width parameters applicable to a particular view
23 * in order to facilitate filtering of events and request handling.
24 *
25 * @author alvaro
26 *
27 */
28public class ParamsUpdater {
29 // ========================================================================
30 // Data
31 // ========================================================================
32
33 private long startTime = 0;
34 private long endTime = Long.MAX_VALUE;
35 private Long selectedTime = null;
8827c197
FC
36 private final int DEFAULT_WIDTH = 2000; // number of estimated pixels
37 // that
6e512b93 38 // can hold the time range space
8827c197 39 private int width = DEFAULT_WIDTH; // width in pixels used to represent the
6e512b93
ASL
40 // time interval
41 private double pixelsPerNs = 0;
42 private int eventsDiscarded = 0;
43 private int eventsDiscardedWrongOrder = 0;
44 private TmfTimeRange trange = null;
45
46 // ========================================================================
47 // Methods
48 // ========================================================================
49
50 /**
51 * @param event
52 * @return
53 */
54 public synchronized boolean processTimeScaleEvent(
55 TmfTimeScaleSelectionEvent event) {
56
57 boolean updated = false;
58 if (event != null) {
59 long time0 = event.getTime0();
60 long time1 = event.getTime1();
61 int dwidth = event.getWidth();
62
63 updated = update(time0, time1, dwidth);
8827c197
FC
64
65 // initialization only, otherwise wait for the actual selection
66 // event to update its value. Note that the time must be different
67 // upon selection of a new time in order to trigger an update to all
68 if (selectedTime == null) {
69 setSelectedTime(event.getSelectedTime());
70 }
71
6e512b93
ASL
72 }
73
74 return updated;
75
76 }
77
78 /**
79 * Save the selected time
80 * @param selTime
81 */
82 public void setSelectedTime(long selTime) {
8827c197
FC
83 TraceDebug.debug("Selected time changed from: \n\t" + selectedTime
84 + " to: \n\t" + selTime);
85 selectedTime = selTime;
6e512b93
ASL
86 }
87
88 /**
89 * May return null, if the selected time is invalid
90 *
91 * @return
92 */
93 public Long getSelectedTime() {
94 return selectedTime;
95 }
96
d712a5f3
FC
97 /**
98 * Update time range but keep width as is
99 *
100 * @param time0
101 * @param time1
102 * @return
103 */
104 public boolean update(long time0, long time1) {
105 return update(time0, time1, width);
106 }
107
6e512b93
ASL
108 /**
109 * Only positive attributes are expected
110 *
111 * @param time0
112 * @param time1
113 * @param dwidth
114 * @return
115 */
116 public boolean update(long time0, long time1, int dwidth) {
117 boolean updated = false;
118
119 if (time0 == startTime && time1 == endTime && dwidth == width) {
120 // No updated needed
121 return updated;
122 }
123
124 // Negatives are invalid
125 time0 = time0 > 0 ? time0 : 0;
126 time1 = time1 > 0 ? time1 : 0;
127 dwidth = dwidth > 0 ? dwidth : 0;
128
129 if (time1 > time0) {
130 // Store the new values as long as they are within range
131 startTime = time0;
132 endTime = time1;
133 width = dwidth;
134
135 pixelsPerNs = (double) width / (double) (endTime - startTime);
63eecb47
FC
136
137 TmfTimestamp fTimeStart = new LttngTimestamp(startTime);
138 TmfTimestamp fTimeEnd = new LttngTimestamp(endTime);
139 trange = new TmfTimeRange(fTimeStart, fTimeEnd);
6e512b93 140
d712a5f3
FC
141 // make sure the selected time is within the new range or else set
142 // mark it as invalid
143 if (selectedTime != null) {
144 setSelectedTime(selectedTime);
145 }
146
6e512b93
ASL
147 // update succeeded
148 updated = true;
149
150 TraceDebug.debug("Configuration updated to: StartTime: " /* */
63eecb47
FC
151 + fTimeStart /* */
152 + "-" /* */
153 + fTimeEnd /* */
6e512b93
ASL
154 + " width: " /* */
155 + width + " k: " + pixelsPerNs); /* */
156 } else {
157 TraceDebug
158 .debug("End time is not greater than start time, start time: "
159 + time0 + " end time: " + time1);
160 }
161
162 return updated;
163 }
164
165 /**
166 * @return
167 */
168 public long getStartTime() {
169 return startTime;
170 }
171
172 /**
173 * @return
174 */
175 public long getEndTime() {
176 return endTime;
177 }
178
179 /**
180 * @return
181 */
182 public int getWidth() {
183 if (width == 0) {
8827c197
FC
184 TraceDebug
185 .debug("Unexpected width value of 0 pixels, returning default");
186 return DEFAULT_WIDTH;
6e512b93
ASL
187 }
188
189 return width;
190 }
191
192 /**
193 * Return the current constant "K" of pixels per nano second used for the
194 * widest time space widget registered in this instance.
195 *
196 * @return
197 */
198 public double getPixelsPerNs() {
199 return pixelsPerNs;
200 }
201
202 /**
203 * Set the value of pixels per nano second as long as the value is grater
204 * positive
205 *
206 * @return
207 */
208 public void setPixelsPerNs(double pixperNsec) {
209 if (pixperNsec > 0) {
210 pixelsPerNs = pixperNsec;
211 }
212 }
213
214 /**
215 * @param value
216 */
217 public void setEventsDiscarded(int value) {
218 eventsDiscarded = value;
219 if (value == 0) {
220 eventsDiscardedWrongOrder = 0;
221 }
222 }
223
224 /**
225 *
226 */
227 public void incrementEventsDiscarded() {
228 this.eventsDiscarded++;
229 }
230
231 /**
232 * @return
233 */
234 public int getEventsDiscarded() {
235 return eventsDiscarded;
236 }
237
238 /**
239 * increase the number of events discarder since they were not received in a
240 * later time than previous events
241 */
242 public void incrementEventsDiscardedWrongOrder() {
243 this.eventsDiscarded++;
244 this.eventsDiscardedWrongOrder++;
245 }
246
247 /**
248 * @return
249 */
250 public int getEventsDiscardedWrongOrder() {
251 return eventsDiscardedWrongOrder;
252
253 }
254
255 /**
256 * @return
257 */
258 public TmfTimeRange getTrange() {
259 return trange;
260 }
261
262}
This page took 0.035389 seconds and 5 git commands to generate.