Commit | Line | Data |
---|---|---|
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 | *******************************************************************************/ | |
14 | package org.eclipse.linuxtools.lttng.tracecontrol.model; | |
15 | ||
16 | import java.util.ArrayList; | |
17 | import java.util.Arrays; | |
18 | import java.util.List; | |
19 | ||
20 | import org.eclipse.linuxtools.lttng.LttngConstants; | |
21 | import org.eclipse.linuxtools.lttng.tracecontrol.model.TargetResource; | |
22 | import org.eclipse.rse.core.subsystems.AbstractResource; | |
23 | import org.eclipse.rse.core.subsystems.ISubSystem; | |
24 | ||
25 | /** | |
26 | * <b><u>ProviderResource</u></b> | |
27 | * <p> | |
28 | * This models a remote resource representing a provider defined on a particular system. | |
29 | * </p> | |
30 | */ | |
31 | public class ProviderResource extends AbstractResource { | |
32 | ||
33 | // ------------------------------------------------------------------------ | |
34 | // Attributes | |
35 | // ------------------------------------------------------------------------ | |
36 | private String fName; | |
37 | private TargetResource[] fTargets; | |
38 | ||
39 | // ------------------------------------------------------------------------ | |
40 | // Constructors | |
41 | // ------------------------------------------------------------------------ | |
42 | /** | |
43 | * Default constructor | |
44 | */ | |
45 | public ProviderResource() { | |
46 | super(); | |
47 | } | |
48 | ||
49 | /** | |
50 | * Constructor for ProviderResource when given a parent subsystem. | |
51 | */ | |
52 | public ProviderResource(ISubSystem parentSubSystem) { | |
53 | super(parentSubSystem); | |
54 | } | |
55 | ||
56 | // ------------------------------------------------------------------------ | |
57 | // Operations | |
58 | // ------------------------------------------------------------------------ | |
59 | /** | |
60 | * Returns the name of the provider resource. | |
61 | * | |
62 | * @return String | |
63 | */ | |
64 | public String getName() { | |
65 | return fName; | |
66 | } | |
67 | ||
68 | /** | |
69 | * Sets the name of the provider resource. | |
70 | * | |
71 | * @param name The fName to set | |
72 | */ | |
73 | public void setName(String name) { | |
74 | fName = name; | |
75 | } | |
76 | ||
77 | /** | |
78 | * Returns the targets (children). | |
79 | * | |
80 | * @return TargetResource[] | |
81 | */ | |
82 | public TargetResource[] getTargets() { | |
83 | Arrays.sort(fTargets); | |
84 | return fTargets; | |
85 | } | |
86 | ||
87 | /** | |
88 | * Returns whether the provider is for UST or kernel traces. | |
89 | * | |
90 | * @return true if UST, false for kernel | |
91 | */ | |
92 | public boolean isUst() { | |
93 | return fName.equals(LttngConstants.Lttng_Provider_Ust); | |
94 | } | |
95 | ||
96 | /** | |
97 | * Sets the targets (children). | |
98 | * | |
99 | * @param newTargets The new targets to set | |
100 | */ | |
101 | public void setTargets(TargetResource[] newTargets) { | |
102 | fTargets = newTargets; | |
103 | } | |
104 | ||
105 | /** | |
106 | * Removes all targets (children). | |
107 | */ | |
108 | public void removeAllTargets() { | |
109 | for (int i = 0; i < fTargets.length; i++) { | |
110 | fTargets[i].removeAllTraces(); | |
111 | } | |
112 | fTargets = null; | |
113 | } | |
114 | ||
115 | /** | |
116 | * Refreshes provider with other targets list. If target already exists in this | |
117 | * provider, reuse the target from this provider and don't override. | |
118 | * | |
119 | * @param otherTargets | |
120 | */ | |
121 | public void refreshTargets(TargetResource[] otherTargets) { | |
122 | List<TargetResource> newTargets = new ArrayList<TargetResource>(); | |
123 | for (int i = 0; i < otherTargets.length; i++) { | |
124 | boolean added = false; | |
125 | for (int j = 0; j < fTargets.length; j++) { | |
126 | if (otherTargets[i].equals(fTargets[j])) { | |
127 | newTargets.add(fTargets[j]); | |
128 | fTargets[j].refreshTraces(otherTargets[i].getTraces()); | |
129 | added = true; | |
130 | break; | |
131 | } | |
132 | } | |
133 | if (!added) { | |
134 | newTargets.add(otherTargets[i]); | |
135 | } | |
136 | } | |
137 | fTargets = newTargets.toArray(new TargetResource[0]); | |
138 | } | |
139 | ||
140 | /* | |
141 | * (non-Javadoc) | |
142 | * @see java.lang.Object#toString() | |
143 | */ | |
144 | @Override | |
145 | @SuppressWarnings("nls") | |
146 | public String toString() { | |
147 | return "[ProviderResource (" + fName + ")]"; | |
148 | } | |
149 | } |