Commit | Line | Data |
---|---|---|
be222f56 | 1 | /******************************************************************************* |
7a0b1e3c | 2 | * Copyright (c) 2010, 2015 Ericsson |
be222f56 PT |
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 | * Patrick Tasse - Initial API and implementation | |
baafe54c | 11 | * Alexandre Montplaisir - Update for TmfEventTableColumn |
be222f56 PT |
12 | *******************************************************************************/ |
13 | ||
b04903a2 | 14 | package org.eclipse.tracecompass.internal.tmf.core.parsers.custom; |
be222f56 | 15 | |
5db5a3a4 AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
be222f56 PT |
18 | import java.util.List; |
19 | ||
baafe54c | 20 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 | 21 | import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; |
9447c7ee | 22 | import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; |
2bdf0193 AM |
23 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomEvent; |
24 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition; | |
25 | import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.OutputColumn; | |
be222f56 | 26 | |
baafe54c AM |
27 | import com.google.common.collect.ImmutableList; |
28 | ||
a0a88f65 | 29 | /** |
b04903a2 | 30 | * Event aspects for Custom {Text|XML} traces. |
a0a88f65 | 31 | * |
b04903a2 AM |
32 | * Since this definition will be different for every single custom trace, we |
33 | * cannot define specific {@link ITmfEventAspect} in advance. | |
99d7adc6 | 34 | * |
b04903a2 AM |
35 | * Instead, one has to call {@link #generateAspects(CustomTraceDefinition)} |
36 | * with the CustomTraceDefinition of the the particular trace to display. | |
99d7adc6 AM |
37 | * |
38 | * @author Alexandre Montplaisir | |
a0a88f65 | 39 | */ |
b04903a2 | 40 | public class CustomEventAspects { |
be222f56 | 41 | |
baafe54c | 42 | /** |
b04903a2 AM |
43 | * Aspects for custom events, which use an integer ID to represent each |
44 | * field. | |
baafe54c | 45 | */ |
9447c7ee | 46 | private static final class CustomEventFieldAspect implements ITmfEventAspect { |
baafe54c | 47 | |
9447c7ee | 48 | private final @NonNull String fName; |
baafe54c AM |
49 | private final int fIndex; |
50 | ||
51 | /** | |
52 | * Constructor | |
53 | * | |
54 | * @param name | |
b04903a2 | 55 | * The name of this aspect |
baafe54c | 56 | * @param idx |
b04903a2 | 57 | * The index of this field in the event's content to display |
baafe54c | 58 | */ |
9447c7ee AM |
59 | public CustomEventFieldAspect(@NonNull String name, int idx) { |
60 | fName = name; | |
baafe54c AM |
61 | fIndex = idx; |
62 | } | |
63 | ||
64 | @Override | |
9447c7ee AM |
65 | public String getName() { |
66 | return fName; | |
67 | } | |
68 | ||
69 | @Override | |
70 | public String getHelpText() { | |
71 | return EMPTY_STRING; | |
72 | } | |
73 | ||
74 | @Override | |
75 | public String resolve(ITmfEvent event) { | |
baafe54c AM |
76 | if (event instanceof CustomEvent) { |
77 | String ret = ((CustomEvent) event).getEventString(fIndex); | |
78 | return (ret == null ? EMPTY_STRING : ret); | |
79 | } | |
80 | return EMPTY_STRING; | |
81 | } | |
baafe54c | 82 | } |
be222f56 | 83 | |
a0a88f65 | 84 | /** |
b04903a2 | 85 | * Build a set of event aspects for a given trace definition |
a0a88f65 | 86 | * |
b04903a2 AM |
87 | * @param definition |
88 | * The {@link CustomTraceDefinition} of the trace for which you | |
89 | * want the aspects | |
90 | * @return The set of event aspects for the given trace | |
a0a88f65 | 91 | */ |
8192209b | 92 | public static @NonNull Iterable<ITmfEventAspect> generateAspects(CustomTraceDefinition definition) { |
b04903a2 | 93 | ImmutableList.Builder<ITmfEventAspect> builder = new ImmutableList.Builder<>(); |
baafe54c AM |
94 | List<OutputColumn> outputs = definition.outputs; |
95 | for (int i = 0; i < outputs.size(); i++) { | |
96 | String name = outputs.get(i).name; | |
7a0b1e3c | 97 | builder.add(new CustomEventFieldAspect(name, i)); |
be222f56 | 98 | } |
5db5a3a4 | 99 | return checkNotNull(builder.build()); |
be222f56 PT |
100 | } |
101 | } |