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