tmf: Null-annotate state system API classes
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core / src / org / eclipse / tracecompass / internal / tmf / core / statesystem / mipmap / AbstractTmfMipmapStateProvider.java
CommitLineData
8e364f8e
PT
1/*******************************************************************************
2 * Copyright (c) 2013 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 * Jean-Christian Kouamé - Initial API and implementation
11 * Patrick Tasse - Updates to mipmap feature
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap;
8e364f8e 15
d0c7e4ba
AM
16import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
8e364f8e
PT
18import java.util.HashMap;
19import java.util.LinkedHashSet;
20import java.util.Map;
21import java.util.Set;
22
d0c7e4ba
AM
23import org.eclipse.jdt.annotation.NonNull;
24import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
e894a508
AM
25import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
26import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
27import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
28import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
29import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
30import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue.Type;
2bdf0193
AM
31import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
32import org.eclipse.tracecompass.tmf.core.statesystem.AbstractTmfStateProvider;
33import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
8e364f8e
PT
34
35/**
36 * This is an abstract state provider that allows attributes to be mipmapped
37 * for one or more of the supported mipmap features (min, max, average).
38 *
39 * Extend this class for a specific implementation
40 */
41public abstract class AbstractTmfMipmapStateProvider extends AbstractTmfStateProvider {
42
43 /**
44 * Feature bit for the maximum mipmap feature (value is 1<<1).
45 */
46 public static final int MAX = 1 << 1;
47
48 /**
49 * Feature bit for the minimum mipmap feature (value is 1&lt;&lt;2).
50 */
51 public static final int MIN = 1 << 2;
52
53 /**
54 * Feature bit for the average mipmap feature (value is 1&lt;&lt;3).
55 */
56 public static final int AVG = 1 << 3;
57
58 /**
59 * The string for maximum mipmap feature sub-attribute.
60 * This attribute value is the mipmap number of levels.
61 * It has sub-attributes for every level ("1", "2", etc.)
62 */
63 public static final String MAX_STRING = "max"; //$NON-NLS-1$
64
65 /**
66 * The string for minimum mipmap feature sub-attribute.
67 * This attribute value is the mipmap number of levels.
68 * It has sub-attributes for every level ("1", "2", etc.)
69 */
70 public static final String MIN_STRING = "min"; //$NON-NLS-1$
71
72 /**
73 * The string for average mipmap feature sub-attribute.
74 * This attribute value is the mipmap number of levels.
75 * It has sub-attributes for every level ("1", "2", etc.)
76 */
77 public static final String AVG_STRING = "avg"; //$NON-NLS-1$
78
79 /**
80 * Map of mipmap features per attribute. The map's key is the base attribute quark.
81 */
a4524c1b 82 private Map<Integer, Set<ITmfMipmapFeature>> featureMap = new HashMap<>();
8e364f8e
PT
83
84 // ------------------------------------------------------------------------
85 // Constructor
86 // ------------------------------------------------------------------------
87
88 /**
89 * Constructor
90 *
91 * @param trace
92 * The trace directory
93 * @param eventType
94 * The specific class for the event type
95 * @param id
96 * The name given to this state change input. Only used
97 * internally.
98 */
d0c7e4ba
AM
99 public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace,
100 @NonNull Class<? extends ITmfEvent> eventType,
101 @NonNull String id) {
8e364f8e
PT
102 super(trace, eventType, id);
103 }
104
105 // ------------------------------------------------------------------------
106 // Public methods
107 // ------------------------------------------------------------------------
108
109 @Override
110 public void dispose() {
111 waitForEmptyQueue();
112 for (Set<ITmfMipmapFeature> features : featureMap.values()) {
113 for (ITmfMipmapFeature feature : features) {
114 feature.updateAndCloseMipmap();
115 }
116 }
117 super.dispose();
118 }
119
120 /**
121 * Modify a mipmap attribute. The base attribute is modified and the mipmap
122 * attributes for the feature(s) specified in the mipmap feature bitmap are
123 * created and/or updated.<br>
124 * Note: The mipmapFeatureBits and resolution are only used on the first
125 * call of this method for a particular attribute, and the mipmap features
126 * for this attribute are then activated until the end of the trace.<br>
127 * Note: The base attribute should only be modified by calling this method.
128 *
129 * @param ts
130 * The timestamp of the event
131 * @param value
132 * The value of the base attribute
133 * @param baseQuark
134 * The quark of the base attribute
135 * @param mipmapFeatureBits
136 * The mipmap feature bit(s)
137 * @param resolution
138 * The mipmap resolution (must be greater than 1)
139 * @throws TimeRangeException
140 * If the requested time is outside of the trace's range
141 * @throws AttributeNotFoundException
142 * If the requested attribute quark is invalid
143 * @throws StateValueTypeException
144 * If the inserted state value's type does not match what is
145 * already assigned to this attribute.
146 * @see #MAX
147 * @see #MIN
148 * @see #AVG
149 */
150 public void modifyMipmapAttribute(long ts, ITmfStateValue value, int baseQuark, int mipmapFeatureBits, int resolution)
151 throws TimeRangeException, AttributeNotFoundException, StateValueTypeException {
d0c7e4ba 152 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
8e364f8e
PT
153 ss.modifyAttribute(ts, value, baseQuark);
154 if (value.getType() == Type.LONG || value.getType() == Type.INTEGER || value.getType() == Type.DOUBLE || value.isNull()) {
155 Set<ITmfMipmapFeature> features = getFeatureSet(baseQuark, ts, value, mipmapFeatureBits, resolution);
156 for (ITmfMipmapFeature mf : features) {
157 mf.updateMipmap(value, ts);
158 }
159 }
160 }
161
162 // ------------------------------------------------------------------------
163 // Private methods
164 // ------------------------------------------------------------------------
165
166 private Set<ITmfMipmapFeature> getFeatureSet(int baseQuark, long ts, ITmfStateValue value, int mipmapFeatureBits, int resolution) {
d0c7e4ba
AM
167 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
168
8e364f8e
PT
169 Set<ITmfMipmapFeature> features = featureMap.get(baseQuark);
170 if (features != null) {
171 return features;
172 }
a4524c1b 173 features = new LinkedHashSet<>();
8e364f8e
PT
174 if (value.isNull()) {
175 return features;
176 }
177 featureMap.put(baseQuark, features);
178 if (resolution > 1) {
179 try {
180 if ((mipmapFeatureBits & MAX) != 0) {
181 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MAX_STRING);
182 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
183 MaxMipmapFeature mf = new MaxMipmapFeature(baseQuark, featureQuark, resolution, ss);
184 features.add(mf);
185 }
186 if ((mipmapFeatureBits & MIN) != 0) {
187 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, MIN_STRING);
188 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
189 MinMipmapFeature mf = new MinMipmapFeature(baseQuark, featureQuark, resolution, ss);
190 features.add(mf);
191 }
192 if ((mipmapFeatureBits & AVG) != 0) {
193 int featureQuark = ss.getQuarkRelativeAndAdd(baseQuark, AVG_STRING);
194 ss.modifyAttribute(ts, TmfStateValue.newValueInt(0), featureQuark);
195 AvgMipmapFeature mf = new AvgMipmapFeature(baseQuark, featureQuark, resolution, ss);
196 features.add(mf);
197 }
198 } catch (TimeRangeException e) {
199 e.printStackTrace();
200 } catch (AttributeNotFoundException e) {
201 e.printStackTrace();
202 } catch (StateValueTypeException e) {
203 e.printStackTrace();
204 }
205 }
206 return features;
207 }
208}
This page took 0.054204 seconds and 5 git commands to generate.