1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Jean-Christian Kouamé - Initial API and implementation
11 * Patrick Tasse - Updates to mipmap feature
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.tests
.statesystem
.mipmap
;
16 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.Activator
;
17 import org
.eclipse
.linuxtools
.internal
.tmf
.core
.statesystem
.mipmap
.AbstractTmfMipmapStateProvider
;
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
;
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
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.TmfNanoTimestamp
;
33 * A mipmap state provider for test
35 * @author Jean-Christian Kouamé
38 class TmfMipmapStateProviderStub
extends AbstractTmfMipmapStateProvider
{
39 /** test attribute name */
40 public final static String TEST_ATTRIBUTE_NAME
= "test_attribute"; //$NON-NLS-1$
42 private int resolution
;
43 private ITmfStateValue
.Type type
;
44 private final static String MIPMAP_ID
= "MIPMAP_ID"; //$NON-NLS-1$
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$
54 * the mipmap resolution array (max, min, avg)
56 * the type of value to use
58 public TmfMipmapStateProviderStub(int resolution
, ITmfStateValue
.Type type
) {
59 super(null, TmfEvent
.class, MIPMAP_ID
);
60 this.resolution
= resolution
;
65 protected void eventHandle(ITmfEvent ev
) {
66 final long ts
= ev
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
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
);
81 public int getVersion() {
86 public TmfMipmapStateProviderStub
getNewInstance() {
87 return new TmfMipmapStateProviderStub(resolution
, type
);
94 * The event value or null
95 * @return A new TmfEvent
97 public ITmfEvent
createEvent(long time
, Long longVal
) {
99 if (longVal
== null) {
100 value
= TmfStateValue
.nullValue();
101 } else if (type
== ITmfStateValue
.Type
.LONG
) {
102 value
= TmfStateValue
.newValueLong(longVal
);
103 } else if (type
== ITmfStateValue
.Type
.INTEGER
) {
104 value
= TmfStateValue
.newValueInt(longVal
.intValue());
105 } else if (type
== ITmfStateValue
.Type
.DOUBLE
) {
106 value
= TmfStateValue
.newValueDouble(longVal
.doubleValue());
108 value
= TmfStateValue
.nullValue();
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);