Commit | Line | Data |
---|---|---|
b1baa808 | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2012, 2014 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 | *******************************************************************************/ |
9722e5d7 AM |
13 | |
14 | package org.eclipse.tracecompass.tmf.ctf.core.context; | |
a3fc8213 | 15 | |
032ecd45 MAL |
16 | import java.nio.ByteBuffer; |
17 | ||
2bdf0193 AM |
18 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; |
19 | import org.eclipse.tracecompass.tmf.core.trace.location.TmfLocation; | |
a3fc8213 | 20 | |
b1baa808 | 21 | /** |
d09f973b | 22 | * The nugget of information that is unique to a location in a CTF trace. |
132a02b0 | 23 | * |
d09f973b | 24 | * It can be copied and used to restore a position in a given trace. |
132a02b0 | 25 | * |
d09f973b | 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 | |
b1baa808 | 48 | */ |
d62bb185 FC |
49 | public CtfLocation(final ITmfTimestamp timestamp) { |
50 | this(timestamp.getValue(), 0); | |
a3fc8213 | 51 | } |
ce2388e0 | 52 | |
b1baa808 | 53 | /** |
a749efcb | 54 | * Constructor using timestamp object and index |
132a02b0 MK |
55 | * |
56 | * @param timestamp | |
57 | * The timestamp of this location | |
58 | * @param index | |
59 | * The index of this location for this timestamp | |
132a02b0 | 60 | */ |
d62bb185 FC |
61 | public CtfLocation(final ITmfTimestamp timestamp, long index) { |
62 | this(timestamp.getValue(), index); | |
132a02b0 MK |
63 | } |
64 | ||
65 | /** | |
a749efcb | 66 | * Constructor using a long value for the timestamp, and an index |
132a02b0 | 67 | * |
d62bb185 FC |
68 | * @param timestampValue |
69 | * The new timestamp | |
70 | * @param index | |
71 | * The new index | |
b1baa808 | 72 | */ |
d62bb185 | 73 | public CtfLocation(final long timestampValue, final long index) { |
a749efcb | 74 | super(new CtfLocationInfo(timestampValue, index)); |
a3fc8213 AM |
75 | } |
76 | ||
132a02b0 | 77 | /** |
a749efcb | 78 | * Constructor using a pre-made locationInfo object |
132a02b0 | 79 | * |
a749efcb AM |
80 | * @param locationInfo |
81 | * The locationInfo object to use | |
b1baa808 | 82 | */ |
a749efcb AM |
83 | public CtfLocation(CtfLocationInfo locationInfo) { |
84 | super(locationInfo); | |
a3fc8213 AM |
85 | } |
86 | ||
b1baa808 | 87 | /** |
a749efcb | 88 | * Copy constructor |
132a02b0 | 89 | * |
a749efcb AM |
90 | * @param location |
91 | * Other location to copy | |
b1baa808 | 92 | */ |
a749efcb AM |
93 | public CtfLocation(final CtfLocation location) { |
94 | super(location); | |
a3fc8213 AM |
95 | } |
96 | ||
a749efcb AM |
97 | // ------------------------------------------------------------------------ |
98 | // TmfLocation | |
99 | // ------------------------------------------------------------------------ | |
132a02b0 | 100 | |
032ecd45 MAL |
101 | /** |
102 | * Construct the location from the ByteBuffer. | |
103 | * | |
104 | * @param bufferIn | |
105 | * the buffer to read from | |
032ecd45 MAL |
106 | */ |
107 | public CtfLocation(ByteBuffer bufferIn) { | |
108 | super(new CtfLocationInfo(bufferIn)); | |
109 | } | |
110 | ||
81c8e6f7 | 111 | @Override |
a749efcb AM |
112 | public CtfLocationInfo getLocationInfo() { |
113 | return (CtfLocationInfo) super.getLocationInfo(); | |
81c8e6f7 MK |
114 | } |
115 | ||
a749efcb AM |
116 | // ------------------------------------------------------------------------ |
117 | // Object | |
118 | // ------------------------------------------------------------------------ | |
81c8e6f7 | 119 | |
eea58fe7 MK |
120 | @Override |
121 | public String toString() { | |
283b5dc7 | 122 | if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) { |
a749efcb | 123 | return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$ |
eea58fe7 | 124 | } |
a749efcb | 125 | return super.toString(); |
eea58fe7 MK |
126 | } |
127 | ||
032ecd45 MAL |
128 | /** |
129 | * Constructs the location from the ByteBuffer. This typically happens when reading from disk. | |
032ecd45 MAL |
130 | */ |
131 | @Override | |
132 | public void serialize(ByteBuffer bufferOut) { | |
133 | getLocationInfo().serialize(bufferOut); | |
032ecd45 | 134 | } |
a3fc8213 | 135 | } |