Improve javadoc for ctfAdapter in Tmf.Core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / trace / Stream.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.HashSet;
17 import java.util.Set;
18
19 import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
20 import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
21 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
22 import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
23
24 /**
25 * <b><u>Stream</u></b>
26 * <p>
27 * Represents a stream in a trace.
28 */
29 public class Stream {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34
35
36 /**
37 * The numerical ID of the stream
38 */
39 private Long id = null;
40
41 /**
42 * Declarations of the stream-specific structures
43 */
44 private StructDeclaration packetContextDecl = null;
45 private StructDeclaration eventHeaderDecl = null;
46 private StructDeclaration eventContextDecl = null;
47
48 /**
49 * The trace to which the stream belongs
50 */
51 private CTFTrace trace = null;
52
53 /**
54 * Maps event ids to events
55 */
56 private HashMap<Long, EventDeclaration> events;
57
58 /**
59 * The inputs associated to this stream
60 */
61 private final Set<StreamInput> inputs = new HashSet<StreamInput>();
62
63 // ------------------------------------------------------------------------
64 // Constructors
65 // ------------------------------------------------------------------------
66
67 /**
68 * Constructs a Stream that belongs to a Trace
69 *
70 * @param trace
71 * The trace to which belongs this stream.
72 */
73 public Stream(CTFTrace trace) {
74 this.trace = trace;
75 }
76
77 // ------------------------------------------------------------------------
78 // Getters/Setters/Predicates
79 // ------------------------------------------------------------------------
80
81 /**
82 * Sets the id of a stream
83 * @param id the id of a stream
84 */
85 public void setId(long id) {
86 this.id = id;
87 this.events = trace.createEvents(this.id);
88 }
89
90 /**
91 * Gets the id of a stream
92 * @return id the id of a stream
93 */
94 public Long getId() {
95 return id;
96 }
97
98 /**
99 * Is the id of a stream set
100 * @param Is id the id of a stream set
101 */
102 public boolean isIdSet() {
103 return id != null;
104 }
105
106 /**
107 *
108 * @return is the event header set (timestamp and stuff) (see Ctf Spec)
109 */
110 public boolean isEventHeaderSet() {
111 return eventHeaderDecl != null;
112 }
113
114 /**
115 *
116 * @return is the event context set (pid and stuff) (see Ctf Spec)
117 */
118 public boolean isEventContextSet() {
119 return eventContextDecl != null;
120 }
121
122 /**
123 *
124 * @return Is the packet context set (see Ctf Spec)
125 */
126 public boolean isPacketContextSet() {
127 return packetContextDecl != null;
128 }
129
130 /**
131 *
132 * @param eventHeader the current event header for all events in this stream
133 */
134 public void setEventHeader(StructDeclaration eventHeader) {
135 this.eventHeaderDecl = eventHeader;
136 }
137
138 /**
139 *
140 * @param eventContext the context for all events in this stream
141 */
142 public void setEventContext(StructDeclaration eventContext) {
143 this.eventContextDecl = eventContext;
144 }
145
146 /**
147 *
148 * @param packetContext the packet context for all packets in this stream
149 */
150 public void setPacketContext(StructDeclaration packetContext) {
151 this.packetContextDecl = packetContext;
152 }
153
154 /**
155 *
156 * @return the event header declaration in structdeclaration form
157 */
158 public StructDeclaration getEventHeaderDecl() {
159 return eventHeaderDecl;
160 }
161
162 /**
163 *
164 * @return the event context declaration in structdeclaration form
165 */
166 public StructDeclaration getEventContextDecl() {
167 return eventContextDecl;
168 }
169
170 /**
171 *
172 * @return the packet context declaration in structdeclaration form
173 */
174 public StructDeclaration getPacketContextDecl() {
175 return packetContextDecl;
176 }
177
178 /**
179 *
180 * @return the set of all stream inputs for this stream
181 */
182 public Set<StreamInput> getStreamInputs() {
183 return inputs;
184 }
185
186 /**
187 *
188 * @return the parent trace
189 */
190 public CTFTrace getTrace() {
191 return trace;
192 }
193
194 /**
195 *
196 * @return all the event declarations for this stream, using the id as a key for the hashmap.
197 */
198 public HashMap<Long, EventDeclaration> getEvents() {
199 return events;
200 }
201
202 // ------------------------------------------------------------------------
203 // Operations
204 // ------------------------------------------------------------------------
205
206 /**
207 * Adds an event to the event map.
208 *
209 * An event in a stream can omit its id if it is the only event in this
210 * stream. An event for which no id has been specified has a null id. It is
211 * thus not possible to add an event with the null key if the map is not
212 * empty. It is also not possible to add an event to the map if the null key
213 * is present in the map.
214 *
215 * @param event
216 * The event to add.
217 * @throws ParseException
218 */
219 public void addEvent(EventDeclaration event) throws ParseException {
220 /*
221 * If there is an event without id (the null key), it must be the only
222 * one
223 */
224 if (events.get(null) != null) {
225 throw new ParseException(
226 "Event without id with multiple events in a stream"); //$NON-NLS-1$
227 }
228
229 /*
230 * If there is an event without id (the null key), it must be the only
231 * one
232 */
233 if ((event.getId() == null) && (events.size() != 0)) {
234 throw new ParseException(
235 "Event without id with multiple events in a stream"); //$NON-NLS-1$
236 }
237
238 /* Check if an event with the same ID already exists */
239 if (events.get(event.getId()) != null) {
240 throw new ParseException("Event id already exists"); //$NON-NLS-1$
241 }
242
243 /* Put the event in the map */
244 events.put(event.getId(), event);
245 }
246
247 /**
248 * Add an input to this Stream
249 *
250 * @param input
251 * The StreamInput to add.
252 */
253 public void addInput(StreamInput input) {
254 inputs.add(input);
255 }
256
257
258 /* (non-Javadoc)
259 * @see java.lang.Object#toString()
260 */
261 @Override
262 public String toString() {
263 return "Stream [id=" + id + ", packetContextDecl=" + packetContextDecl //$NON-NLS-1$ //$NON-NLS-2$
264 + ", eventHeaderDecl=" + eventHeaderDecl //$NON-NLS-1$
265 + ", eventContextDecl=" + eventContextDecl + ", trace=" + trace //$NON-NLS-1$ //$NON-NLS-2$
266 + ", events=" + events + ", inputs=" + inputs + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
267 }
268 }
This page took 0.039669 seconds and 6 git commands to generate.