Fix test case. It really is supposed to return true.
[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/**
24 * <b><u>EventDefinition</u></b>
25 * <p>
26 * Represents an instance of an event.
27 */
28public class EventDefinition implements IDefinitionScope {
29
30 // ------------------------------------------------------------------------
31 // Attributes
32 // ------------------------------------------------------------------------
33
34 /**
35 * The corresponding event declaration.
36 */
37 public final EventDeclaration declaration;
38
39 /**
40 * The timestamp of the current event.
41 */
42 public long timestamp;
43
44 /**
45 * The event context structure definition.
46 */
47 public StructDefinition context;
48
49 /**
50 * The event fields structure definition.
51 */
52 public StructDefinition fields;
53
54 /**
55 * The StreamInputReader that reads this event definition.
56 */
57 public final StreamInputReader streamInputReader;
58
59 // ------------------------------------------------------------------------
60 // Constructors
61 // ------------------------------------------------------------------------
62
63 /**
64 * Constructs an event definition.
65 *
66 * @param declaration
67 * The corresponding event declaration.
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
84 public EventDeclaration getDeclaration() {
85 return declaration;
86 }
87
88 public StructDefinition getFields() {
89 return fields;
90 }
91
92 public StructDefinition getContext() {
93 return context;
94 }
95
96 public StreamInputReader getStreamInputReader() {
97 return streamInputReader;
98 }
99
100 public StructDefinition getPacketContext() {
101 return streamInputReader.getCurrentPacketContext();
102 }
103
104 public int getCPU() {
105 return streamInputReader.getCPU();
106 }
107
108 // ------------------------------------------------------------------------
109 // Operations
110 // ------------------------------------------------------------------------
111
112 @Override
113 public Definition lookupDefinition(String lookupPath) {
114 if (lookupPath.equals("context")) { //$NON-NLS-1$
115 return context;
116 } else if (lookupPath.equals("fields")) { //$NON-NLS-1$
117 return fields;
118 } else {
119 return null;
120 }
121 }
122
123 @Override
124 public String toString() {
125 HashMap<String, Definition> f;
126 List<String> list;
127 StringBuilder b = new StringBuilder();
128
129 b.append("Event type: " + declaration.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
130 b.append("Timestamp: " + Long.toString(timestamp) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
131
132 if (context != null) {
133 f = context.getDefinitions();
134 list = context.getDeclaration().getFieldsList();
135
136 for (String field : list) {
137 b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
138 }
139 }
140
141 if (fields != null) {
142 f = fields.getDefinitions();
143 list = fields.getDeclaration().getFieldsList();
144
145 for (String field : list) {
146 b.append(field + " : " + f.get(field).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
147 }
148 }
149
150 return b.toString();
151 }
152
153}
This page took 0.028763 seconds and 5 git commands to generate.