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