~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to lttng/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2012-06-29 12:07:30 UTC
  • Revision ID: package-import@ubuntu.com-20120629120730-bfri1xys1i71dpn6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**********************************************************************
 
2
 * Copyright (c) 2012 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
 *   Bernd Hufmann - Initial API and implementation
 
11
 **********************************************************************/
 
12
package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl;
 
13
 
 
14
import java.util.ArrayList;
 
15
import java.util.List;
 
16
 
 
17
import org.eclipse.core.commands.ExecutionException;
 
18
import org.eclipse.core.runtime.IProgressMonitor;
 
19
import org.eclipse.core.runtime.NullProgressMonitor;
 
20
import org.eclipse.linuxtools.internal.lttng2.core.control.model.IChannelInfo;
 
21
import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
 
22
import org.eclipse.linuxtools.internal.lttng2.core.control.model.LogLevelType;
 
23
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEnablement;
 
24
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel;
 
25
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ChannelInfo;
 
26
import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.ProbeEventInfo;
 
27
import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 
28
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.messages.Messages;
 
29
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
 
30
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.property.TraceChannelPropertySource;
 
31
import org.eclipse.swt.graphics.Image;
 
32
import org.eclipse.ui.views.properties.IPropertySource;
 
33
 
 
34
 
 
35
/**
 
36
 * <p>
 
37
 * Implementation of the trace channel component.
 
38
 * </p>
 
39
 * 
 
40
 * @author Bernd Hufmann
 
41
 */
 
