TMF: Add utility method to return the result of an aspect for an event
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.core.tests / src / org / eclipse / tracecompass / tmf / core / tests / statesystem / mipmap / TmfMipmapStateProviderStub.java
CommitLineData
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 14package org.eclipse.tracecompass.tmf.core.tests.statesystem.mipmap;
8e364f8e 15
d0c7e4ba
AM
16import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
17
18import org.eclipse.jdt.annotation.NonNull;
2bdf0193
AM
19import org.eclipse.tracecompass.internal.tmf.core.Activator;
20import org.eclipse.tracecompass.internal.tmf.core.statesystem.mipmap.AbstractTmfMipmapStateProvider;
d0c7e4ba 21import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
e894a508
AM
22import org.eclipse.tracecompass.statesystem.core.exceptions.AttributeNotFoundException;
23import org.eclipse.tracecompass.statesystem.core.exceptions.StateValueTypeException;
24import org.eclipse.tracecompass.statesystem.core.exceptions.TimeRangeException;
25import org.eclipse.tracecompass.statesystem.core.statevalue.ITmfStateValue;
26import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
2bdf0193
AM
27import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
28import org.eclipse.tracecompass.tmf.core.event.ITmfEventField;
29import org.eclipse.tracecompass.tmf.core.event.ITmfEventType;
30import org.eclipse.tracecompass.tmf.core.event.TmfEvent;
31import org.eclipse.tracecompass.tmf.core.event.TmfEventField;
32import org.eclipse.tracecompass.tmf.core.event.TmfEventType;
33import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp;
34import org.eclipse.tracecompass.tmf.core.timestamp.TmfNanoTimestamp;
0c7471fb 35import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
d0c7e4ba 36import 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é
42 * @since 3.0
43 */
44class TmfMipmapStateProviderStub extends AbstractTmfMipmapStateProvider {
45 /** test attribute name */
46 public final static String TEST_ATTRIBUTE_NAME = "test_attribute"; //$NON-NLS-1$
47
48 private int resolution;
bcec0116 49 private ITmfStateValue.Type type;
d0c7e4ba 50 private static final @NonNull String MIPMAP_ID = "MIPMAP_ID"; //$NON-NLS-1$
8e364f8e
PT
51
52 private final String ERROR_ATTRIBUTE_NOT_FOUND = "Error : Impossible to find the attribute"; //$NON-NLS-1$
53 private final String ERROR_INVALID_STATE_VALUE = "Error : Invalid state value"; //$NON-NLS-1$
54 private final String ERROR_INVALID_TIMESTAMP = "Error : Invalid timestamp"; //$NON-NLS-1$
55
56 /**
57 * Constructor
58 *
59 * @param resolution
60 * the mipmap resolution array (max, min, avg)
61 * @param type
62 * the type of value to use
63 */
bcec0116 64 public TmfMipmapStateProviderStub(int resolution, ITmfStateValue.Type type) {
d0c7e4ba 65 super(new TmfTraceStub(), TmfEvent.class, MIPMAP_ID);
8e364f8e
PT
66 this.resolution = resolution;
67 this.type = type;
68 }
69
70 @Override
71 protected void eventHandle(ITmfEvent ev) {
d0c7e4ba 72 ITmfStateSystemBuilder ss = checkNotNull(getStateSystemBuilder());
8e364f8e
PT
73 final long ts = ev.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue();
74 try {
75 int quark = ss.getQuarkAbsoluteAndAdd(TEST_ATTRIBUTE_NAME);
76 ITmfStateValue value = (ITmfStateValue) ev.getContent().getValue();
77 modifyMipmapAttribute(ts, value, quark, MIN | MAX | AVG, resolution);
78 } catch (TimeRangeException e) {
79 Activator.logError(ERROR_INVALID_TIMESTAMP, e);
80 } catch (AttributeNotFoundException e) {
81 Activator.logError(ERROR_ATTRIBUTE_NOT_FOUND, e);
82 } catch (StateValueTypeException e) {
83 Activator.logError(ERROR_INVALID_STATE_VALUE, e);
84 }
85 }
86
87 @Override
88 public int getVersion() {
89 return 0;
90 }
91
92 @Override
93 public TmfMipmapStateProviderStub getNewInstance() {
94 return new TmfMipmapStateProviderStub(resolution, type);
95 }
96
97 /**
98 * @param time
99 * The event type
100 * @param longVal
101 * The event value or null
102 * @return A new TmfEvent
103 */
d0c7e4ba 104 public @NonNull ITmfEvent createEvent(long time, Long longVal) {
8e364f8e
PT
105 ITmfStateValue value;
106 if (longVal == null) {
107 value = TmfStateValue.nullValue();
bcec0116 108 } else if (type == ITmfStateValue.Type.LONG) {
8e364f8e 109 value = TmfStateValue.newValueLong(longVal);
bcec0116 110 } else if (type == ITmfStateValue.Type.INTEGER) {
8e364f8e 111 value = TmfStateValue.newValueInt(longVal.intValue());
bcec0116 112 } else if (type == ITmfStateValue.Type.DOUBLE) {
8e364f8e
PT
113 value = TmfStateValue.newValueDouble(longVal.doubleValue());
114 } else {
115 value = TmfStateValue.nullValue();
116 }
117 ITmfTimestamp timestamp = new TmfNanoTimestamp(time);
e600c338 118 ITmfEventType eventType = new TmfEventType(MIPMAP_ID, null);
8e364f8e 119 ITmfEventField content = new TmfEventField(ITmfEventField.ROOT_FIELD_ID, value, null);
e1de2fd4 120 ITmfEvent event = new TmfEvent(null, ITmfContext.UNKNOWN_RANK, timestamp, eventType, content);
8e364f8e
PT
121 return event;
122 }
123}
This page took 0.052324 seconds and 5 git commands to generate.