Workaround for bug 391232: ISharedImages constants not recognized.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / EventDefinition.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
13package org.eclipse.linuxtools.ctf.core.event;
14
15import java.util.HashMap;
16import java.util.List;
17
18import org.eclipse.linuxtools.ctf.core.event.types.Definition;
19import org.eclipse.linuxtools.ctf.core.event.types.IDefinitionScope;
20import org.eclipse.linuxtools.ctf.core.event.types.StructDefinition;
21import org.eclipse.linuxtools.ctf.core.trace.StreamInputReader;
22
23/**
be6df2d8 24 * Representation of a particular instance of an event.
866e5b51
FC
25 */
26public class EventDefinition implements IDefinitionScope {
27
28 // ------------------------------------------------------------------------
29 // Attributes
30 // ------------------------------------------------------------------------
31
32 /**
33 * The corresponding event declaration.
34 */
aa572e22 35 private final EventDeclaration declaration;
866e5b51
FC
36
37 /**
38 * The timestamp of the current event.
39 */
aa572e22 40 private long timestamp;
866e5b51
FC
41
42 /**
43 * The event context structure definition.
44 */
aa572e22 45 private StructDefinition context;
866e5b51
FC
46
47 /**
48 * The event fields structure definition.
49 */
aa572e22 50 private StructDefinition fields;
866e5b51
FC
51
52 /**
53 * The StreamInputReader that reads this event definition.
54 */
07002e0a 55 private final StreamInputReader streamInputReader;
866e5b51
FC
56
57 // ------------------------------------------------------------------------
58 // Constructors
59 // ------------------------------------------------------------------------
60
61 /**
62 * Constructs an event definition.
63 *
64 * @param declaration
be6df2d8
AM
65 * The corresponding event declaration
66 * @param streamInputReader
67 * The SIR from where this EventDef was read
866e5b51
FC
68 */
69 public EventDefinition(EventDeclaration declaration,
70 StreamInputReader streamInputReader) {
71 this.declaration = declaration;
72 this.streamInputReader = streamInputReader;
73 }
74
75 // ------------------------------------------------------------------------
76 // Getters/Setters/Predicates
77 // ------------------------------------------------------------------------
78
79 @Override
80 public String getPath() {
81 return "event"; //$NON-NLS-1$
82 }
83
9ac2eb62
MK
84 /**
85 * Gets the declaration (the form) of the data
86 *
87 * @return the event declaration
88 */
866e5b51
FC
89 public EventDeclaration getDeclaration() {
90 return declaration;
91 }
92
9ac2eb62
MK
93 /**
94 * Gets the fields of a definition
95 *
96 * @return the fields of a definition in struct form. Can be null.
97 */
866e5b51
FC
98 public StructDefinition getFields() {
99 return fields;
100 }
101
9ac2eb62
MK
102 /**
103 * Gets the context of this event
104 *
105 * @return the context in struct form
106 */
866e5b51
FC
107 public StructDefinition getContext() {
108 return context;
109 }
110
9ac2eb62
MK
111 /**
112 * Gets the stream input reader that this event was made by
113 *
114 * @return the parent
115 */
866e5b51
FC
116 public StreamInputReader getStreamInputReader() {
117 return streamInputReader;
118 }
119
9ac2eb62
MK
120 /**
121 * Gets the context of packet the event is in.
122 *
123 * @return the packet context
124 */
866e5b51
FC
125 public StructDefinition getPacketContext() {
126 return streamInputReader.getCurrentPacketContext();
127 }
128
9ac2eb62
MK
129 /**
130 * gets the CPU the event was generated by. Slightly LTTng specific
131 *
132 * @return The CPU the event was generated by
133 */
866e5b51
FC
134 public int getCPU() {
135 return streamInputReader.getCPU();
136 }
137
aa572e22
MK
138 /**
139 * @return the timestamp
140 */
141 public long getTimestamp() {
142 return timestamp;
143 }
144
145 /**
9ac2eb62
MK
146 * @param timestamp
147 * the timestamp to set
aa572e22
MK
148 */
149 public void setTimestamp(long timestamp) {
150 this.timestamp = timestamp;
151 }
152
153 /**
9ac2eb62
MK
154 * @param context
155 * the context to set
aa572e22
MK
156 */
157 public void setContext(StructDefinition context) {
158 this.context = context;
159 }
160
161 /**
9ac2eb62
MK
162 * @param fields
163 * the fields to set
aa572e22
MK
164 */
165 public void setFields(StructDefinition fields) {
166 this.fields = fields;
167 }
168
866e5b51
FC
169 // ------------------------------------------------------------------------
170 // Operations
171 // ------------------------------------------------------------------------
172
173 @Override
174 public Definition lookupDefinition(String lookupPath) {
175 if (lookupPath.equals("context")) { //$NON-NLS-1$
176 return context;
177 } else if (lookupPath.equals("fields")) { //$NON-NLS-1$
178 return fields;
179 } else {
180 return null;
181 }
182 }
183
184 @Override
185 public String toString() {
07002e0a 186 HashMap<String, Definition> definitions;
866e5b51 187 List<String> list;
07002e0a
MK
188 StringBuilder retString = new StringBuilder();
189 final String cr = System.getProperty("line.separator");//$NON-NLS-1$
866e5b51 190
07002e0a
MK
191 retString.append("Event type: " + declaration.getName() + cr); //$NON-NLS-1$
192 retString.append("Timestamp: " + Long.toString(timestamp) + cr); //$NON-NLS-1$
866e5b51
FC
193
194 if (context != null) {
07002e0a 195 definitions = context.getDefinitions();
866e5b51
FC
196 list = context.getDeclaration().getFieldsList();
197
198 for (String field : list) {
9ac2eb62
MK
199 retString.append(field
200 + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$
866e5b51
FC
201 }
202 }
203
204 if (fields != null) {
07002e0a 205 definitions = fields.getDefinitions();
866e5b51
FC
206 list = fields.getDeclaration().getFieldsList();
207
208 for (String field : list) {
9ac2eb62
MK
209 retString.append(field
210 + " : " + definitions.get(field).toString() + cr); //$NON-NLS-1$
866e5b51
FC
211 }
212 }
213
07002e0a 214 return retString.toString();
866e5b51
FC
215 }
216
217}
This page took 0.039538 seconds and 5 git commands to generate.