common: Generalize the BufferedBlockingQueue's concurrent test
[deliverable/tracecompass.git] / org.eclipse.tracecompass.btf.core / src / org / eclipse / tracecompass / btf / core / event / BtfEventType.java
CommitLineData
ff71e543 1/*******************************************************************************
df854ddb 2 * Copyright (c) 2014, 2015 Ericsson
ff71e543
MK
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made 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
df854ddb 11 * Patrick Tasse - Fix target instance field
ff71e543
MK
12 *******************************************************************************/
13
7ce90559 14package org.eclipse.tracecompass.btf.core.event;
ff71e543
MK
15
16import java.util.Collection;
17import java.util.List;
18
7ce90559
AM
19import org.eclipse.tracecompass.btf.core.Messages;
20import org.eclipse.tracecompass.btf.core.trace.BtfColumnNames;
2bdf0193
AM
21import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
22import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
23import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
ff71e543
MK
24
25import com.google.common.collect.ImmutableList;
26
27/**
28 * Btf event type, can get a description from the spec
29 *
30 * @author Matthew Khouzam
31 */
32public class BtfEventType extends TmfEventType {
33
34 private static final String[] FIELD_WITH_NOTES_COLUMNS = new String[] {
35 BtfColumnNames.EVENT.toString(),
36 BtfColumnNames.SOURCE_INSTANCE.toString(),
37 BtfColumnNames.TARGET_INSTANCE.toString() };
38
39 private static final String[] FIELDS_WITHOUT_NOTES_COLUMNS = new String[] {
40 BtfColumnNames.EVENT.toString(),
41 BtfColumnNames.SOURCE_INSTANCE.toString(),
42 BtfColumnNames.TARGET_INSTANCE.toString(),
43 BtfColumnNames.NOTES.toString() };
44 private static final ITmfEventField FIELDS_WITHOUT_NOTES = TmfEventField.makeRoot(FIELD_WITH_NOTES_COLUMNS);
45 private static final ITmfEventField FIELDS_WITH_NOTES = TmfEventField.makeRoot(FIELDS_WITHOUT_NOTES_COLUMNS);
46 private final String fName;
47 private final String fDescription;
48 private final boolean fHasNotes;
49 private final List<String> fCols;
50 private final ITmfEventField fFields;
51
52 /**
53 * The type constructor
54 * @param name the event name
55 * @param description the event description
56 */
57 public BtfEventType(String name, String description) {
58 super();
59 fName = name;
60 fDescription = description;
61 fHasNotes = (fName.equals(Messages.BtfTypeId_SIGName) || fName.equals(Messages.BtfTypeId_SEMName));
62 fCols = ImmutableList.copyOf(fHasNotes ? FIELDS_WITHOUT_NOTES_COLUMNS : FIELD_WITH_NOTES_COLUMNS);
63 fFields = (fHasNotes ? FIELDS_WITH_NOTES : FIELDS_WITHOUT_NOTES);
64 }
65
66 /**
67 * does the event have an eighth column
68 *
69 * @return if the name is "sem" or "sig" true
70 */
71 public boolean hasNotes() {
72 return fHasNotes;
73 }
74
75 /**
76 * @return the name
77 */
78 @Override
79 public String getName() {
80 return fName;
81 }
82
83 @Override
84 public Collection<String> getFieldNames() {
85 return fCols;
86 }
87
88 @Override
89 public ITmfEventField getRootField() {
90 return fFields;
91 }
92
93 /**
94 * @return the description
95 */
96 public String getDescription() {
97 return fDescription;
98 }
99
100 /**
101 * Gets the event field values
102 *
103 * @param event
104 * the "event" payload
105 * @param sourceInstance
106 * source instance
107 * @param targetInstance
108 * target instance
109 * @return a field.
110 */
111 public ITmfEventField generateContent(String event, long sourceInstance, long targetInstance) {
112 String[] data;
113 TmfEventField retField;
df854ddb
PT
114 TmfEventField sourceInstanceField = new TmfEventField(BtfColumnNames.SOURCE_INSTANCE.toString(), sourceInstance, null);
115 TmfEventField targetInstanceField = new TmfEventField(BtfColumnNames.TARGET_INSTANCE.toString(), targetInstance, null);
ff71e543
MK
116 if (fHasNotes) {
117 data = event.split(",", 2); //$NON-NLS-1$
df854ddb 118 TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0]));
3a723766 119 TmfEventField notesField = new TmfEventField(BtfColumnNames.NOTES.toString(), data.length == 2 ? data[1] : null, null);
ff71e543
MK
120 retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField, notesField });
121 } else {
122 data = new String[] { event };
df854ddb 123 TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0]));
ff71e543
MK
124 retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField });
125 }
126 return retField;
127 }
128}
This page took 0.048102 seconds and 5 git commands to generate.