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