[219097] LTTng updates
[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;
8035003b 36 private final int defaultWidth = 2000; // number of estimated pixels that
6e512b93 37 // can hold the time range space
8035003b 38 private int width = defaultWidth; // width in pixels used to represent the
6e512b93
ASL
39 // time interval
40 private double pixelsPerNs = 0;
41 private int eventsDiscarded = 0;
42 private int eventsDiscardedWrongOrder = 0;
43 private TmfTimeRange trange = null;
44
45 // ========================================================================
46 // Methods
47 // ========================================================================
48
49 /**
50 * @param event
51 * @return
52 */
53 public synchronized boolean processTimeScaleEvent(
54 TmfTimeScaleSelectionEvent event) {
55
56 boolean updated = false;
57 if (event != null) {
58 long time0 = event.getTime0();
59 long time1 = event.getTime1();
60 int dwidth = event.getWidth();
61
62 updated = update(time0, time1, dwidth);
8035003b 63 setSelectedTime(event.getSelectedTime());
6e512b93
ASL
64 }
65
66 return updated;
67
68 }
69
70 /**
71 * Save the selected time
72 * @param selTime
73 */
74 public void setSelectedTime(long selTime) {
8035003b
ASL
75 if (selTime > startTime && selTime < endTime) {
76 selectedTime = selTime;
77 } else {
78 selectedTime = null;
79 }
6e512b93
ASL
80 }
81
82 /**
83 * May return null, if the selected time is invalid
84 *
85 * @return
86 */
87 public Long getSelectedTime() {
88 return selectedTime;
89 }
90
6e512b93
ASL
91 /**
92 * Only positive attributes are expected
93 *
94 * @param time0
95 * @param time1
96 * @param dwidth
97 * @return
98 */
99 public boolean update(long time0, long time1, int dwidth) {
100 boolean updated = false;
101
102 if (time0 == startTime && time1 == endTime && dwidth == width) {
103 // No updated needed
104 return updated;
105 }
106
107 // Negatives are invalid
108 time0 = time0 > 0 ? time0 : 0;
109 time1 = time1 > 0 ? time1 : 0;
110 dwidth = dwidth > 0 ? dwidth : 0;
111
112 if (time1 > time0) {
113 // Store the new values as long as they are within range
114 startTime = time0;
115 endTime = time1;
116 width = dwidth;
117
118 pixelsPerNs = (double) width / (double) (endTime - startTime);
63eecb47
FC
119
120 TmfTimestamp fTimeStart = new LttngTimestamp(startTime);
121 TmfTimestamp fTimeEnd = new LttngTimestamp(endTime);
122 trange = new TmfTimeRange(fTimeStart, fTimeEnd);
6e512b93
ASL
123
124 // update succeeded
125 updated = true;
126
127 TraceDebug.debug("Configuration updated to: StartTime: " /* */
63eecb47
FC
128 + fTimeStart /* */
129 + "-" /* */
130 + fTimeEnd /* */
6e512b93
ASL
131 + " width: " /* */
132 + width + " k: " + pixelsPerNs); /* */
133 } else {
134 TraceDebug
135 .debug("End time is not greater than start time, start time: "
136 + time0 + " end time: " + time1);
137 }
138
139 return updated;
140 }
141
142 /**
143 * @return
144 */
145 public long getStartTime() {
146 return startTime;
147 }
148
149 /**
150 * @return
151 */
152 public long getEndTime() {
153 return endTime;
154 }
155
156 /**
157 * @return
158 */
159 public int getWidth() {
160 if (width == 0) {
8035003b
ASL
161 return defaultWidth;
162 } else {
163 TraceDebug.debug("Unexpected width value of 0 pixels");
6e512b93
ASL
164 }
165
166 return width;
167 }
168
169 /**
170 * Return the current constant "K" of pixels per nano second used for the
171 * widest time space widget registered in this instance.
172 *
173 * @return
174 */
175 public double getPixelsPerNs() {
176 return pixelsPerNs;
177 }
178
179 /**
180 * Set the value of pixels per nano second as long as the value is grater
181 * positive
182 *
183 * @return
184 */
185 public void setPixelsPerNs(double pixperNsec) {
186 if (pixperNsec > 0) {
187 pixelsPerNs = pixperNsec;
188 }
189 }
190
191 /**
192 * @param value
193 */
194 public void setEventsDiscarded(int value) {
195 eventsDiscarded = value;
196 if (value == 0) {
197 eventsDiscardedWrongOrder = 0;
198 }
199 }
200
201 /**
202 *
203 */
204 public void incrementEventsDiscarded() {
205 this.eventsDiscarded++;
206 }
207
208 /**
209 * @return
210 */
211 public int getEventsDiscarded() {
212 return eventsDiscarded;
213 }
214
215 /**
216 * increase the number of events discarder since they were not received in a
217 * later time than previous events
218 */
219 public void incrementEventsDiscardedWrongOrder() {
220 this.eventsDiscarded++;
221 this.eventsDiscardedWrongOrder++;
222 }
223
224 /**
225 * @return
226 */
227 public int getEventsDiscardedWrongOrder() {
228 return eventsDiscardedWrongOrder;
229
230 }
231
232 /**
233 * @return
234 */
235 public TmfTimeRange getTrange() {
236 return trange;
237 }
238
239}
This page took 0.033599 seconds and 5 git commands to generate.