//Create a pattern segment and test its content
TmfXmlPatternSegment segment = builder.generatePatternSegment(PatternSegmentFactoryStub.TEST_2_END_EVENT,
PatternSegmentFactoryStub.TEST_2_START_EVENT.getTimestamp(),
- PatternSegmentFactoryStub.TEST_2_END_EVENT.getTimestamp());
+ PatternSegmentFactoryStub.TEST_2_END_EVENT.getTimestamp(),
+ null);
XmlUtilsTest.testPatternSegmentData(PatternSegmentFactoryStub.TEST_2, segment);
}
}
* builder mode.
*
* @param startQuark
- * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to search
- * the full attribute tree
+ * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
+ * search the full attribute tree
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return the quark described by attribute or
- * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be found
+ * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
+ * found
+ * @since 2.0
*/
- int getAttributeQuark(int startQuark);
+ int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
/**
* This method gets the quark for this state attribute in the State System.
* @param event
* The current event being handled
* @param startQuark
- * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to search
- * the full attribute tree
+ * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
+ * search the full attribute tree
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return the quark described by attribute or
- * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be found
+ * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
+ * found
+ * @since 2.0
*/
- int getAttributeQuark(@Nullable ITmfEvent event, int startQuark);
+ int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo);
}
* @param event
* The current event or <code>null</code> if no event is
* available.
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return the {@link ITmfStateValue}
* @throws AttributeNotFoundException
* May be thrown by the state system during the query
+ * @since 2.0
*/
- ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException;
+ ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
/**
* Get the value of the event field that is the path of this state value
*
* @param event
* The event to process
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @throws AttributeNotFoundException
* Pass through the exception it received
* @throws TimeRangeException
* Pass through the exception it received
* @throws StateValueTypeException
* Pass through the exception it received
+ * @since 2.0
*/
- void handleEvent(ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
+ void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
}
*
* @param event
* The event on which to test the condition
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return Whether the condition is true or not
* @throws AttributeNotFoundException
* The state attribute was not found
- * @since 1.0
+ * @since 2.0
*/
- public boolean testForEvent(ITmfEvent event) throws AttributeNotFoundException {
+ public boolean testForEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
ITmfStateSystem ss = fContainer.getStateSystem();
if (!fStateValues.isEmpty()) {
- return testForEvent(event, NonNullUtils.checkNotNull(ss));
+ return testForEvent(event, NonNullUtils.checkNotNull(ss), scenarioInfo);
} else if (!fConditions.isEmpty()) {
/* Verify a condition tree */
switch (fOperator) {
case AND:
for (TmfXmlCondition childCondition : fConditions) {
- if (!childCondition.testForEvent(event)) {
+ if (!childCondition.testForEvent(event, scenarioInfo)) {
return false;
}
}
case NONE:
break;
case NOT:
- return !fConditions.get(0).testForEvent(event);
+ return !fConditions.get(0).testForEvent(event, scenarioInfo);
case OR:
for (TmfXmlCondition childCondition : fConditions) {
- if (childCondition.testForEvent(event)) {
+ if (childCondition.testForEvent(event, scenarioInfo)) {
return true;
}
}
return true;
}
- private boolean testForEvent(ITmfEvent event, ITmfStateSystem ss) throws AttributeNotFoundException {
+ private boolean testForEvent(ITmfEvent event, ITmfStateSystem ss, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
/*
* The condition is either the equality check of a state value or a
* boolean operation on other conditions
ITmfXmlStateValue filter = fStateValues.get(0);
int quark = IXmlStateSystemContainer.ROOT_QUARK;
for (ITmfXmlStateAttribute attribute : filter.getAttributes()) {
- quark = attribute.getAttributeQuark(event, quark);
+ quark = attribute.getAttributeQuark(event, quark, scenarioInfo);
/*
* When verifying a condition, the state attribute must exist,
* if it does not, the query is not valid, we stop the condition
/* Get the value to compare to from the XML file */
ITmfStateValue valueXML;
- valueXML = filter.getValue(event);
+ valueXML = filter.getValue(event, scenarioInfo);
return compare(valueState, valueXML, fConditionOperator);
}
/* Get the two values needed for the comparison */
- ITmfStateValue valuesXML1 = fStateValues.get(0).getValue(event);
- ITmfStateValue valuesXML2 = fStateValues.get(1).getValue(event);
+ ITmfStateValue valuesXML1 = fStateValues.get(0).getValue(event, scenarioInfo);
+ ITmfStateValue valuesXML2 = fStateValues.get(1).getValue(event, scenarioInfo);
return valuesXML1.equals(valuesXML2);
}
/* Process all state changes */
for (TmfXmlStateChange stateChange : fStateChangeList) {
try {
- stateChange.handleEvent(event);
+ stateChange.handleEvent(event, null);
} catch (AttributeNotFoundException ae) {
/*
* This would indicate a problem with the logic of the manager
*
* @param event
* The event being handled
+ *
* @param startQuark
* The starting quark for relative search, use
* {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
* the attribute tree
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return The quark at the leaf of the path
+ * @since 2.0
*/
- public int getLocationQuark(@Nullable ITmfEvent event, int startQuark) {
+ public int getLocationQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
int quark = startQuark;
for (ITmfXmlStateAttribute attrib : fPath) {
- quark = attrib.getAttributeQuark(event, quark);
+ quark = attrib.getAttributeQuark(event, quark, scenarioInfo);
if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
break;
}
* The starting quark for relative search, use
* {@link IXmlStateSystemContainer#ROOT_QUARK} for the root of
* the attribute tree
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return The quark at the leaf of the path
+ * @since 2.0
*/
- public int getLocationQuark(int startQuark) {
+ public int getLocationQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
int quark = startQuark;
for (ITmfXmlStateAttribute attrib : fPath) {
- quark = attrib.getAttributeQuark(quark);
+ quark = attrib.getAttributeQuark(quark, scenarioInfo);
if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
break;
}
* Start time of the pattern segment to generate
* @param end
* End time of the pattern segment to generate
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return The pattern segment generated
*/
- public TmfXmlPatternSegment generatePatternSegment(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end) {
+ public TmfXmlPatternSegment generatePatternSegment(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, @Nullable TmfXmlScenarioInfo scenarioInfo) {
int scale = event.getTimestamp().getScale();
long startValue = start.toNanos();
long endValue = end.toNanos();
- String segmentName = getPatternSegmentName(event);
+ String segmentName = getPatternSegmentName(event, scenarioInfo);
Map<String, ITmfStateValue> fields = new HashMap<>();
- setPatternSegmentContent(event, start, end, fields);
+ setPatternSegmentContent(event, start, end, fields, scenarioInfo);
TmfXmlPatternSegment segment = new TmfXmlPatternSegment(startValue, endValue, scale, segmentName, fields);
if (fContainer instanceof XmlPatternStateProvider) {
((XmlPatternStateProvider) fContainer).getListener().onNewSegment(segment);
*
* @param event
* The active event
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
* @return The name of the segment
*/
- private String getPatternSegmentName(ITmfEvent event) {
- return fSegmentType.getName(event);
+ private String getPatternSegmentName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+ return fSegmentType.getName(event, scenarioInfo);
}
/**
* The end timestamp of this segment
* @param fields
* The map that will contained all the fields
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there is
+ * no scenario.
*/
- private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map<String, ITmfStateValue> fields) {
+ private void setPatternSegmentContent(ITmfEvent event, ITmfTimestamp start, ITmfTimestamp end, Map<String, ITmfStateValue> fields, @Nullable TmfXmlScenarioInfo scenarioInfo) {
for (TmfXmlPatternSegmentField field : fFields) {
- fields.put(field.getName(), field.getValue(event));
+ fields.put(field.getName(), field.getValue(event, scenarioInfo));
}
}
}
}
- private static void getNameFromXmlStateValue(ITmfEvent event, StringBuilder builder, ITmfXmlStateValue xmlStateValue) {
+ private static void getNameFromXmlStateValue(ITmfEvent event, StringBuilder builder, ITmfXmlStateValue xmlStateValue, @Nullable TmfXmlScenarioInfo scenarioInfo) {
try {
- ITmfStateValue value = xmlStateValue.getValue(event);
+ ITmfStateValue value = xmlStateValue.getValue(event, scenarioInfo);
switch (value.getType()) {
case DOUBLE:
builder.append(value.unboxDouble());
* The active event
* @return The state value representing the value of the XML pattern
* segment field
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there
+ * is no scenario.
*/
- public ITmfStateValue getValue(ITmfEvent event) {
+ public ITmfStateValue getValue(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
if (fStateValue != null) {
return fStateValue;
}
try {
- return checkNotNull(fXmlStateValue).getValue(event);
+ return checkNotNull(fXmlStateValue).getValue(event, scenarioInfo);
} catch (AttributeNotFoundException e) {
Activator.logError("Failed to get the state value", e); //$NON-NLS-1$
}
*
* @param event
* The active event
+ * @param scenarioInfo
+ * The active scenario details. Or <code>null</code> if there
+ * is no scenario.
* @return The segment name
*/
- public String getName(ITmfEvent event) {
+ public String getName(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
StringBuilder name = new StringBuilder(PATTERN_SEGMENT_NAME_PREFIX);
if (fNameStateValue != null) {
- getNameFromXmlStateValue(event, name, fNameStateValue);
+ getNameFromXmlStateValue(event, name, fNameStateValue, scenarioInfo);
} else {
name.append(fSegmentNameAttribute);
}
--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2016 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ ******************************************************************************/
+package org.eclipse.tracecompass.tmf.analysis.xml.core.model;
+
+/**
+ * This class gives basic details about a scenario (quark, scenarioName, ...)
+ *
+ * @author Jean-Christian Kouame
+ * @since 2.0
+ */
+public class TmfXmlScenarioInfo {
+ private final String fScenarioName;
+ private final int fQuark;
+ private String fActiveState;
+
+ /**
+ * Constructor
+ *
+ * @param scenarioName
+ * The scenario name
+ * @param activeState
+ * The active state
+ * @param quark
+ * The scenario quark
+ */
+ public TmfXmlScenarioInfo(String scenarioName, String activeState, int quark) {
+ fScenarioName = scenarioName;
+ fActiveState = activeState;
+ fQuark = quark;
+ }
+
+ /**
+ * Set the active state
+ *
+ * @param activeState
+ * The active state
+ */
+ public void setActiveState(String activeState) {
+ fActiveState = activeState;
+ }
+
+ /**
+ * Get the scenario quark
+ *
+ * @return The quark
+ */
+ public int getQuark() {
+ return fQuark;
+ }
+
+ /**
+ * Get the scenario name
+ *
+ * @return The name
+ */
+ public String getScenarioName() {
+ return fScenarioName;
+ }
+
+ /**
+ * Get the scenario active state
+ *
+ * @return The active state
+ */
+ public String getActiveState() {
+ return fActiveState;
+ }
+}
import java.util.List;
import org.eclipse.jdt.annotation.Nullable;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyString;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
+
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystemBuilder;
EVENTNAME
}
+ private final String SCENARIO_NAME = "#scenarioName"; //$NON-NLS-1$
+
+ private final String CURRENT_STATE = "#currentState"; //$NON-NLS-1$
+
/** Type of attribute */
private final StateAttributeType fType;
}
/**
- * This method gets the quark for this state attribute in the State System.
- *
- * Unless this attribute is a location, in which case the quark must exist,
- * the quark will be added to the state system if the state system is in
- * builder mode.
- *
- * @param startQuark
- * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
- * search the full attribute tree
- * @return the quark described by attribute or
- * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
- * found
+ * @since 2.0
*/
@Override
- public int getAttributeQuark(int startQuark) {
- return getAttributeQuark(null, startQuark);
+ public int getAttributeQuark(int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
+ return getAttributeQuark(null, startQuark, scenarioInfo);
}
/**
}
/**
- * This method gets the quark for this state attribute in the State System.
- *
- * Unless this attribute is a location, in which case the quark must exist,
- * the quark will be added to the state system if the state system is in
- * builder mode.
- *
- * @param event
- * The current event being handled, or <code>null</code> if no
- * event available in the context
- * @param startQuark
- * root quark, use {@link IXmlStateSystemContainer#ROOT_QUARK} to
- * search the full attribute tree
- * @return the quark described by attribute or
- * {@link IXmlStateSystemContainer#ERROR_QUARK} if quark cannot be
- * found
+ * @since 2.0
*/
@Override
- public int getAttributeQuark(@Nullable ITmfEvent event, int startQuark) {
+ public int getAttributeQuark(@Nullable ITmfEvent event, int startQuark, @Nullable TmfXmlScenarioInfo scenarioInfo) {
ITmfStateSystem ss = getStateSystem();
if (ss == null) {
throw new IllegalStateException("The state system hasn't been initialized yet"); //$NON-NLS-1$
}
+ String name = nullToEmptyString(fName);
+ if (name.length() > 0 && name.charAt(0) == '#' && scenarioInfo == null) {
+ throw new IllegalStateException("XML Attribute needs " + fName + " but the data is not available."); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ name = name.equals(SCENARIO_NAME) ? checkNotNull(scenarioInfo).getScenarioName() : name.equals(CURRENT_STATE) ? checkNotNull(scenarioInfo).getActiveState() : fName;
try {
switch (fType) {
case CONSTANT: {
int quark;
+ if (name == null) {
+ throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
+ }
if (startQuark == IXmlStateSystemContainer.ROOT_QUARK) {
- quark = getQuarkAbsoluteAndAdd(fName);
+ quark = getQuarkAbsoluteAndAdd(name);
} else {
- quark = getQuarkRelativeAndAdd(startQuark, fName);
+ quark = getQuarkRelativeAndAdd(startQuark, name);
}
return quark;
}
Activator.logWarning("XML State attribute: looking for an event field, but event is null"); //$NON-NLS-1$
return quark;
}
- /* special case if field is CPU which is not in the field */
- String name = fName;
if (name == null) {
- throw new IllegalStateException();
+ throw new IllegalStateException("Invalid attribute name"); //$NON-NLS-1$
}
if (name.equals(TmfXmlStrings.CPU)) {
/* See if the event advertises a CPU aspect */
} else {
final ITmfEventField content = event.getContent();
/* stop if the event field doesn't exist */
- if (content.getField(fName) == null) {
+ if (content.getField(name) == null) {
return IXmlStateSystemContainer.ERROR_QUARK;
}
- Object field = content.getField(fName).getValue();
+ Object field = content.getField(name).getValue();
if (field instanceof String) {
String fieldString = (String) field;
int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
for (ITmfXmlStateAttribute attrib : fQueryList) {
- quarkQuery = attrib.getAttributeQuark(event, quarkQuery);
+ quarkQuery = attrib.getAttributeQuark(event, quarkQuery, scenarioInfo);
if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
break;
}
}
case LOCATION: {
int quark = startQuark;
- String idLocation = fName;
+ String idLocation = name;
/* TODO: Add a fContainer.getLocation(id) method */
for (TmfXmlLocation location : fContainer.getLocations()) {
if (location.getId().equals(idLocation)) {
- quark = location.getLocationQuark(event, quark);
+ quark = location.getLocationQuark(event, quark, scenarioInfo);
if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
break;
}
*
* @param event
* The event to process
+ * @param scenarioInfo
+ * The active scenario details. The value should be null if there
+ * no scenario.
* @throws AttributeNotFoundException
* Pass through the exception it received
* @throws TimeRangeException
* Pass through the exception it received
* @throws StateValueTypeException
* Pass through the exception it received
+ * @since 2.0
*/
- public void handleEvent(ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
- fChange.handleEvent(event);
+ public void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+ fChange.handleEvent(event, scenarioInfo);
}
@Override
/* Interface for both private classes to handle the event */
private interface IXmlStateChange {
- void handleEvent(ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
+ void handleEvent(ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException;
}
/**
}
@Override
- public void handleEvent(@NonNull ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+ public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
TmfXmlStateChange toExecute = fThenChange;
try {
- if (!fCondition.testForEvent(event)) {
+ if (!fCondition.testForEvent(event, scenarioInfo)) {
toExecute = fElseChange;
}
} catch (AttributeNotFoundException e) {
if (toExecute == null) {
return;
}
- toExecute.handleEvent(event);
+ toExecute.handleEvent(event, scenarioInfo);
}
@Override
}
@Override
- public void handleEvent(@NonNull ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
- fValue.handleEvent(event);
+ public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+ fValue.handleEvent(event, scenarioInfo);
}
@Override
}
/**
- * Get the current {@link ITmfStateValue} of this state value for an event.
- * It does not increment the value and does not any other processing of the
- * value.
- *
- * @param event
- * The current event, or <code>null</code> if no event available.
- * @return the {@link ITmfStateValue}
- * @throws AttributeNotFoundException
- * May be thrown by the state system during the query
+ * @since 2.0
*/
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
- return fStateValue.getValue(event);
+ public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
+ return fStateValue.getValue(event, scenarioInfo);
}
/**
}
/**
- * Handles an event, by setting the value of the attribute described by the
- * state attribute path in the state system.
- *
- * @param event
- * The event to process
- * @throws AttributeNotFoundException
- * Pass through the exception it received
- * @throws TimeRangeException
- * Pass through the exception it received
- * @throws StateValueTypeException
- * Pass through the exception it received
+ * @since 2.0
*/
@Override
- public void handleEvent(@NonNull ITmfEvent event) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
+ public void handleEvent(@NonNull ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException, StateValueTypeException, TimeRangeException {
int quark = IXmlStateSystemContainer.ROOT_QUARK;
for (ITmfXmlStateAttribute attribute : fPath) {
- quark = attribute.getAttributeQuark(event, quark);
+ quark = attribute.getAttributeQuark(event, quark, scenarioInfo);
/* the query is not valid, we stop the state change */
if (quark == IXmlStateSystemContainer.ERROR_QUARK) {
throw new AttributeNotFoundException("Not found XML attribute " + attribute); //$NON-NLS-1$
}
long ts = event.getTimestamp().getValue();
- fStateValue.handleEvent(event, quark, ts);
+ fStateValue.handleEvent(event, quark, ts, scenarioInfo);
}
@Override
* The event which can be used to retrieve the value if
* necessary. The event can be <code>null</code> if no event
* is required.
+ * @param scenarioInfo
+ * The active scenario details. The value should be null if
+ * there no scenario.
* @return The state value corresponding to this XML state value
* @throws AttributeNotFoundException
* Pass through the exception it received
+ * @since 2.0
*/
- public abstract ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException;
+ public abstract ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException;
/**
* Do something with the state value, possibly using an event
* The quark for this value
* @param timestamp
* The timestamp of the event
+ * @param scenarioInfo
+ * The active scenario details. The value should be null if
+ * there no scenario.
* @throws StateValueTypeException
* Pass through the exception it received
* @throws TimeRangeException
* Pass through the exception it received
* @throws AttributeNotFoundException
* Pass through the exception it received
+ * @since 2.0
*/
- public void handleEvent(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ public void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
if (fIncrement) {
- incrementValue(event, quark, timestamp);
+ incrementValue(event, quark, timestamp, scenarioInfo);
} else {
- ITmfStateValue value = getValue(event);
+ ITmfStateValue value = getValue(event, scenarioInfo);
processValue(quark, timestamp, value);
}
}
* The quark for this value
* @param timestamp
* The timestamp of the event
+ * @param scenarioInfo
+ * The active scenario details. The value should be null if
+ * there no scenario.
* @throws StateValueTypeException
* Pass through the exception it received
* @throws TimeRangeException
* Pass through the exception it received
* @throws AttributeNotFoundException
* Pass through the exception it received
+ * @since 2.0
*/
@SuppressWarnings("unused")
- protected void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
}
}
private class TmfXmlStateValueNull extends TmfXmlStateValueBase {
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
return TmfStateValue.nullValue();
}
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.internal.tmf.analysis.xml.core.Activator;
import org.eclipse.tracecompass.statesystem.core.ITmfStateSystem;
import org.eclipse.tracecompass.statesystem.core.statevalue.TmfStateValue;
import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlModelFactory;
import org.eclipse.tracecompass.tmf.analysis.xml.core.model.ITmfXmlStateAttribute;
+import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlScenarioInfo;
import org.eclipse.tracecompass.tmf.analysis.xml.core.model.TmfXmlStateValue;
import org.eclipse.tracecompass.tmf.analysis.xml.core.module.IXmlStateSystemContainer;
import org.eclipse.tracecompass.tmf.analysis.xml.core.module.XmlUtils;
protected abstract class TmfXmlStateValueTypeReadWrite extends TmfXmlStateValueBase {
@Override
- public final void handleEvent(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ public final void handleEvent(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
if (isIncrement()) {
- incrementValue(event, quark, timestamp);
+ incrementValue(event, quark, timestamp, scenarioInfo);
} else {
- ITmfStateValue value = getValue(event);
+ ITmfStateValue value = getValue(event, scenarioInfo);
processValue(quark, timestamp, value);
}
}
}
@Override
- protected void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ protected void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystemBuilder ss = getStateSystem();
if (ss == null) {
throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
}
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
return fValue;
}
@Override
- public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getStateSystem();
if (ss == null) {
throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
}
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) {
if (event == null) {
Activator.logWarning("XML State value: requested an event field, but event is null"); //$NON-NLS-1$
return TmfStateValue.nullValue();
}
@Override
- public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getSsContainer().getStateSystem();
if (ss == null) {
throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
}
- ITmfStateValue incrementValue = getValue(event);
+ ITmfStateValue incrementValue = getValue(event, scenarioInfo);
ITmfStateValue value = incrementByType(quark, ss, incrementValue);
if (value != null) {
processValue(quark, timestamp, value);
private class TmfXmlStateValueEventName extends TmfXmlStateValueTypeReadWrite {
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) {
+ public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
if (event == null) {
Activator.logWarning("XML State value: request event name, but event is null"); //$NON-NLS-1$
return TmfStateValue.nullValue();
public String toString() {
return "Event name"; //$NON-NLS-1$
}
-
}
/* The state value deletes an attribute */
private class TmfXmlStateValueDelete extends TmfXmlStateValueTypeReadWrite {
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
+ public @NonNull ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
return TmfStateValue.nullValue();
}
}
@Override
- public ITmfStateValue getValue(@Nullable ITmfEvent event) throws AttributeNotFoundException {
+ public ITmfStateValue getValue(@Nullable ITmfEvent event, @Nullable TmfXmlScenarioInfo scenarioInfo) throws AttributeNotFoundException {
/* Query the state system for the value */
ITmfStateValue value = TmfStateValue.nullValue();
int quarkQuery = IXmlStateSystemContainer.ROOT_QUARK;
}
for (ITmfXmlStateAttribute attribute : fQueryValue) {
- quarkQuery = attribute.getAttributeQuark(event, quarkQuery);
+ quarkQuery = attribute.getAttributeQuark(event, quarkQuery, scenarioInfo);
if (quarkQuery == IXmlStateSystemContainer.ERROR_QUARK) {
/* the query is not valid, we stop the state change */
break;
}
@Override
- public void incrementValue(ITmfEvent event, int quark, long timestamp) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
+ public void incrementValue(ITmfEvent event, int quark, long timestamp, @Nullable TmfXmlScenarioInfo scenarioInfo) throws StateValueTypeException, TimeRangeException, AttributeNotFoundException {
ITmfStateSystem ss = getStateSystem();
if (ss == null) {
throw new IllegalStateException(ILLEGAL_STATE_EXCEPTION_MESSAGE);
}
- ITmfStateValue incrementValue = getValue(event);
+ ITmfStateValue incrementValue = getValue(event, scenarioInfo);
ITmfStateValue value = incrementByType(quark, ss, incrementValue);
if (value != null) {
processValue(quark, timestamp, value);
if (seriesNameAttrib == null) {
seriesName = ss.getAttributeName(quark);
} else {
- int seriesNameQuark = seriesNameAttrib.getAttributeQuark(quark);
+ int seriesNameQuark = seriesNameAttrib.getAttributeQuark(quark, null);
try {
ITmfStateValue seriesNameValue = ss.querySingleState(start, seriesNameQuark).getStateValue();
if (!seriesNameValue.isNull()) {
seriesName = ss.getAttributeName(quark);
}
}
- fSeriesData.put(quark, new SeriesData(xvalues.length, display.getAttributeQuark(quark), seriesName, entry.getType()));
+ fSeriesData.put(quark, new SeriesData(xvalues.length, display.getAttributeQuark(quark, null), seriesName, entry.getType()));
}
for (int i = 0; i < xvalues.length; i++) {
if (monitor != null && monitor.isCanceled()) {
ITmfXmlModelFactory factory = TmfXmlReadOnlyModelFactory.getInstance();
ITmfXmlStateAttribute display = factory.createStateAttribute(stateAttribute, this);
- int quark = display.getAttributeQuark(fBaseQuark);
+ int quark = display.getAttributeQuark(fBaseQuark, null);
if (quark != IXmlStateSystemContainer.ERROR_QUARK) {
ITmfStateInterval firstInterval = StateSystemUtils.queryUntilNonNullValue(fSs, quark, getStartTime(), getEndTime());
if (firstInterval != null) {
* attribute
*/
ITmfXmlStateAttribute display = fFactory.createStateAttribute(displayEl, parentEntry);
- int displayQuark = display.getAttributeQuark(quark);
+ int displayQuark = display.getAttributeQuark(quark, null);
if (displayQuark == IXmlStateSystemContainer.ERROR_QUARK) {
return new XmlEntry(quark, parentEntry.getTrace(),
String.format("Unknown display quark for %s", ss.getAttributeName(quark)), ss); //$NON-NLS-1$