Commit | Line | Data |
---|---|---|
8e364f8e PT |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
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 | |
2bdf0193 AM |
16 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
17 | import org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap.AbstractTmfMipmapStateProvider; | |
e894a508 AM |
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; | |
2bdf0193 AM |
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; | |
0c7471fb | 31 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
8e364f8e PT |
32 | |
33 | /** | |
34 | * A mipmap state provider for test | |
35 | * | |
36 | * @author Jean-Christian Kouamé | |
37 | * @since 3.0 | |
38 | */ | |
39 | class TmfMipmapStateProviderStub extends AbstractTmfMipmapStateProvider { | |
40 | /** test attribute name */ | |
41 | public final static String TEST_ATTRIBUTE_NAME = "test_attribute"; //$NON-NLS-1$ | |
42 | ||
43 | private int resolution; | |
bcec0116 | 44 | private ITmfStateValue.Type type; |
8e364f8e PT |
45 | private final static String MIPMAP_ID = "MIPMAP_ID"; //$NON-NLS-1$ |
46 | ||
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$ | |
50 | ||
51 | /** | |
52 | * Constructor | |
53 | * | |
54 | * @param resolution | |
55 | * the mipmap resolution array (max, min, avg) | |
56 | * @param type | |
57 | * the type of value to use | |
58 | */ | |
bcec0116 | 59 | public TmfMipmapStateProviderStub(int resolution, ITmfStateValue.Type type) { |
8e364f8e PT |
60 | super(null, TmfEvent.class, MIPMAP_ID); |
61 | this.resolution = resolution; | |
62 | this.type = type; | |
63 | } | |
64 | ||
65 | @Override | |
66 | protected void eventHandle(ITmfEvent ev) { | |
67 | final long ts = ev.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); | |
68 | try { | |
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); | |
78 | } | |
79 | } | |
80 | ||
81 | @Override | |
82 | public int getVersion() { | |
83 | return 0; | |
84 | } | |
85 | ||
86 | @Override | |
87 | public TmfMipmapStateProviderStub getNewInstance() { | |
88 | return new TmfMipmapStateProviderStub(resolution, type); | |
89 | } | |
90 | ||
91 | /** | |
92 | * @param time | |
93 | * The event type | |
94 | * @param longVal | |
95 | * The event value or null | |
96 | * @return A new TmfEvent | |
97 | */ | |
98 | public ITmfEvent createEvent(long time, Long longVal) { | |
99 | ITmfStateValue value; | |
100 | if (longVal == null) { | |
101 | value = TmfStateValue.nullValue(); | |
bcec0116 | 102 | } else if (type == ITmfStateValue.Type.LONG) { |
8e364f8e | 103 | value = TmfStateValue.newValueLong(longVal); |
bcec0116 | 104 | } else if (type == ITmfStateValue.Type.INTEGER) { |
8e364f8e | 105 | value = TmfStateValue.newValueInt(longVal.intValue()); |
bcec0116 | 106 | } else if (type == ITmfStateValue.Type.DOUBLE) { |
8e364f8e PT |
107 | value = TmfStateValue.newValueDouble(longVal.doubleValue()); |
108 | } else { | |
109 | value = TmfStateValue.nullValue(); | |
110 | } | |
111 | ITmfTimestamp timestamp = new TmfNanoTimestamp(time); | |
e600c338 | 112 | ITmfEventType eventType = new TmfEventType(MIPMAP_ID, null); |
8e364f8e | 113 | ITmfEventField content = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, value, null); |
e1de2fd4 | 114 | ITmfEvent event = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, timestamp, eventType, content); |
8e364f8e PT |
115 | return event; |
116 | } | |
117 | } |