Commit | Line | Data |
---|---|---|
b1baa808 | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 Ericsson |
b1baa808 MK |
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 | * | |
a749efcb AM |
9 | * Contributors: |
10 | * Matthew Khouzam - Initial API and implementation | |
11 | * Alexandre Montplaisir - Extends TmfLocation | |
b1baa808 | 12 | *******************************************************************************/ |
91e7f946 | 13 | package org.eclipse.linuxtools.tmf.ctf.core; |
a3fc8213 | 14 | |
032ecd45 MAL |
15 | import java.nio.ByteBuffer; |
16 | ||
3bd46eef | 17 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
a3db8436 | 18 | import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation; |
a3fc8213 | 19 | |
b1baa808 | 20 | /** |
d09f973b | 21 | * The nugget of information that is unique to a location in a CTF trace. |
132a02b0 | 22 | * |
d09f973b | 23 | * It can be copied and used to restore a position in a given trace. |
132a02b0 | 24 | * |
d09f973b FC |
25 | * @version 1.0 |
26 | * @author Matthew Khouzam | |
b1baa808 | 27 | */ |
a749efcb | 28 | public final class CtfLocation extends TmfLocation { |
132a02b0 | 29 | |
a749efcb AM |
30 | // ------------------------------------------------------------------------ |
31 | // Attributes | |
32 | // ------------------------------------------------------------------------ | |
a3fc8213 | 33 | |
9ac2eb62 MK |
34 | /** |
35 | * An invalid location | |
36 | */ | |
f5df94f8 | 37 | public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1); |
57c073c5 | 38 | |
a749efcb AM |
39 | // ------------------------------------------------------------------------ |
40 | // Constructors | |
41 | // ------------------------------------------------------------------------ | |
42 | ||
b1baa808 | 43 | /** |
a749efcb | 44 | * Basic constructor for CtfLocation. Uses a default index of 0. |
132a02b0 | 45 | * |
f0f3a065 AM |
46 | * @param timestamp |
47 | * The timestamp of this location | |
3bd46eef | 48 | * @since 2.0 |
b1baa808 | 49 | */ |
d62bb185 FC |
50 | public CtfLocation(final ITmfTimestamp timestamp) { |
51 | this(timestamp.getValue(), 0); | |
a3fc8213 | 52 | } |
ce2388e0 | 53 | |
b1baa808 | 54 | /** |
a749efcb | 55 | * Constructor using timestamp object and index |
132a02b0 MK |
56 | * |
57 | * @param timestamp | |
58 | * The timestamp of this location | |
59 | * @param index | |
60 | * The index of this location for this timestamp | |
61 | * @since 2.0 | |
62 | */ | |
d62bb185 FC |
63 | public CtfLocation(final ITmfTimestamp timestamp, long index) { |
64 | this(timestamp.getValue(), index); | |
132a02b0 MK |
65 | } |
66 | ||
67 | /** | |
a749efcb | 68 | * Constructor using a long value for the timestamp, and an index |
132a02b0 | 69 | * |
d62bb185 FC |
70 | * @param timestampValue |
71 | * The new timestamp | |
72 | * @param index | |
73 | * The new index | |
f0f3a065 | 74 | * @since 2.0 |
b1baa808 | 75 | */ |
d62bb185 | 76 | public CtfLocation(final long timestampValue, final long index) { |
a749efcb | 77 | super(new CtfLocationInfo(timestampValue, index)); |
a3fc8213 AM |
78 | } |
79 | ||
132a02b0 | 80 | /** |
a749efcb | 81 | * Constructor using a pre-made locationInfo object |
132a02b0 | 82 | * |
a749efcb AM |
83 | * @param locationInfo |
84 | * The locationInfo object to use | |
132a02b0 | 85 | * @since 2.0 |
b1baa808 | 86 | */ |
a749efcb AM |
87 | public CtfLocation(CtfLocationInfo locationInfo) { |
88 | super(locationInfo); | |
a3fc8213 AM |
89 | } |
90 | ||
b1baa808 | 91 | /** |
a749efcb | 92 | * Copy constructor |
132a02b0 | 93 | * |
a749efcb AM |
94 | * @param location |
95 | * Other location to copy | |
132a02b0 | 96 | * @since 2.0 |
b1baa808 | 97 | */ |
a749efcb AM |
98 | public CtfLocation(final CtfLocation location) { |
99 | super(location); | |
a3fc8213 AM |
100 | } |
101 | ||
a749efcb AM |
102 | // ------------------------------------------------------------------------ |
103 | // TmfLocation | |
104 | // ------------------------------------------------------------------------ | |
132a02b0 | 105 | |
032ecd45 MAL |
106 | /** |
107 | * Construct the location from the ByteBuffer. | |
108 | * | |
109 | * @param bufferIn | |
110 | * the buffer to read from | |
111 | * | |
112 | * @since 3.0 | |
113 | */ | |
114 | public CtfLocation(ByteBuffer bufferIn) { | |
115 | super(new CtfLocationInfo(bufferIn)); | |
116 | } | |
117 | ||
a749efcb AM |
118 | /** |
119 | * @since 2.0 | |
81c8e6f7 MK |
120 | */ |
121 | @Override | |
a749efcb AM |
122 | public CtfLocationInfo getLocationInfo() { |
123 | return (CtfLocationInfo) super.getLocationInfo(); | |
81c8e6f7 MK |
124 | } |
125 | ||
a749efcb AM |
126 | // ------------------------------------------------------------------------ |
127 | // Object | |
128 | // ------------------------------------------------------------------------ | |
81c8e6f7 | 129 | |
eea58fe7 MK |
130 | @Override |
131 | public String toString() { | |
283b5dc7 | 132 | if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) { |
a749efcb | 133 | return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$ |
eea58fe7 | 134 | } |
a749efcb | 135 | return super.toString(); |
eea58fe7 MK |
136 | } |
137 | ||
032ecd45 MAL |
138 | /** |
139 | * Constructs the location from the ByteBuffer. This typically happens when reading from disk. | |
140 | * | |
141 | * @since 3.0 | |
142 | */ | |
143 | @Override | |
144 | public void serialize(ByteBuffer bufferOut) { | |
145 | getLocationInfo().serialize(bufferOut); | |
032ecd45 | 146 | } |
a3fc8213 | 147 | } |