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
.tmf
.core
.tests
.statesystem
.mipmap
;
16 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import org
.eclipse
.jdt
.annotation
.NonNull
;
19 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
20 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.statesystem
.mipmap
.AbstractTmfMipmapStateProvider
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystemBuilder
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
26 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
35 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
36 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
39 * A mipmap state provider for test
41 * @author Jean-Christian Kouamé
44 class TmfMipmapStateProviderStub
extends AbstractTmfMipmapStateProvider
{
45 /** test attribute name */
46 public final static String TEST_ATTRIBUTE_NAME
= "test_attribute"; //$NON-NLS-1$
48 private int resolution
;
49 private ITmfStateValue
.Type type
;
50 private static final @NonNull String MIPMAP_ID
= "MIPMAP_ID"; //$NON-NLS-1$
52 private final String ERROR_ATTRIBUTE_NOT_FOUND
= "Error : Impossible to find the attribute"; //$NON-NLS-1$
53 private final String ERROR_INVALID_STATE_VALUE
= "Error : Invalid state value"; //$NON-NLS-1$
54 private final String ERROR_INVALID_TIMESTAMP
= "Error : Invalid timestamp"; //$NON-NLS-1$
60 * the mipmap resolution array (max, min, avg)
62 * the type of value to use
64 public TmfMipmapStateProviderStub(int resolution
, ITmfStateValue
.Type type
) {
65 super(new TmfTraceStub(), TmfEvent
.class, MIPMAP_ID
);
66 this.resolution
= resolution
;
71 protected void eventHandle(ITmfEvent ev
) {
72 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
73 final long ts
= ev
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
75 int quark
= ss
.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME
);
76 ITmfStateValue value
= (ITmfStateValue
) ev
.getContent().getValue();
77 modifyMipmapAttribute(ts
, value
, quark
, MIN
| MAX
| AVG
, resolution
);
78 } catch (TimeRangeException e
) {
79 Activator
.logError(ERROR_INVALID_TIMESTAMP
, e
);
80 } catch (AttributeNotFoundException e
) {
81 Activator
.logError(ERROR_ATTRIBUTE_NOT_FOUND
, e
);
82 } catch (StateValueTypeException e
) {
83 Activator
.logError(ERROR_INVALID_STATE_VALUE
, e
);
88 public int getVersion() {
93 public TmfMipmapStateProviderStub
getNewInstance() {
94 return new TmfMipmapStateProviderStub(resolution
, type
);
101 * The event value or null
102 * @return A new TmfEvent
104 public @NonNull ITmfEvent
createEvent(long time
, Long longVal
) {
105 ITmfStateValue value
;
106 if (longVal
== null) {
107 value
= TmfStateValue
.nullValue();
108 } else if (type
== ITmfStateValue
.Type
.LONG
) {
109 value
= TmfStateValue
.newValueLong(longVal
);
110 } else if (type
== ITmfStateValue
.Type
.INTEGER
) {
111 value
= TmfStateValue
.newValueInt(longVal
.intValue());
112 } else if (type
== ITmfStateValue
.Type
.DOUBLE
) {
113 value
= TmfStateValue
.newValueDouble(longVal
.doubleValue());
115 value
= TmfStateValue
.nullValue();
117 ITmfTimestamp timestamp
= new TmfNanoTimestamp(time
);
118 ITmfEventType eventType
= new TmfEventType(MIPMAP_ID
, null);
119 ITmfEventField content
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, value
, null);
120 ITmfEvent event
= new TmfEvent(null, ITmfContext
.UNKNOWN_RANK
, timestamp
, eventType
, content
);