1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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
.TmfTimestamp
;
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é
43 class TmfMipmapStateProviderStub
extends AbstractTmfMipmapStateProvider
{
44 /** test attribute name */
45 public final static String TEST_ATTRIBUTE_NAME
= "test_attribute"; //$NON-NLS-1$
47 private int resolution
;
48 private ITmfStateValue
.Type type
;
49 private static final @NonNull String MIPMAP_ID
= "MIPMAP_ID"; //$NON-NLS-1$
51 private final String ERROR_ATTRIBUTE_NOT_FOUND
= "Error : Impossible to find the attribute"; //$NON-NLS-1$
52 private final String ERROR_INVALID_STATE_VALUE
= "Error : Invalid state value"; //$NON-NLS-1$
53 private final String ERROR_INVALID_TIMESTAMP
= "Error : Invalid timestamp"; //$NON-NLS-1$
59 * the mipmap resolution array (max, min, avg)
61 * the type of value to use
63 public TmfMipmapStateProviderStub(int resolution
, ITmfStateValue
.Type type
) {
64 super(new TmfTraceStub(), MIPMAP_ID
);
65 this.resolution
= resolution
;
70 protected void eventHandle(ITmfEvent ev
) {
71 ITmfStateSystemBuilder ss
= checkNotNull(getStateSystemBuilder());
72 final long ts
= ev
.getTimestamp().toNanos();
74 int quark
= ss
.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME
);
75 ITmfStateValue value
= (ITmfStateValue
) ev
.getContent().getValue();
76 modifyMipmapAttribute(ts
, value
, quark
, MIN
| MAX
| AVG
, resolution
);
77 } catch (TimeRangeException e
) {
78 Activator
.logError(ERROR_INVALID_TIMESTAMP
, e
);
79 } catch (AttributeNotFoundException e
) {
80 Activator
.logError(ERROR_ATTRIBUTE_NOT_FOUND
, e
);
81 } catch (StateValueTypeException e
) {
82 Activator
.logError(ERROR_INVALID_STATE_VALUE
, e
);
87 public int getVersion() {
92 public TmfMipmapStateProviderStub
getNewInstance() {
93 return new TmfMipmapStateProviderStub(resolution
, type
);
100 * The event value or null
101 * @return A new TmfEvent
103 public @NonNull ITmfEvent
createEvent(long time
, Long longVal
) {
104 ITmfStateValue value
;
105 if (longVal
== null) {
106 value
= TmfStateValue
.nullValue();
107 } else if (type
== ITmfStateValue
.Type
.LONG
) {
108 value
= TmfStateValue
.newValueLong(longVal
);
109 } else if (type
== ITmfStateValue
.Type
.INTEGER
) {
110 value
= TmfStateValue
.newValueInt(longVal
.intValue());
111 } else if (type
== ITmfStateValue
.Type
.DOUBLE
) {
112 value
= TmfStateValue
.newValueDouble(longVal
.doubleValue());
114 value
= TmfStateValue
.nullValue();
116 ITmfTimestamp timestamp
= TmfTimestamp
.fromNanos(time
);
117 ITmfEventType eventType
= new TmfEventType(MIPMAP_ID
, null);
118 ITmfEventField content
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, value
, null);
119 ITmfEvent event
= new TmfEvent(null, ITmfContext
.UNKNOWN_RANK
, timestamp
, eventType
, content
);