Commit | Line | Data |
---|---|---|
ff71e543 MK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2014 Ericsson | |
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 | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.btf.core.event; | |
14 | ||
15 | import java.util.Collection; | |
16 | import java.util.List; | |
17 | ||
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; | |
23 | ||
24 | import com.google.common.collect.ImmutableList; | |
25 | ||
26 | /** | |
27 | * Btf event type, can get a description from the spec | |
28 | * | |
29 | * @author Matthew Khouzam | |
30 | */ | |
31 | public class BtfEventType extends TmfEventType { | |
32 | ||
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() }; | |
37 | ||
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; | |
50 | ||
51 | /** | |
52 | * The type constructor | |
53 | * @param name the event name | |
54 | * @param description the event description | |
55 | */ | |
56 | public BtfEventType(String name, String description) { | |
57 | super(); | |
58 | fName = name; | |
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); | |
63 | } | |
64 | ||
65 | /** | |
66 | * does the event have an eighth column | |
67 | * | |
68 | * @return if the name is "sem" or "sig" true | |
69 | */ | |
70 | public boolean hasNotes() { | |
71 | return fHasNotes; | |
72 | } | |
73 | ||
74 | /** | |
75 | * @return the name | |
76 | */ | |
77 | @Override | |
78 | public String getName() { | |
79 | return fName; | |
80 | } | |
81 | ||
82 | @Override | |
83 | public Collection<String> getFieldNames() { | |
84 | return fCols; | |
85 | } | |
86 | ||
87 | @Override | |
88 | public ITmfEventField getRootField() { | |
89 | return fFields; | |
90 | } | |
91 | ||
92 | /** | |
93 | * @return the description | |
94 | */ | |
95 | public String getDescription() { | |
96 | return fDescription; | |
97 | } | |
98 | ||
99 | /** | |
100 | * Gets the event field values | |
101 | * | |
102 | * @param event | |
103 | * the "event" payload | |
104 | * @param sourceInstance | |
105 | * source instance | |
106 | * @param targetInstance | |
107 | * target instance | |
108 | * @return a field. | |
109 | */ | |
110 | public ITmfEventField generateContent(String event, long sourceInstance, long targetInstance) { | |
111 | String[] data; | |
112 | TmfEventField retField; | |
113 | TmfEventField sourceInstanceField = new TmfEventField(fCols.get(1), sourceInstance, null); | |
114 | TmfEventField targetInstanceField = new TmfEventField(fCols.get(2), sourceInstance, null); | |
115 | if (fHasNotes) { | |
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 }); | |
120 | } else { | |
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 }); | |
124 | } | |
125 | return retField; | |
126 | } | |
127 | } |