42
public class TraceChannelComponent extends TraceControlComponent {
 
43
    // ------------------------------------------------------------------------
 
44
    // Constants
 
45
    // ------------------------------------------------------------------------
 
46
    /**
 
47
     * Path to icon file for this component (state enabled).
 
48
     */
 
49
    public static final String TRACE_CHANNEL_ICON_FILE_ENABLED = "icons/obj16/channel.gif"; //$NON-NLS-1$
 
50
    /**
 
51
     * Path to icon file for this component (state disabled).
 
52
     */
 
53
    public static final String TRACE_CHANNEL_ICON_FILE_DISABLED = "icons/obj16/channel_disabled.gif"; //$NON-NLS-1$
 
54
    
 
55
    // ------------------------------------------------------------------------
 
56
    // Attributes
 
57
    // ------------------------------------------------------------------------
 
58
    /**
 
59
     * The channel information.
 
60
     */
 
61
    private IChannelInfo fChannelInfo = null;
 
62
    /**
 
63
     * The image to be displayed in disabled state.
 
64
     */
 
65
    private Image fDisabledImage = null;
 
66
    
 
67
    // ------------------------------------------------------------------------
 
68
    // Constructors
 
69
    // ------------------------------------------------------------------------
 
70
    /**
 
71
     * Constructor 
 
72
     * @param name - the name of the component.
 
73
     * @param parent - the parent of this component.
 
74
     */
 
75
    public TraceChannelComponent(String name, ITraceControlComponent parent) {
 
76
        super(name, parent);
 
77
        setImage(TRACE_CHANNEL_ICON_FILE_ENABLED);
 
78
        setToolTip(Messages.TraceControl_ChannelDisplayName);
 
79
        fChannelInfo = new ChannelInfo(name);
 
80
        fDisabledImage = Activator.getDefault().loadIcon(TRACE_CHANNEL_ICON_FILE_DISABLED);
 
81
    }
 
82
    
 
83
    // ------------------------------------------------------------------------
 
84
    // Accessors
 
85
    // ------------------------------------------------------------------------
 
86
    /*
 
87
     * (non-Javadoc)
 
88
     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getImage()
 
89
     */
 
90
    @Override
 
91
    public Image getImage() {
 
92
        if (fChannelInfo.getState() == TraceEnablement.DISABLED) {
 
93
            return fDisabledImage;
 
94
        }
 
95
        return super.getImage();
 
96
    }
 
97
 
 
98
    /**
 
99
     * Sets the channel information.
 
100
     * @param channelInfo
 
101
     */
 
102
    public void setChannelInfo(IChannelInfo channelInfo) {
 
103
        fChannelInfo = channelInfo;
 
104
        IEventInfo[] events = fChannelInfo.getEvents();
 
105
        List<ITraceControlComponent> eventComponents = new ArrayList<ITraceControlComponent>();
 
106
        for (int i = 0; i < events.length; i++) {
 
107
            TraceEventComponent event = null;
 
108
            if (events[i].getClass() == ProbeEventInfo.class) {
 
109
                event = new TraceProbeEventComponent(events[i].getName(), this);
 
110
            } else {
 
111
                event = new TraceEventComponent(events[i].getName(), this);
 
112
            }
 
113
 
 
114
            eventComponents.add(event);
 
115
            event.setEventInfo(events[i]);
 
116
//            addChild(event);
 
117
        }
 
118
        if (!eventComponents.isEmpty()) {
 
119
            setChildren(eventComponents);
 
120
        }
 
121
    }
 
122
 
 
123
    /**
 
124
     * @return the overwrite mode value.
 
125
     */
 
126
    public boolean isOverwriteMode() {
 
127
        return fChannelInfo.isOverwriteMode();
 
128
    }
 
129
    /**
 
130
     * Sets the overwrite mode value to the given mode.
 
131
     * @param mode - mode to set.
 
132
     */
 
133
    public void setOverwriteMode(boolean mode){
 
134
        fChannelInfo.setOverwriteMode(mode);
 
135
    }
 
136
    /**
 
137
     * @return the sub-buffer size.
 
138
     */
 
139
    public long getSubBufferSize() {
 
140
        return fChannelInfo.getSubBufferSize();
 
141
    }
 
142
    /**
 
143
     * Sets the sub-buffer size to the given value.
 
144
     * @param bufferSize - size to set to set.
 
145
     */
 
146
    public void setSubBufferSize(long bufferSize) {
 
147
        fChannelInfo.setSubBufferSize(bufferSize);
 
148
    }
 
149
    /**
 
150
     * @return the number of sub-buffers.
 
151
     */
 
152
    public int getNumberOfSubBuffers() {
 
153
        return fChannelInfo.getNumberOfSubBuffers();
 
154
    }
 
155
    /**
 
156
     * Sets the number of sub-buffers to the given value.
 
157
     * @param numberOfSubBuffers - value to set.
 
158
     */
 
159
    public void setNumberOfSubBuffers(int numberOfSubBuffers) {
 
160
        fChannelInfo.setNumberOfSubBuffers(numberOfSubBuffers);
 
161
    }
 
162
    /**
 
163
     * @return the switch timer interval.
 
164
     */
 
165
    public long getSwitchTimer() {
 
166
        return fChannelInfo.getSwitchTimer();
 
167
    }
 
168
    /**
 
169
     * Sets the switch timer interval to the given value.
 
170
     * @param timer - timer value to set.
 
171
     */
 
172
    public void setSwitchTimer(long timer) {
 
173
        fChannelInfo.setSwitchTimer(timer);
 
174
    }
 
175
    /**
 
176
     * @return the read timer interval.
 
177
     */
 
178
    public long getReadTimer() {
 
179
        return fChannelInfo.getReadTimer(); 
 
180
    }
 
181
    /**
 
182
     * Sets the read timer interval to the given value.
 
183
     * @param timer - timer value to set..
 
184
     */
 
185
    public void setReadTimer(long timer) {
 
186
        fChannelInfo.setReadTimer(timer);
 
187
    }
 
188
    /**
 
189
     * @return the output type.
 
190
     */
 
191
    public String getOutputType() {
 
192
        return fChannelInfo.getOutputType();
 
193
    }
 
194
    /**
 
195
     * Sets the output type to the given value.
 
196
     * @param type - type to set.
 
197
     */
 
198
    public void setOutputType(String type) {
 
199
        fChannelInfo.setOutputType(type);
 
200
    }
 
201
    /**
 
202
     * @return the channel state (enabled or disabled).
 
203
     */
 
204
    public TraceEnablement getState() {
 
205
        return fChannelInfo.getState();
 
206
    }
 
207
    /**
 
208
     * Sets the channel state (enablement) to the given value.
 
209
     * @param state - state to set.
 
210
     */
 
211
    public void setState(TraceEnablement state) {
 
212
        fChannelInfo.setState(state);
 
213
    }
 
214
    /**
 
215
     * Sets the channel state (enablement) to the value specified by the given name.
 
216
     * @param stateName - state to set.
 
217
     */
 
218
    public void setState(String stateName) {
 
219
        fChannelInfo.setState(stateName);
 
220
    }
 
221
    /*
 
222
     * (non-Javadoc)
 
223
     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceControlComponent#getAdapter(java.lang.Class)
 
224
     */
 
225
    @SuppressWarnings("rawtypes")
 
226
    @Override
 
227
    public Object getAdapter(Class adapter) {
 
228
        if (adapter == IPropertySource.class) {
 
229
            return new TraceChannelPropertySource(this);
 
230
        }
 
231
        return null;
 
232
    } 
 
233
 
 
234
    /**
 
235
     * @return session name from parent
 
236
     */
 
237
    public String getSessionName() {
 
238
       return ((TraceDomainComponent)getParent()).getSessionName(); 
 
239
    }
 
240
 
 
241
    /**
 
242
     * @return session from parent
 
243
     */
 
244
    public TraceSessionComponent getSession() {
 
245
       return ((TraceDomainComponent)getParent()).getSession(); 
 
246
    }
 
247
 
 
248
    /**
 
249
     * @return if domain is kernel or UST
 
250
     */
 
251
    public boolean isKernel() {
 
252
        return ((TraceDomainComponent)getParent()).isKernel();
 
253
    }
 
254
    
 
255
    /**
 
256
     * @return the parent target node
 
257
     */
 
258
    public TargetNodeComponent getTargetNode() {
 
259
        return ((TraceDomainComponent)getParent()).getTargetNode();
 
260
    }
 
261
    
 
262
    // ------------------------------------------------------------------------
 
263
    // Operations
 
264
    // ------------------------------------------------------------------------
 
265
    /**
 
266
     * Enables a list of events with no additional parameters.
 
267
     * @param eventNames - a list of event names to enabled.
 
268
     * @throws ExecutionException
 
269
     */
 
270
    public void enableEvents(List<String> eventNames) throws ExecutionException {
 
271
        enableEvents(eventNames, new NullProgressMonitor());
 
272
    }
 
273
 
 
274
    /**
 
275
     * Enables a list of events with no additional parameters.
 
276
     * @param eventNames - a list of event names to enabled.
 
277
     * @param monitor - a progress monitor
 
278
     * @throws ExecutionException
 
279
     */
 
280
    public void enableEvents(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
 
281
        getControlService().enableEvents(getSessionName(), getName(), eventNames, isKernel(), monitor);
 
282
    }
 
283
    
 
284
    /**
 
285
     * Enables all syscalls (for kernel domain)
 
286
     * @throws ExecutionException
 
287
     */
 
288
    public void enableSyscalls() throws ExecutionException {
 
289
        enableSyscalls(new NullProgressMonitor());
 
290
    }
 
291
 
 
292
    /**
 
293
     * Enables all syscalls (for kernel domain)
 
294
     * @param monitor - a progress monitor
 
295
     * @throws ExecutionException
 
296
     */
 
297
    public void enableSyscalls(IProgressMonitor monitor) throws ExecutionException {
 
298
        getControlService().enableSyscalls(getSessionName(), getName(), monitor);
 
299
    }
 
300
 
 
301
    /**
 
302
     * Enables a dynamic probe (for kernel domain)
 
303
     * @param eventName - event name for probe
 
304
     * @param isFunction - true for dynamic function entry/return probe else false
 
305
     * @param probe - the actual probe
 
306
     * @throws ExecutionException
 
307
     */
 
308
    public void enableProbe(String eventName, boolean isFunction, String probe) throws ExecutionException {
 
309
        enableProbe(eventName, isFunction, probe, new NullProgressMonitor());
 
310
    }
 
311
 
 
312
    /**
 
313
     * Enables a dynamic probe (for kernel domain)
 
314
     * @param eventName - event name for probe
 
315
     * @param isFunction - true for dynamic function entry/return probe else false 
 
316
     * @param probe - the actual probe
 
317
     * @param monitor - a progress monitor
 
318
     * @throws ExecutionException
 
319
     */
 
320
    public void enableProbe(String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
 
321
        getControlService().enableProbe(getSessionName(), getName(), eventName, isFunction, probe, monitor);
 
322
    }
 
323
 
 
324
    /**
 
325
     * Enables events using log level.
 
326
     * @param eventName - a event name
 
327
     * @param logLevelType - a log level type 
 
328
     * @param level - a log level 
 
329
     * @throws ExecutionException
 
330
     */
 
331
    public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level) throws ExecutionException {
 
332
        enableLogLevel(eventName, logLevelType, level, new NullProgressMonitor());
 
333
    }
 
