Genericized CTF parser and events handling.
[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
17 /**
18 * <b><u>StreamInputPacketIndexEntry</u></b>
19 * <p>
20 * Represents an entry in the index of event packets.
21 */
22 public class StreamInputPacketIndexEntry {
23
24 // ------------------------------------------------------------------------
25 // Attributes
26 // ------------------------------------------------------------------------
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 // ------------------------------------------------------------------------
72 // Constructors
73 // ------------------------------------------------------------------------
74
75 /**
76 * Constructs an index entry.
77 *
78 * @param offset
79 * The offset of the packet in the file, in bytes.
80 */
81
82 public StreamInputPacketIndexEntry(long offset) {
83 this.offsetBytes = offset;
84 }
85
86 // ------------------------------------------------------------------------
87 // Operations
88 // ------------------------------------------------------------------------
89
90 /**
91 * Returns whether the packet includes (inclusively) the given timestamp in
92 * the begin-end timestamp range.
93 *
94 * @param ts
95 * The timestamp to check.
96 * @return True if the packet includes the timestamp.
97 */
98 boolean includes(long ts) {
99 return (ts >= timestampBegin) && (ts <= timestampEnd);
100 }
101
102 /*
103 * (non-Javadoc)
104 *
105 * @see java.lang.Object#toString()
106 */
107 @Override
108 public String toString() {
109 return "StreamInputPacketIndexEntry [offsetBytes=" + offsetBytes //$NON-NLS-1$
110 + ", timestampBegin=" + timestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
111 + timestampEnd + "]"; //$NON-NLS-1$
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 */
128 public int getDataOffsetBits() {
129 return dataOffsetBits;
130 }
131
132 /**
133 * @param dataOffsetBits
134 * the dataOffsetBits to set
135 */
136 public void setDataOffsetBits(int dataOffsetBits) {
137 this.dataOffsetBits = dataOffsetBits;
138 }
139
140 /**
141 * @return the packetSizeBits
142 */
143 public int getPacketSizeBits() {
144 return packetSizeBits;
145 }
146
147 /**
148 * @param packetSizeBits
149 * the packetSizeBits to set
150 */
151 public void setPacketSizeBits(int packetSizeBits) {
152 this.packetSizeBits = packetSizeBits;
153 }
154
155 /**
156 * @return the contentSizeBits
157 */
158 public int getContentSizeBits() {
159 return contentSizeBits;
160 }
161
162 /**
163 * @param contentSizeBits
164 * the contentSizeBits to set
165 */
166 public void setContentSizeBits(int contentSizeBits) {
167 this.contentSizeBits = contentSizeBits;
168 }
169
170 /**
171 * @return the timestampBegin
172 */
173 public long getTimestampBegin() {
174 return timestampBegin;
175 }
176
177 /**
178 * @param timestampBegin
179 * the timestampBegin to set
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 /**
193 * @param timestampEnd
194 * the timestampEnd to set
195 */
196 public void setTimestampEnd(long timestampEnd) {
197 this.timestampEnd = timestampEnd;
198 }
199
200 /**
201 * @return the lostEvents
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 }
213
214 private final HashMap<String, Object> attributes = new HashMap<String, Object>();
215 public void addAttribute(String field, Object value) {
216 attributes.put(field, value);
217 }
218 public Object lookupAttribute(String field){
219 return attributes.get(field);
220 }
221
222 public String getTarget() {
223 return target;
224 }
225
226 public void setTarget(String target) {
227 this.target = target;
228 this.targetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
229 }
230
231 public long getTargetId(){
232 return targetID;
233 }
234 }
This page took 0.053294 seconds and 6 git commands to generate.