Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / lttng / core / tracecontrol / model / TraceResource.java
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 *******************************************************************************/
14 package org.eclipse.linuxtools.lttng.core.tracecontrol.model;
15
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.concurrent.TimeUnit;
19
20 import org.eclipse.linuxtools.lttng.core.tracecontrol.Messages;
21 import org.eclipse.linuxtools.lttng.core.tracecontrol.model.config.TraceConfig;
22 import org.eclipse.linuxtools.lttng.core.tracecontrol.service.ILttControllerService;
23 import org.eclipse.rse.core.subsystems.AbstractResource;
24 import org.eclipse.rse.core.subsystems.ISubSystem;
25 import org.eclipse.tm.tcf.protocol.IToken;
26 import org.eclipse.tm.tcf.util.TCFTask;
27
28 /**
29 * <b><u>ProviderResource</u></b>
30 * <p>
31 * This models a remote resource representing a trace defined on a particular system.
32 * </p>
33 */
34 public class TraceResource extends AbstractResource implements Comparable<TraceResource> {
35
36
37 public static enum TraceState { CREATED, CONFIGURED, STARTED, PAUSED, STOPPED };
38
39 public static final String Ltt_Trace_Property_TracePath = "trace_path"; //$NON-NLS-1$
40 public static final String Ltt_Trace_Property_TraceNumberOfChannels = "num_threads"; //$NON-NLS-1$
41 public static final String Ltt_Trace_Property_FlightRecorderMode = "flight_only"; //$NON-NLS-1$
42 public static final String Ltt_Trace_Property_NormalMode = "normal_only"; //$NON-NLS-1$
43 public static final String Ltt_Trace_Property_NetworkTrace = "isNetwork"; //$NON-NLS-1$
44 public static final String Ltt_Trace_Property_TraceTransport = "transport"; //$NON-NLS-1$
45
46 public static final int DEFAULT_TCF_TASK_TIMEOUT = 10;
47
48 private static final Map<String, PropertyInfo> fPropertyInfo = new HashMap<String, PropertyInfo>();
49
50 static {
51 fPropertyInfo.put(Ltt_Trace_Property_TracePath, new PropertyInfo(Messages.Ltt_Trace_Property_TracePathName, Messages.Ltt_Trace_Property_TracePathDescription));
52 fPropertyInfo.put(Ltt_Trace_Property_TraceNumberOfChannels, new PropertyInfo(Messages.Ltt_Trace_Property_NumberOfChannelsName, Messages.Ltt_Trace_Property_NumberOfChannelsDescr));
53 fPropertyInfo.put(Ltt_Trace_Property_FlightRecorderMode, new PropertyInfo(Messages.Ltt_Trace_Property_FlighRecorderModeName, Messages.Ltt_Trace_Property_FlighRecorderModeDesc));
54 fPropertyInfo.put(Ltt_Trace_Property_NormalMode, new PropertyInfo(Messages.Ltt_Trace_Property_NormalModeName, Messages.Ltt_Trace_Property_NormalModeDesc));
55 fPropertyInfo.put(Ltt_Trace_Property_NetworkTrace, new PropertyInfo(Messages.Ltt_Trace_Property_NetworkTraceName, Messages.Ltt_Trace_Property_NetWorkTraceDescr));
56 fPropertyInfo.put(Ltt_Trace_Property_TraceTransport, new PropertyInfo(Messages.Ltt_Trace_Property_TraceTransportName, Messages.Ltt_Trace_Property_TraceTransportDesc));
57 }
58
59 public static class PropertyInfo {
60 private final String name;
61 private final String description;
62 PropertyInfo(String name, String description) {
63 this.name = name;
64 this.description = description;
65 }
66 public String getName() {
67 return name;
68 }
69 public String getDescription() {
70 return description;
71 }
72 }
73
74 // ------------------------------------------------------------------------
75 // Attributes
76 // ------------------------------------------------------------------------
77
78 private String fName;
79 private String fId;
80 private TargetResource fParent;
81 private TraceState fTraceState;
82 private TraceConfig fTraceConfig;
83 private ILttControllerService fService;
84
85 // ------------------------------------------------------------------------
86 // Constructors
87 // ------------------------------------------------------------------------
88 /**
89 * Constructor for TraceResource when given fParent subsystem.
90 */
91 public TraceResource(ISubSystem parentSubSystem, ILttControllerService service) {
92 super(parentSubSystem);
93 fService = service;
94 }
95
96 // ------------------------------------------------------------------------
97 // Operations
98 // ------------------------------------------------------------------------
99
100 /**
101 * Returns the trace state.
102 */
103 public TraceState getTraceState() {
104 return fTraceState;
105 }
106
107 /**
108 * Sets the trace state.
109 *
110 * @param traceState The new state.
111 */
112 public void setTraceState(TraceState traceState) {
113 fTraceState = traceState;
114 }
115
116 /**
117 * Returns the trace configuration for this trace.
118 *
119 * @return traceConfig
120 */
121 public TraceConfig getTraceConfig() {
122 return fTraceConfig;
123 }
124
125 /**
126 * Sets the trace configuration for this trace.
127 *
128 * @param traceConfig
129 */
130 public void setTraceConfig(TraceConfig traceConfig) {
131 fTraceConfig = traceConfig;
132 }
133
134 /**
135 * Returns the name of the trace resource.
136 *
137 * @return String
138 */
139 public String getName() {
140 return fName;
141 }
142
143 /**
144 * Sets the name of the trace resource.
145 *
146 * @param fName The fName to set
147 */
148 public void setName(String name) {
149 fName = name;
150 }
151
152 /**
153 * Returns the ID of the trace resource.
154 *
155 * @return String
156 */
157 public String getId() {
158 return fId;
159 }
160
161 /**
162 * Sets the ID of the trace resource.
163 *
164 * @param fId The fId to set
165 */
166 public void setId(String id) {
167 fId = id;
168 }
169
170 /**
171 * Returns the parent target resource.
172 * @return
173 */
174 public TargetResource getParent() {
175 return fParent;
176 }
177
178 /**
179 * Sets the parent target resource.
180 *
181 * @param target
182 */
183 public void setParent(TargetResource target) {
184 fParent = target;
185 }
186
187 /**
188 * Returns the property information for this trace.
189 *
190 * @return the value
191 */
192 public Map<String,PropertyInfo> getPropertyInfo() {
193 return fPropertyInfo;
194 }
195
196 /**
197 * Gets the property information for a given property name.
198 *
199 * @param property the property to get
200 *
201 * @return the value
202 */
203 public String getProperty(String property) {
204 if ((fTraceConfig != null) && (fPropertyInfo.containsKey(property))) {
205 if (Ltt_Trace_Property_TracePath.equals(property)) {
206 return fTraceConfig.getTracePath();
207 }
208 else if (Ltt_Trace_Property_TraceNumberOfChannels.equals(property)) {
209 return String.valueOf(fTraceConfig.getNumChannel());
210 }
211 else if (Ltt_Trace_Property_FlightRecorderMode.equals(property)) {
212 return String.valueOf(fTraceConfig.getMode() == TraceConfig.FLIGHT_RECORDER_MODE);
213 }
214 else if (Ltt_Trace_Property_NormalMode.equals(property)) {
215 return String.valueOf(fTraceConfig.getMode() == TraceConfig.NORMAL_MODE);
216 }
217 else if (Ltt_Trace_Property_NetworkTrace.equals(property)) {
218 return String.valueOf(fTraceConfig.isNetworkTrace());
219 }
220 else if (Ltt_Trace_Property_TraceTransport.equals(property)) {
221 return String.valueOf(fTraceConfig.getTraceTransport());
222 }
223 }
224 return ""; //$NON-NLS-1$
225 }
226
227 /**
228 * @return true if the trace is a network trace and has been already started.
229 */
230 public boolean isNetworkTraceAndStarted () {
231 // for network traces, if trace path is available and if state is started
232 return (fTraceConfig != null) && fTraceConfig.isNetworkTrace() &&
233 !(TraceConfig.InvalidTracePath.equals(fTraceConfig.getTracePath())) &&
234 (fTraceState == TraceState.STARTED);
235 }
236
237 /**
238 * Returns whether the trace is a UST or kernel trace.
239 *
240 * @return true if UST, false for kernel
241 */
242 public boolean isUst() {
243 return fParent.isUst();
244 }
245
246 /*
247 * (non-Javadoc)
248 * @see java.lang.Object#equals(java.lang.Object)
249 */
250 @Override
251 public boolean equals(Object other) {
252
253 if (this == other) {
254 return true;
255 }
256
257 // We only check the name because the trace name has to be unique
258 if (other instanceof TraceResource) {
259 TraceResource otherTrace = (TraceResource) other;
260
261 if ((fName == null) && (otherTrace.fName == null)) {
262 return false;
263 } else if ((fName == null) && (otherTrace.fName != null)) {
264 return false;
265 }
266 else if ((fName != null) && (otherTrace.fName == null)) {
267 return false;
268 }
269 else {
270 return fName.equals(otherTrace.fName);
271 }
272 }
273 return false;
274 }
275
276 /*
277 * (non-Javadoc)
278 * @see java.lang.Object#hashCode()
279 */
280 @Override
281 public int hashCode() {
282 // We only use the name because the trace name has to be unique
283 return fName.hashCode();
284 }
285
286 /*
287 * (non-Javadoc)
288 * @see java.lang.Comparable#compareTo(java.lang.Object)
289 */
290 @Override
291 public int compareTo(TraceResource o) {
292 // We only check the name because the trace name has to be unique
293 return fName.toLowerCase().compareTo(o.fName.toLowerCase());
294 }
295
296 /*
297 * (non-Javadoc)
298 * @see java.lang.Object#toString()
299 */
300 @Override
301 @SuppressWarnings("nls")
302 public String toString() {
303 return "[TraceResource (" + fName + ")]";
304 }
305
306 /*
307 * Setup trace on the remote system.
308 */
309 public void setupTrace() throws Exception {
310 // Create future task
311 new TCFTask<Boolean>() {
312 @Override
313 public void run() {
314
315 // Setup trace using Lttng controller service proxy
316 fService.setupTrace(fParent.getParent().getName(),
317 fParent.getName(),
318 fName,
319 new ILttControllerService.DoneSetupTrace() {
320
321 @Override
322 public void doneSetupTrace(IToken token, Exception error, Object str) {
323 if (error != null) {
324 // Notify with error
325 error(error);
326 return;
327 }
328
329 // Notify about success
330 done(Boolean.valueOf(true));
331 }
332 });
333 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
334 }
335
336 /*
337 * Enable or disable a channel on the remote system.
338 */
339 public void setChannelEnable(final String channelName, final boolean enabled) throws Exception {
340 // Create future task
341 new TCFTask<Boolean>() {
342 @Override
343 public void run() {
344
345 // Set marker enable using Lttng controller service proxy
346 fService.setChannelEnable(fParent.getParent().getName(),
347 fParent.getName(),
348 fName,
349 channelName,
350 enabled,
351 new ILttControllerService.DoneSetChannelEnable() {
352
353 @Override
354 public void doneSetChannelEnable(IToken token, Exception error, Object str) {
355 if (error != null) {
356 // Notify with error
357 error(error);
358 return;
359 }
360
361 // Notify about success
362 done(Boolean.valueOf(true));
363 }
364 });
365 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
366 }
367
368 /*
369 * Set channel overwrite on the remote system.
370 */
371 public void setChannelOverwrite(final String channelName, final boolean overwrite) throws Exception {
372 // Create future task
373 new TCFTask<Boolean>() {
374 @Override
375 public void run() {
376
377 // Set marker overwrite using Lttng controller service proxy
378 fService.setChannelOverwrite(fParent.getParent().getName(),
379 fParent.getName(),
380 fName,
381 channelName,
382 overwrite,
383 new ILttControllerService.DoneSetChannelOverwrite() {
384
385 @Override
386 public void doneSetChannelOverwrite(IToken token, Exception error, Object str) {
387 if (error != null) {
388 // Notify with error
389 error(error);
390 return;
391 }
392
393 // Notify about success
394 done(Boolean.valueOf(true));
395 }
396 });
397 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
398 }
399
400 /*
401 * Set channel timer on the remote system.
402 */
403 public void setChannelTimer(final String channelName, final long timer) throws Exception {
404 // Create future task
405 new TCFTask<Boolean>() {
406 @Override
407 public void run() {
408
409 // Set marker switch_timer using Lttng controller service proxy
410 fService.setChannelTimer(fParent.getParent().getName(),
411 fParent.getName(),
412 fName,
413 channelName,
414 timer,
415 new ILttControllerService.DoneSetChannelTimer() {
416
417 @Override
418 public void doneSetChannelTimer(IToken token, Exception error, Object str) {
419 if (error != null) {
420 // Notify with error
421 error(error);
422 return;
423 }
424
425 // Notify about success
426 done(Boolean.valueOf(true));
427 }
428 });
429 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
430 }
431
432 /*
433 * Setup the size of the sub-buffer on the remote system.
434 */
435 public void setChannelSubbufNum(final String channelName, final long subbufNum) throws Exception {
436 // Create future task
437 new TCFTask<Boolean>() {
438 @Override
439 public void run() {
440
441 // Set marker enable using Lttng controller service proxy
442 fService.setChannelSubbufNum(fParent.getParent().getName(),
443 fParent.getName(),
444 fName,
445 channelName,
446 subbufNum,
447 new ILttControllerService.DoneSetChannelSubbufNum() {
448
449 @Override
450 public void doneSetChannelSubbufNum(IToken token, Exception error, Object str) {
451 if (error != null) {
452 // Notify with error
453 error(error);
454 return;
455 }
456
457 // Notify about success
458 done(Boolean.valueOf(true));
459 }
460 });
461 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
462 }
463
464 /*
465 * Setup the size of the sub-buffer on the remote system.
466 */
467 public void setChannelSubbufSize(final String channelName, final long subbufSize) throws Exception {
468 // Create future task
469 new TCFTask<Boolean>() {
470 @Override
471 public void run() {
472
473 // Set marker enable using Lttng controller service proxy
474 fService.setChannelSubbufSize(fParent.getParent().getName(),
475 fParent.getName(),
476 fName,
477 channelName,
478 subbufSize,
479 new ILttControllerService.DoneSetChannelSubbufSize() {
480
481 @Override
482 public void doneSetChannelSubbufSize(IToken token, Exception error, Object str) {
483 if (error != null) {
484 // Notify with error
485 error(error);
486 return;
487 }
488
489 // Notify about success
490 done(Boolean.valueOf(true));
491 }
492 });
493 }}.get(DEFAULT_TCF_TASK_TIMEOUT, TimeUnit.SECONDS);
494 }
495
496
497 }
This page took 0.062747 seconds and 5 git commands to generate.