1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.core
.event
.aspect
;
15 import org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.jdt
.annotation
.Nullable
;
17 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
18 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
21 * An aspect is a piece of information that can be extracted, directly or
22 * indirectly, from a trace event.
24 * Simple examples could be timestamp, or event fields. But it could also be
25 * something like a state system request, at the timestamp of the given event.
27 * The aspect can then be used to populate event table columns, to filter
28 * on to only keep certain events, to plot XY charts, etc.
30 * @author Alexandre Montplaisir
32 public interface ITmfEventAspect
{
35 * Static definition of an empty string. You can use this instead of 'null'!
37 String EMPTY_STRING
= ""; //$NON-NLS-1$
40 * Some basic aspects that all trace types should be able to use, using
41 * methods found in {@link ITmfEvent}.
43 interface BaseAspects
{
46 * Aspect for the event timestamp
48 ITmfEventAspect TIMESTAMP
= new ITmfEventAspect() {
50 public String
getName() {
51 return Messages
.getMessage(Messages
.AspectName_Timestamp
);
55 public String
getHelpText() {
60 public String
resolve(ITmfEvent event
) {
61 String ret
= event
.getTimestamp().toString();
62 return (ret
== null ? EMPTY_STRING
: ret
);
66 public @NonNull String
getFilterId() {
67 return ITmfEvent
.EVENT_FIELD_TIMESTAMP
;
72 * Aspect for the event type
74 ITmfEventAspect EVENT_TYPE
= new ITmfEventAspect() {
76 public String
getName() {
77 return Messages
.getMessage(Messages
.AspectName_EventType
);
81 public String
getHelpText() {
82 return Messages
.getMessage(Messages
.AspectHelpText_EventType
);
86 public String
resolve(ITmfEvent event
) {
87 ITmfEventType type
= event
.getType();
91 String typeName
= type
.getName();
92 return (typeName
== null ? EMPTY_STRING
: typeName
);
96 public @NonNull String
getFilterId() {
97 return ITmfEvent
.EVENT_FIELD_TYPE
;
102 * Aspect for the aggregated event contents (fields)
104 ITmfEventAspect CONTENTS
= new ITmfEventAspect() {
106 public String
getName() {
107 return Messages
.getMessage(Messages
.AspectName_Contents
);
111 public String
getHelpText() {
112 return Messages
.getMessage(Messages
.AspectHelpText_Contents
);
116 public String
resolve(ITmfEvent event
) {
117 String ret
= event
.getContent().toString();
118 return (ret
== null ? EMPTY_STRING
: ret
);
122 public @NonNull String
getFilterId() {
123 return ITmfEvent
.EVENT_FIELD_CONTENT
;
129 * Get the name of this aspect. This name will be user-visible and, as such,
130 * should be localized.
132 * @return The name of this aspect.
137 * Return a descriptive help text of what this aspect does. This could then
138 * be shown in tooltip or in option dialogs for instance. It should also be
141 * You can return {@link #EMPTY_STRING} if you judge that the aspect name
144 * @return The help text of this aspect
146 String
getHelpText();
149 * The "functor" representing this aspect. Basically, what to do for an
150 * event that is passed in parameter.
152 * Note to implementers:
154 * The parameter type here is {@link ITmfEvent}. This is because you could
155 * receive any type of event here. Do not assume you will only receive
156 * events of your own trace type. It is perfectly fine to return
157 * {@link #EMPTY_STRING} for event types you don't support.
159 * You also can (and should) provide a more specific return type than
163 * The event to process
164 * @return The resulting tidbit of information for this event.
166 Object
resolve(ITmfEvent event
);
169 * The filter ID of this aspect. This is currently used by the Filter View,
170 * and to filter on columns in the event table.
172 * TODO Remove this, replace with calls to {@link #resolve(ITmfEvent)}
175 * @return The filter_id
177 @Nullable String
getFilterId();