tmf: Split "CTF adaptor" into separate plugins/feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.kernel.core / src / org / eclipse / linuxtools / lttng2 / kernel / core / trace / LttngKernelTrace.java
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 * Alexandre Montplaisir - Initial API and implementation
11 * Matthew Khouzam - Improved validation
12 ******************************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.kernel.core.trace;
15
16 import java.nio.BufferOverflowException;
17
18 import org.eclipse.core.resources.IProject;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
22 import org.eclipse.linuxtools.ctf.core.trace.CTFTrace;
23 import org.eclipse.linuxtools.internal.lttng2.kernel.core.Activator;
24 import org.eclipse.linuxtools.tmf.core.trace.TraceValidationStatus;
25 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
26
27 /**
28 * This is the specification of CtfTmfTrace for use with LTTng 2.x kernel
29 * traces.
30 *
31 * @author Alexandre Montplaisir
32 * @since 2.0
33 */
34 public class LttngKernelTrace extends CtfTmfTrace {
35
36 private static final int CONFIDENCE = 100;
37
38 /**
39 * Default constructor
40 */
41 public LttngKernelTrace() {
42 super();
43 }
44
45 /**
46 * {@inheritDoc}
47 * <p>
48 * This implementation sets the confidence to 100 if the trace is a valid
49 * CTF trace in the "kernel" domain.
50 */
51 @Override
52 public IStatus validate(final IProject project, final String path) {
53 CTFTrace temp;
54 IStatus validStatus;
55 /*
56 * Make sure the trace is openable as a CTF trace. We do this here
57 * instead of calling super.validate() to keep the reference to "temp".
58 */
59 try {
60 temp = new CTFTrace(path);
61 } catch (CTFReaderException e) {
62 validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
63 return validStatus;
64 } catch (NullPointerException e){
65 validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
66 return validStatus;
67 } catch (final BufferOverflowException e) {
68 validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_TraceReadError + ": " + Messages.LttngKernelTrace_MalformedTrace); //$NON-NLS-1$
69 return validStatus;
70 }
71
72 /* Make sure the domain is "kernel" in the trace's env vars */
73 String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$
74 temp.dispose();
75 if (dom != null && dom.equals("\"kernel\"")) { //$NON-NLS-1$
76 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
77 }
78 validStatus = new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
79 return validStatus;
80 }
81
82 }
This page took 0.033246 seconds and 5 git commands to generate.