1 /*******************************************************************************
2 * Copyright (c) 2014 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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.btf
.core
.event
;
15 import java
.util
.Collection
;
16 import java
.util
.List
;
18 import org
.eclipse
.linuxtools
.btf
.core
.Messages
;
19 import org
.eclipse
.linuxtools
.btf
.core
.trace
.BtfColumnNames
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
24 import com
.google
.common
.collect
.ImmutableList
;
27 * Btf event type, can get a description from the spec
29 * @author Matthew Khouzam
31 public class BtfEventType
extends TmfEventType
{
33 private static final String
[] FIELD_WITH_NOTES_COLUMNS
= new String
[] {
34 BtfColumnNames
.EVENT
.toString(),
35 BtfColumnNames
.SOURCE_INSTANCE
.toString(),
36 BtfColumnNames
.TARGET_INSTANCE
.toString() };
38 private static final String
[] FIELDS_WITHOUT_NOTES_COLUMNS
= new String
[] {
39 BtfColumnNames
.EVENT
.toString(),
40 BtfColumnNames
.SOURCE_INSTANCE
.toString(),
41 BtfColumnNames
.TARGET_INSTANCE
.toString(),
42 BtfColumnNames
.NOTES
.toString() };
43 private static final ITmfEventField FIELDS_WITHOUT_NOTES
= TmfEventField
.makeRoot(FIELD_WITH_NOTES_COLUMNS
);
44 private static final ITmfEventField FIELDS_WITH_NOTES
= TmfEventField
.makeRoot(FIELDS_WITHOUT_NOTES_COLUMNS
);
45 private final String fName
;
46 private final String fDescription
;
47 private final boolean fHasNotes
;
48 private final List
<String
> fCols
;
49 private final ITmfEventField fFields
;
52 * The type constructor
53 * @param name the event name
54 * @param description the event description
56 public BtfEventType(String name
, String description
) {
59 fDescription
= description
;
60 fHasNotes
= (fName
.equals(Messages
.BtfTypeId_SIGName
) || fName
.equals(Messages
.BtfTypeId_SEMName
));
61 fCols
= ImmutableList
.copyOf(fHasNotes ? FIELDS_WITHOUT_NOTES_COLUMNS
: FIELD_WITH_NOTES_COLUMNS
);
62 fFields
= (fHasNotes ? FIELDS_WITH_NOTES
: FIELDS_WITHOUT_NOTES
);
66 * does the event have an eighth column
68 * @return if the name is "sem" or "sig" true
70 public boolean hasNotes() {
78 public String
getName() {
83 public Collection
<String
> getFieldNames() {
88 public ITmfEventField
getRootField() {
93 * @return the description
95 public String
getDescription() {
100 * Gets the event field values
103 * the "event" payload
104 * @param sourceInstance
106 * @param targetInstance
110 public ITmfEventField
generateContent(String event
, long sourceInstance
, long targetInstance
) {
112 TmfEventField retField
;
113 TmfEventField sourceInstanceField
= new TmfEventField(fCols
.get(1), sourceInstance
, null);
114 TmfEventField targetInstanceField
= new TmfEventField(fCols
.get(2), sourceInstance
, null);
116 data
= event
.split(",", 2); //$NON-NLS-1$
117 TmfEventField eventField
= new TmfEventField(fCols
.get(0), data
[0], BTFPayload
.getFieldDescription(data
[0]));
118 TmfEventField notesField
= new TmfEventField(fCols
.get(3), data
[1], null);
119 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
, notesField
});
121 data
= new String
[] { event
};
122 TmfEventField eventField
= new TmfEventField(fCols
.get(0), data
[0], BTFPayload
.getFieldDescription(data
[0]));
123 retField
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, null, new TmfEventField
[] { eventField
, sourceInstanceField
, targetInstanceField
});