Clean up duplicate function
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / internal / ctf / core / trace / Stream.java
CommitLineData
866e5b51
FC
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
ce2388e0 13package org.eclipse.linuxtools.internal.ctf.core.trace;
866e5b51
FC
14
15import java.util.HashMap;
16import java.util.HashSet;
17import java.util.Set;
18
19import org.eclipse.linuxtools.ctf.core.event.EventDeclaration;
866e5b51 20import org.eclipse.linuxtools.ctf.core.event.types.StructDeclaration;
ce2388e0
FC
21import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
22import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException;
866e5b51
FC
23
24/**
25 * <b><u>Stream</u></b>
26 * <p>
27 * Represents a stream in a trace.
28 */
29public 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 final HashMap<Long, EventDeclaration> events = new HashMap<Long, EventDeclaration>();
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 public void setId(long id) {
82 this.id = id;
83 }
84
85 public Long getId() {
86 return id;
87 }
88
89 public boolean idIsSet() {
90 return id != null;
91 }
92
93 public boolean eventHeaderIsSet() {
94 return eventHeaderDecl != null;
95 }
96
97 public boolean eventContextIsSet() {
98 return eventContextDecl != null;
99 }
100
101 public boolean packetContextIsSet() {
102 return packetContextDecl != null;
103 }
104
105 public void setEventHeader(StructDeclaration eventHeader) {
106 this.eventHeaderDecl = eventHeader;
107 }
108
109 public void setEventContext(StructDeclaration eventContext) {
110 this.eventContextDecl = eventContext;
111 }
112
113 public void setPacketContext(StructDeclaration packetContext) {
114 this.packetContextDecl = packetContext;
115 }
116
117 public StructDeclaration getEventHeaderDecl() {
118 return eventHeaderDecl;
119 }
120
121 public StructDeclaration getEventContextDecl() {
122 return eventContextDecl;
123 }
124
125 public StructDeclaration getPacketContextDecl() {
126 return packetContextDecl;
127 }
128
129 public Set<StreamInput> getStreamInputs() {
130 return inputs;
131 }
132
133 public CTFTrace getTrace() {
134 return trace;
135 }
136
137 public HashMap<Long, EventDeclaration> getEvents() {
138 return events;
139 }
140
141 // ------------------------------------------------------------------------
142 // Operations
143 // ------------------------------------------------------------------------
144
145 /**
146 * Adds an event to the event map.
147 *
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.
153 *
154 * @param event
155 * The event to add.
156 * @throws ParseException
157 */
158 public void addEvent(EventDeclaration event) throws ParseException {
159 /*
160 * If there is an event without id (the null key), it must be the only
161 * one
162 */
163 if (events.get(null) != null) {
164 throw new ParseException(
165 "Event without id with multiple events in a stream"); //$NON-NLS-1$
166 }
167
168 /*
169 * If there is an event without id (the null key), it must be the only
170 * one
171 */
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$
175 }
176
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$
180 }
181
182 /* Put the event in the map */
183 events.put(event.getId(), event);
184 }
185
186 /**
187 * Add an input to this Stream
188 *
189 * @param input
190 * The StreamInput to add.
191 */
192 public void addInput(StreamInput input) {
193 inputs.add(input);
194 }
195
196
197 /* (non-Javadoc)
198 * @see java.lang.Object#toString()
199 */
200 @Override
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$
206 }
207}
This page took 0.034654 seconds and 5 git commands to generate.