1 /*******************************************************************************
2 * Copyright (c) 2013 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 * Jean-Christian Kouamé - Initial API and implementation
11 * Patrick Tasse - Updates to mipmap feature
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.internal
.tmf
.core
.statesystem
.mipmap
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import java
.util
.HashMap
;
19 import java
.util
.LinkedHashSet
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
27 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
28 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
29 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
30 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
.Type
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
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).
39 * Extend this class for a specific implementation
41 public abstract class AbstractTmfMipmapStateProvider
extends AbstractTmfStateProvider
{
44 * Feature bit for the maximum mipmap feature (value is 1<<1).
46 public static final int MAX
= 1 << 1;
49 * Feature bit for the minimum mipmap feature (value is 1<<2).
51 public static final int MIN
= 1 << 2;
54 * Feature bit for the average mipmap feature (value is 1<<3).
56 public static final int AVG
= 1 << 3;
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.)
63 public static final String MAX_STRING
= "max"; //$NON-NLS-1$
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.)
70 public static final String MIN_STRING
= "min"; //$NON-NLS-1$
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.)
77 public static final String AVG_STRING
= "avg"; //$NON-NLS-1$
80 * Map of mipmap features per attribute. The map's key is the base attribute quark.
82 private Map
<Integer
, Set
<ITmfMipmapFeature
>> featureMap
= new HashMap
<>();
84 // ------------------------------------------------------------------------
86 // ------------------------------------------------------------------------
94 * The specific class for the event type
96 * The name given to this state change input. Only used
99 public AbstractTmfMipmapStateProvider(@NonNull ITmfTrace trace
,
100 @NonNull Class
<?
extends ITmfEvent
> eventType
,
101 @NonNull String id
) {
102 super(trace
, eventType
, id
);
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 public void dispose() {
112 for (Set
<ITmfMipmapFeature
> features
: featureMap
.values()) {
113 for (ITmfMipmapFeature feature
: features
) {
114 feature
.updateAndCloseMipmap();
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.
130 * The timestamp of the event
132 * The value of the base attribute
134 * The quark of the base attribute
135 * @param mipmapFeatureBits
136 * The mipmap feature bit(s)
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.
150 public void modifyMipmapAttribute(long ts
, ITmfStateValue value
, int baseQuark
, int mipmapFeatureBits
, int resolution
)
151 throws TimeRangeException
, AttributeNotFoundException
, StateValueTypeException
{
152 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
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
);
162 // ------------------------------------------------------------------------
164 // ------------------------------------------------------------------------
166 private Set
<ITmfMipmapFeature
> getFeatureSet(int baseQuark
, long ts
, ITmfStateValue value
, int mipmapFeatureBits
, int resolution
) {
167 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
169 Set
<ITmfMipmapFeature
> features
= featureMap
.get(baseQuark
);
170 if (features
!= null) {
173 features
= new LinkedHashSet
<>();
174 if (value
.isNull()) {
177 featureMap
.put(baseQuark
, features
);
178 if (resolution
> 1) {
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
);
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
);
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
);
198 } catch (TimeRangeException e
) {
200 } catch (AttributeNotFoundException e
) {
202 } catch (StateValueTypeException e
) {