tmf: Rename CtfLocationData to CtfLocationInfo
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfTmfContext.java
CommitLineData
788ddcbc
MK
1/*******************************************************************************
2 * Copyright (c) 2012 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are made
5 * 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: Matthew Khouzam - Initial API and implementation
10 *******************************************************************************/
11
12package org.eclipse.linuxtools.tmf.core.ctfadaptor;
13
788ddcbc
MK
14import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
15import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
16
17/**
18 * Lightweight Context for CtfTmf traces. Should only use 3 references, 1 ref to
19 * a boxed Long, a long and an int.
20 *
21 * @author Matthew Khouzam
81a2d02e
AM
22 * @version 1.0
23 * @since 2.0
788ddcbc 24 */
81a2d02e 25public class CtfTmfContext implements ITmfContext {
788ddcbc 26
788ddcbc
MK
27 // -------------------------------------------
28 // Fields
29 // -------------------------------------------
81a2d02e 30
788ddcbc
MK
31 private CtfLocation curLocation;
32 private long curRank;
788ddcbc 33
53b235e1 34 private final CtfTmfTrace fTrace;
788ddcbc
MK
35
36 // -------------------------------------------
37 // Constructor
38 // -------------------------------------------
53b235e1
MK
39
40 /**
81a2d02e 41 * Constructor
53b235e1
MK
42 *
43 * @param ctfTmfTrace
44 * the parent trace
45 * @since 1.1
46 */
81a2d02e 47 public CtfTmfContext(CtfTmfTrace ctfTmfTrace) {
53b235e1 48 fTrace = ctfTmfTrace;
f5df94f8 49 curLocation = new CtfLocation(new CtfLocationInfo(0, 0));
788ddcbc
MK
50 }
51
52 // -------------------------------------------
53 // TmfContext Overrides
54 // -------------------------------------------
55
56 @Override
57 public long getRank() {
58 return curRank;
59 }
60
61 @Override
1e1bef82 62 public ITmfLocation getLocation() {
788ddcbc
MK
63 return curLocation;
64 }
65
66 @Override
67 public boolean hasValidRank() {
132a02b0 68 return curRank != CtfLocation.INVALID_LOCATION.getTimestamp();
788ddcbc
MK
69 }
70
71 @Override
1e1bef82 72 public void setLocation(ITmfLocation location) {
788ddcbc 73 curLocation = (CtfLocation) location;
575beffc
PT
74 if (curLocation != null) {
75 getIterator().seek(curLocation.getLocationInfo());
76 }
788ddcbc
MK
77 }
78
79 @Override
80 public void setRank(long rank) {
81 curRank = rank;
82
83 }
84
85 @Override
86 public void increaseRank() {
87 if (hasValidRank()) {
88 curRank++;
89 }
90 }
91
92 // -------------------------------------------
93 // CtfTmfTrace Helpers
94 // -------------------------------------------
95
81a2d02e
AM
96 /**
97 * Gets the trace of this context.
98 *
99 * @return The trace of this context
100 */
101 public CtfTmfTrace getTrace() {
102 return fTrace;
103 }
104
788ddcbc
MK
105 /**
106 * Gets the current event. Wrapper to help CtfTmfTrace
53b235e1 107 *
788ddcbc
MK
108 * @return The event or null
109 */
110 public synchronized CtfTmfEvent getCurrentEvent() {
53b235e1 111 return getIterator().getCurrentEvent();
788ddcbc
MK
112 }
113
114 /**
115 * Advances to a the next event. Wrapper to help CtfTmfTrace
53b235e1 116 *
788ddcbc
MK
117 * @return success or not
118 */
119 public synchronized boolean advance() {
f5df94f8 120 final CtfLocationInfo curLocationData = this.curLocation.getLocationInfo();
53b235e1
MK
121 boolean retVal = getIterator().advance();
122 CtfTmfEvent currentEvent = getIterator().getCurrentEvent();
132a02b0 123
788ddcbc 124 if (currentEvent != null) {
58f3bc52 125 final long timestampValue = currentEvent.getTimestamp().getValue();
132a02b0 126 if (curLocationData.getTimestamp() == timestampValue) {
d62bb185 127 curLocation = new CtfLocation(timestampValue, curLocationData.getIndex() + 1);
132a02b0 128 } else {
d62bb185 129 curLocation = new CtfLocation(timestampValue, 0L);
132a02b0 130 }
788ddcbc 131 } else {
d62bb185 132 curLocation = new CtfLocation(CtfLocation.INVALID_LOCATION);
788ddcbc
MK
133 }
134
135 return retVal;
136 }
137
138 @Override
139 public void dispose() {
140 // do nothing
141 }
142
143 /**
144 * Seeks to a given timestamp. Wrapper to help CtfTmfTrace
53b235e1
MK
145 *
146 * @param timestamp
147 * desired timestamp
788ddcbc
MK
148 * @return success or not
149 */
150 public synchronized boolean seek(final long timestamp) {
d62bb185 151 curLocation = new CtfLocation(timestamp, 0);
53b235e1 152 return getIterator().seek(timestamp);
788ddcbc
MK
153 }
154
132a02b0
MK
155 /**
156 * Seeks to a given location. Wrapper to help CtfTmfTrace
157 * @param location
158 * unique location to find the event.
159 *
160 * @return success or not
161 * @since 2.0
162 */
f5df94f8 163 public synchronized boolean seek(final CtfLocationInfo location) {
d62bb185 164 curLocation = new CtfLocation(location);
132a02b0
MK
165 return getIterator().seek(location);
166 }
167
788ddcbc 168 @Override
81a2d02e
AM
169 public CtfTmfContext clone() {
170 CtfTmfContext ret = null;
171 try {
172 ret = (CtfTmfContext) super.clone();
173 /* Fields are immutable, no need to deep-copy them */
174 } catch (CloneNotSupportedException e) {
175 /* Should not happen, we're calling Object.clone() */
176 }
788ddcbc
MK
177 return ret;
178 }
179
180 // -------------------------------------------
181 // Private helpers
182 // -------------------------------------------
81a2d02e 183
788ddcbc 184 /**
53b235e1
MK
185 * Get iterator, called every time to get an iterator, no local copy is
186 * stored so that there is no need to "update"
788ddcbc 187 *
53b235e1 188 * @return an iterator
788ddcbc
MK
189 */
190 private CtfIterator getIterator() {
53b235e1 191 return CtfIteratorManager.getIterator(fTrace, this);
788ddcbc 192 }
788ddcbc 193}
This page took 0.039675 seconds and 5 git commands to generate.