Improve package tangle index for LTTng 2.0 control design
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core / src / org / eclipse / linuxtools / internal / lttng2 / core / 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.lttng2.core.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.lttng2.core.control.model.IChannelInfo;
19 import org.eclipse.linuxtools.internal.lttng2.core.control.model.IEventInfo;
20 import org.eclipse.linuxtools.internal.lttng2.core.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.internal.lttng2.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.lttng2.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.lttng2.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.lttng2.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.lttng2.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.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.lttng2.ui.views.control.model.impl.TraceInfo#hashCode()
279 */
280 @Override
281 public int hashCode() {
282 final int prime = 31;
283 int result = super.hashCode();
284 result = prime * result + ((fEvents == null) ? 0 : fEvents.hashCode());
285 result = prime * result + fNumberOfSubBuffers;
286 result = prime * result + ((fOutputType == null) ? 0 : fOutputType.hashCode());
287 result = prime * result + (fOverwriteMode ? 1231 : 1237);
288 result = prime * result + (int) (fReadTimer ^ (fReadTimer >>> 32));
289 result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1));
290 result = prime * result + (int) (fSubBufferSize ^ (fSubBufferSize >>> 32));
291 result = prime * result + (int) (fSwitchTimer ^ (fSwitchTimer >>> 32));
292 return result;
293 }
294
295 /*
296 * (non-Javadoc)
297 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object)
298 */
299 @Override
300 public boolean equals(Object obj) {
301 if (this == obj) {
302 return true;
303 }
304 if (!super.equals(obj)) {
305 return false;
306 }
307 if (getClass() != obj.getClass()) {
308 return false;
309 }
310 ChannelInfo other = (ChannelInfo) obj;
311 if (fEvents == null) {
312 if (other.fEvents != null) {
313 return false;
314 }
315 } else if (!fEvents.equals(other.fEvents)) {
316 return false;
317 }
318 if (fNumberOfSubBuffers != other.fNumberOfSubBuffers) {
319 return false;
320 }
321 if (fOutputType == null) {
322 if (other.fOutputType != null) {
323 return false;
324 }
325 } else if (!fOutputType.equals(other.fOutputType)) {
326 return false;
327 }
328 if (fOverwriteMode != other.fOverwriteMode) {
329 return false;
330 }
331 if (fReadTimer != other.fReadTimer) {
332 return false;
333 }
334 if (fState != other.fState) {
335 return false;
336 }
337 if (fSubBufferSize != other.fSubBufferSize) {
338 return false;
339 }
340 if (fSwitchTimer != other.fSwitchTimer) {
341 return false;
342 }
343 return true;
344 }
345
346 /*
347 * (non-Javadoc)
348 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString()
349 */
350 @SuppressWarnings("nls")
351 @Override
352 public String toString() {
353 StringBuffer output = new StringBuffer();
354 output.append("[ChannelInfo(");
355 output.append(super.toString());
356 output.append(",State=");
357 output.append(fState);
358 output.append(",OverwriteMode=");
359 output.append(fOverwriteMode);
360 output.append(",SubBuffersSize=");
361 output.append(fSubBufferSize);
362 output.append(",NumberOfSubBuffers=");
363 output.append(fNumberOfSubBuffers);
364 output.append(",SwitchTimer=");
365 output.append(fSwitchTimer);
366 output.append(",ReadTimer=");
367 output.append(fReadTimer);
368 output.append(",output=");
369 output.append(fOutputType);
370 output.append(",Events=");
371 if (fEvents.isEmpty()) {
372 output.append("None");
373 } else {
374 for (Iterator<IEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) {
375 IEventInfo event = (IEventInfo) iterator.next();
376 output.append(event.toString());
377 }
378 }
379 output.append(")]");
380 return output.toString();
381 }
382
383
384 }
This page took 0.046096 seconds and 6 git commands to generate.