tmf: Introduce the core concept of event aspects
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / tmf / core / event / aspect / TmfStateSystemAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.core.event.aspect;
14
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
19 import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
20 import org.eclipse.tracecompass.statesystem.core.exceptions.StateSystemDisposedException;
21 import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
22 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
23
24 /**
25 * Aspect representing a query in a given state system, at the timestamp of the
26 * event.
27 *
28 * This is a good example of how aspects can be "indirect" with regards to their
29 * events.
30 *
31 * @author Alexandre Montplaisir
32 */
33 public class TmfStateSystemAspect implements ITmfEventAspect {
34
35 private final @Nullable String fName;
36 private final ITmfStateSystem fSS;
37 private final int fAttribute;
38
39 /**
40 * Constructor
41 *
42 * @param name
43 * The name of this aspect. You can use 'null' to use the
44 * default name, which is the (base) name of the attribute.
45 * @param ss
46 * The state system in which we want to query
47 * @param attributeQuark
48 * The quark of the attribute in the state system to look for
49 */
50 public TmfStateSystemAspect(@Nullable String name, ITmfStateSystem ss, int attributeQuark) {
51 fName = name;
52 fSS = ss;
53 fAttribute = attributeQuark;
54 }
55
56 @Override
57 public String getName() {
58 String name = fName;
59 if (name != null) {
60 return name;
61 }
62
63 name = fSS.getAttributeName(fAttribute);
64 return (name == null ? EMPTY_STRING : name);
65 }
66
67 @Override
68 public @NonNull String getHelpText() {
69 return Messages.getMessage(NLS.bind(Messages.AspectHelpText_Statesystem,
70 fSS.getSSID(), fSS.getFullAttributePath(fAttribute)));
71 }
72
73 @Override
74 public String resolve(ITmfEvent event) {
75 try {
76 ITmfStateValue value = fSS.querySingleState(event.getTimestamp().getValue(), fAttribute).getStateValue();
77
78 @SuppressWarnings("null")
79 @NonNull String ret = value.toString();
80 return ret;
81 } catch (AttributeNotFoundException | StateSystemDisposedException e) {
82 return EMPTY_STRING;
83 }
84 }
85
86 @Override
87 public @Nullable String getFilterId() {
88 return null;
89 }
90
91 }
This page took 0.037051 seconds and 5 git commands to generate.