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