| 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.IBaseEventInfo; |
| 19 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo; |
| 20 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceEventType; |
| 21 | import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceLogLevel; |
| 22 | |
| 23 | /** |
| 24 | * <p> |
| 25 | * Implementation of the basic trace event interface (IEventInfo) to store event |
| 26 | * related data. |
| 27 | * </p> |
| 28 | * |
| 29 | * @author Bernd Hufmann |
| 30 | */ |
| 31 | public class BaseEventInfo extends TraceInfo implements IBaseEventInfo { |
| 32 | |
| 33 | // ------------------------------------------------------------------------ |
| 34 | // Attributes |
| 35 | // ------------------------------------------------------------------------ |
| 36 | /** |
| 37 | * The trace event type. |
| 38 | */ |
| 39 | private TraceEventType fEventType = TraceEventType.UNKNOWN; |
| 40 | /** |
| 41 | * The trace log level. |
| 42 | */ |
| 43 | private TraceLogLevel fLogLevel = TraceLogLevel.TRACE_DEBUG; |
| 44 | /** |
| 45 | * The Event fields |
| 46 | */ |
| 47 | private final List<IFieldInfo> fFields = new ArrayList<IFieldInfo>(); |
| 48 | /** |
| 49 | * The filter expression. |
| 50 | */ |
| 51 | private String fFilterExpression; |
| 52 | |
| 53 | // ------------------------------------------------------------------------ |
| 54 | // Constructors |
| 55 | // ------------------------------------------------------------------------ |
| 56 | /** |
| 57 | * Constructor |
| 58 | * @param name - name of base event |
| 59 | */ |
| 60 | public BaseEventInfo(String name) { |
| 61 | super(name); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Copy constructor |
| 66 | * @param other - the instance to copy |
| 67 | */ |
| 68 | public BaseEventInfo(BaseEventInfo other) { |
| 69 | super(other); |
| 70 | fEventType = other.fEventType; |
| 71 | if(other.fFields != null) { |
| 72 | for (Iterator<IFieldInfo> iterator = other.fFields.iterator(); iterator.hasNext();) { |
| 73 | IFieldInfo field = iterator.next(); |
| 74 | if (field instanceof FieldInfo) { |
| 75 | fFields.add(new FieldInfo((FieldInfo)field)); |
| 76 | } else { |
| 77 | fFields.add(field); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | fFilterExpression = other.fFilterExpression; |
| 82 | } |
| 83 | |
| 84 | // ------------------------------------------------------------------------ |
| 85 | // Accessors |
| 86 | // ------------------------------------------------------------------------ |
| 87 | /* |
| 88 | * (non-Javadoc) |
| 89 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#getEventType() |
| 90 | */ |
| 91 | @Override |
| 92 | public TraceEventType getEventType() { |
| 93 | return fEventType; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * (non-Javadoc) |
| 98 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#setEventType(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceEventType) |
| 99 | */ |
| 100 | @Override |
| 101 | public void setEventType(TraceEventType type) { |
| 102 | fEventType = type; |
| 103 | } |
| 104 | |
| 105 | /* |
| 106 | * (non-Javadoc) |
| 107 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#setEventType(java.lang.String) |
| 108 | */ |
| 109 | @Override |
| 110 | public void setEventType(String typeName) { |
| 111 | if(TraceEventType.TRACEPOINT.getInName().equals(typeName)) { |
| 112 | fEventType = TraceEventType.TRACEPOINT; |
| 113 | } else if(TraceEventType.SYSCALL.getInName().equals(typeName)) { |
| 114 | fEventType = TraceEventType.SYSCALL; |
| 115 | } else if (TraceEventType.PROBE.getInName().equals(typeName)) { |
| 116 | fEventType = TraceEventType.PROBE; |
| 117 | } else { |
| 118 | fEventType = TraceEventType.UNKNOWN; |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | * (non-Javadoc) |
| 124 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#getLogLevel() |
| 125 | */ |
| 126 | @Override |
| 127 | public TraceLogLevel getLogLevel() { |
| 128 | return fLogLevel; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * (non-Javadoc) |
| 133 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#setLogLevel(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceLogLevel) |
| 134 | */ |
| 135 | @Override |
| 136 | public void setLogLevel(TraceLogLevel level) { |
| 137 | fLogLevel = level; |
| 138 | } |
| 139 | |
| 140 | /* |
| 141 | * (non-Javadoc) |
| 142 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IBaseEventInfo#setLogLevel(java.lang.String) |
| 143 | */ |
| 144 | @Override |
| 145 | public void setLogLevel(String levelName) { |
| 146 | if(TraceLogLevel.TRACE_EMERG.getInName().equals(levelName)) { |
| 147 | fLogLevel = TraceLogLevel.TRACE_EMERG; |
| 148 | } else if(TraceLogLevel.TRACE_ALERT.getInName().equals(levelName)) { |
| 149 | fLogLevel = TraceLogLevel.TRACE_ALERT; |
| 150 | } else if(TraceLogLevel.TRACE_CRIT.getInName().equals(levelName)) { |
| 151 | fLogLevel = TraceLogLevel.TRACE_CRIT; |
| 152 | } else if(TraceLogLevel.TRACE_ERR.getInName().equals(levelName)) { |
| 153 | fLogLevel = TraceLogLevel.TRACE_ERR; |
| 154 | } else if(TraceLogLevel.TRACE_WARNING.getInName().equals(levelName)) { |
| 155 | fLogLevel = TraceLogLevel.TRACE_WARNING; |
| 156 | } else if(TraceLogLevel.TRACE_NOTICE.getInName().equals(levelName)) { |
| 157 | fLogLevel = TraceLogLevel.TRACE_NOTICE; |
| 158 | } else if(TraceLogLevel.TRACE_INFO.getInName().equals(levelName)) { |
| 159 | fLogLevel = TraceLogLevel.TRACE_INFO; |
| 160 | } else if(TraceLogLevel.TRACE_DEBUG_SYSTEM.getInName().equals(levelName)) { |
| 161 | fLogLevel = TraceLogLevel.TRACE_DEBUG_SYSTEM; |
| 162 | } else if(TraceLogLevel.TRACE_DEBUG_PROGRAM.getInName().equals(levelName)) { |
| 163 | fLogLevel = TraceLogLevel.TRACE_DEBUG_PROGRAM; |
| 164 | } else if(TraceLogLevel.TRACE_DEBUG_PROCESS.getInName().equals(levelName)) { |
| 165 | fLogLevel = TraceLogLevel.TRACE_DEBUG_PROCESS; |
| 166 | } else if(TraceLogLevel.TRACE_DEBUG_MODULE.getInName().equals(levelName)) { |
| 167 | fLogLevel = TraceLogLevel.TRACE_DEBUG_MODULE; |
| 168 | } else if(TraceLogLevel.TRACE_DEBUG_UNIT.getInName().equals(levelName)) { |
| 169 | fLogLevel = TraceLogLevel.TRACE_DEBUG_UNIT; |
| 170 | } else if(TraceLogLevel.TRACE_DEBUG_FUNCTION.getInName().equals(levelName)) { |
| 171 | fLogLevel = TraceLogLevel.TRACE_DEBUG_FUNCTION; |
| 172 | } else if(TraceLogLevel.TRACE_DEBUG_LINE.getInName().equals(levelName)) { |
| 173 | fLogLevel = TraceLogLevel.TRACE_DEBUG_LINE; |
| 174 | } else if(TraceLogLevel.TRACE_DEBUG.getInName().equals(levelName)) { |
| 175 | fLogLevel = TraceLogLevel.TRACE_DEBUG; |
| 176 | } else if(TraceLogLevel.LEVEL_UNKNOWN.getInName().equals(levelName)) { |
| 177 | fLogLevel = TraceLogLevel.LEVEL_UNKNOWN; |
| 178 | } else { |
| 179 | fLogLevel = TraceLogLevel.TRACE_DEBUG; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | /* |
| 184 | * (non-Javadoc) |
| 185 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo#getFields() |
| 186 | */ |
| 187 | @Override |
| 188 | public IFieldInfo[] getFields() { |
| 189 | return fFields.toArray(new IFieldInfo[fFields.size()]); |
| 190 | } |
| 191 | |
| 192 | /* |
| 193 | * (non-Javadoc) |
| 194 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo#addField(org.eclipse.linuxtools.internal.lttng2.core.control.model.IFieldInfo) |
| 195 | */ |
| 196 | @Override |
| 197 | public void addField(IFieldInfo field) { |
| 198 | fFields.add(field); |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * (non-Javadoc) |
| 203 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo#setFields(java.util.List) |
| 204 | */ |
| 205 | @Override |
| 206 | public void setFields(List<IFieldInfo> fields) { |
| 207 | for (Iterator<IFieldInfo> iterator = fields.iterator(); iterator.hasNext();) { |
| 208 | IFieldInfo fieldInfo = iterator.next(); |
| 209 | fFields.add(fieldInfo); |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * (non-Javadoc) |
| 215 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo#getFilterExpression() |
| 216 | */ |
| 217 | @Override |
| 218 | public String getFilterExpression() { |
| 219 | return fFilterExpression; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * (non-Javadoc) |
| 224 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.IBaseEventInfo#setFilterExpression(java.lang.String) |
| 225 | */ |
| 226 | @Override |
| 227 | public void setFilterExpression(String filter) { |
| 228 | fFilterExpression = filter; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | /* |
| 233 | * (non-Javadoc) |
| 234 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.TraceInfo#hashCode() |
| 235 | */ |
| 236 | @Override |
| 237 | public int hashCode() { |
| 238 | final int prime = 31; |
| 239 | int result = super.hashCode(); |
| 240 | result = prime * result + ((fEventType == null) ? 0 : fEventType.hashCode()); |
| 241 | result = prime * result + ((fFields == null) ? 0 : fFields.hashCode()); |
| 242 | result = prime * result + ((fFilterExpression == null) ? 0 : fFilterExpression.hashCode()); |
| 243 | result = prime * result + ((fLogLevel == null) ? 0 : fLogLevel.hashCode()); |
| 244 | return result; |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * (non-Javadoc) |
| 249 | * @see org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.TraceInfo#equals(java.lang.Object) |
| 250 | */ |
| 251 | @Override |
| 252 | public boolean equals(Object obj) { |
| 253 | if (this == obj) { |
| 254 | return true; |
| 255 | } |
| 256 | if (!super.equals(obj)) { |
| 257 | return false; |
| 258 | } |
| 259 | if (getClass() != obj.getClass()) { |
| 260 | return false; |
| 261 | } |
| 262 | BaseEventInfo other = (BaseEventInfo) obj; |
| 263 | if (fEventType != other.fEventType) { |
| 264 | return false; |
| 265 | } |
| 266 | if (fFields == null) { |
| 267 | if (other.fFields != null) { |
| 268 | return false; |
| 269 | } |
| 270 | } else if (!fFields.equals(other.fFields)) { |
| 271 | return false; |
| 272 | } |
| 273 | if (fFilterExpression == null) { |
| 274 | if (other.fFilterExpression != null) { |
| 275 | return false; |
| 276 | } |
| 277 | } else if (!fFilterExpression.equals(other.fFilterExpression)) { |
| 278 | return false; |
| 279 | } |
| 280 | if (fLogLevel != other.fLogLevel) { |
| 281 | return false; |
| 282 | } |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | /* |
| 287 | * (non-Javadoc) |
| 288 | * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceInfo#toString() |
| 289 | */ |
| 290 | @SuppressWarnings("nls") |
| 291 | @Override |
| 292 | public String toString() { |
| 293 | StringBuffer output = new StringBuffer(); |
| 294 | output.append("[BaseEventInfo("); |
| 295 | output.append(super.toString()); |
| 296 | output.append(",type="); |
| 297 | output.append(fEventType); |
| 298 | output.append(",level="); |
| 299 | output.append(fLogLevel); |
| 300 | if ((fFields != null) && (!fFields.isEmpty())) { |
| 301 | output.append(",Fields="); |
| 302 | for (Iterator<IFieldInfo> iterator = fFields.iterator(); iterator.hasNext();) { |
| 303 | IFieldInfo field = iterator.next(); |
| 304 | output.append(field.toString()); |
| 305 | } |
| 306 | } |
| 307 | if (fFilterExpression != null) { |
| 308 | output.append(",Filter="); |
| 309 | output.append(fFilterExpression); |
| 310 | } |
| 311 | output.append(")]"); |
| 312 | return output.toString(); |
| 313 | } |
| 314 | } |