1 /*******************************************************************************
2 * Copyright (c) 2011-2012 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
.internal
.ctf
.core
.trace
;
15 import java
.util
.HashMap
;
16 import java
.util
.HashSet
;
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
;
25 * <b><u>Stream</u></b>
27 * Represents a stream in a trace.
31 // ------------------------------------------------------------------------
33 // ------------------------------------------------------------------------
37 * The numerical ID of the stream
39 private Long id
= null;
42 * Declarations of the stream-specific structures
44 private StructDeclaration packetContextDecl
= null;
45 private StructDeclaration eventHeaderDecl
= null;
46 private StructDeclaration eventContextDecl
= null;
49 * The trace to which the stream belongs
51 private CTFTrace trace
= null;
54 * Maps event ids to events
56 private final HashMap
<Long
, EventDeclaration
> events
= new HashMap
<Long
, EventDeclaration
>();
59 * The inputs associated to this stream
61 private final Set
<StreamInput
> inputs
= new HashSet
<StreamInput
>();
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
68 * Constructs a Stream that belongs to a Trace
71 * The trace to which belongs this stream.
73 public Stream(CTFTrace trace
) {
77 // ------------------------------------------------------------------------
78 // Getters/Setters/Predicates
79 // ------------------------------------------------------------------------
81 public void setId(long id
) {
89 public boolean idIsSet() {
93 public boolean eventHeaderIsSet() {
94 return eventHeaderDecl
!= null;
97 public boolean eventContextIsSet() {
98 return eventContextDecl
!= null;
101 public boolean packetContextIsSet() {
102 return packetContextDecl
!= null;
105 public void setEventHeader(StructDeclaration eventHeader
) {
106 this.eventHeaderDecl
= eventHeader
;
109 public void setEventContext(StructDeclaration eventContext
) {
110 this.eventContextDecl
= eventContext
;
113 public void setPacketContext(StructDeclaration packetContext
) {
114 this.packetContextDecl
= packetContext
;
117 public StructDeclaration
getEventHeaderDecl() {
118 return eventHeaderDecl
;
121 public StructDeclaration
getEventContextDecl() {
122 return eventContextDecl
;
125 public StructDeclaration
getPacketContextDecl() {
126 return packetContextDecl
;
129 public Set
<StreamInput
> getStreamInputs() {
133 public CTFTrace
getTrace() {
137 public HashMap
<Long
, EventDeclaration
> getEvents() {
141 // ------------------------------------------------------------------------
143 // ------------------------------------------------------------------------
146 * Adds an event to the event map.
148 * An event in a stream can omit its id if it is the only event in this
149 * stream. An event for which no id has been specified has a null id. It is
150 * thus not possible to add an event with the null key if the map is not
151 * empty. It is also not possible to add an event to the map if the null key
152 * is present in the map.
156 * @throws ParseException
158 public void addEvent(EventDeclaration event
) throws ParseException
{
160 * If there is an event without id (the null key), it must be the only
163 if (events
.get(null) != null) {
164 throw new ParseException(
165 "Event without id with multiple events in a stream"); //$NON-NLS-1$
169 * If there is an event without id (the null key), it must be the only
172 if ((event
.getId() == null) && (events
.size() != 0)) {
173 throw new ParseException(
174 "Event without id with multiple events in a stream"); //$NON-NLS-1$
177 /* Check if an event with the same ID already exists */
178 if (events
.get(event
.getId()) != null) {
179 throw new ParseException("Event id already exists"); //$NON-NLS-1$
182 /* Put the event in the map */
183 events
.put(event
.getId(), event
);
187 * Add an input to this Stream
190 * The StreamInput to add.
192 public void addInput(StreamInput input
) {
198 * @see java.lang.Object#toString()
201 public String
toString() {
202 return "Stream [id=" + id
+ ", packetContextDecl=" + packetContextDecl
//$NON-NLS-1$ //$NON-NLS-2$
203 + ", eventHeaderDecl=" + eventHeaderDecl
//$NON-NLS-1$
204 + ", eventContextDecl=" + eventContextDecl
+ ", trace=" + trace
//$NON-NLS-1$ //$NON-NLS-2$
205 + ", events=" + events
+ ", inputs=" + inputs
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$