| 1 | /********************************************************************** |
| 2 | * Copyright (c) 2012, 2014 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.control.core.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.control.core.model.IDomainInfo; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState; |
| 23 | |
| 24 | /** |
| 25 | * <p> |
| 26 | * Implementation of the trace session interface (ISessionInfo) to store session |
| 27 | * related data. |
| 28 | * </p> |
| 29 | * |
| 30 | * @author Bernd Hufmann |
| 31 | */ |
| 32 | public class SessionInfo extends TraceInfo implements ISessionInfo { |
| 33 | |
| 34 | // ------------------------------------------------------------------------ |
| 35 | // Attributes |
| 36 | // ------------------------------------------------------------------------ |
| 37 | /** |
| 38 | * The trace session state. |
| 39 | */ |
| 40 | private TraceSessionState fState = TraceSessionState.INACTIVE; |
| 41 | /** |
| 42 | * The trace session path for storing traces. |
| 43 | */ |
| 44 | private String fSessionPath = ""; //$NON-NLS-1$ |
| 45 | /** |
| 46 | * The domains information of this session. |
| 47 | */ |
| 48 | private final List<IDomainInfo> fDomains = new ArrayList<>(); |
| 49 | /** |
| 50 | * Flag to indicate whether trace is streamed over network or not. |
| 51 | */ |
| 52 | private boolean fIsStreamedTrace = false; |
| 53 | /** |
| 54 | * Flag to indicate whether the session is a snapshot session or not. |
| 55 | */ |
| 56 | private boolean fIsSnapshot = false; |
| 57 | /** |
| 58 | * The snapshot information of the session |
| 59 | */ |
| 60 | private ISnapshotInfo fSnapshotInfo = null; |
| 61 | /** |
| 62 | * The network URL for the session (-U) |
| 63 | */ |
| 64 | private String fNetworkUrl = null; |
| 65 | /** |
| 66 | * The control URL for the session (-C) |
| 67 | */ |
| 68 | private String fControlUrl = null; |
| 69 | /** |
| 70 | * The data URL for the session (-D) |
| 71 | */ |
| 72 | private String fDataUrl = null; |
| 73 | |
| 74 | |
| 75 | // ------------------------------------------------------------------------ |
| 76 | // Constructors |
| 77 | // ------------------------------------------------------------------------ |
| 78 | /** |
| 79 | * Constructor |
| 80 | * @param name - name of base event |
| 81 | */ |
| 82 | public SessionInfo(String name) { |
| 83 | super(name); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Copy constructor |
| 88 | * @param other - the instance to copy |
| 89 | */ |
| 90 | public SessionInfo(SessionInfo other) { |
| 91 | super(other); |
| 92 | fState = other.fState; |
| 93 | fSessionPath = other.fSessionPath; |
| 94 | fIsStreamedTrace = other.fIsStreamedTrace; |
| 95 | fIsSnapshot = other.fIsSnapshot; |
| 96 | fSnapshotInfo = other.fSnapshotInfo; |
| 97 | fNetworkUrl = other.fNetworkUrl; |
| 98 | fControlUrl = other.fControlUrl; |
| 99 | fDataUrl = other.fDataUrl; |
| 100 | |
| 101 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { |
| 102 | IDomainInfo domain = iterator.next(); |
| 103 | if (domain instanceof DomainInfo) { |
| 104 | fDomains.add(new DomainInfo((DomainInfo)domain)); |
| 105 | } else { |
| 106 | fDomains.add(domain); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // ------------------------------------------------------------------------ |
| 112 | // Accessors |
| 113 | // ------------------------------------------------------------------------ |
| 114 | |
| 115 | @Override |
| 116 | public TraceSessionState getSessionState() { |
| 117 | return fState; |
| 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void setSessionState(TraceSessionState state) { |
| 122 | fState = state; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public void setSessionState(String stateName) { |
| 127 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { |
| 128 | fState = TraceSessionState.INACTIVE; |
| 129 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { |
| 130 | fState = TraceSessionState.ACTIVE; |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public String getSessionPath() { |
| 136 | if (isSnapshotSession() && fSnapshotInfo != null) { |
| 137 | return fSnapshotInfo.getSnapshotPath(); |
| 138 | } |
| 139 | return fSessionPath; |
| 140 | } |
| 141 | |
| 142 | @Override |
| 143 | public void setSessionPath(String path) { |
| 144 | fSessionPath = path; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public IDomainInfo[] getDomains() { |
| 149 | return fDomains.toArray(new IDomainInfo[fDomains.size()]); |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | public void setDomains(List<IDomainInfo> domains) { |
| 154 | fDomains.clear(); |
| 155 | for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) { |
| 156 | IDomainInfo domainInfo = iterator.next(); |
| 157 | fDomains.add(domainInfo); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | @Override |
| 162 | public boolean isStreamedTrace() { |
| 163 | return fIsStreamedTrace; |
| 164 | } |
| 165 | |
| 166 | @Override |
| 167 | public void setStreamedTrace(boolean isStreamedTrace) { |
| 168 | fIsStreamedTrace = isStreamedTrace; |
| 169 | } |
| 170 | |
| 171 | @Override |
| 172 | public boolean isSnapshotSession() { |
| 173 | return fIsSnapshot || fSnapshotInfo != null; |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void setSnapshot(boolean isSnapshot) { |
| 178 | fIsSnapshot = isSnapshot; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public ISnapshotInfo getSnapshotInfo() { |
| 183 | return fSnapshotInfo; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public void setSnapshotInfo(ISnapshotInfo info) { |
| 188 | fSnapshotInfo = info; |
| 189 | } |
| 190 | |
| 191 | // ------------------------------------------------------------------------ |
| 192 | // Operations |
| 193 | // ------------------------------------------------------------------------ |
| 194 | |
| 195 | @Override |
| 196 | public void addDomain(IDomainInfo domainInfo) { |
| 197 | fDomains.add(domainInfo); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | @SuppressWarnings("nls") |
| 202 | @Override |
| 203 | public String toString() { |
| 204 | StringBuffer output = new StringBuffer(); |
| 205 | output.append("[SessionInfo("); |
| 206 | output.append(super.toString()); |
| 207 | output.append(",Path="); |
| 208 | output.append(getSessionPath()); |
| 209 | output.append(",State="); |
| 210 | output.append(fState); |
| 211 | output.append(",isStreamedTrace="); |
| 212 | output.append(fIsStreamedTrace); |
| 213 | output.append(",isSnapshot="); |
| 214 | output.append(fIsSnapshot); |
| 215 | |
| 216 | if (fSnapshotInfo != null) { |
| 217 | output.append(",snapshotInfo="); |
| 218 | output.append(fSnapshotInfo.toString()); |
| 219 | } |
| 220 | output.append(",Domains="); |
| 221 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { |
| 222 | IDomainInfo domain = iterator.next(); |
| 223 | output.append(domain.toString()); |
| 224 | } |
| 225 | |
| 226 | output.append(",NetworkUrl="); |
| 227 | output.append(getNetworkUrl()); |
| 228 | output.append(",ControlUrl="); |
| 229 | output.append(getControlUrl()); |
| 230 | output.append(",DataUrl="); |
| 231 | output.append(getDataUrl()); |
| 232 | |
| 233 | output.append(")]"); |
| 234 | return output.toString(); |
| 235 | } |
| 236 | |
| 237 | @Override |
| 238 | public String getNetworkUrl() { |
| 239 | return fNetworkUrl; |
| 240 | } |
| 241 | |
| 242 | @Override |
| 243 | public void setNetworkUrl(String networkUrl) { |
| 244 | fNetworkUrl = networkUrl; |
| 245 | } |
| 246 | |
| 247 | @Override |
| 248 | public String getControlUrl() { |
| 249 | return fControlUrl; |
| 250 | } |
| 251 | |
| 252 | @Override |
| 253 | public void setControlUrl(String controlUrl) { |
| 254 | fControlUrl = controlUrl; |
| 255 | } |
| 256 | |
| 257 | @Override |
| 258 | public void setDataUrl(String datalUrl) { |
| 259 | fDataUrl = datalUrl; |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public String getDataUrl() { |
| 264 | return fDataUrl; |
| 265 | } |
| 266 | } |