0ca7d58199a28c98ba3b5f21ccf00cd04836f1ea
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.ctf.core / src / org / eclipse / tracecompass / internal / ctf / core / event / types / composite / EventHeaderDefinition.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
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:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.internal.ctf.core.event.types.composite;
14
15 import java.util.List;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
19 import org.eclipse.tracecompass.ctf.core.event.types.Declaration;
20 import org.eclipse.tracecompass.ctf.core.event.types.Definition;
21 import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
22 import org.eclipse.tracecompass.ctf.core.event.types.IEventHeaderDeclaration;
23 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
24 import org.eclipse.tracecompass.ctf.core.event.types.IntegerDefinition;
25
26 import com.google.common.collect.ImmutableList;
27
28 /**
29 * An event header definition, as shown in the example of the CTF spec examples
30 * section 6.1.1
31 *
32 * @author Matthew Khouzam
33 */
34 public final class EventHeaderDefinition extends Definition implements ICompositeDefinition {
35
36 private static final List<String> FIELD_NAMES = ImmutableList.of(
37 IEventHeaderDeclaration.ID,
38 IEventHeaderDeclaration.TIMESTAMP
39 );
40
41 private final int fId;
42 private final long fTimestamp;
43 private final int fTimestampLength;
44
45 /**
46 * Event header defintion
47 *
48 * @param id
49 * the event id
50 * @param timestamp
51 * the timestamp
52 * @param eventHeaderDecl
53 * The declaration of this defintion
54 * @param timestampLength
55 * the number of bits valid in the timestamp
56 */
57 public EventHeaderDefinition(@NonNull Declaration eventHeaderDecl, int id, long timestamp, int timestampLength) {
58 super(eventHeaderDecl, null, ILexicalScope.EVENT_HEADER.getPath(), ILexicalScope.EVENT_HEADER);
59 fId = id;
60 fTimestamp = timestamp;
61 fTimestampLength = timestampLength;
62 }
63
64 /**
65 * Gets the timestamp declaration
66 *
67 * @return the timestamp declaration
68 */
69 public int getTimestampLength() {
70 return fTimestampLength;
71 }
72
73 /**
74 * Get the event id
75 *
76 * @return the event id
77 */
78 public int getId() {
79 return fId;
80 }
81
82 /**
83 * Get the timestamp
84 *
85 * @return the timestamp
86 */
87 public long getTimestamp() {
88 return fTimestamp;
89 }
90
91 @Override
92 public Definition getDefinition(String fieldName) {
93 if (fieldName.equals(IEventHeaderDeclaration.ID)) {
94 return new IntegerDefinition(IntegerDeclaration.INT_32B_DECL, null, IEventHeaderDeclaration.ID, getId());
95 } else if (fieldName.equals(IEventHeaderDeclaration.TIMESTAMP)) {
96 return new IntegerDefinition(IntegerDeclaration.INT_64B_DECL, null, IEventHeaderDeclaration.TIMESTAMP, getTimestamp());
97 }
98 return null;
99 }
100
101 @Override
102 public List<String> getFieldNames() {
103 return FIELD_NAMES;
104 }
105 }
This page took 0.034999 seconds and 4 git commands to generate.