tmf/lttng: Update 2014 copyrights
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / trace / StreamInputPacketIndexEntry.java
1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 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 fOffsetBytes;
33
34 /**
35 * Offset of the data in the packet, in bits
36 */
37 private long fDataOffsetBits = 0;
38
39 /**
40 * Packet size, in bits
41 */
42 private long fPacketSizeBits = 0;
43
44 /**
45 * Content size, in bits
46 */
47 private long fContentSizeBits = 0;
48
49 /**
50 * Begin timestamp
51 */
52 private long fTimestampBegin = 0;
53
54 /**
55 * End timestamp
56 */
57 private long fTimestampEnd = 0;
58
59 /**
60 * How many lost events are there?
61 */
62 private long fLostEvents = 0;
63
64 /**
65 * Which target is being traced
66 */
67 private String fTarget ;
68 private long fTargetID;
69
70 /**
71 * Attributes of this index entry
72 */
73 private final Map<String, Object> fAttributes = new HashMap<>();
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 fOffsetBytes = 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 >= fTimestampBegin) && (ts <= fTimestampEnd);
105 }
106
107 @Override
108 public String toString() {
109 return "StreamInputPacketIndexEntry [offsetBytes=" + fOffsetBytes //$NON-NLS-1$
110 + ", timestampBegin=" + fTimestampBegin + ", timestampEnd=" //$NON-NLS-1$ //$NON-NLS-2$
111 + fTimestampEnd + "]"; //$NON-NLS-1$
112 }
113
114 // ------------------------------------------------------------------------
115 // Getters and Setters
116 // ------------------------------------------------------------------------
117
118 /**
119 * @return the offsetBytes
120 */
121 public long getOffsetBytes() {
122 return fOffsetBytes;
123 }
124
125 /**
126 * @return the dataOffsetBits
127 */
128 public long getDataOffsetBits() {
129 return fDataOffsetBits;
130 }
131
132 /**
133 * @param dataOffsetBits
134 * the dataOffsetBits to set
135 */
136 public void setDataOffsetBits(long dataOffsetBits) {
137 fDataOffsetBits = dataOffsetBits;
138 }
139
140 /**
141 * @return the packetSizeBits
142 */
143 public long getPacketSizeBits() {
144 return fPacketSizeBits;
145 }
146
147 /**
148 * @param packetSizeBits
149 * the packetSizeBits to set
150 */
151 public void setPacketSizeBits(long packetSizeBits) {
152 fPacketSizeBits = packetSizeBits;
153 }
154
155 /**
156 * @return the contentSizeBits
157 */
158 public long getContentSizeBits() {
159 return fContentSizeBits;
160 }
161
162 /**
163 * @param contentSizeBits
164 * the contentSizeBits to set
165 */
166 public void setContentSizeBits(long contentSizeBits) {
167 fContentSizeBits = contentSizeBits;
168 }
169
170 /**
171 * @return the timestampBegin
172 */
173 public long getTimestampBegin() {
174 return fTimestampBegin;
175 }
176
177 /**
178 * @param timestampBegin
179 * the timestampBegin to set
180 */
181 public void setTimestampBegin(long timestampBegin) {
182 fTimestampBegin = timestampBegin;
183 }
184
185 /**
186 * @return the timestampEnd
187 */
188 public long getTimestampEnd() {
189 return fTimestampEnd;
190 }
191
192 /**
193 * @param timestampEnd
194 * the timestampEnd to set
195 */
196 public void setTimestampEnd(long timestampEnd) {
197 fTimestampEnd = timestampEnd;
198 }
199
200 /**
201 * @return the lostEvents in this packet
202 */
203 public long getLostEvents() {
204 return fLostEvents;
205 }
206
207 /**
208 * @param lostEvents the lostEvents to set
209 */
210 public void setLostEvents(long lostEvents) {
211 fLostEvents = lostEvents;
212 }
213
214 /**
215 * Add an attribute to this index entry
216 *
217 * @param field
218 * The name of the attribute
219 * @param value
220 * The value to insert
221 */
222 public void addAttribute(String field, Object value) {
223 fAttributes.put(field, value);
224 }
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 */
233 public Object lookupAttribute(String field){
234 return fAttributes.get(field);
235 }
236
237 /**
238 * @return The target that is being traced
239 */
240 public String getTarget() {
241 return fTarget;
242 }
243
244 /**
245 * Assign a target to this index entry
246 *
247 * @param target
248 * The target to assign
249 */
250 public void setTarget(String target) {
251 fTarget = target;
252 fTargetID = Integer.parseInt(target.replaceAll("[\\D]", "")); //$NON-NLS-1$ //$NON-NLS-2$ // slow
253 }
254
255 /**
256 * @return The ID of the target
257 */
258 public long getTargetId(){
259 return fTargetID;
260 }
261 }
This page took 0.039817 seconds and 5 git commands to generate.