1
/*******************************************************************************
2
* Copyright (c) 2011 Ericsson
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
10
* Polytechnique Montréal - Initial API and implementation
11
* Bernd Hufmann - Productification, enhancements and fixes
13
*******************************************************************************/
14
package org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model;
16
import java.util.ArrayList;
17
import java.util.Arrays;
18
import java.util.List;
20
import org.eclipse.linuxtools.internal.lttng.core.LttngConstants;
21
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.ProviderResource;
22
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TargetResource;
23
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TraceResource;
24
import org.eclipse.rse.core.subsystems.AbstractResource;
25
import org.eclipse.rse.core.subsystems.ISubSystem;
28
* <b><u>TargetResource</u></b>
30
* This models a remote resource representing a target defined on a particular system.
33
public class TargetResource extends AbstractResource implements Comparable<TargetResource> {
35
// ------------------------------------------------------------------------
37
// ------------------------------------------------------------------------
39
private List<TraceResource> fTraces;
40
private ProviderResource fParent;
41
private String fCanCreateNewTrace;
43
// ------------------------------------------------------------------------
45
// ------------------------------------------------------------------------
47
* Constructor for TargetResource when given fParent subsystem.
49
public TargetResource(ISubSystem parentSubSystem) {
50
super(parentSubSystem);
51
fCanCreateNewTrace = LttngConstants.Rse_Resource_Action_Enabled;
52
fTraces = new ArrayList<TraceResource>();
55
// ------------------------------------------------------------------------
57
// ------------------------------------------------------------------------
59
* Returns the name of the target resource.
63
public String getName() {
68
* Sets the name of the target resource.
70
* @param fName The fName to set
72
public void setName(String name) {
77
* Sets the traces (children).
79
* @param newTraces The new traces to set
81
public void setTraces(TraceResource[] newTraces) {
83
fTraces.addAll(Arrays.asList(newTraces));
87
* Gets the traces (children).
89
* @return traces (children)
91
public TraceResource[] getTraces() {
92
TraceResource[] traces = fTraces.toArray(new TraceResource[0]);
98
* Gets the trace for a given name.
100
* @param name The name of trace to search for.
101
* @return trace if exists else null
103
public TraceResource getTrace(String name) {
104
for (TraceResource trace : fTraces) {
105
if (trace.getName().equals(name)) {
113
* Adds a new trace (child) to the existing list of traces.
115
* @param trace The new trace to add.
117
public void addTrace(TraceResource trace) {
122
* Removes a new trace (child) from the existing list of traces.
124
* @param trace The new trace to add.
126
public void removeTrace(TraceResource trace) {
127
fTraces.remove(trace);
131
* Removes all traces (children).
133
public void removeAllTraces() {
138
* Refreshes target with other traces list. If trace already exists in this
139
* target, reuse the trace from this target and don't override.
141
* @param otherTargets
143
public void refreshTraces(TraceResource[] otherTraces) {
144
List<TraceResource> newTraces = new ArrayList<TraceResource>();
145
for (int i = 0; i < otherTraces.length; i++) {
146
boolean added = false;
147
for (TraceResource trace : fTraces) {
148
if (otherTraces[i].equals(trace)) {
149
newTraces.add(trace);
155
newTraces.add(otherTraces[i]);
162
* Returns the parent provider resource.
164
* @return parent provider resource
166
public ProviderResource getParent() {
171
* Sets the parent provider resource.
174
public void setParent(ProviderResource provider) {
179
* Returns whether the target is for UST or kernel traces.
181
* @return true if UST, false for kernel
183
public boolean isUst() {
184
return fParent.isUst();
188
* Gets property whether target can create new trace or not
189
* @return fCanCreateNewTrace
191
public String getCanCreateNewTrace() {
192
return fCanCreateNewTrace;
197
* @see java.lang.Object#equals(java.lang.Object)
200
public boolean equals(Object other) {
206
// We only check the name because the target name has to be unique
207
if (other instanceof TargetResource) {
208
TargetResource otherTarget = (TargetResource) other;
210
return fName.equals(otherTarget.fName);
218
* @see java.lang.Object#hashCode()
221
public int hashCode() {
222
// We only use the name because the target name has to be unique
223
return fName.hashCode();
228
* @see java.lang.Comparable#compareTo(java.lang.Object)
231
public int compareTo(TargetResource o) {
232
// We only check the name because the trace name has to be unique
233
return fName.toLowerCase().compareTo(o.fName.toLowerCase());
238
* @see java.lang.Object#toString()
241
@SuppressWarnings("nls")
242
public String toString() {
243
return "[TargetResource (" + fName + ")]";