Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 980a0899fd2fc9453979465f9cd098e4b5db9ccc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*******************************************************************************
 * Copyright (c) 2011 Ericsson
 * 
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Polytechnique Montréal - Initial API and implementation
 *   Bernd Hufmann - Productification, enhancements and fixes
 *   
 *******************************************************************************/
package org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.linuxtools.internal.lttng.core.LttngConstants;
import org.eclipse.linuxtools.internal.lttng.core.tracecontrol.model.TargetResource;
import org.eclipse.rse.core.subsystems.AbstractResource;
import org.eclipse.rse.core.subsystems.ISubSystem;

/**
 * <b><u>ProviderResource</u></b>
 * <p>
 * This models a remote resource representing a provider defined on a particular system.
 * </p>
 */
public class ProviderResource extends AbstractResource {

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------
    private String fName;
    private TargetResource[] fTargets;

    // ------------------------------------------------------------------------
    // Constructors
    // ------------------------------------------------------------------------
    /**
     * Default constructor
     */
    public ProviderResource() {
        super();
    }

    /**
     * Constructor for ProviderResource when given a parent subsystem.
     */
    public ProviderResource(ISubSystem parentSubSystem) {
        super(parentSubSystem);
    }

    // ------------------------------------------------------------------------
    // Operations
    // ------------------------------------------------------------------------
    /**
     * Returns the name of the provider resource.
     * 
     * @return String
     */
    public String getName() {
        return fName;
    }

    /**
     * Sets the name of the provider resource.
     * 
     * @param name The fName to set
     */
    public void setName(String name) {
        fName = name;
    }

    /**
     * Returns the targets (children).
     * 
     * @return TargetResource[]
     */
    public TargetResource[] getTargets() {
    	Arrays.sort(fTargets);
        return fTargets;
    }

    /**
     * Returns whether the provider is for UST or kernel traces. 
     * 
     * @return true if UST, false for kernel 
     */
    public boolean isUst() {
        return fName.equals(LttngConstants.Lttng_Provider_Ust);        
    }
    
    /**
     * Sets the targets (children).
     * 
     * @param newTargets The new targets to set
     */
    public void setTargets(TargetResource[] newTargets) {
        fTargets = newTargets;
    }

    /**
     * Removes all targets (children).
     */
    public void removeAllTargets() {
        for (int i = 0; i < fTargets.length; i++) {
            fTargets[i].removeAllTraces();
        }
        fTargets = null;
    }

    /**
     * Refreshes provider with other targets list. If target already exists in this
     * provider, reuse the target from this provider and don't override.   
     * 
     * @param otherTargets
     */
    public void refreshTargets(TargetResource[] otherTargets) {
        List<TargetResource>  newTargets = new ArrayList<TargetResource>();
        for (int i = 0; i < otherTargets.length; i++) {
            boolean added = false;
            for (int j = 0; j < fTargets.length; j++) {
                if (otherTargets[i].equals(fTargets[j])) {
                    newTargets.add(fTargets[j]);
                    fTargets[j].refreshTraces(otherTargets[i].getTraces());
                    added = true;
                    break;
                }
            }
            if (!added) {
                newTargets.add(otherTargets[i]);
            }
        }
        fTargets = newTargets.toArray(new TargetResource[0]);
    }
    
    /*
     * (non-Javadoc)
     * @see java.lang.Object#toString()
     */
    @Override
    @SuppressWarnings("nls")
    public String toString() {
        return "[ProviderResource (" + fName + ")]";
    }
}

Back to the top