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
.ctf
.core
.event
;
15 import java
.util
.HashMap
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.Definition
;
19 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.IDefinitionScope
;
20 import org
.eclipse
.linuxtools
.ctf
.core
.event
.types
.StructDefinition
;
21 import org
.eclipse
.linuxtools
.ctf
.core
.trace
.StreamInputReader
;
24 * <b><u>EventDefinition</u></b>
26 * Represents an instance of an event.
28 public class EventDefinition
implements IDefinitionScope
{
30 // ------------------------------------------------------------------------
32 // ------------------------------------------------------------------------
35 * The corresponding event declaration.
37 private final EventDeclaration declaration
;
40 * The timestamp of the current event.
42 private long timestamp
;
45 * The event context structure definition.
47 private StructDefinition context
;
50 * The event fields structure definition.
52 private StructDefinition fields
;
55 * The StreamInputReader that reads this event definition.
57 public final StreamInputReader streamInputReader
;
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
64 * Constructs an event definition.
67 * The corresponding event declaration.
69 public EventDefinition(EventDeclaration declaration
,
70 StreamInputReader streamInputReader
) {
71 this.declaration
= declaration
;
72 this.streamInputReader
= streamInputReader
;
75 // ------------------------------------------------------------------------
76 // Getters/Setters/Predicates
77 // ------------------------------------------------------------------------
80 public String
getPath() {
81 return "event"; //$NON-NLS-1$
84 public EventDeclaration
getDeclaration() {
88 public StructDefinition
getFields() {
92 public StructDefinition
getContext() {
96 public StreamInputReader
getStreamInputReader() {
97 return streamInputReader
;
100 public StructDefinition
getPacketContext() {
101 return streamInputReader
.getCurrentPacketContext();
104 public int getCPU() {
105 return streamInputReader
.getCPU();
109 * @return the timestamp
111 public long getTimestamp() {
116 * @param timestamp the timestamp to set
118 public void setTimestamp(long timestamp
) {
119 this.timestamp
= timestamp
;
123 * @param context the context to set
125 public void setContext(StructDefinition context
) {
126 this.context
= context
;
130 * @param fields the fields to set
132 public void setFields(StructDefinition fields
) {
133 this.fields
= fields
;
136 // ------------------------------------------------------------------------
138 // ------------------------------------------------------------------------
141 public Definition
lookupDefinition(String lookupPath
) {
142 if (lookupPath
.equals("context")) { //$NON-NLS-1$
144 } else if (lookupPath
.equals("fields")) { //$NON-NLS-1$
152 public String
toString() {
153 HashMap
<String
, Definition
> f
;
155 StringBuilder b
= new StringBuilder();
157 b
.append("Event type: " + declaration
.getName() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
158 b
.append("Timestamp: " + Long
.toString(timestamp
) + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
160 if (context
!= null) {
161 f
= context
.getDefinitions();
162 list
= context
.getDeclaration().getFieldsList();
164 for (String field
: list
) {
165 b
.append(field
+ " : " + f
.get(field
).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
169 if (fields
!= null) {
170 f
= fields
.getDefinitions();
171 list
= fields
.getDeclaration().getFieldsList();
173 for (String field
: list
) {
174 b
.append(field
+ " : " + f
.get(field
).toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$