Commit | Line | Data |
---|---|---|
c068a752 | 1 | /******************************************************************************* |
60ae41e1 | 2 | * Copyright (c) 2013, 2014 École Polytechnique de Montréal |
c068a752 GB |
3 | * |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made 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 | * Geneviève Bastien - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.tests.stubs.analysis; |
c068a752 GB |
14 | |
15 | import org.eclipse.core.runtime.IProgressMonitor; | |
ba27dd38 | 16 | import org.eclipse.jdt.annotation.NonNull; |
2bdf0193 AM |
17 | import org.eclipse.tracecompass.tmf.core.analysis.TmfAbstractAnalysisModule; |
18 | import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace; | |
c068a752 GB |
19 | |
20 | /** | |
21 | * Simple analysis type for test | |
22 | */ | |
23 | public class TestAnalysis extends TmfAbstractAnalysisModule { | |
24 | ||
c068a752 GB |
25 | /** |
26 | * Test parameter. If set, simulate cancellation | |
27 | */ | |
ba27dd38 GB |
28 | public static final @NonNull String PARAM_TEST = "test"; |
29 | ||
30 | private int fOutput = 0; | |
c068a752 GB |
31 | |
32 | /** | |
33 | * Constructor | |
34 | */ | |
35 | public TestAnalysis() { | |
36 | super(); | |
37 | } | |
38 | ||
39 | @Override | |
40 | public boolean canExecute(ITmfTrace trace) { | |
41 | return true; | |
42 | } | |
43 | ||
44 | @Override | |
45 | protected boolean executeAnalysis(final IProgressMonitor monitor) { | |
46 | if (getParameter(PARAM_TEST) == null) { | |
47 | throw new RuntimeException("The parameter should be set"); | |
48 | } | |
49 | /* If PARAM_TEST is set to 0, simulate cancellation */ | |
50 | if ((Integer) getParameter(PARAM_TEST) == 0) { | |
ba27dd38 | 51 | fOutput = 0; |
c068a752 GB |
52 | return false; |
53 | } else if ((Integer) getParameter(PARAM_TEST) == 999) { | |
54 | /* just stay in an infinite loop until cancellation */ | |
55 | while (!monitor.isCanceled()) { | |
56 | ||
57 | } | |
58 | return !monitor.isCanceled(); | |
59 | } | |
ba27dd38 GB |
60 | Object obj = getParameter(PARAM_TEST); |
61 | if (obj == null) { | |
62 | throw new IllegalStateException(); | |
63 | } | |
64 | fOutput = (Integer) obj; | |
c068a752 GB |
65 | return true; |
66 | } | |
67 | ||
68 | @Override | |
69 | protected void canceling() { | |
ba27dd38 | 70 | fOutput = -1; |
c068a752 GB |
71 | } |
72 | ||
73 | @Override | |
74 | public Object getParameter(String name) { | |
75 | Object value = super.getParameter(name); | |
76 | if ((value != null) && name.equals(PARAM_TEST) && (value instanceof String)) { | |
0126a8ca | 77 | return Integer.decode((String) value); |
c068a752 GB |
78 | } |
79 | return value; | |
80 | } | |
81 | ||
82 | @Override | |
83 | protected void parameterChanged(String name) { | |
84 | schedule(); | |
85 | } | |
86 | ||
87 | /** | |
88 | * Get the analysis output value | |
89 | * | |
90 | * @return The analysis output | |
91 | */ | |
92 | public int getAnalysisOutput() { | |
ba27dd38 | 93 | return fOutput; |
c068a752 GB |
94 | } |
95 | ||
96 | } |