temporary re-factoring project
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / experiment / StateExperimentManager.java
1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.state.experiment;
13
14 import java.util.HashMap;
15 import java.util.Map;
16
17 import org.eclipse.linuxtools.lttng.state.IStateDataRequestListener;
18 import org.eclipse.linuxtools.lttng.state.StateManager;
19 import org.eclipse.linuxtools.tmf.component.TmfComponent;
20 import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
21 import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;
22 import org.eclipse.linuxtools.tmf.trace.TmfExperiment;
23 import org.eclipse.linuxtools.tmf.trace.TmfExperimentSelectedSignal;
24
25 /**
26 * @author alvaro
27 *
28 */
29 public class StateExperimentManager extends TmfComponent {
30
31 // ========================================================================
32 // Data
33 // =======================================================================
34
35 private final Map<String, StateManager> managersByID = new HashMap<String, StateManager>();
36 private TmfExperiment fExperiment = null; // one experiment supported
37
38 // ========================================================================
39 // Constructors
40 // =======================================================================
41
42 /**
43 * package level constructor, creation from factory
44 */
45 StateExperimentManager() {
46 super();
47 }
48
49 // ========================================================================
50 // Methods
51 // =======================================================================
52
53 /**
54 * Return the Map of unique id to Manager instance
55 *
56 * @return
57 */
58 public Map<String, StateManager> getManagersByID() {
59 return managersByID;
60 }
61
62 /**
63 * Read all available traces from the nearest checkpoint from start position
64 * to the end of a specified time range
65 *
66 * @param trange
67 * @param obs
68 * @param transactionID
69 * @param display
70 */
71 public void readExperimentTimeWindow(TmfTimeRange trange,
72 String transactionID, IStateDataRequestListener listener) {
73 if (fExperiment != null) {
74 String id = fExperiment.getExperimentId();
75 StateManager manager = managersByID.get(id);
76 if (manager != null) {
77 // TODO: A loop to request data for each trace needs to be used
78 // here when multiple traces are supported.
79 manager.executeDataRequest(trange, transactionID, listener);
80 }
81 }
82 }
83
84 public void readExperiment(String transactionID,
85 IStateDataRequestListener listener) {
86 // Need someone to listen to the updates as well as an fExperiment
87 // loaded.
88 if (listener != null && fExperiment != null) {
89 TmfTimeRange trange = fExperiment.getTimeRange();
90 String experimentId = fExperiment.getExperimentId();
91
92 // FIXME: there should be an id field available at the trace level
93 // to be fixed with the support of multiple files.
94 // We also need to iterate over the traces in the Experiment and
95 // execute a data Request on each of them
96 // This is also on hold till the request can be performed at a trace
97 // level.
98 // ITmfTrace[] fTraces = fExperiment.getTraces();
99 // for (int i=0; i < fTraces.length; i++) {
100 StateManager manager = StateManagerFactory.getManager(experimentId);
101 manager.executeDataRequest(trange, transactionID, listener);
102 // }
103 }
104 }
105
106 /*
107 * (non-Javadoc)
108 *
109 * @see
110 * org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEventListener#handleEvent
111 * (org.eclipse.linuxtools.tmf.eventlog.ITmfEventLogEvent)
112 */
113 @TmfSignalHandler
114 public void experimentSelected(TmfExperimentSelectedSignal signal) {
115 // TmfExperiment experiment = signal.getExperiment();
116 // ITmfTrace[] traces = experiment.getTraces();
117 // for (ITmfTrace trace : traces) {
118 //
119 // }
120 if (signal != null) {
121 fExperiment = signal.getExperiment();
122 traceSelected(fExperiment);
123 }
124 }
125
126 /**
127 * A new Experiment selected, notification received from the framework
128 * Notify the new log selection to the state handling managers
129 *
130 * @param experiment
131 */
132 private void traceSelected(TmfExperiment experiment) {
133 // TODO: Re-factor when multiple traces are supported
134 // traceId, as well as when the request can be specified at the trace
135 // level
136 // For the moment it does work for only one trace per experiment.
137 String experimentId = experiment.getExperimentId();
138 StateManager manager = StateManagerFactory.getManager(experimentId);
139 // TODO: clearAllData shall not be applied to all manager calls below
140 // since that would clean all data loaded within previous iterations in
141 // the future loop. i.e. It can be applied to first manager in the loop.
142 boolean clearAllData = true;
143 manager.setTraceSelection(experiment, clearAllData);
144 }
145
146 /**
147 * @return
148 */
149 public TmfTimeRange getExperimentTimeRange() {
150 TmfTimeRange timeRangeResult = null;
151 if (fExperiment != null) {
152 timeRangeResult = fExperiment.getTimeRange();
153 }
154 return timeRangeResult;
155 }
156
157 }
This page took 0.03365 seconds and 5 git commands to generate.