Commit | Line | Data |
---|---|---|
eb1bab5b | 1 | /********************************************************************** |
60ae41e1 | 2 | * Copyright (c) 2012, 2014 Ericsson |
b0318660 | 3 | * |
eb1bab5b BH |
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 | |
b0318660 AM |
8 | * |
9 | * Contributors: | |
eb1bab5b BH |
10 | * Bernd Hufmann - Initial API and implementation |
11 | **********************************************************************/ | |
9bc60be7 | 12 | package org.eclipse.tracecompass.internal.lttng2.control.core.model.impl; |
eb1bab5b BH |
13 | |
14 | import java.util.ArrayList; | |
15 | import java.util.Iterator; | |
16 | import java.util.List; | |
17 | ||
9bc60be7 AM |
18 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IChannelInfo; |
19 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.IDomainInfo; | |
eb1bab5b BH |
20 | |
21 | /** | |
eb1bab5b BH |
22 | * <p> |
23 | * Implementation of the trace domain interface (IDomainInfo) to store domain | |
b0318660 | 24 | * related data. |
eb1bab5b | 25 | * </p> |
b0318660 | 26 | * |
dbd4432d | 27 | * @author Bernd Hufmann |
eb1bab5b BH |
28 | */ |
29 | public class DomainInfo extends TraceInfo implements IDomainInfo { | |
30 | ||
31 | // ------------------------------------------------------------------------ | |
32 | // Attributes | |
33 | // ------------------------------------------------------------------------ | |
34 | /** | |
35 | * The channels information of the domain. | |
36 | */ | |
e0838ca1 | 37 | private final List<IChannelInfo> fChannels = new ArrayList<>(); |
bbb3538a | 38 | private boolean fIsKernel = false; |
6303c000 | 39 | private BufferType fBufferType = BufferType.BUFFER_TYPE_UNKNOWN; |
eb1bab5b BH |
40 | |
41 | // ------------------------------------------------------------------------ | |
42 | // Constructors | |
43 | // ------------------------------------------------------------------------ | |
44 | /** | |
45 | * Constructor | |
46 | * @param name - name of domain | |
47 | */ | |
48 | public DomainInfo(String name) { | |
49 | super(name); | |
50 | } | |
51 | ||
52 | /** | |
53 | * Copy constructor | |
54 | * @param other - the instance to copy | |
55 | */ | |
56 | public DomainInfo(DomainInfo other) { | |
57 | super(other); | |
58 | for (int i = 0; i < other.fChannels.size(); i++) { | |
59 | if (other.fChannels.get(i) instanceof ChannelInfo) { | |
60 | fChannels.add(new ChannelInfo((ChannelInfo)other.fChannels.get(i))); | |
61 | } else { | |
62 | fChannels.add(other.fChannels.get(i)); | |
63 | } | |
64 | } | |
bbb3538a | 65 | fIsKernel = other.fIsKernel; |
83051fc3 | 66 | fBufferType = other.fBufferType; |
bbb3538a | 67 | } |
b0318660 | 68 | |
bbb3538a BH |
69 | @Override |
70 | public boolean isKernel() { | |
71 | return fIsKernel; | |
72 | } | |
b0318660 | 73 | |
bbb3538a BH |
74 | @Override |
75 | public void setIsKernel(boolean isKernel) { | |
76 | fIsKernel = isKernel; | |
eb1bab5b BH |
77 | } |
78 | ||
79 | // ------------------------------------------------------------------------ | |
80 | // Accessors | |
81 | // ------------------------------------------------------------------------ | |
11252342 | 82 | |
eb1bab5b BH |
83 | @Override |
84 | public IChannelInfo[] getChannels() { | |
85 | return fChannels.toArray(new IChannelInfo[fChannels.size()]); | |
86 | } | |
87 | ||
eb1bab5b BH |
88 | @Override |
89 | public void setChannels(List<IChannelInfo> channels) { | |
a6702bfa | 90 | fChannels.clear(); |
eb1bab5b | 91 | for (Iterator<IChannelInfo> iterator = channels.iterator(); iterator.hasNext();) { |
b0318660 | 92 | IChannelInfo channelInfo = iterator.next(); |
eb1bab5b BH |
93 | fChannels.add(channelInfo); |
94 | } | |
95 | } | |
96 | ||
eb1bab5b BH |
97 | @Override |
98 | public void addChannel(IChannelInfo channel) { | |
99 | fChannels.add(channel); | |
100 | } | |
b0318660 | 101 | |
eb1bab5b BH |
102 | @Override |
103 | public int hashCode() { | |
d132bcc7 BH |
104 | final int prime = 31; |
105 | int result = super.hashCode(); | |
77fdc5df | 106 | result = prime * result + fChannels.hashCode(); |
d132bcc7 | 107 | result = prime * result + (fIsKernel ? 1231 : 1237); |
83051fc3 | 108 | result = prime * result + ((fBufferType == null) ? 0 : (fBufferType.ordinal() + 1)); |
eb1bab5b BH |
109 | return result; |
110 | } | |
111 | ||
eb1bab5b | 112 | @Override |
d132bcc7 BH |
113 | public boolean equals(Object obj) { |
114 | if (this == obj) { | |
115 | return true; | |
eb1bab5b | 116 | } |
d132bcc7 | 117 | if (!super.equals(obj)) { |
eb1bab5b BH |
118 | return false; |
119 | } | |
d132bcc7 | 120 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
121 | return false; |
122 | } | |
d132bcc7 | 123 | DomainInfo other = (DomainInfo) obj; |
77fdc5df | 124 | if (!fChannels.equals(other.fChannels)) { |
d132bcc7 | 125 | return false; |
eb1bab5b | 126 | } |
d132bcc7 | 127 | if (fIsKernel != other.fIsKernel) { |
bbb3538a BH |
128 | return false; |
129 | } | |
83051fc3 BH |
130 | if (fBufferType != other.fBufferType) { |
131 | return false; | |
132 | } | |
eb1bab5b BH |
133 | return true; |
134 | } | |
d132bcc7 | 135 | |
ca8c54b3 | 136 | @Override |
83051fc3 | 137 | public BufferType getBufferType() { |
ca8c54b3 | 138 | if (fIsKernel) { |
83051fc3 | 139 | return BufferType.BUFFER_SHARED; |
ca8c54b3 SD |
140 | } |
141 | return fBufferType; | |
142 | } | |
143 | ||
144 | @Override | |
83051fc3 | 145 | public void setBufferType(BufferType bufferType) { |
ca8c54b3 SD |
146 | fBufferType = bufferType; |
147 | } | |
148 | ||
eb1bab5b BH |
149 | @SuppressWarnings("nls") |
150 | @Override | |
151 | public String toString() { | |
152 | StringBuffer output = new StringBuffer(); | |
153 | output.append("[DomainInfo("); | |
154 | output.append(super.toString()); | |
155 | output.append(",Channels="); | |
156 | if (fChannels.isEmpty()) { | |
157 | output.append("None"); | |
158 | } else { | |
159 | for (Iterator<IChannelInfo> iterator = fChannels.iterator(); iterator.hasNext();) { | |
b0318660 | 160 | IChannelInfo channel = iterator.next(); |
eb1bab5b BH |
161 | output.append(channel.toString()); |
162 | } | |
163 | } | |
bbb3538a BH |
164 | output.append(",isKernel="); |
165 | output.append(String.valueOf(fIsKernel)); | |
6303c000 | 166 | if ((fBufferType != null) && !fBufferType.equals(BufferType.BUFFER_TYPE_UNKNOWN) && !fBufferType.equals(BufferType.BUFFER_SHARED)) { |
83051fc3 BH |
167 | output.append(",BufferType="); |
168 | output.append(fBufferType); | |
169 | } | |
eb1bab5b BH |
170 | output.append(")]"); |
171 | return output.toString(); | |
172 | } | |
173 | } |