Merge branch 'FixJUnits'
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / tracecontrol / model / TraceResource.java
CommitLineData
e8d771d5
BH
1/*******************************************************************************
2 * Copyright (c) 2011 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 * Polytechnique Montréal - Initial API and implementation
11 * Bernd Hufmann - Productification, enhancements and fixes
12 *
13 *******************************************************************************/
14package org.eclipse.linuxtools.lttng.tracecontrol.model;
15
16import java.util.HashMap;
17import java.util.Map;
18
19import org.eclipse.linuxtools.lttng.tracecontrol.Messages;
20import org.eclipse.linuxtools.lttng.tracecontrol.model.config.TraceConfig;
21//import org.eclipse.linuxtools.lttng.ui.tracecontrol.Messages;
22import org.eclipse.linuxtools.lttng.tracecontrol.model.TargetResource;
23import org.eclipse.linuxtools.lttng.tracecontrol.model.TraceResource;
24import org.eclipse.rse.core.subsystems.AbstractResource;
25import org.eclipse.rse.core.subsystems.ISubSystem;
26
27/**
28 * <b><u>ProviderResource</u></b>
29 * <p>
30 * This models a remote resource representing a trace defined on a particular system.
31 * </p>
32 */
33public class TraceResource extends AbstractResource implements Comparable<TraceResource> {
34
35
36 public static enum TraceState { CREATED, CONFIGURED, STARTED, PAUSED, STOPPED };
37
38 public static final String Ltt_Trace_Property_TracePath = "trace_path"; //$NON-NLS-1$
39 public static final String Ltt_Trace_Property_TraceNumberOfChannels = "num_threads"; //$NON-NLS-1$
40 public static final String Ltt_Trace_Property_FlightRecorderMode = "flight_only"; //$NON-NLS-1$
41 public static final String Ltt_Trace_Property_NormalMode = "normal_only"; //$NON-NLS-1$
42 public static final String Ltt_Trace_Property_NetworkTrace = "isNetwork"; //$NON-NLS-1$
43 public static final String Ltt_Trace_Property_TraceTransport = "transport"; //$NON-NLS-1$
44
45 private static final Map<String, PropertyInfo> fPropertyInfo = new HashMap<String, PropertyInfo>();
46
47 static {
48 fPropertyInfo.put(Ltt_Trace_Property_TracePath, new PropertyInfo(Messages.Ltt_Trace_Property_TracePathName, Messages.Ltt_Trace_Property_TracePathDescription));
49 fPropertyInfo.put(Ltt_Trace_Property_TraceNumberOfChannels, new PropertyInfo(Messages.Ltt_Trace_Property_NumberOfChannelsName, Messages.Ltt_Trace_Property_NumberOfChannelsDescr));
50 fPropertyInfo.put(Ltt_Trace_Property_FlightRecorderMode, new PropertyInfo(Messages.Ltt_Trace_Property_FlighRecorderModeName, Messages.Ltt_Trace_Property_FlighRecorderModeDesc));
51 fPropertyInfo.put(Ltt_Trace_Property_NormalMode, new PropertyInfo(Messages.Ltt_Trace_Property_NormalModeName, Messages.Ltt_Trace_Property_NormalModeDesc));
52 fPropertyInfo.put(Ltt_Trace_Property_NetworkTrace, new PropertyInfo(Messages.Ltt_Trace_Property_NetworkTraceName, Messages.Ltt_Trace_Property_NetWorkTraceDescr));
53 fPropertyInfo.put(Ltt_Trace_Property_TraceTransport, new PropertyInfo(Messages.Ltt_Trace_Property_TraceTransportName, Messages.Ltt_Trace_Property_TraceTransportDesc));
54 }
55
56 public static class PropertyInfo {
57 private final String name;
58 private final String description;
59 PropertyInfo(String name, String description) {
60 this.name = name;
61 this.description = description;
62 }
63 public String getName() {
64 return name;
65 }
66 public String getDescription() {
67 return description;
68 }
69 }
70
71 // ------------------------------------------------------------------------
72 // Attributes
73 // ------------------------------------------------------------------------
74
75 private String fName;
76 private String fId;
77 private TargetResource fParent;
78 private TraceState fTraceState;
79 private TraceConfig fTraceConfig;
80
81 // ------------------------------------------------------------------------
82 // Constructors
83 // ------------------------------------------------------------------------
84 /**
85 * Constructor for TraceResource when given fParent subsystem.
86 */
87 public TraceResource(ISubSystem parentSubSystem) {
88 super(parentSubSystem);
89 }
90
91 // ------------------------------------------------------------------------
92 // Operations
93 // ------------------------------------------------------------------------
94
95 /**
96 * Returns the trace state.
97 */
98 public TraceState getTraceState() {
99 return fTraceState;
100 }
101
102 /**
103 * Sets the trace state.
104 *
105 * @param traceState The new state.
106 */
107 public void setTraceState(TraceState traceState) {
108 fTraceState = traceState;
109 }
110
111 /**
112 * Returns the trace configuration for this trace.
113 *
114 * @return traceConfig
115 */
116 public TraceConfig getTraceConfig() {
117 return fTraceConfig;
118 }
119
120 /**
121 * Sets the trace configuration for this trace.
122 *
123 * @param traceConfig
124 */
125 public void setTraceConfig(TraceConfig traceConfig) {
126 fTraceConfig = traceConfig;
127 }
128
129 /**
130 * Returns the name of the trace resource.
131 *
132 * @return String
133 */
134 public String getName() {
135 return fName;
136 }
137
138 /**
139 * Sets the name of the trace resource.
140 *
141 * @param fName The fName to set
142 */
143 public void setName(String name) {
144 fName = name;
145 }
146
147 /**
148 * Returns the ID of the trace resource.
149 *
150 * @return String
151 */
152 public String getId() {
153 return fId;
154 }
155
156 /**
157 * Sets the ID of the trace resource.
158 *
159 * @param fId The fId to set
160 */
161 public void setId(String id) {
162 fId = id;
163 }
164
165 /**
166 * Returns the parent target resource.
167 * @return
168 */
169 public TargetResource getParent() {
170 return fParent;
171 }
172
173 /**
174 * Sets the parent target resource.
175 *
176 * @param target
177 */
178 public void setParent(TargetResource target) {
179 fParent = target;
180 }
181
182 /**
183 * Returns the property information for this trace.
184 *
185 * @return the value
186 */
187 public Map<String,PropertyInfo> getPropertyInfo() {
188 return fPropertyInfo;
189 }
190
191 /**
192 * Gets the property information for a given property name.
193 *
194 * @param property the property to get
195 *
196 * @return the value
197 */
198 public String getProperty(String property) {
199 if ((fTraceConfig != null) && (fPropertyInfo.containsKey(property))) {
200 if (Ltt_Trace_Property_TracePath.equals(property)) {
201 return fTraceConfig.getTracePath();
202 }
203 else if (Ltt_Trace_Property_TraceNumberOfChannels.equals(property)) {
204 return String.valueOf(fTraceConfig.getNumChannel());
205 }
206 else if (Ltt_Trace_Property_FlightRecorderMode.equals(property)) {
207 return String.valueOf(fTraceConfig.getMode() == TraceConfig.FLIGHT_RECORDER_MODE);
208 }
209 else if (Ltt_Trace_Property_NormalMode.equals(property)) {
210 return String.valueOf(fTraceConfig.getMode() == TraceConfig.NORMAL_MODE);
211 }
212 else if (Ltt_Trace_Property_NetworkTrace.equals(property)) {
213 return String.valueOf(fTraceConfig.isNetworkTrace());
214 }
215 else if (Ltt_Trace_Property_TraceTransport.equals(property)) {
216 return String.valueOf(fTraceConfig.getTraceTransport());
217 }
218 }
219 return ""; //$NON-NLS-1$
220 }
221
222 /**
223 * @return true if the trace is a network trace and has been already started.
224 */
225 public boolean isNetworkTraceAndStarted () {
226 // for network traces, if trace path is available and if state is started
227 return (fTraceConfig != null) && fTraceConfig.isNetworkTrace() &&
228 !(TraceConfig.InvalidTracePath.equals(fTraceConfig.getTracePath())) &&
229 (fTraceState == TraceState.STARTED);
230 }
231
232 /**
233 * Returns whether the trace is a UST or kernel trace.
234 *
235 * @return true if UST, false for kernel
236 */
237 public boolean isUst() {
238 return fParent.isUst();
239 }
240
241 /*
242 * (non-Javadoc)
243 * @see java.lang.Object#equals(java.lang.Object)
244 */
245 @Override
246 public boolean equals(Object other) {
247
248 if (this == other) {
249 return true;
250 }
251
252 // We only check the name because the trace name has to be unique
253 if (other instanceof TraceResource) {
254 TraceResource otherTrace = (TraceResource) other;
255
256 if ((fName == null) && (otherTrace.fName == null)) {
257 return false;
258 } else if ((fName == null) && (otherTrace.fName != null)) {
259 return false;
260 }
261 else if ((fName != null) && (otherTrace.fName == null)) {
262 return false;
263 }
264 else {
265 return fName.equals(otherTrace.fName);
266 }
267 }
268 return false;
269 }
270
271 /*
272 * (non-Javadoc)
273 * @see java.lang.Object#hashCode()
274 */
275 @Override
276 public int hashCode() {
277 // We only use the name because the trace name has to be unique
278 return fName.hashCode();
279 }
280
281 /*
282 * (non-Javadoc)
283 * @see java.lang.Comparable#compareTo(java.lang.Object)
284 */
285 @Override
286 public int compareTo(TraceResource o) {
287 // We only check the name because the trace name has to be unique
288 return fName.toLowerCase().compareTo(o.fName.toLowerCase());
289 }
290
291 /*
292 * (non-Javadoc)
293 * @see java.lang.Object#toString()
294 */
295 @Override
296 @SuppressWarnings("nls")
297 public String toString() {
298 return "[TraceResource (" + fName + ")]";
299 }
300}
This page took 0.037406 seconds and 5 git commands to generate.