Commit | Line | Data |
---|---|---|
ce2388e0 | 1 | /******************************************************************************* |
11252342 | 2 | * Copyright (c) 2011, 2013 Ericsson, Ecole Polytechnique de Montreal and others |
ce2388e0 FC |
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 | */ | |
47ca6c05 | 37 | private long dataOffsetBits = 0; |
ce2388e0 FC |
38 | |
39 | /** | |
40 | * Packet size, in bits | |
41 | */ | |
47ca6c05 | 42 | private long packetSizeBits = 0; |
ce2388e0 FC |
43 | |
44 | /** | |
45 | * Content size, in bits | |
46 | */ | |
47ca6c05 | 47 | private long contentSizeBits = 0; |
ce2388e0 FC |
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 | ||
ce2388e0 FC |
107 | @Override |
108 | public String toString() { | |
109 | return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes //$NON-NLS-1$ | |
110 | + ", timestampBegin=" + timestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$ | |
bfe038ff | 111 | + timestampEnd + "]"; //$NON-NLS-1$ |
ce2388e0 FC |
112 | } |
113 | ||
114 | // ------------------------------------------------------------------------ | |
115 | // Getters and Setters | |
116 | // ------------------------------------------------------------------------ | |
117 | ||
118 | /** | |
119 | * @return the offsetBytes | |
120 | */ | |
121 | public long getOffsetBytes() { | |
122 | return offsetBytes; | |
123 | } | |
124 | ||
125 | /** | |
126 | * @return the dataOffsetBits | |
127 | */ | |
47ca6c05 | 128 | public long getDataOffsetBits() { |
ce2388e0 FC |
129 | return dataOffsetBits; |
130 | } | |
131 | ||
132 | /** | |
bfe038ff MK |
133 | * @param dataOffsetBits |
134 | * the dataOffsetBits to set | |
ce2388e0 | 135 | */ |
47ca6c05 | 136 | public void setDataOffsetBits(long dataOffsetBits) { |
ce2388e0 FC |
137 | this.dataOffsetBits = dataOffsetBits; |
138 | } | |
139 | ||
140 | /** | |
141 | * @return the packetSizeBits | |
142 | */ | |
47ca6c05 | 143 | public long getPacketSizeBits() { |
ce2388e0 FC |
144 | return packetSizeBits; |
145 | } | |
146 | ||
147 | /** | |
bfe038ff MK |
148 | * @param packetSizeBits |
149 | * the packetSizeBits to set | |
ce2388e0 | 150 | */ |
47ca6c05 | 151 | public void setPacketSizeBits(long packetSizeBits) { |
ce2388e0 FC |
152 | this.packetSizeBits = packetSizeBits; |
153 | } | |
154 | ||
155 | /** | |
156 | * @return the contentSizeBits | |
157 | */ | |
47ca6c05 | 158 | public long getContentSizeBits() { |
ce2388e0 FC |
159 | return contentSizeBits; |
160 | } | |
161 | ||
162 | /** | |
bfe038ff MK |
163 | * @param contentSizeBits |
164 | * the contentSizeBits to set | |
ce2388e0 | 165 | */ |
47ca6c05 | 166 | public void setContentSizeBits(long contentSizeBits) { |
ce2388e0 FC |
167 | this.contentSizeBits = contentSizeBits; |
168 | } | |
169 | ||
170 | /** | |
171 | * @return the timestampBegin | |
172 | */ | |
173 | public long getTimestampBegin() { | |
174 | return timestampBegin; | |
175 | } | |
176 | ||
177 | /** | |
bfe038ff MK |
178 | * @param timestampBegin |
179 | * the timestampBegin to set | |
ce2388e0 FC |
180 | */ |
181 | public void setTimestampBegin(long timestampBegin) { | |
182 | this.timestampBegin = timestampBegin; | |
183 | } | |
184 | ||
185 | /** | |
186 | * @return the timestampEnd | |
187 | */ | |
188 | public long getTimestampEnd() { | |
189 | return timestampEnd; | |
190 | } | |
191 | ||
192 | /** | |
bfe038ff MK |
193 | * @param timestampEnd |
194 | * the timestampEnd to set | |
ce2388e0 FC |
195 | */ |
196 | public void setTimestampEnd(long timestampEnd) { | |
197 | this.timestampEnd = timestampEnd; | |
198 | } | |
199 | ||
5c7202b5 | 200 | /** |
132a02b0 | 201 | * @return the lostEvents in this packet |
5c7202b5 MK |
202 | */ |
203 | public long getLostEvents() { | |
204 | return lostEvents; | |
205 | } | |
206 | ||
207 | /** | |
208 | * @param lostEvents the lostEvents to set | |
209 | */ | |
210 | public void setLostEvents(long lostEvents) { | |
211 | this.lostEvents = lostEvents; | |
212 | } | |
21fb02fa | 213 | |
8de0528f AM |
214 | /** |
215 | * Add an attribute to this index entry | |
216 | * | |
217 | * @param field | |
132a02b0 | 218 | * The name of the attribute |
8de0528f AM |
219 | * @param value |
220 | * The value to insert | |
221 | */ | |
21fb02fa MK |
222 | public void addAttribute(String field, Object value) { |
223 | attributes.put(field, value); | |
224 | } | |
8de0528f AM |
225 | |
226 | /** | |
227 | * Retrieve the value of an existing attribute | |
228 | * | |
229 | * @param field | |
230 | * The name of the attribute | |
231 | * @return The value that was stored, or null if it wasn't found | |
232 | */ | |
21fb02fa MK |
233 | public Object lookupAttribute(String field){ |
234 | return attributes.get(field); | |
235 | } | |
236 | ||
8de0528f AM |
237 | /** |
238 | * @return The target that is being traced | |
239 | */ | |
21fb02fa MK |
240 | public String getTarget() { |
241 | return target; | |
242 | } | |
243 | ||
8de0528f AM |
244 | /** |
245 | * Assign a target to this index entry | |
246 | * | |
247 | * @param target | |
248 | * The target to assign | |
249 | */ | |
21fb02fa MK |
250 | public void setTarget(String target) { |
251 | this.target = target; | |
252 | this.targetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow | |
253 | } | |
254 | ||
8de0528f AM |
255 | /** |
256 | * @return The ID of the target | |
257 | */ | |
21fb02fa MK |
258 | public long getTargetId(){ |
259 | return targetID; | |
260 | } | |
ce2388e0 | 261 | } |