Merge branch 'master' into lttng_2_0_control_dev
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / internal / lttng / ui / views / control / model / impl / ChannelInfo.java
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.lttng.ui.views.control.model.impl;
13
14 import java.util.ArrayList;
15 import java.util.Iterator;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo;
19 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IEventInfo;
20 import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceEnablement;
21
22 /**
23 * <b><u>ChannelInfo</u></b>
24 * <p>
25 * Implementation of the trace channel interface (IChannelInfo) to store channel
26 * related data.
27 * </p>
28 */
29 public class ChannelInfo extends TraceInfo implements IChannelInfo {
30
31 // ------------------------------------------------------------------------
32 // Attributes
33 // ------------------------------------------------------------------------
34 /**
35 * The overwrite mode of the channel.
36 */
37 private boolean fOverwriteMode;
38 /**
39 * The sub-buffer size of the channel.
40 */
41 private long fSubBufferSize;
42 /**
43 * The number of sub-buffers of the channel.
44 */
45 private int fNumberOfSubBuffers;
46 /**
47 * The switch timer interval of the channel.
48 */
49 private long fSwitchTimer;
50 /**
51 * The read timer interval of the channel.
52 */
53 private long fReadTimer;
54 /**
55 * The Output type of the channel.
56 */
57 private String fOutputType = ""; //$NON-NLS-1$
58 /**
59 * The channel enable state.
60 */
61 private TraceEnablement fState = TraceEnablement.DISABLED;
62 /**
63 * The events information of the channel.
64 */
65 private List<IEventInfo> fEvents = new ArrayList<IEventInfo>();
66
67
68 // ------------------------------------------------------------------------
69 // Constructors
70 // ------------------------------------------------------------------------
71 /**
72 * Constructor
73 * @param name - name channel
74 */
75 public ChannelInfo(String name) {
76 super(name);
77 }
78
79 /**
80 * Copy constructor
81 * @param other - the instance to copy
82 */
83 public ChannelInfo(ChannelInfo other) {
84 super(other);
85 fOverwriteMode = other.fOverwriteMode;
86 fSubBufferSize = other.fSubBufferSize;
87 fNumberOfSubBuffers = other.fNumberOfSubBuffers;
88 fSwitchTimer = other.fSwitchTimer;
89 fReadTimer = other.fReadTimer;
90 fOutputType = (other.fOutputType == null ? null : String.valueOf(other.fOutputType));
91 fState = other.fState;
92 for (Iterator<IEventInfo> iterator = other.fEvents.iterator(); iterator.hasNext();) {
93 IEventInfo event = iterator.next();
94 if (event instanceof EventInfo) {
95 fEvents.add(new EventInfo((EventInfo)event));
96 } else {
97 fEvents.add(event);
98 }
99 }
100 }
101
102 // ------------------------------------------------------------------------
103 // Accessors
104 // ------------------------------------------------------------------------
105 /*
106 * (non-Javadoc)
107 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getOverwriteMode()
108 */
109 @Override
110 public boolean isOverwriteMode() {
111 return fOverwriteMode;
112 }
113
114 /*
115 * (non-Javadoc)
116 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setOverwriteMode(boolean)
117 */
118 @Override
119 public void setOverwriteMode(boolean mode) {
120 fOverwriteMode = mode;
121 }
122
123 /*
124 * (non-Javadoc)
125 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getSubBufferSize()
126 */
127 @Override
128 public long getSubBufferSize() {
129 return fSubBufferSize;
130 }
131
132 /*
133 * (non-Javadoc)
134 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setSubBufferSize(long)
135 */
136 @Override
137 public void setSubBufferSize(long bufferSize) {
138 fSubBufferSize = bufferSize;
139
140 }
141
142 /*
143 * (non-Javadoc)
144 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getNumberOfSubBuffers()
145 */
146 @Override
147 public int getNumberOfSubBuffers() {
148 return fNumberOfSubBuffers;
149 }
150
151 /*
152 * (non-Javadoc)
153 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setNumberOfSubBuffers(int)
154 */
155 @Override
156 public void setNumberOfSubBuffers(int numberOfSubBuffers) {
157 fNumberOfSubBuffers = numberOfSubBuffers;
158 }
159
160 /*
161 * (non-Javadoc)
162 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getSwitchTimer()
163 */
164 @Override
165 public long getSwitchTimer() {
166 return fSwitchTimer;
167 }
168
169 /*
170 * (non-Javadoc)
171 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setSwitchTimer(long)
172 */
173 @Override
174 public void setSwitchTimer(long timer) {
175 fSwitchTimer = timer;
176 }
177
178 /*
179 * (non-Javadoc)
180 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getReadTimer()
181 */
182 @Override
183 public long getReadTimer() {
184 return fReadTimer;
185 }
186
187 /*
188 * (non-Javadoc)
189 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setReadTimer(long)
190 */
191 @Override
192 public void setReadTimer(long timer) {
193 fReadTimer = timer;
194 }
195
196 /*
197 * (non-Javadoc)
198 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getOutputType()
199 */
200 @Override
201 public String getOutputType() {
202 return fOutputType;
203 }
204
205 /*
206 * (non-Javadoc)
207 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setOutputType(java.lang.String)
208 */
209 @Override
210 public void setOutputType(String type) {
211 fOutputType = type;
212 }
213
214 /*
215 * (non-Javadoc)
216 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getState()
217 */
218 @Override
219 public TraceEnablement getState() {
220 return fState;
221 }
222
223 /*
224 * (non-Javadoc)
225 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.TraceEnablement)
226 */
227 @Override
228 public void setState(TraceEnablement state) {
229 fState = state;
230 }
231
232 /*
233 * (non-Javadoc)
234 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setState(java.lang.String)
235 */
236 @Override
237 public void setState(String stateName) {
238 fState = TraceEnablement.ENABLED;
239 if (TraceEnablement.DISABLED.getInName().equals(stateName)) {
240 fState = TraceEnablement.DISABLED;
241 } else if (TraceEnablement.ENABLED.getInName().equals(stateName)) {
242 fState = TraceEnablement.ENABLED;
243 }
244 }
245
246 /*
247 * (non-Javadoc)
248 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#getEvents()
249 */
250 @Override
251 public IEventInfo[] getEvents() {
252 return fEvents.toArray(new IEventInfo[fEvents.size()]);
253 }
254
255 /*
256 * (non-Javadoc)
257 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#setEvents(java.util.List)
258 */
259 @Override
260 public void setEvents(List<IEventInfo> events) {
261 for (Iterator<IEventInfo> iterator = events.iterator(); iterator.hasNext();) {
262 IEventInfo eventInfo = (IEventInfo) iterator.next();
263 fEvents.add(eventInfo);
264 }
265 }
266
267 /*
268 * (non-Javadoc)
269 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.IEventInfo)
270 */
271 @Override
272 public void addEvent(IEventInfo channel) {
273 fEvents.add(channel);
274 }
275
276 /*
277 * (non-Javadoc)
278 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.ITraceInfo#formatString()
279 */
280 @SuppressWarnings("nls")
281 @Override
282 public String formatString() {
283 StringBuffer output = new StringBuffer();
284 //- channel0: [enabled]
285 output.append("\n- ");
286 output.append(getName());
287 output.append(": [");
288 output.append(getState().getInName());
289 output.append("]\n");
290 // Attributes:
291 output.append("\n Attributes:\n");
292 // overwrite mode: 0
293 output.append(" overwrite mode: ");
294 output.append(isOverwriteMode() ? "1" : "0");
295 // subbufers size: 262144
296 output.append("\n subbufers size: ");
297 output.append(getSubBufferSize());
298 // number of subbufers: 4
299 output.append("\n number of subbufers: ");
300 output.append(getNumberOfSubBuffers());
301 // switch timer interval: 0
302 output.append("\n switch timer interval: ");
303 output.append(getSwitchTimer());
304 // read timer interval: 200
305 output.append("\n read timer interval: ");
306 output.append(getReadTimer());
307 // output: splice()
308 output.append("\n output: ");
309 output.append(getOutputType());
310 output.append("\n\n");
311
312 output.append(" Events:");
313 if (fEvents.isEmpty()) {
314 output.append("\n None");
315 } else {
316 for (Iterator<IEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) {
317 IEventInfo event = (IEventInfo) iterator.next();
318 output.append(event.formatString());
319 }
320 }
321 output.append("\n");
322
323 return output.toString();
324 }
325
326 /*
327 * (non-Javadoc)
328 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#hashCode()
329 */
330 @Override
331 public int hashCode() {
332 final int prime = 31;
333 int result = super.hashCode();
334 result = prime * result + ((fEvents == null) ? 0 : fEvents.hashCode());
335 result = prime * result + fNumberOfSubBuffers;
336 result = prime * result + ((fOutputType == null) ? 0 : fOutputType.hashCode());
337 result = prime * result + (fOverwriteMode ? 1231 : 1237);
338 result = prime * result + (int) (fReadTimer ^ (fReadTimer >>> 32));
339 result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1));
340 result = prime * result + (int) (fSubBufferSize ^ (fSubBufferSize >>> 32));
341 result = prime * result + (int) (fSwitchTimer ^ (fSwitchTimer >>> 32));
342 return result;
343 }
344
345 /*
346 * (non-Javadoc)
347 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
348 */
349 @Override
350 public boolean equals(Object obj) {
351 if (this == obj) {
352 return true;
353 }
354 if (!super.equals(obj)) {
355 return false;
356 }
357 if (getClass() != obj.getClass()) {
358 return false;
359 }
360 ChannelInfo other = (ChannelInfo) obj;
361 if (fEvents == null) {
362 if (other.fEvents != null) {
363 return false;
364 }
365 } else if (!fEvents.equals(other.fEvents)) {
366 return false;
367 }
368 if (fNumberOfSubBuffers != other.fNumberOfSubBuffers) {
369 return false;
370 }
371 if (fOutputType == null) {
372 if (other.fOutputType != null) {
373 return false;
374 }
375 } else if (!fOutputType.equals(other.fOutputType)) {
376 return false;
377 }
378 if (fOverwriteMode != other.fOverwriteMode) {
379 return false;
380 }
381 if (fReadTimer != other.fReadTimer) {
382 return false;
383 }
384 if (fState != other.fState) {
385 return false;
386 }
387 if (fSubBufferSize != other.fSubBufferSize) {
388 return false;
389 }
390 if (fSwitchTimer != other.fSwitchTimer) {
391 return false;
392 }
393 return true;
394 }
395
396 /*
397 * (non-Javadoc)
398 * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceInfo#toString()
399 */
400 @SuppressWarnings("nls")
401 @Override
402 public String toString() {
403 StringBuffer output = new StringBuffer();
404 output.append("[ChannelInfo(");
405 output.append(super.toString());
406 output.append(",State=");
407 output.append(fState);
408 output.append(",OverwriteMode=");
409 output.append(fOverwriteMode);
410 output.append(",SubBuffersSize=");
411 output.append(fSubBufferSize);
412 output.append(",NumberOfSubBuffers=");
413 output.append(fNumberOfSubBuffers);
414 output.append(",SwitchTimer=");
415 output.append(fSwitchTimer);
416 output.append(",ReadTimer=");
417 output.append(fReadTimer);
418 output.append(",output=");
419 output.append(fOutputType);
420 output.append(",Events=");
421 if (fEvents.isEmpty()) {
422 output.append("None");
423 } else {
424 for (Iterator<IEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) {
425 IEventInfo event = (IEventInfo) iterator.next();
426 output.append(event.toString());
427 }
428 }
429 output.append(")]");
430 return output.toString();
431 }
432
433
434 }
This page took 0.040299 seconds and 5 git commands to generate.