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.IDomainInfo; |
19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo; | |
20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState; | |
eb1bab5b BH |
21 | |
22 | /** | |
eb1bab5b BH |
23 | * <p> |
24 | * Implementation of the trace session interface (ISessionInfo) to store session | |
25 | * related data. | |
26 | * </p> | |
dbd4432d BH |
27 | * |
28 | * @author Bernd Hufmann | |
eb1bab5b BH |
29 | */ |
30 | public class SessionInfo extends TraceInfo implements ISessionInfo { | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Attributes | |
34 | // ------------------------------------------------------------------------ | |
35 | /** | |
36 | * The trace session state. | |
37 | */ | |
38 | private TraceSessionState fState = TraceSessionState.INACTIVE; | |
39 | /** | |
40 | * The trace session path for storing traces. | |
41 | */ | |
42 | private String fSessionPath = ""; //$NON-NLS-1$ | |
43 | /** | |
44 | * The domains information of this session. | |
45 | */ | |
46 | private List<IDomainInfo> fDomains = new ArrayList<IDomainInfo>(); | |
47 | ||
48 | // ------------------------------------------------------------------------ | |
49 | // Constructors | |
50 | // ------------------------------------------------------------------------ | |
51 | /** | |
52 | * Constructor | |
53 | * @param name - name of base event | |
54 | */ | |
55 | public SessionInfo(String name) { | |
56 | super(name); | |
57 | } | |
58 | ||
59 | /** | |
60 | * Copy constructor | |
61 | * @param other - the instance to copy | |
62 | */ | |
63 | public SessionInfo(SessionInfo other) { | |
64 | super(other); | |
65 | fState = other.fState; | |
66 | fSessionPath = other.fSessionPath; | |
67 | ||
68 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { | |
69 | IDomainInfo domain = iterator.next(); | |
70 | if (domain instanceof DomainInfo) { | |
71 | fDomains.add(new DomainInfo((DomainInfo)domain)); | |
72 | } else { | |
73 | fDomains.add(domain); | |
74 | } | |
75 | } | |
76 | } | |
77 | ||
78 | // ------------------------------------------------------------------------ | |
79 | // Accessors | |
80 | // ------------------------------------------------------------------------ | |
81 | /* | |
82 | * (non-Javadoc) | |
115b4a01 | 83 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getSessionState() |
eb1bab5b BH |
84 | */ |
85 | @Override | |
86 | public TraceSessionState getSessionState() { | |
87 | return fState; | |
88 | } | |
89 | ||
90 | /* | |
91 | * (non-Javadoc) | |
115b4a01 | 92 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionState(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState) |
eb1bab5b BH |
93 | */ |
94 | @Override | |
95 | public void setSessionState(TraceSessionState state) { | |
96 | fState = state; | |
97 | } | |
98 | ||
99 | /* | |
100 | * (non-Javadoc) | |
115b4a01 | 101 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionState(java.lang.String) |
eb1bab5b BH |
102 | */ |
103 | @Override | |
104 | public void setSessionState(String stateName) { | |
105 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { | |
106 | fState = TraceSessionState.INACTIVE; | |
107 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { | |
108 | fState = TraceSessionState.ACTIVE; | |
109 | } | |
110 | } | |
111 | ||
112 | /* | |
113 | * (non-Javadoc) | |
115b4a01 | 114 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getSessionPath() |
eb1bab5b BH |
115 | */ |
116 | @Override | |
117 | public String getSessionPath() { | |
118 | return fSessionPath; | |
119 | } | |
120 | ||
121 | /* | |
122 | * (non-Javadoc) | |
115b4a01 | 123 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setSessionPath(java.lang.String) |
eb1bab5b BH |
124 | */ |
125 | @Override | |
126 | public void setSessionPath(String path) { | |
127 | fSessionPath = path; | |
128 | } | |
129 | ||
130 | /* | |
131 | * (non-Javadoc) | |
115b4a01 | 132 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#getDomains() |
eb1bab5b BH |
133 | */ |
134 | @Override | |
135 | public IDomainInfo[] getDomains() { | |
136 | return fDomains.toArray(new IDomainInfo[fDomains.size()]); | |
137 | } | |
138 | ||
139 | /* | |
140 | * (non-Javadoc) | |
115b4a01 | 141 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#setDomains(java.util.List) |
eb1bab5b BH |
142 | */ |
143 | @Override | |
144 | public void setDomains(List<IDomainInfo> domains) { | |
145 | for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) { | |
146 | IDomainInfo domainInfo = (IDomainInfo) iterator.next(); | |
147 | fDomains.add(domainInfo); | |
148 | } | |
149 | } | |
150 | ||
151 | // ------------------------------------------------------------------------ | |
152 | // Operations | |
153 | // ------------------------------------------------------------------------ | |
154 | /* | |
155 | * (non-Javadoc) | |
115b4a01 | 156 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ISessionInfo#addDomain(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IDomainInfo) |
eb1bab5b BH |
157 | */ |
158 | @Override | |
159 | public void addDomain(IDomainInfo domainInfo) { | |
160 | fDomains.add(domainInfo); | |
161 | } | |
d132bcc7 BH |
162 | |
163 | /* | |
164 | * (non-Javadoc) | |
115b4a01 | 165 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#hashCode() |
d132bcc7 BH |
166 | */ |
167 | @Override | |
168 | public int hashCode() { | |
169 | final int prime = 31; | |
170 | int result = super.hashCode(); | |
171 | result = prime * result + ((fDomains == null) ? 0 : fDomains.hashCode()); | |
172 | result = prime * result + ((fSessionPath == null) ? 0 : fSessionPath.hashCode()); | |
173 | result = prime * result + ((fState == null) ? 0 : (fState.ordinal() + 1)); | |
eb1bab5b BH |
174 | return result; |
175 | } | |
176 | ||
177 | /* | |
178 | * (non-Javadoc) | |
115b4a01 | 179 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#equals(java.lang.Object) |
eb1bab5b BH |
180 | */ |
181 | @Override | |
d132bcc7 BH |
182 | public boolean equals(Object obj) { |
183 | if (this == obj) { | |
184 | return true; | |
eb1bab5b | 185 | } |
d132bcc7 | 186 | if (!super.equals(obj)) { |
eb1bab5b BH |
187 | return false; |
188 | } | |
d132bcc7 | 189 | if (getClass() != obj.getClass()) { |
eb1bab5b BH |
190 | return false; |
191 | } | |
d132bcc7 BH |
192 | SessionInfo other = (SessionInfo) obj; |
193 | if (fDomains == null) { | |
194 | if (other.fDomains != null) { | |
195 | return false; | |
196 | } | |
197 | } else if (!fDomains.equals(other.fDomains)) { | |
eb1bab5b BH |
198 | return false; |
199 | } | |
d132bcc7 BH |
200 | if (fSessionPath == null) { |
201 | if (other.fSessionPath != null) { | |
eb1bab5b BH |
202 | return false; |
203 | } | |
d132bcc7 BH |
204 | } else if (!fSessionPath.equals(other.fSessionPath)) { |
205 | return false; | |
206 | } | |
207 | if (fState != other.fState) { | |
208 | return false; | |
eb1bab5b BH |
209 | } |
210 | return true; | |
211 | } | |
d132bcc7 | 212 | |
eb1bab5b BH |
213 | /* |
214 | * (non-Javadoc) | |
115b4a01 | 215 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString() |
eb1bab5b BH |
216 | */ |
217 | @SuppressWarnings("nls") | |
218 | @Override | |
219 | public String toString() { | |
220 | StringBuffer output = new StringBuffer(); | |
221 | output.append("[SessionInfo("); | |
222 | output.append(super.toString()); | |
223 | output.append(",State="); | |
224 | output.append(fState); | |
225 | output.append(",Domains="); | |
226 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { | |
d132bcc7 BH |
227 | IDomainInfo domain = (IDomainInfo) iterator.next(); |
228 | output.append(domain.toString()); | |
eb1bab5b BH |
229 | } |
230 | output.append(")]"); | |
231 | return output.toString(); | |
232 | } | |
233 | } |