Merge branch 'master' into lttng-kepler
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / trace / StreamInputPacketIndexEntry.java
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
15 import java.util.HashMap;
16 import java.util.Map;
17
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
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
59 /**
60 * How many lost events are there?
61 */
62 private long lostEvents = 0;
63
64 /**
65 * Which target is being traced
66 */
67 private String target ;
68 private long targetID;
69
70 /**
71 * Attributes of this index entry
72 */
73 private final Map<String, Object> attributes = new HashMap<String, Object>();
74
75
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
107 /*
108 * (non-Javadoc)
109 *
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$
116 + timestampEnd + "]"; //$NON-NLS-1$
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 /**
138 * @param dataOffsetBits
139 * the dataOffsetBits to set
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 /**
153 * @param packetSizeBits
154 * the packetSizeBits to set
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 /**
168 * @param contentSizeBits
169 * the contentSizeBits to set
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 /**
183 * @param timestampBegin
184 * the timestampBegin to set
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 /**
198 * @param timestampEnd
199 * the timestampEnd to set
200 */
201 public void setTimestampEnd(long timestampEnd) {
202 this.timestampEnd = timestampEnd;
203 }
204
205 /**
206 * @return the lostEvents in this packet
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 }
218
219 /**
220 * Add an attribute to this index entry
221 *
222 * @param field
223 * The name of the attribute
224 * @param value
225 * The value to insert
226 */
227 public void addAttribute(String field, Object value) {
228 attributes.put(field, value);
229 }
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 */
238 public Object lookupAttribute(String field){
239 return attributes.get(field);
240 }
241
242 /**
243 * @return The target that is being traced
244 */
245 public String getTarget() {
246 return target;
247 }
248
249 /**
250 * Assign a target to this index entry
251 *
252 * @param target
253 * The target to assign
254 */
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
260 /**
261 * @return The ID of the target
262 */
263 public long getTargetId(){
264 return targetID;
265 }
266 }
This page took 0.04998 seconds and 6 git commands to generate.