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 HashMap
<Long
, EventDeclaration
> events
;
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
) {
83 this.events
= trace
.createEvents(this.id
);
90 public boolean idIsSet() {
94 public boolean eventHeaderIsSet() {
95 return eventHeaderDecl
!= null;
98 public boolean eventContextIsSet() {
99 return eventContextDecl
!= null;
102 public boolean packetContextIsSet() {
103 return packetContextDecl
!= null;
106 public void setEventHeader(StructDeclaration eventHeader
) {
107 this.eventHeaderDecl
= eventHeader
;
110 public void setEventContext(StructDeclaration eventContext
) {
111 this.eventContextDecl
= eventContext
;
114 public void setPacketContext(StructDeclaration packetContext
) {
115 this.packetContextDecl
= packetContext
;
118 public StructDeclaration
getEventHeaderDecl() {
119 return eventHeaderDecl
;
122 public StructDeclaration
getEventContextDecl() {
123 return eventContextDecl
;
126 public StructDeclaration
getPacketContextDecl() {
127 return packetContextDecl
;
130 public Set
<StreamInput
> getStreamInputs() {
134 public CTFTrace
getTrace() {
138 public HashMap
<Long
, EventDeclaration
> getEvents() {
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
147 * Adds an event to the event map.
149 * An event in a stream can omit its id if it is the only event in this
150 * stream. An event for which no id has been specified has a null id. It is
151 * thus not possible to add an event with the null key if the map is not
152 * empty. It is also not possible to add an event to the map if the null key
153 * is present in the map.
157 * @throws ParseException
159 public void addEvent(EventDeclaration event
) throws ParseException
{
161 * If there is an event without id (the null key), it must be the only
164 if (events
.get(null) != null) {
165 throw new ParseException(
166 "Event without id with multiple events in a stream"); //$NON-NLS-1$
170 * If there is an event without id (the null key), it must be the only
173 if ((event
.getId() == null) && (events
.size() != 0)) {
174 throw new ParseException(
175 "Event without id with multiple events in a stream"); //$NON-NLS-1$
178 /* Check if an event with the same ID already exists */
179 if (events
.get(event
.getId()) != null) {
180 throw new ParseException("Event id already exists"); //$NON-NLS-1$
183 /* Put the event in the map */
184 events
.put(event
.getId(), event
);
188 * Add an input to this Stream
191 * The StreamInput to add.
193 public void addInput(StreamInput input
) {
199 * @see java.lang.Object#toString()
202 public String
toString() {
203 return "Stream [id=" + id
+ ", packetContextDecl=" + packetContextDecl
//$NON-NLS-1$ //$NON-NLS-2$
204 + ", eventHeaderDecl=" + eventHeaderDecl
//$NON-NLS-1$
205 + ", eventContextDecl=" + eventContextDecl
+ ", trace=" + trace
//$NON-NLS-1$ //$NON-NLS-2$
206 + ", events=" + events
+ ", inputs=" + inputs
+ "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$