tmf.ctf: Split the classes into proper packages
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / 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.tracecompass.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.tracecompass.ctf.core.trace.CTFReaderException;
22 import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
23 import org.eclipse.tracecompass.internal.lttng2.kernel.core.Activator;
24 import org.eclipse.tracecompass.tmf.core.trace.TraceValidationStatus;
25 import org.eclipse.tracecompass.tmf.ctf.core.trace.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 /*
54 * Make sure the trace is openable as a CTF trace. We do this here
55 * instead of calling super.validate() to keep the reference to "temp".
56 */
57 try (CTFTrace temp = new CTFTrace(path);) {
58 /* Make sure the domain is "kernel" in the trace's env vars */
59 String dom = temp.getEnvironment().get("domain"); //$NON-NLS-1$
60 if (dom != null && dom.equals("\"kernel\"")) { //$NON-NLS-1$
61 return new TraceValidationStatus(CONFIDENCE, Activator.PLUGIN_ID);
62 }
63 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_DomainError);
64
65 } catch (CTFReaderException e) {
66 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
67 } catch (NullPointerException e) {
68 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.toString(), e);
69 } catch (final BufferOverflowException e) {
70 return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.LttngKernelTrace_TraceReadError + ": " + Messages.LttngKernelTrace_MalformedTrace); //$NON-NLS-1$
71 }
72 }
73
74 }
This page took 0.060126 seconds and 5 git commands to generate.