Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 76825783e12cf9353a13c45ded49262bfaffae19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*******************************************************************************
 * Copyright (c) 2016 École Polytechnique de Montréal
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.tracecompass.tmf.core.event.aspect;

import java.util.List;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;

import com.google.common.collect.ImmutableList;

/**
 * Some basic aspects that all trace types should be able to use, using methods
 * found in {@link ITmfEvent}.
 *
 * @author Alexandre Montplaisir
 * @author Geneviève Bastien
 * @since 2.0
 */
public final class TmfBaseAspects {

    private static final ITmfEventAspect<ITmfTimestamp> TIMESTAMP_ASPECT = new ITmfEventAspect<ITmfTimestamp>() {
        @Override
        public String getName() {
            return Messages.getMessage(Messages.AspectName_Timestamp);
        }

        @Override
        public String getHelpText() {
            return ITmfEventAspect.EMPTY_STRING;
        }

        @Override
        public @Nullable ITmfTimestamp resolve(ITmfEvent event) {
            return event.getTimestamp();
        }
    };

    private static final ITmfEventAspect<String> EVENT_TYPE_ASPECT = new ITmfEventAspect<String>() {
        @Override
        public String getName() {
            return Messages.getMessage(Messages.AspectName_EventType);
        }

        @Override
        public String getHelpText() {
            return Messages.getMessage(Messages.AspectHelpText_EventType);
        }

        @Override
        public @Nullable String resolve(ITmfEvent event) {
            ITmfEventType type = event.getType();
            if (type == null) {
                return null;
            }
            return type.getName();
        }
    };

    private static final TmfEventFieldAspect CONTENTS_ASPECT = new TmfEventFieldAspect(Messages.getMessage(Messages.AspectName_Contents), null, new TmfEventFieldAspect.IRootField() {
        @Override
        public @Nullable ITmfEventField getRootField(ITmfEvent event) {
            return event.getContent();
        }
    }) {
        @Override
        public String getHelpText() {
            return Messages.getMessage(Messages.AspectHelpText_Contents);
        }
    };

    private static final ITmfEventAspect<String> TRACE_NAME_ASPECT = new ITmfEventAspect<String>() {
        @Override
        public String getName() {
            return Messages.getMessage(Messages.AspectName_TraceName);
        }

        @Override
        public String getHelpText() {
            return Messages.getMessage(Messages.AspectHelpText_TraceName);
        }

        @Override
        public @Nullable String resolve(ITmfEvent event) {
            return event.getTrace().getName();
        }
    };

    private static final List<ITmfEventAspect<?>> BASE_ASPECTS = ImmutableList.of(
            getTimestampAspect(),
            getEventTypeAspect(),
            getContentsAspect(),
            getTraceNameAspect());

    private TmfBaseAspects() {

    }

    /**
     * Get the aspect for the event timestamp
     *
     * @return The timestamp aspect
     */
    public static ITmfEventAspect<ITmfTimestamp> getTimestampAspect() {
        return TIMESTAMP_ASPECT;
    }

    /**
     * Get the aspect for the event type
     *
     * @return The aspect for the event type
     */
    public static ITmfEventAspect<String> getEventTypeAspect() {
        return EVENT_TYPE_ASPECT;
    }

    /**
     * Get the aspect for the aggregated event contents (fields)
     *
     * @return The aspect for the aggregate event contents
     */
    public static TmfEventFieldAspect getContentsAspect() {
        return CONTENTS_ASPECT;
    }

    /**
     * Get the aspect for the trace's name (for experiments with many traces)
     *
     * @return The trace name aspect
     */
    public static ITmfEventAspect<String> getTraceNameAspect() {
        return TRACE_NAME_ASPECT;
    }

    /**
     * Get the list of all common base aspects
     *
     * @return the list of base aspects
     */
    public static List<ITmfEventAspect<?>> getBaseAspects() {
        return BASE_ASPECTS;
    }

}

Back to the top