1 /*******************************************************************************
2 * Copyright (c) 2013, 2016 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
.StateValueTypeException
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
24 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
25 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
32 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
33 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
34 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
35 import org
.eclipse
.tracecompass
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
38 * A mipmap state provider for test
40 * @author Jean-Christian Kouamé
42 class TmfMipmapStateProviderStub
extends AbstractTmfMipmapStateProvider
{
43 /** test attribute name */
44 public final static String TEST_ATTRIBUTE_NAME
= "test_attribute"; //$NON-NLS-1$
46 private int resolution
;
47 private ITmfStateValue
.Type type
;
48 private static final @NonNull String MIPMAP_ID
= "MIPMAP_ID"; //$NON-NLS-1$
50 private final String ERROR_INVALID_STATE_VALUE
= "Error : Invalid state value"; //$NON-NLS-1$
51 private final String ERROR_INVALID_TIMESTAMP
= "Error : Invalid timestamp"; //$NON-NLS-1$
57 * the mipmap resolution array (max, min, avg)
59 * the type of value to use
61 public TmfMipmapStateProviderStub(int resolution
, ITmfStateValue
.Type type
) {
62 super(new TmfTraceStub(), MIPMAP_ID
);
63 this.resolution
= resolution
;
68 protected void eventHandle(ITmfEvent ev
) {
69 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
70 final long ts
= ev
.getTimestamp().toNanos();
72 int quark
= ss
.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME
);
73 ITmfStateValue value
= (ITmfStateValue
) ev
.getContent().getValue();
74 modifyMipmapAttribute(ts
, value
, quark
, MIN
| MAX
| AVG
, resolution
);
75 } catch (TimeRangeException e
) {
76 Activator
.logError(ERROR_INVALID_TIMESTAMP
, e
);
77 } catch (StateValueTypeException e
) {
78 Activator
.logError(ERROR_INVALID_STATE_VALUE
, e
);
83 public int getVersion() {
88 public TmfMipmapStateProviderStub
getNewInstance() {
89 return new TmfMipmapStateProviderStub(resolution
, type
);
96 * The event value or null
97 * @return A new TmfEvent
99 public @NonNull ITmfEvent
createEvent(long time
, Long longVal
) {
100 ITmfStateValue value
;
101 if (longVal
== null) {
102 value
= TmfStateValue
.nullValue();
103 } else if (type
== ITmfStateValue
.Type
.LONG
) {
104 value
= TmfStateValue
.newValueLong(longVal
);
105 } else if (type
== ITmfStateValue
.Type
.INTEGER
) {
106 value
= TmfStateValue
.newValueInt(longVal
.intValue());
107 } else if (type
== ITmfStateValue
.Type
.DOUBLE
) {
108 value
= TmfStateValue
.newValueDouble(longVal
.doubleValue());
110 value
= TmfStateValue
.nullValue();
112 ITmfTimestamp timestamp
= TmfTimestamp
.fromNanos(time
);
113 ITmfEventType eventType
= new TmfEventType(MIPMAP_ID
, null);
114 ITmfEventField content
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, value
, null);
115 ITmfEvent event
= new TmfEvent(null, ITmfContext
.UNKNOWN_RANK
, timestamp
, eventType
, content
);