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