Commit | Line | Data |
---|---|---|
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 | 14 | package org.eclipse.tracecompass.btf.core.event; |
ff71e543 MK |
15 | |
16 | import java.util.Collection; | |
17 | import java.util.List; | |
18 | ||
66838307 | 19 | import org.eclipse.jdt.annotation.NonNull; |
7ce90559 AM |
20 | import org.eclipse.tracecompass.btf.core.Messages; |
21 | import org.eclipse.tracecompass.btf.core.trace.BtfColumnNames; | |
2bdf0193 AM |
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; | |
ff71e543 MK |
25 | |
26 | import com.google.common.collect.ImmutableList; | |
27 | ||
28 | /** | |
29 | * Btf event type, can get a description from the spec | |
30 | * | |
31 | * @author Matthew Khouzam | |
32 | */ | |
33 | public class BtfEventType extends TmfEventType { | |
34 | ||
66838307 | 35 | private static final String @NonNull [] FIELD_WITH_NOTES_COLUMNS = new String[] { |
ff71e543 MK |
36 | BtfColumnNames.EVENT.toString(), |
37 | BtfColumnNames.SOURCE_INSTANCE.toString(), | |
38 | BtfColumnNames.TARGET_INSTANCE.toString() }; | |
39 | ||
66838307 | 40 | private static final String @NonNull [] FIELDS_WITHOUT_NOTES_COLUMNS = new String[] { |
ff71e543 MK |
41 | BtfColumnNames.EVENT.toString(), |
42 | BtfColumnNames.SOURCE_INSTANCE.toString(), | |
43 | BtfColumnNames.TARGET_INSTANCE.toString(), | |
44 | BtfColumnNames.NOTES.toString() }; | |
66838307 MAL |
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); | |
ff71e543 MK |
47 | private final String fName; |
48 | private final String fDescription; | |
49 | private final boolean fHasNotes; | |
50 | private final List<String> fCols; | |
51 | private final ITmfEventField fFields; | |
52 | ||
53 | /** | |
54 | * The type constructor | |
55 | * @param name the event name | |
56 | * @param description the event description | |
57 | */ | |
58 | public BtfEventType(String name, String description) { | |
59 | super(); | |
60 | fName = name; | |
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); | |
65 | } | |
66 | ||
67 | /** | |
68 | * does the event have an eighth column | |
69 | * | |
70 | * @return if the name is "sem" or "sig" true | |
71 | */ | |
72 | public boolean hasNotes() { | |
73 | return fHasNotes; | |
74 | } | |
75 | ||
76 | /** | |
77 | * @return the name | |
78 | */ | |
79 | @Override | |
80 | public String getName() { | |
81 | return fName; | |
82 | } | |
83 | ||
84 | @Override | |
85 | public Collection<String> getFieldNames() { | |
86 | return fCols; | |
87 | } | |
88 | ||
89 | @Override | |
90 | public ITmfEventField getRootField() { | |
91 | return fFields; | |
92 | } | |
93 | ||
94 | /** | |
95 | * @return the description | |
96 | */ | |
97 | public String getDescription() { | |
98 | return fDescription; | |
99 | } | |
100 | ||
101 | /** | |
102 | * Gets the event field values | |
103 | * | |
104 | * @param event | |
105 | * the "event" payload | |
106 | * @param sourceInstance | |
107 | * source instance | |
108 | * @param targetInstance | |
109 | * target instance | |
110 | * @return a field. | |
111 | */ | |
112 | public ITmfEventField generateContent(String event, long sourceInstance, long targetInstance) { | |
113 | String[] data; | |
114 | TmfEventField retField; | |
df854ddb PT |
115 | TmfEventField sourceInstanceField = new TmfEventField(BtfColumnNames.SOURCE_INSTANCE.toString(), sourceInstance, null); |
116 | TmfEventField targetInstanceField = new TmfEventField(BtfColumnNames.TARGET_INSTANCE.toString(), targetInstance, null); | |
ff71e543 MK |
117 | if (fHasNotes) { |
118 | data = event.split(",", 2); //$NON-NLS-1$ | |
df854ddb | 119 | TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0])); |
3a723766 | 120 | TmfEventField notesField = new TmfEventField(BtfColumnNames.NOTES.toString(), data.length == 2 ? data[1] : null, null); |
ff71e543 MK |
121 | retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField, notesField }); |
122 | } else { | |
123 | data = new String[] { event }; | |
df854ddb | 124 | TmfEventField eventField = new TmfEventField(BtfColumnNames.EVENT.toString(), data[0], BTFPayload.getFieldDescription(data[0])); |
ff71e543 MK |
125 | retField = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, null, new TmfEventField[] { eventField, sourceInstanceField, targetInstanceField }); |
126 | } | |
127 | return retField; | |
128 | } | |
129 | } |