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 org
.eclipse
.tracecompass
.internal
.tmf
.core
.Activator
;
17 import org
.eclipse
.tracecompass
.internal
.tmf
.core
.statesystem
.mipmap
.AbstractTmfMipmapStateProvider
;
18 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
19 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.StateValueTypeException
;
20 import org
.eclipse
.tracecompass
.statesystem
.core
.exceptions
.TimeRangeException
;
21 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.ITmfStateValue
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.statevalue
.TmfStateValue
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventField
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEventType
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEvent
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventField
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.event
.TmfEventType
;
29 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
31 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
34 * A mipmap state provider for test
36 * @author Jean-Christian Kouamé
39 class TmfMipmapStateProviderStub
extends AbstractTmfMipmapStateProvider
{
40 /** test attribute name */
41 public final static String TEST_ATTRIBUTE_NAME
= "test_attribute"; //$NON-NLS-1$
43 private int resolution
;
44 private ITmfStateValue
.Type type
;
45 private final static String MIPMAP_ID
= "MIPMAP_ID"; //$NON-NLS-1$
47 private final String ERROR_ATTRIBUTE_NOT_FOUND
= "Error : Impossible to find the attribute"; //$NON-NLS-1$
48 private final String ERROR_INVALID_STATE_VALUE
= "Error : Invalid state value"; //$NON-NLS-1$
49 private final String ERROR_INVALID_TIMESTAMP
= "Error : Invalid timestamp"; //$NON-NLS-1$
55 * the mipmap resolution array (max, min, avg)
57 * the type of value to use
59 public TmfMipmapStateProviderStub(int resolution
, ITmfStateValue
.Type type
) {
60 super(null, TmfEvent
.class, MIPMAP_ID
);
61 this.resolution
= resolution
;
66 protected void eventHandle(ITmfEvent ev
) {
67 final long ts
= ev
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
69 int quark
= ss
.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME
);
70 ITmfStateValue value
= (ITmfStateValue
) ev
.getContent().getValue();
71 modifyMipmapAttribute(ts
, value
, quark
, MIN
| MAX
| AVG
, resolution
);
72 } catch (TimeRangeException e
) {
73 Activator
.logError(ERROR_INVALID_TIMESTAMP
, e
);
74 } catch (AttributeNotFoundException e
) {
75 Activator
.logError(ERROR_ATTRIBUTE_NOT_FOUND
, e
);
76 } catch (StateValueTypeException e
) {
77 Activator
.logError(ERROR_INVALID_STATE_VALUE
, e
);
82 public int getVersion() {
87 public TmfMipmapStateProviderStub
getNewInstance() {
88 return new TmfMipmapStateProviderStub(resolution
, type
);
95 * The event value or null
96 * @return A new TmfEvent
98 public ITmfEvent
createEvent(long time
, Long longVal
) {
100 if (longVal
== null) {
101 value
= TmfStateValue
.nullValue();
102 } else if (type
== ITmfStateValue
.Type
.LONG
) {
103 value
= TmfStateValue
.newValueLong(longVal
);
104 } else if (type
== ITmfStateValue
.Type
.INTEGER
) {
105 value
= TmfStateValue
.newValueInt(longVal
.intValue());
106 } else if (type
== ITmfStateValue
.Type
.DOUBLE
) {
107 value
= TmfStateValue
.newValueDouble(longVal
.doubleValue());
109 value
= TmfStateValue
.nullValue();
111 ITmfTimestamp timestamp
= new TmfNanoTimestamp(time
);
112 ITmfEventType eventType
= new TmfEventType(MIPMAP_ID
, null);
113 ITmfEventField content
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, value
, null);
114 ITmfEvent event
= new TmfEvent(null, ITmfContext
.UNKNOWN_RANK
, timestamp
, eventType
, content
);