Commit | Line | Data |
---|---|---|
8e364f8e | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2013, 2015 Ericsson |
8e364f8e PT |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Jean-Christian Kouamé - Initial API and implementation | |
11 | * Patrick Tasse - Updates to mipmap feature | |
12 | *******************************************************************************/ | |
13 | ||
2bdf0193 | 14 | package org.eclipse.tracecompass.tmf.core.tests.statesystem.mipmap; |
8e364f8e | 15 | |
d0c7e4ba AM |
16 | import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull; |
17 | ||
18 | import org.eclipse.jdt.annotation.NonNull; | |
2bdf0193 AM |
19 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
20 | import org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap.AbstractTmfMipmapStateProvider; | |
d0c7e4ba | 21 | import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder; |
e894a508 AM |
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; | |
2bdf0193 AM |
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; | |
0c7471fb | 35 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
d0c7e4ba | 36 | import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub; |
8e364f8e PT |
37 | |
38 | /** | |
39 | * A mipmap state provider for test | |
40 | * | |
41 | * @author Jean-Christian Kouamé | |
8e364f8e PT |
42 | */ |
43 | class TmfMipmapStateProviderStub extends AbstractTmfMipmapStateProvider { | |
44 | /** test attribute name */ | |
45 | public final static String TEST_ATTRIBUTE_NAME = "test_attribute"; //$NON-NLS-1$ | |
46 | ||
47 | private int resolution; | |
bcec0116 | 48 | private ITmfStateValue.Type type; |
d0c7e4ba | 49 | private static final @NonNull String MIPMAP_ID = "MIPMAP_ID"; //$NON-NLS-1$ |
8e364f8e PT |
50 | |
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$ | |
54 | ||
55 | /** | |
56 | * Constructor | |
57 | * | |
58 | * @param resolution | |
59 | * the mipmap resolution array (max, min, avg) | |
60 | * @param type | |
61 | * the type of value to use | |
62 | */ | |
bcec0116 | 63 | public TmfMipmapStateProviderStub(int resolution, ITmfStateValue.Type type) { |
e2bcc8a5 | 64 | super(new TmfTraceStub(), MIPMAP_ID); |
8e364f8e PT |
65 | this.resolution = resolution; |
66 | this.type = type; | |
67 | } | |
68 | ||
69 | @Override | |
70 | protected void eventHandle(ITmfEvent ev) { | |
d0c7e4ba | 71 | ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder()); |
8e364f8e PT |
72 | final long ts = ev.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
73 | try { | |
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); | |
83 | } | |
84 | } | |
85 | ||
86 | @Override | |
87 | public int getVersion() { | |
88 | return 0; | |
89 | } | |
90 | ||
91 | @Override | |
92 | public TmfMipmapStateProviderStub getNewInstance() { | |
93 | return new TmfMipmapStateProviderStub(resolution, type); | |
94 | } | |
95 | ||
96 | /** | |
97 | * @param time | |
98 | * The event type | |
99 | * @param longVal | |
100 | * The event value or null | |
101 | * @return A new TmfEvent | |
102 | */ | |
d0c7e4ba | 103 | public @NonNull ITmfEvent createEvent(long time, Long longVal) { |
8e364f8e PT |
104 | ITmfStateValue value; |
105 | if (longVal == null) { | |
106 | value = TmfStateValue.nullValue(); | |
bcec0116 | 107 | } else if (type == ITmfStateValue.Type.LONG) { |
8e364f8e | 108 | value = TmfStateValue.newValueLong(longVal); |
bcec0116 | 109 | } else if (type == ITmfStateValue.Type.INTEGER) { |
8e364f8e | 110 | value = TmfStateValue.newValueInt(longVal.intValue()); |
bcec0116 | 111 | } else if (type == ITmfStateValue.Type.DOUBLE) { |
8e364f8e PT |
112 | value = TmfStateValue.newValueDouble(longVal.doubleValue()); |
113 | } else { | |
114 | value = TmfStateValue.nullValue(); | |
115 | } | |
116 | ITmfTimestamp timestamp = new TmfNanoTimestamp(time); | |
e600c338 | 117 | ITmfEventType eventType = new TmfEventType(MIPMAP_ID, null); |
8e364f8e | 118 | ITmfEventField content = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, value, null); |
e1de2fd4 | 119 | ITmfEvent event = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, timestamp, eventType, content); |
8e364f8e PT |
120 | return event; |
121 | } | |
122 | } |