Commit | Line | Data |
---|---|---|
eb1bab5b BH |
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 | **********************************************************************/ | |
9315aeee | 12 | package org.eclipse.linuxtools.internal.lttng2.core.control.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
9315aeee BH |
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; | |
eb1bab5b BH |
21 | |
22 | /** | |
eb1bab5b BH |
23 | * <p> |
24 | * Implementation of the trace channel interface (IChannelInfo) to store channel | |
25 | * related data. | |
26 | * </p> | |
dbd4432d BH |
27 | * |
28 | * @author Bernd Hufmann | |
eb1bab5b BH |
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 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) | |
115b4a01 | 108 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOverwriteMode() |
eb1bab5b BH |
109 | */ |
110 | @Override | |
111 | public boolean isOverwriteMode() { | |
112 | return fOverwriteMode; | |
113 | } | |
114 | ||
115 | /* | |
116 | * (non-Javadoc) | |
115b4a01 | 117 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOverwriteMode(boolean) |
eb1bab5b BH |
118 | */ |
119 | @Override | |
120 | public void setOverwriteMode(boolean mode) { | |
121 | fOverwriteMode = mode; | |
122 | } | |
123 | ||
124 | /* | |
125 | * (non-Javadoc) | |
115b4a01 | 126 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSubBufferSize() |
eb1bab5b BH |
127 | */ |
128 | @Override | |
129 | public long getSubBufferSize() { | |
130 | return fSubBufferSize; | |
131 | } | |
132 | ||
133 | /* | |
134 | * (non-Javadoc) | |
115b4a01 | 135 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSubBufferSize(long) |
eb1bab5b BH |
136 | */ |
137 | @Override | |
138 | public void setSubBufferSize(long bufferSize) { | |
139 | fSubBufferSize = bufferSize; | |
140 | ||
141 | } | |
142 | ||
143 | /* | |
144 | * (non-Javadoc) | |
115b4a01 | 145 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getNumberOfSubBuffers() |
eb1bab5b BH |
146 | */ |
147 | @Override | |
148 | public int getNumberOfSubBuffers() { | |
149 | return fNumberOfSubBuffers; | |
150 | } | |
151 | ||
152 | /* | |
153 | * (non-Javadoc) | |
115b4a01 | 154 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setNumberOfSubBuffers(int) |
eb1bab5b BH |
155 | */ |
156 | @Override | |
157 | public void setNumberOfSubBuffers(int numberOfSubBuffers) { | |
158 | fNumberOfSubBuffers = numberOfSubBuffers; | |
159 | } | |
160 | ||
161 | /* | |
162 | * (non-Javadoc) | |
115b4a01 | 163 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getSwitchTimer() |
eb1bab5b BH |
164 | */ |
165 | @Override | |
166 | public long getSwitchTimer() { | |
167 | return fSwitchTimer; | |
168 | } | |
169 | ||
170 | /* | |
171 | * (non-Javadoc) | |
115b4a01 | 172 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setSwitchTimer(long) |
eb1bab5b BH |
173 | */ |
174 | @Override | |
175 | public void setSwitchTimer(long timer) { | |
176 | fSwitchTimer = timer; | |
177 | } | |
178 | ||
179 | /* | |
180 | * (non-Javadoc) | |
115b4a01 | 181 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getReadTimer() |
eb1bab5b BH |
182 | */ |
183 | @Override | |
184 | public long getReadTimer() { | |
185 | return fReadTimer; | |
186 | } | |
187 | ||
188 | /* | |
189 | * (non-Javadoc) | |
115b4a01 | 190 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setReadTimer(long) |
eb1bab5b BH |
191 | */ |
192 | @Override | |
193 | public void setReadTimer(long timer) { | |
194 | fReadTimer = timer; | |
195 | } | |
196 | ||
197 | /* | |
198 | * (non-Javadoc) | |
115b4a01 | 199 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getOutputType() |
eb1bab5b BH |
200 | */ |
201 | @Override | |
202 | public String getOutputType() { | |
203 | return fOutputType; | |
204 | } | |
205 | ||
206 | /* | |
207 | * (non-Javadoc) | |
115b4a01 | 208 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setOutputType(java.lang.String) |
eb1bab5b BH |
209 | */ |
210 | @Override | |
211 | public void setOutputType(String type) { | |
212 | fOutputType = type; | |
213 | } | |
214 | ||
215 | /* | |
216 | * (non-Javadoc) | |
115b4a01 | 217 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getState() |
eb1bab5b BH |
218 | */ |
219 | @Override | |
220 | public TraceEnablement getState() { | |
221 | return fState; | |
222 | } | |
223 | ||
224 | /* | |
225 | * (non-Javadoc) | |
115b4a01 | 226 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEnablement) |
eb1bab5b BH |
227 | */ |
228 | @Override | |
229 | public void setState(TraceEnablement state) { | |
230 | fState = state; | |
231 | } | |
232 | ||
233 | /* | |
234 | * (non-Javadoc) | |
115b4a01 | 235 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setState(java.lang.String) |
eb1bab5b BH |
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) | |
115b4a01 | 249 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#getEvents() |
eb1bab5b BH |
250 | */ |
251 | @Override | |
252 | public IEventInfo[] getEvents() { | |
253 | return fEvents.toArray(new IEventInfo[fEvents.size()]); | |
254 | } | |
255 | ||
256 | /* | |
257 | * (non-Javadoc) | |
115b4a01 | 258 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#setEvents(java.util.List) |
eb1bab5b BH |
259 | */ |
260 | @Override | |
261 | public void setEvents(List<IEventInfo> events) { | |
262 | for (Iterator<IEventInfo> iterator = events.iterator(); iterator.hasNext();) { | |
263 | IEventInfo eventInfo = (IEventInfo) iterator.next(); | |
264 | fEvents.add(eventInfo); | |
265 | } | |
266 | } | |
267 | ||
268 | /* | |
269 | * (non-Javadoc) | |
115b4a01 | 270 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IChannelInfo#addEvent(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo) |
eb1bab5b BH |
271 | */ |
272 | @Override | |
273 | public void addEvent(IEventInfo channel) { | |
274 | fEvents.add(channel); | |
275 | } | |
276 | ||
277 | /* | |
278 | * (non-Javadoc) | |
115b4a01 | 279 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode() |
eb1bab5b BH |
280 | */ |
281 | @Override | |
282 | public int hashCode() { | |
d132bcc7 BH |
283 | final int prime = 31; |
284 | int result = super.hashCode(); | |
285 | result = prime * result + ((fEvents == null) ? 0 : 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)); | |
eb1bab5b | 293 | return result; |
d132bcc7 | 294 | } |
eb1bab5b BH |
295 | |
296 | /* | |
297 | * (non-Javadoc) | |
115b4a01 | 298 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
299 | */ |
300 | @Override | |
d132bcc7 BH |
301 | public boolean equals(Object obj) { |
302 | if (this == obj) { | |
303 | return true; | |
eb1bab5b | 304 | } |
d132bcc7 | 305 | if (!super.equals(obj)) { |
eb1bab5b BH |
306 | return false; |
307 | } | |
d132bcc7 | 308 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
309 | return false; |
310 | } | |
d132bcc7 BH |
311 | ChannelInfo other = (ChannelInfo) obj; |
312 | if (fEvents == null) { | |
313 | if (other.fEvents != null) { | |
314 | return false; | |
315 | } | |
316 | } else if (!fEvents.equals(other.fEvents)) { | |
eb1bab5b BH |
317 | return false; |
318 | } | |
d132bcc7 | 319 | if (fNumberOfSubBuffers != other.fNumberOfSubBuffers) { |
eb1bab5b BH |
320 | return false; |
321 | } | |
d132bcc7 BH |
322 | if (fOutputType == null) { |
323 | if (other.fOutputType != null) { | |
324 | return false; | |
325 | } | |
326 | } else if (!fOutputType.equals(other.fOutputType)) { | |
eb1bab5b BH |
327 | return false; |
328 | } | |
d132bcc7 | 329 | if (fOverwriteMode != other.fOverwriteMode) { |
eb1bab5b BH |
330 | return false; |
331 | } | |
d132bcc7 | 332 | if (fReadTimer != other.fReadTimer) { |
eb1bab5b BH |
333 | return false; |
334 | } | |
d132bcc7 | 335 | if (fState != other.fState) { |
eb1bab5b BH |
336 | return false; |
337 | } | |
d132bcc7 | 338 | if (fSubBufferSize != other.fSubBufferSize) { |
eb1bab5b BH |
339 | return false; |
340 | } | |
d132bcc7 BH |
341 | if (fSwitchTimer != other.fSwitchTimer) { |
342 | return false; | |
eb1bab5b BH |
343 | } |
344 | return true; | |
345 | } | |
346 | ||
347 | /* | |
348 | * (non-Javadoc) | |
115b4a01 | 349 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
350 | */ |
351 | @SuppressWarnings("nls") | |
352 | @Override | |
353 | public String toString() { | |
354 | StringBuffer output = new StringBuffer(); | |
355 | output.append("[ChannelInfo("); | |
356 | output.append(super.toString()); | |
357 | output.append(",State="); | |
358 | output.append(fState); | |
359 | output.append(",OverwriteMode="); | |
360 | output.append(fOverwriteMode); | |
361 | output.append(",SubBuffersSize="); | |
362 | output.append(fSubBufferSize); | |
363 | output.append(",NumberOfSubBuffers="); | |
364 | output.append(fNumberOfSubBuffers); | |
365 | output.append(",SwitchTimer="); | |
366 | output.append(fSwitchTimer); | |
367 | output.append(",ReadTimer="); | |
368 | output.append(fReadTimer); | |
369 | output.append(",output="); | |
370 | output.append(fOutputType); | |
371 | output.append(",Events="); | |
372 | if (fEvents.isEmpty()) { | |
373 | output.append("None"); | |
374 | } else { | |
375 | for (Iterator<IEventInfo> iterator = fEvents.iterator(); iterator.hasNext();) { | |
376 | IEventInfo event = (IEventInfo) iterator.next(); | |
377 | output.append(event.toString()); | |
378 | } | |
379 | } | |
380 | output.append(")]"); | |
381 | return output.toString(); | |
382 | } | |
d132bcc7 BH |
383 | |
384 | ||
eb1bab5b | 385 | } |