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