| 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.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.ISnapshotInfo; |
| 22 | import org.eclipse.linuxtools.internal.lttng2.core.control.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 ISnapshotInfo fSnapshotInfo = null; |
| 57 | |
| 58 | |
| 59 | // ------------------------------------------------------------------------ |
| 60 | // Constructors |
| 61 | // ------------------------------------------------------------------------ |
| 62 | /** |
| 63 | * Constructor |
| 64 | * @param name - name of base event |
| 65 | */ |
| 66 | public SessionInfo(String name) { |
| 67 | super(name); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Copy constructor |
| 72 | * @param other - the instance to copy |
| 73 | */ |
| 74 | public SessionInfo(SessionInfo other) { |
| 75 | super(other); |
| 76 | fState = other.fState; |
| 77 | fSessionPath = other.fSessionPath; |
| 78 | fIsStreamedTrace = other.fIsStreamedTrace; |
| 79 | fSnapshotInfo = other.fSnapshotInfo; |
| 80 | |
| 81 | for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) { |
| 82 | IDomainInfo domain = iterator.next(); |
| 83 | if (domain instanceof DomainInfo) { |
| 84 | fDomains.add(new DomainInfo((DomainInfo)domain)); |
| 85 | } else { |
| 86 | fDomains.add(domain); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // ------------------------------------------------------------------------ |
| 92 | // Accessors |
| 93 | // ------------------------------------------------------------------------ |
| 94 | |
| 95 | @Override |
| 96 | public TraceSessionState getSessionState() { |
| 97 | return fState; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public void setSessionState(TraceSessionState state) { |
| 102 | fState = state; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public void setSessionState(String stateName) { |
| 107 | if (TraceSessionState.INACTIVE.getInName().equals(stateName)) { |
| 108 | fState = TraceSessionState.INACTIVE; |
| 109 | } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) { |
| 110 | fState = TraceSessionState.ACTIVE; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String getSessionPath() { |
| 116 | if(isSnapshotSession()) { |
| 117 | return fSnapshotInfo.getSnapshotPath(); |
| 118 | } |
| 119 | return fSessionPath; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void setSessionPath(String path) { |
| 124 | fSessionPath = path; |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public IDomainInfo[] getDomains() { |
| 129 | return fDomains.toArray(new IDomainInfo[fDomains.size()]); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void setDomains(List<IDomainInfo> domains) { |
| 134 | fDomains.clear(); |
| 135 | for (Iterator<IDomainInfo> iterator = domains.iterator(); iterator.hasNext();) { |
| 136 | IDomainInfo domainInfo = iterator.next(); |
| 137 | fDomains.add(domainInfo); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public boolean isStreamedTrace() { |
| 143 | if (isSnapshotSession()) { |
| 144 | return fSnapshotInfo.isStreamedSnapshot(); |
| 145 | } |
| 146 | return fIsStreamedTrace; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public void setStreamedTrace(boolean isStreamedTrace) { |
| 151 | fIsStreamedTrace = isStreamedTrace; |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public boolean isSnapshotSession() { |
| 156 | return fSnapshotInfo != null; |
| 157 | } |
| 158 | |
| 159 | @Override |
| 160 | public ISnapshotInfo getSnapshotInfo() { |
| 161 | return fSnapshotInfo; |
| 162 | } |
| 163 | |
| 164 | @Override |
| 165 | public void setSnapshotInfo(ISnapshotInfo info) { |
| 166 | fSnapshotInfo = info; |
| 167 | } |
| 168 | |
| 169 | // ------------------------------------------------------------------------ |
| 170 | // Operations |
| 171 | // ------------------------------------------------------------------------ |
| 172 | |
| 173 | @Override |
| 174 | public void addDomain(IDomainInfo domainInfo) { |
| 175 | fDomains.add(domainInfo); |
| 176 | } |
| 177 | |
| 178 | |
| 179 | @SuppressWarnings("nls") |
| 180 | @Override |
| 181 | public String toString() { |
| 182 | StringBuffer output = new StringBuffer(); |
| 183 | output.append("[SessionInfo("); |
| 184 | output.append(super.toString()); |
| 185 | output.append(",Path="); |
| 186 | output.append(getSessionPath()); |
| 187 | output.append(",State="); |
| 188 | output.append(fState); |
| 189 | output.append(",isStreamedTrace="); |
| 190 | output.append(fIsStreamedTrace); |
| 191 | if (fSnapshotInfo != null) { |
| 192 | output.append(",snapshotInfo="); |
| 193 | output.append(fSnapshotInfo.toString()); |
| 194 | } |
| 195 | output.append(",Domains="); |
| 196 | for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) { |
| 197 | IDomainInfo domain = iterator.next(); |
| 198 | output.append(domain.toString()); |
| 199 | } |
| 200 | output.append(")]"); |
| 201 | return output.toString(); |
| 202 | } |
| 203 | } |