334
 
 
335
    /**
 
336
     * Enables events using log level.
 
337
     * @param eventName - a event name
 
338
     * @param logLevelType - a log level type 
 
339
     * @param level - a log level 
 
340
     * @param monitor - a progress monitor  
 
341
     * @throws ExecutionException
 
342
     */
 
343
    public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
 
344
        getControlService().enableLogLevel(getSessionName(), getName(), eventName, logLevelType, level, monitor);
 
345
    }
 
346
 
 
347
    /**
 
348
     * Enables a list of events with no additional parameters.
 
349
     * @param eventNames - a list of event names to enabled.
 
350
     * @throws ExecutionException
 
351
     */
 
352
    public void disableEvent(List<String> eventNames) throws ExecutionException {
 
353
        disableEvent(eventNames, new NullProgressMonitor());
 
354
    }
 
355
 
 
356
    /**
 
357
     * Enables a list of events with no additional parameters.
 
358
     * @param eventNames - a list of event names to enabled.
 
359
     * @param monitor - a progress monitor
 
360
     * @throws ExecutionException
 
361
     */
 
362
    public void disableEvent(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
 
363
        getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames, isKernel(), monitor);
 
364
    }
 
365
    
 
366
    /**
 
367
     * Add contexts to given channels and or events
 
368
     * @param contexts - a list of contexts to add
 
369
     * @throws ExecutionException
 
370
     */
 
371
    public void addContexts(List<String> contexts) throws ExecutionException {
 
372
        addContexts(contexts, new NullProgressMonitor());
 
373
    }
 
374
 
 
375
    /**
 
376
     * Add contexts to given channels and or events
 
377
     * @param contexts - a list of contexts to add
 
378
     * @param monitor - a progress monitor
 
379
     * @throws ExecutionException
 
380
     */
 
381
    public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
 
382
        getControlService().addContexts(getSessionName(), getName(), null, isKernel(), contexts, monitor);
 
383
    }
 
384
}