1 /*******************************************************************************
2 * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
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
9 * Contributors: Matthew Khouzam - Initial API and implementation
10 * Contributors: Simon Marchi - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.ctf
.core
.trace
;
15 import java
.util
.HashMap
;
16 import java
.util
.HashSet
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.IEventDeclaration
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDeclaration
;
22 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.EventDeclaration
;
23 import org
.eclipse
.linuxtools
.internal
.ctf
.core
.event
.metadata
.exceptions
.ParseException
;
26 * <b><u>Stream</u></b>
28 * Represents a stream in a trace.
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
39 * The numerical ID of the stream
41 private Long fId
= null;
44 * Declarations of the stream-specific structures
46 private StructDeclaration fPacketContextDecl
= null;
47 private StructDeclaration fEventHeaderDecl
= null;
48 private StructDeclaration fEventContextDecl
= null;
51 * The trace to which the stream belongs
53 private CTFTrace fTrace
= null;
56 * Maps event ids to events
58 private Map
<Long
, IEventDeclaration
> fEvents
= new HashMap
<>();
61 * The inputs associated to this stream
63 private final Set
<StreamInput
> fInputs
= new HashSet
<>();
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 * Constructs a Stream that belongs to a Trace
73 * The trace to which belongs this stream.
75 public Stream(CTFTrace trace
) {
79 // ------------------------------------------------------------------------
80 // Getters/Setters/Predicates
81 // ------------------------------------------------------------------------
84 * Sets the id of a stream
85 * @param id the id of a stream
87 public void setId(long id
) {
92 * Gets the id of a stream
93 * @return id the id of a stream
100 * Is the id of a stream set
102 * @return If the ID is set or not
104 public boolean isIdSet() {
110 * @return is the event header set (timestamp and stuff) (see Ctf Spec)
112 public boolean isEventHeaderSet() {
113 return fEventHeaderDecl
!= null;
118 * @return is the event context set (pid and stuff) (see Ctf Spec)
120 public boolean isEventContextSet() {
121 return fEventContextDecl
!= null;
126 * @return Is the packet context set (see Ctf Spec)
128 public boolean isPacketContextSet() {
129 return fPacketContextDecl
!= null;
134 * @param eventHeader the current event header for all events in this stream
136 public void setEventHeader(StructDeclaration eventHeader
) {
137 fEventHeaderDecl
= eventHeader
;
142 * @param eventContext the context for all events in this stream
144 public void setEventContext(StructDeclaration eventContext
) {
145 fEventContextDecl
= eventContext
;
150 * @param packetContext the packet context for all packets in this stream
152 public void setPacketContext(StructDeclaration packetContext
) {
153 fPacketContextDecl
= packetContext
;
158 * @return the event header declaration in structdeclaration form
160 public StructDeclaration
getEventHeaderDecl() {
161 return fEventHeaderDecl
;
166 * @return the event context declaration in structdeclaration form
168 public StructDeclaration
getEventContextDecl() {
169 return fEventContextDecl
;
174 * @return the packet context declaration in structdeclaration form
176 public StructDeclaration
getPacketContextDecl() {
177 return fPacketContextDecl
;
182 * @return the set of all stream inputs for this stream
184 public Set
<StreamInput
> getStreamInputs() {
190 * @return the parent trace
192 public CTFTrace
getTrace() {
198 * @return all the event declarations for this stream, using the id as a key for the hashmap.
200 public Map
<Long
, IEventDeclaration
> getEvents() {
204 // ------------------------------------------------------------------------
206 // ------------------------------------------------------------------------
209 * Adds an event to the event map.
211 * An event in a stream can omit its id if it is the only event in this
212 * stream. An event for which no id has been specified has a null id. It is
213 * thus not possible to add an event with the null key if the map is not
214 * empty. It is also not possible to add an event to the map if the null key
215 * is present in the map.
219 * @throws ParseException
220 * If there was a problem reading the event or adding it to the
223 public void addEvent(IEventDeclaration event
) throws ParseException
{
225 * If there is an event without id (the null key), it must be the only
228 if (fEvents
.get(null) != null) {
229 throw new ParseException(
230 "Event without id with multiple events in a stream"); //$NON-NLS-1$
234 * If there is an event without id (the null key), it must be the only
237 if ((event
.getId() == null) && (fEvents
.size() != 0)) {
238 throw new ParseException(
239 "Event without id with multiple events in a stream"); //$NON-NLS-1$
242 /* Check if an event with the same ID already exists */
243 if (fEvents
.get(event
.getId()) != null) {
244 throw new ParseException("Event id already exists"); //$NON-NLS-1$
246 if (event
.getId() == null) {
247 fEvents
.put(EventDeclaration
.UNSET_EVENT_ID
, event
);
249 /* Put the event in the map */
250 fEvents
.put(event
.getId(), event
);
255 * Add an input to this Stream
258 * The StreamInput to add.
260 public void addInput(StreamInput input
) {
265 public String
toString() {
266 return "Stream [id=" + fId
+ ", packetContextDecl=" + fPacketContextDecl
//$NON-NLS-1$ //$NON-NLS-2$
267 + ", eventHeaderDecl=" + fEventHeaderDecl
//$NON-NLS-1$
268 + ", eventContextDecl=" + fEventContextDecl
+ ", trace=" + fTrace
//$NON-NLS-1$ //$NON-NLS-2$
269 + ", events=" + fEvents
+ ", inputs=" + fInputs
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$