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
.tracecompass
.btf
.core
.Messages
;
20 import org
.eclipse
.tracecompass
.btf
.core
.trace
.BtfColumnNames
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
25 import com
.google
.common
.collect
.ImmutableList
;
28 * Btf event type, can get a description from the spec
30 * @author Matthew Khouzam
32 public class BtfEventType
extends TmfEventType
{
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() };
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
;
53 * The type constructor
54 * @param name the event name
55 * @param description the event description
57 public BtfEventType(String name
, String description
) {
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
);
67 * does the event have an eighth column
69 * @return if the name is "sem" or "sig" true
71 public boolean hasNotes() {
79 public String
getName() {
84 public Collection
<String
> getFieldNames() {
89 public ITmfEventField
getRootField() {
94 * @return the description
96 public String
getDescription() {
101 * Gets the event field values
104 * the "event" payload
105 * @param sourceInstance
107 * @param targetInstance
111 public ITmfEventField
generateContent(String event
, long sourceInstance
, long targetInstance
) {
113 TmfEventField retField
;
114 TmfEventField sourceInstanceField
= new TmfEventField(BtfColumnNames
.SOURCE_INSTANCE
.toString(), sourceInstance
, null);
115 TmfEventField targetInstanceField
= new TmfEventField(BtfColumnNames
.TARGET_INSTANCE
.toString(), targetInstance
, null);
117 data
= event
.split(",", 2); //$NON-NLS-1$
118 TmfEventField eventField
= new TmfEventField(BtfColumnNames
.EVENT
.toString(), data
[0], BTFPayload
.getFieldDescription(data
[0]));
119 TmfEventField notesField
= new TmfEventField(BtfColumnNames
.NOTES
.toString(), data
.length
== 2 ? data
[1] : null, null);
120 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
, notesField
});
122 data
= new String
[] { event
};
123 TmfEventField eventField
= new TmfEventField(BtfColumnNames
.EVENT
.toString(), data
[0], BTFPayload
.getFieldDescription(data
[0]));
124 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
});