Commit | Line | Data |
---|---|---|
ce2388e0 FC |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others | |
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 | * Contributors: Simon Marchi - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.internal.ctf.core.trace; | |
14 | ||
21fb02fa | 15 | import java.util.HashMap; |
8de0528f | 16 | import java.util.Map; |
21fb02fa | 17 | |
ce2388e0 FC |
18 | /** |
19 | * <b><u>StreamInputPacketIndexEntry</u></b> | |
20 | * <p> | |
21 | * Represents an entry in the index of event packets. | |
22 | */ | |
23 | public class StreamInputPacketIndexEntry { | |
24 | ||
25 | // ------------------------------------------------------------------------ | |
26 | // Attributes | |
27 | // ------------------------------------------------------------------------ | |
28 | ||
ce2388e0 FC |
29 | /** |
30 | * Offset of the packet in the file, in bytes | |
31 | */ | |
32 | final private long offsetBytes; | |
33 | ||
34 | /** | |
35 | * Offset of the data in the packet, in bits | |
36 | */ | |
37 | private int dataOffsetBits = 0; | |
38 | ||
39 | /** | |
40 | * Packet size, in bits | |
41 | */ | |
42 | private int packetSizeBits = 0; | |
43 | ||
44 | /** | |
45 | * Content size, in bits | |
46 | */ | |
47 | private int contentSizeBits = 0; | |
48 | ||
49 | /** | |
50 | * Begin timestamp | |
51 | */ | |
52 | private long timestampBegin = 0; | |
53 | ||
54 | /** | |
55 | * End timestamp | |
56 | */ | |
57 | private long timestampEnd = 0; | |
58 | ||
5c7202b5 MK |
59 | /** |
60 | * How many lost events are there? | |
61 | */ | |
62 | private long lostEvents = 0; | |
63 | ||
21fb02fa MK |
64 | /** |
65 | * Which target is being traced | |
66 | */ | |
67 | private String target ; | |
68 | private long targetID; | |
69 | ||
8de0528f AM |
70 | /** |
71 | * Attributes of this index entry | |
72 | */ | |
73 | private final Map<String, Object> attributes = new HashMap<String, Object>(); | |
74 | ||
21fb02fa | 75 | |
ce2388e0 FC |
76 | // ------------------------------------------------------------------------ |
77 | // Constructors | |
78 | // ------------------------------------------------------------------------ | |
79 | ||
80 | /** | |
81 | * Constructs an index entry. | |
82 | * | |
83 | * @param offset | |
84 | * The offset of the packet in the file, in bytes. | |
85 | */ | |
86 | ||
87 | public StreamInputPacketIndexEntry(long offset) { | |
88 | this.offsetBytes = offset; | |
89 | } | |
90 | ||
91 | // ------------------------------------------------------------------------ | |
92 | // Operations | |
93 | // ------------------------------------------------------------------------ | |
94 | ||
95 | /** | |
96 | * Returns whether the packet includes (inclusively) the given timestamp in | |
97 | * the begin-end timestamp range. | |
98 | * | |
99 | * @param ts | |
100 | * The timestamp to check. | |
101 | * @return True if the packet includes the timestamp. | |
102 | */ | |
103 | boolean includes(long ts) { | |
104 | return (ts >= timestampBegin) && (ts <= timestampEnd); | |
105 | } | |
106 | ||
bfe038ff MK |
107 | /* |
108 | * (non-Javadoc) | |
109 | * | |
ce2388e0 FC |
110 | * @see java.lang.Object#toString() |
111 | */ | |
112 | @Override | |
113 | public String toString() { | |
114 | return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes //$NON-NLS-1$ | |
115 | + ", timestampBegin=" + timestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$ | |
bfe038ff | 116 | + timestampEnd + "]"; //$NON-NLS-1$ |
ce2388e0 FC |
117 | } |
118 | ||
119 | // ------------------------------------------------------------------------ | |
120 | // Getters and Setters | |
121 | // ------------------------------------------------------------------------ | |
122 | ||
123 | /** | |
124 | * @return the offsetBytes | |
125 | */ | |
126 | public long getOffsetBytes() { | |
127 | return offsetBytes; | |
128 | } | |
129 | ||
130 | /** | |
131 | * @return the dataOffsetBits | |
132 | */ | |
133 | public int getDataOffsetBits() { | |
134 | return dataOffsetBits; | |
135 | } | |
136 | ||
137 | /** | |
bfe038ff MK |
138 | * @param dataOffsetBits |
139 | * the dataOffsetBits to set | |
ce2388e0 FC |
140 | */ |
141 | public void setDataOffsetBits(int dataOffsetBits) { | |
142 | this.dataOffsetBits = dataOffsetBits; | |
143 | } | |
144 | ||
145 | /** | |
146 | * @return the packetSizeBits | |
147 | */ | |
148 | public int getPacketSizeBits() { | |
149 | return packetSizeBits; | |
150 | } | |
151 | ||
152 | /** | |
bfe038ff MK |
153 | * @param packetSizeBits |
154 | * the packetSizeBits to set | |
ce2388e0 FC |
155 | */ |
156 | public void setPacketSizeBits(int packetSizeBits) { | |
157 | this.packetSizeBits = packetSizeBits; | |
158 | } | |
159 | ||
160 | /** | |
161 | * @return the contentSizeBits | |
162 | */ | |
163 | public int getContentSizeBits() { | |
164 | return contentSizeBits; | |
165 | } | |
166 | ||
167 | /** | |
bfe038ff MK |
168 | * @param contentSizeBits |
169 | * the contentSizeBits to set | |
ce2388e0 FC |
170 | */ |
171 | public void setContentSizeBits(int contentSizeBits) { | |
172 | this.contentSizeBits = contentSizeBits; | |
173 | } | |
174 | ||
175 | /** | |
176 | * @return the timestampBegin | |
177 | */ | |
178 | public long getTimestampBegin() { | |
179 | return timestampBegin; | |
180 | } | |
181 | ||
182 | /** | |
bfe038ff MK |
183 | * @param timestampBegin |
184 | * the timestampBegin to set | |
ce2388e0 FC |
185 | */ |
186 | public void setTimestampBegin(long timestampBegin) { | |
187 | this.timestampBegin = timestampBegin; | |
188 | } | |
189 | ||
190 | /** | |
191 | * @return the timestampEnd | |
192 | */ | |
193 | public long getTimestampEnd() { | |
194 | return timestampEnd; | |
195 | } | |
196 | ||
197 | /** | |
bfe038ff MK |
198 | * @param timestampEnd |
199 | * the timestampEnd to set | |
ce2388e0 FC |
200 | */ |
201 | public void setTimestampEnd(long timestampEnd) { | |
202 | this.timestampEnd = timestampEnd; | |
203 | } | |
204 | ||
5c7202b5 | 205 | /** |
132a02b0 | 206 | * @return the lostEvents in this packet |
5c7202b5 MK |
207 | */ |
208 | public long getLostEvents() { | |
209 | return lostEvents; | |
210 | } | |
211 | ||
212 | /** | |
213 | * @param lostEvents the lostEvents to set | |
214 | */ | |
215 | public void setLostEvents(long lostEvents) { | |
216 | this.lostEvents = lostEvents; | |
217 | } | |
21fb02fa | 218 | |
8de0528f AM |
219 | /** |
220 | * Add an attribute to this index entry | |
221 | * | |
222 | * @param field | |
132a02b0 | 223 | * The name of the attribute |
8de0528f AM |
224 | * @param value |
225 | * The value to insert | |
226 | */ | |
21fb02fa MK |
227 | public void addAttribute(String field, Object value) { |
228 | attributes.put(field, value); | |
229 | } | |
8de0528f AM |
230 | |
231 | /** | |
232 | * Retrieve the value of an existing attribute | |
233 | * | |
234 | * @param field | |
235 | * The name of the attribute | |
236 | * @return The value that was stored, or null if it wasn't found | |
237 | */ | |
21fb02fa MK |
238 | public Object lookupAttribute(String field){ |
239 | return attributes.get(field); | |
240 | } | |
241 | ||
8de0528f AM |
242 | /** |
243 | * @return The target that is being traced | |
244 | */ | |
21fb02fa MK |
245 | public String getTarget() { |
246 | return target; | |
247 | } | |
248 | ||
8de0528f AM |
249 | /** |
250 | * Assign a target to this index entry | |
251 | * | |
252 | * @param target | |
253 | * The target to assign | |
254 | */ | |
21fb02fa MK |
255 | public void setTarget(String target) { |
256 | this.target = target; | |
257 | this.targetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow | |
258 | } | |
259 | ||
8de0528f AM |
260 | /** |
261 | * @return The ID of the target | |
262 | */ | |
21fb02fa MK |
263 | public long getTargetId(){ |
264 | return targetID; | |
265 | } | |
ce2388e0 | 266 | } |