1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 * Patrick Tasse - Fix target instance field
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.btf
.core
.event
;
16 import java
.util
.Collection
;
17 import java
.util
.List
;
19 import org
.eclipse
.jdt
.annotation
.NonNull
;
20 import org
.eclipse
.tracecompass
.btf
.core
.Messages
;
21 import org
.eclipse
.tracecompass
.btf
.core
.trace
.BtfColumnNames
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
26 import com
.google
.common
.collect
.ImmutableList
;
29 * Btf event type, can get a description from the spec
31 * @author Matthew Khouzam
33 public class BtfEventType
extends TmfEventType
{
35 private static final String
@NonNull [] FIELD_WITH_NOTES_COLUMNS
= new String
[] {
36 BtfColumnNames
.EVENT
.toString(),
37 BtfColumnNames
.SOURCE_INSTANCE
.toString(),
38 BtfColumnNames
.TARGET_INSTANCE
.toString() };
40 private static final String
@NonNull [] FIELDS_WITHOUT_NOTES_COLUMNS
= new String
[] {
41 BtfColumnNames
.EVENT
.toString(),
42 BtfColumnNames
.SOURCE_INSTANCE
.toString(),
43 BtfColumnNames
.TARGET_INSTANCE
.toString(),
44 BtfColumnNames
.NOTES
.toString() };
45 private static final @NonNull ITmfEventField FIELDS_WITHOUT_NOTES
= TmfEventField
.makeRoot(FIELD_WITH_NOTES_COLUMNS
);
46 private static final @NonNull ITmfEventField FIELDS_WITH_NOTES
= TmfEventField
.makeRoot(FIELDS_WITHOUT_NOTES_COLUMNS
);
47 private final @NonNull String fName
;
48 private final String fDescription
;
49 private final boolean fHasNotes
;
50 private final List
<String
> fCols
;
51 private final ITmfEventField fFields
;
54 * The type constructor
55 * @param name the event name
56 * @param description the event description
58 public BtfEventType(@NonNull String name
, String description
) {
61 fDescription
= description
;
62 fHasNotes
= (fName
.equals(Messages
.BtfTypeId_SIGName
) || fName
.equals(Messages
.BtfTypeId_SEMName
));
63 fCols
= ImmutableList
.copyOf(fHasNotes ? FIELDS_WITHOUT_NOTES_COLUMNS
: FIELD_WITH_NOTES_COLUMNS
);
64 fFields
= (fHasNotes ? FIELDS_WITH_NOTES
: FIELDS_WITHOUT_NOTES
);
68 * does the event have an eighth column
70 * @return if the name is "sem" or "sig" true
72 public boolean hasNotes() {
80 public String
getName() {
85 public Collection
<String
> getFieldNames() {
90 public ITmfEventField
getRootField() {
95 * @return the description
97 public String
getDescription() {
102 * Gets the event field values
105 * the "event" payload
106 * @param sourceInstance
108 * @param targetInstance
112 public ITmfEventField
generateContent(String event
, long sourceInstance
, long targetInstance
) {
114 TmfEventField retField
;
115 TmfEventField sourceInstanceField
= new TmfEventField(BtfColumnNames
.SOURCE_INSTANCE
.toString(), sourceInstance
, null);
116 TmfEventField targetInstanceField
= new TmfEventField(BtfColumnNames
.TARGET_INSTANCE
.toString(), targetInstance
, null);
118 data
= event
.split(",", 2); //$NON-NLS-1$
119 TmfEventField eventField
= new TmfEventField(BtfColumnNames
.EVENT
.toString(), data
[0], BTFPayload
.getFieldDescription(data
[0]));
120 TmfEventField notesField
= new TmfEventField(BtfColumnNames
.NOTES
.toString(), data
.length
== 2 ? data
[1] : null, null);
121 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
, notesField
});
123 data
= new String
[] { event
};
124 TmfEventField eventField
= new TmfEventField(BtfColumnNames
.EVENT
.toString(), data
[0], BTFPayload
.getFieldDescription(data
[0]));
125 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
});