tmf: lttngControl: mi: basic listing support
authorJonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Thu, 31 Jul 2014 17:13:30 +0000 (13:13 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 27 Aug 2014 15:26:09 +0000 (11:26 -0400)
Change-Id: I8ca572f88d5fff69c27c4f1f345187b3d71b5d0b
Signed-off-by: Jonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/30822
Tested-by: Hudson CI
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
15 files changed:
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceSessionState.java
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/BaseEventInfo.java
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/SessionInfo.java
org.eclipse.linuxtools.lttng2.control.ui.tests/src/org/eclipse/linuxtools/lttng2/control/ui/tests/service/LTTngControlServiceTest.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/handlers/XmlMiValidationErrorHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/Messages.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/messages/messages.properties
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/model/impl/TargetNodeComponent.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/ILttngControlService.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlService.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceConstants.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceFactory.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LttngVersion.java
org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/MIStrings.java [new file with mode: 0644]

index 4a96e030dfe9d688d35c80c3a943b61e596252b5..4473a11d67a2040dc9e1cbff74b8894794f131cb 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,13 +8,13 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Jonathan Rajotte - machine interface support and utility function
  *********************************************************************/
+
 package org.eclipse.linuxtools.internal.lttng2.control.core.model;
 
 /**
- * <p>
  * Session state enumeration.
- * </p>
  *
  * @author Bernd Hufmann
  */
@@ -24,9 +24,9 @@ public enum TraceSessionState {
     // Enum definition
     // ------------------------------------------------------------------------
     /** Trace session inactive */
-    INACTIVE("inactive"), //$NON-NLS-1$
+    INACTIVE("inactive", "false"), //$NON-NLS-1$ //$NON-NLS-2$
     /** Trace session active */
-    ACTIVE("active"); //$NON-NLS-1$
+    ACTIVE("active", "true"); //$NON-NLS-1$ //$NON-NLS-2$
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -35,6 +35,7 @@ public enum TraceSessionState {
      * Name of enum.
      */
     private final String fInName;
+    private final String fMiName;
 
     // ------------------------------------------------------------------------
     // Constuctors
@@ -42,10 +43,13 @@ public enum TraceSessionState {
 
     /**
      * Private constructor
-     * @param name the name of state
+     *
+     * @param name
+     *            the name of state
      */
-    private TraceSessionState(String name) {
+    private TraceSessionState(String name, String miName) {
         fInName = name;
+        fMiName = miName;
     }
 
     // ------------------------------------------------------------------------
@@ -57,4 +61,36 @@ public enum TraceSessionState {
     public String getInName() {
         return fInName;
     }
+
+    /**
+     * @return the machine interface name
+     */
+    public String getfMiName() {
+        return fMiName;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+    /**
+     * Return the corresponding {@link TraceSessionState} to String "name"
+     *
+     * @param name
+     *            String to compare to retrieve the good
+     *            {@link TraceSessionState}
+     * @return the corresponding {@link TraceSessionState}
+     */
+    public static TraceSessionState valueOfString(String name) {
+        if (name == null) {
+            return INACTIVE;
+        }
+        for (TraceSessionState tst : TraceSessionState.values()) {
+            boolean isEqual = tst.fInName.equalsIgnoreCase(name) || tst.fMiName.equalsIgnoreCase(name);
+            if (isEqual) {
+                return tst;
+            }
+        }
+        // No match
+        return INACTIVE;
+    }
 }
index 3b05baf9b63f3134a9b4a96d0867161a20e4db14..aee94936032f8e693f81b9cb0930513d9980eae6 100644 (file)
@@ -96,13 +96,13 @@ public class BaseEventInfo extends TraceInfo implements IBaseEventInfo {
 
     @Override
     public void setEventType(String typeName) {
-        if(TraceEventType.TRACEPOINT.getInName().equals(typeName)) {
+        if(TraceEventType.TRACEPOINT.getInName().equalsIgnoreCase(typeName)) {
             fEventType = TraceEventType.TRACEPOINT;
-        } else if(TraceEventType.SYSCALL.getInName().equals(typeName)) {
+        } else if(TraceEventType.SYSCALL.getInName().equalsIgnoreCase(typeName)) {
             fEventType = TraceEventType.SYSCALL;
-        } else if (TraceEventType.PROBE.getInName().equals(typeName)) {
+        } else if (TraceEventType.PROBE.getInName().equalsIgnoreCase(typeName)) {
             fEventType = TraceEventType.PROBE;
-        } else if (TraceEventType.FUNCTION.getInName().equals(typeName)) {
+        } else if (TraceEventType.FUNCTION.getInName().equalsIgnoreCase(typeName)) {
             fEventType = TraceEventType.FUNCTION;
         } else {
             fEventType = TraceEventType.UNKNOWN;
@@ -121,37 +121,37 @@ public class BaseEventInfo extends TraceInfo implements IBaseEventInfo {
 
     @Override
     public void setLogLevel(String levelName) {
-        if(TraceLogLevel.TRACE_EMERG.getInName().equals(levelName)) {
+        if(TraceLogLevel.TRACE_EMERG.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_EMERG;
-        } else if(TraceLogLevel.TRACE_ALERT.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_ALERT.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_ALERT;
-        } else if(TraceLogLevel.TRACE_CRIT.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_CRIT.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_CRIT;
-        } else if(TraceLogLevel.TRACE_ERR.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_ERR.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_ERR;
-        } else if(TraceLogLevel.TRACE_WARNING.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_WARNING.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_WARNING;
-        } else if(TraceLogLevel.TRACE_NOTICE.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_NOTICE.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_NOTICE;
-        } else if(TraceLogLevel.TRACE_INFO.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_INFO.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_INFO;
-        } else if(TraceLogLevel.TRACE_DEBUG_SYSTEM.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_SYSTEM.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_SYSTEM;
-        } else if(TraceLogLevel.TRACE_DEBUG_PROGRAM.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_PROGRAM.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_PROGRAM;
-        } else if(TraceLogLevel.TRACE_DEBUG_PROCESS.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_PROCESS.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_PROCESS;
-        } else if(TraceLogLevel.TRACE_DEBUG_MODULE.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_MODULE.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_MODULE;
-        } else if(TraceLogLevel.TRACE_DEBUG_UNIT.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_UNIT.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_UNIT;
-        } else if(TraceLogLevel.TRACE_DEBUG_FUNCTION.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_FUNCTION.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_FUNCTION;
-        } else if(TraceLogLevel.TRACE_DEBUG_LINE.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG_LINE.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG_LINE;
-        } else if(TraceLogLevel.TRACE_DEBUG.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.TRACE_DEBUG.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.TRACE_DEBUG;
-        } else if(TraceLogLevel.LEVEL_UNKNOWN.getInName().equals(levelName)) {
+        } else if(TraceLogLevel.LEVEL_UNKNOWN.getInName().equalsIgnoreCase(levelName)) {
             fLogLevel = TraceLogLevel.LEVEL_UNKNOWN;
         } else {
             fLogLevel = TraceLogLevel.TRACE_DEBUG;
index 28e1faae0451675be8af38c332934da0106b5474..57d09fc46b2b87164faaa11714811580ed39fa22 100644 (file)
@@ -1,4 +1,5 @@
 /**********************************************************************
+
  * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
@@ -11,6 +12,7 @@
  *   Bernd Hufmann - Updated for support of LTTng Tools 2.1
  *   Marc-Andre Laperle - Support for creating a live session
  **********************************************************************/
+
 package org.eclipse.linuxtools.internal.lttng2.control.core.model.impl;
 
 import java.util.ArrayList;
@@ -23,10 +25,8 @@ import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
 
 /**
- * <p>
  * Implementation of the trace session interface (ISessionInfo) to store session
  * related data.
- * </p>
  *
  * @author Bernd Hufmann
  */
@@ -102,7 +102,9 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
     // ------------------------------------------------------------------------
     /**
      * Constructor
-     * @param name - name of base event
+     *
+     * @param name
+     *            - name of base event
      */
     public SessionInfo(String name) {
         super(name);
@@ -110,7 +112,9 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
 
     /**
      * Copy constructor
-     * @param other - the instance to copy
+     *
+     * @param other
+     *            - the instance to copy
      */
     public SessionInfo(SessionInfo other) {
         super(other);
@@ -126,7 +130,7 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
         for (Iterator<IDomainInfo> iterator = other.fDomains.iterator(); iterator.hasNext();) {
             IDomainInfo domain = iterator.next();
             if (domain instanceof DomainInfo) {
-                fDomains.add(new DomainInfo((DomainInfo)domain));
+                fDomains.add(new DomainInfo((DomainInfo) domain));
             } else {
                 fDomains.add(domain);
             }
@@ -149,11 +153,7 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
 
     @Override
     public void setSessionState(String stateName) {
-        if (TraceSessionState.INACTIVE.getInName().equals(stateName)) {
-            fState = TraceSessionState.INACTIVE;
-        } else if (TraceSessionState.ACTIVE.getInName().equals(stateName)) {
-            fState = TraceSessionState.ACTIVE;
-        }
+        fState = TraceSessionState.valueOfString(stateName);
     }
 
     @Override
@@ -242,41 +242,40 @@ public class SessionInfo extends TraceInfo implements ISessionInfo {
         fDomains.add(domainInfo);
     }
 
-
     @SuppressWarnings("nls")
     @Override
     public String toString() {
         StringBuffer output = new StringBuffer();
-            output.append("[SessionInfo(");
-            output.append(super.toString());
-            output.append(",Path=");
-            output.append(getSessionPath());
-            output.append(",State=");
-            output.append(fState);
-            output.append(",isStreamedTrace=");
-            output.append(fIsStreamedTrace);
-            output.append(",isSnapshot=");
-            output.append(fIsSnapshot);
-
-            if (fSnapshotInfo != null) {
-                output.append(",snapshotInfo=");
-                output.append(fSnapshotInfo.toString());
-            }
-            output.append(",Domains=");
-            for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
-                IDomainInfo domain = iterator.next();
-                output.append(domain.toString());
-            }
+        output.append("[SessionInfo(");
+        output.append(super.toString());
+        output.append(",Path=");
+        output.append(getSessionPath());
+        output.append(",State=");
+        output.append(fState);
+        output.append(",isStreamedTrace=");
+        output.append(fIsStreamedTrace);
+        output.append(",isSnapshot=");
+        output.append(fIsSnapshot);
+
+        if (fSnapshotInfo != null) {
+            output.append(",snapshotInfo=");
+            output.append(fSnapshotInfo.toString());
+        }
+        output.append(",Domains=");
+        for (Iterator<IDomainInfo> iterator = fDomains.iterator(); iterator.hasNext();) {
+            IDomainInfo domain = iterator.next();
+            output.append(domain.toString());
+        }
 
-            output.append(",NetworkUrl=");
-            output.append(getNetworkUrl());
-            output.append(",ControlUrl=");
-            output.append(getControlUrl());
-            output.append(",DataUrl=");
-            output.append(getDataUrl());
+        output.append(",NetworkUrl=");
+        output.append(getNetworkUrl());
+        output.append(",ControlUrl=");
+        output.append(getControlUrl());
+        output.append(",DataUrl=");
+        output.append(getDataUrl());
 
-            output.append(")]");
-            return output.toString();
+        output.append(")]");
+        return output.toString();
     }
 
     @Override
index e73bbba84afacbb614ee3d8f4a47d24d03df125d..96a1e0dd8bba943fc83dfd5d6318021bdd9d1114 100644 (file)
@@ -159,7 +159,7 @@ public class LTTngControlServiceTest {
             fShell.setScenario(SCEN_LTTNG_VERSION);
             ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
             assertNotNull(service);
-            assertEquals("2.1.0", service.getVersion());
+            assertEquals("2.1.0", service.getVersionString());
         } catch (ExecutionException e) {
             fail("Exeption thrown " + e);
         }
@@ -171,7 +171,7 @@ public class LTTngControlServiceTest {
             fShell.setScenario(SCEN_LTTNG_VERSION_WITH_PROMPT);
             ILttngControlService service = LTTngControlServiceFactory.getInstance().getLttngControlService(fShell);
             assertNotNull(service);
-            assertEquals("2.0.0", service.getVersion());
+            assertEquals("2.0.0", service.getVersionString());
         } catch (ExecutionException e) {
             fail("Exeption thrown " + e);
         }
diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/handlers/XmlMiValidationErrorHandler.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/handlers/XmlMiValidationErrorHandler.java
new file mode 100644 (file)
index 0000000..6f6f5f7
--- /dev/null
@@ -0,0 +1,49 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Jonathan Rajotte - Initial implementation
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers;
+
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlServiceMI;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.Activator;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * <p>
+ * Error handler for xml xsd validation while using machine interface mode
+ * in {@link LTTngControlServiceMI}.
+ * </p>
+ *
+ * @author Jonathan Rajotte
+ */
+public class XmlMiValidationErrorHandler implements ErrorHandler {
+
+    @Override
+    public void error(SAXParseException e) throws SAXException {
+        Activator.getDefault().logError(Messages.TraceControl_XmlValidationError, e);
+        throw new SAXException(Messages.TraceControl_XmlValidationError, e);
+    }
+
+    @Override
+    public void fatalError(SAXParseException e) throws SAXException {
+        Activator.getDefault().logError(Messages.TraceControl_XmlValidationError, e);
+        throw new SAXException(Messages.TraceControl_XmlValidationError, e);
+    }
+
+    @Override
+    public void warning(SAXParseException e) throws SAXException {
+        Activator.getDefault().logWarning(Messages.TraceControl_XmlValidationWarning, e);
+    }
+
+}
index 713fc0efd1d02cdfe41398db18e5f95079c991fa..6486d3b8d8b82aa9152209afa256c9f583a4b29d 100644 (file)
@@ -49,6 +49,18 @@ public final class Messages extends NLS {
     public static String TraceControl_UnsupportedVersionError;
     public static String TraceControl_GettingVersionError;
 
+    // Xml parsing related failures
+    public static String TraceControl_InvalidSchemaError;
+    public static String TraceControl_XmlDocumentBuilderError;
+    public static String TraceControl_XmlParsingError;
+    public static String TraceControl_XmlValidationError;
+    public static String TraceControl_XmlValidationWarning;
+
+    // Xml machine interface failures
+    public static String TraceControl_MiInvalidNumberOfElementError;
+    public static String TraceControl_MiInvalidProviderError;
+    public static String TraceControl_MiMissingRequiredError;
+
     // Commands
     public static String TraceControl_ErrorTitle;
     public static String TraceControl_RetrieveNodeConfigurationJob;
index f9421c13da3b0fafe04bf46ba8d98a9c5de15d1a..edccc586ed01889f785141d7083a982aedf5525c 100644 (file)
@@ -20,15 +20,27 @@ TraceControl_ExecutionFailure=Command Execution failed
 TraceControl_ExecutionTimeout=Command Execution timed-out
 TraceControl_ShellNotConnected=Command shell not connected
 TraceControl_CommandShellError=Could not create HostShellProcessAdapter
-TraceControl_CommandError=Command failed! Command: 
+TraceControl_CommandError=Command failed! Command:
 TraceControl_UnexpectedCommandOutputFormat=Unexpected command output
 TraceControl_UnexpectedNameError=Unexpected session name returned
 TraceControl_UnexpectedPathError=Unexpected session path returned
 
 TraceControl_UnsupportedVersionError=Unsupported LTTng Tracer Control version
 TraceControl_GettingVersionError=Could not get version of LTTng Tracer Control
-# Commands 
+
+# Xml parsing related failures
+TraceControl_InvalidSchemaError=Could not open/validate xsd Schema
+TraceControl_XmlDocumentBuilderError=Unable to create the xml document builder
+TraceControl_XmlParsingError=Unable to parse the xml document
+TraceControl_XmlValidationError=Could not validate the xml response
+TraceControl_XmlValidationWarning=Xml validation warning
+
+# Xml machine interface failures
+TraceControl_MiInvalidNumberOfElementError=Invalid number of element
+TraceControl_MiInvalidProviderError=Invalid provider data
+TraceControl_MiMissingRequiredError=Missing required data
+
+# Commands
 TraceControl_ErrorTitle=Error
 TraceControl_ListSessionFailure=List sessions failed
 TraceControl_RetrieveNodeConfigurationJob=Retrieving Target Node Configuration...
index 309fcba35e043efd2a0954e4867c8eb05407710a..1f3ccb7b8ba7a1387edd9c22589585bb7daacbb2 100644 (file)
@@ -211,7 +211,7 @@ public class TargetNodeComponent extends TraceControlComponent implements ICommu
     public String getNodeVersion() {
         // Control service is null during connection to node
         if (getControlService() != null) {
-            return getControlService().getVersion();
+            return getControlService().getVersionString();
         }
         return ""; //$NON-NLS-1$
     }
index 7684e8078ed09f33ba7f3b795ab6f5251406bf99..1cb020c91448ad828ae82fffe31efff864971f7d 100644 (file)
@@ -35,9 +35,14 @@ import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
 public interface ILttngControlService {
 
     /**
-     * @return the version string.
+     * @return the LTTng version object
      */
-    String getVersion();
+    LttngVersion getVersion();
+
+    /**
+     * @return the version string
+     */
+    String getVersionString();
 
     /**
      * Checks if given version is supported by this ILTTngControlService implementation.
index bcce1d163c6b0d0b5d1fdfb318b63cdffea93231..6e1083cd2c268d73ca76441219f22f138dc515d1 100644 (file)
@@ -91,13 +91,18 @@ public class LTTngControlService implements ILttngControlService {
     // ------------------------------------------------------------------------
 
     @Override
-    public String getVersion() {
+    public String getVersionString() {
         if (fVersion == null) {
             return "Unknown"; //$NON-NLS-1$
         }
         return fVersion.toString();
     }
 
+    @Override
+    public LttngVersion getVersion() {
+        return fVersion;
+    }
+
     /**
      * Sets the version of the LTTng 2.0 control service.
      * @param version - a version to set
@@ -106,6 +111,14 @@ public class LTTngControlService implements ILttngControlService {
         fVersion = new LttngVersion(version);
     }
 
+    /**
+     * Sets the version of the LTTng 2.x control service.
+     * @param version - a version to set
+     */
+    public void setVersion(LttngVersion version) {
+        fVersion = version;
+    }
+
     @Override
     public boolean isVersionSupported(String version) {
         LttngVersion tmp = new LttngVersion(version);
index 83e6c58114e6c75c215f201f5a4b48f2f9f4a51e..44e9b0eab0f83c6fb6c44e7599a796da09a65024 100644 (file)
@@ -40,7 +40,20 @@ public interface LTTngControlServiceConstants {
      * Unused value
      */
     static final int UNUSED_VALUE = -1;
+    /**
+     * String representation of numerical true element
+     */
+    static final String TRUE_NUMERICAL = "1"; //$NON-NLS-1$
 
+    // ------------------------------------------------------------------------
+    // LTTng Machine Interface constants
+    // ------------------------------------------------------------------------
+
+    /**
+     * Name of the XSD to validate against the xml machine interface
+     * output from LTTng
+     */
+    static final String MI_XSD_FILENAME = "mi_lttng.xsd"; //$NON-NLS-1$
     // ------------------------------------------------------------------------
     // Command constants
     // ------------------------------------------------------------------------
@@ -48,6 +61,14 @@ public interface LTTngControlServiceConstants {
      * The lttng tools command.
      */
     static final String CONTROL_COMMAND = "lttng"; //$NON-NLS-1$
+    /**
+     * The lttng tools machine interface command.
+     */
+    static final String CONTROL_COMMAND_MI = CONTROL_COMMAND + " --mi "; //$NON-NLS-1$
+    /**
+     * The lttng tools XML machine interface command.
+     */
+    static final String CONTROL_COMMAND_MI_XML = CONTROL_COMMAND_MI + " xml "; //$NON-NLS-1$
     /**
      * Command: lttng version.
      */
@@ -289,6 +310,11 @@ public interface LTTngControlServiceConstants {
      * Note: file for protocol is not considered as network trace since local consumer will be used.
      */
     static final Pattern TRACE_NETWORK_PATH_PATTERN = Pattern.compile("\\s*Trace\\s+path\\:\\s+(net|net4|net6|tcp|tcp6)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
+    /**
+     * Pattern to match session path for network tracing
+     * Note: file for protocol is not considered as network trace since local consumer will be used.
+     */
+    static final Pattern TRACE_NETWORK_PATTERN = Pattern.compile("\\s*(net|net4|net6|tcp|tcp4|tcp6)\\:\\/\\/(.*)(\\:(\\d*)\\/(.*)\\[data\\:\\s+(\\d*)\\]){0,1}"); //$NON-NLS-1$
     /**
      * Sub-pattern to pattern TRACE_NETWORK_PATH_PATTERN to match file protocol
      */
index 851387f97e3a9d3a825da388831d7705d804e358..2ac956b86a0b6d14615a193f29ae7cf51d5426d7 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2012, 2013. 2013 Ericsson
+ * Copyright (c) 2012, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Jonathan Rajotte - machine interface support
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
 
@@ -22,10 +23,8 @@ import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandRe
 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandShell;
 
 /**
- * <p>
- * Factory to create LTTngControlService instances depending on the version of the LTTng Trace Control
- * installed on the remote host.
- * </p>
+ * Factory to create LTTngControlService instances depending on the version of
+ * the LTTng Trace Control installed on the remote host.
  *
  * @author Bernd Hufmann
  */
@@ -68,30 +67,65 @@ public class LTTngControlServiceFactory {
      * Gets the LTTng Control Service implementation based on the version of the
      * remote LTTng Tools.
      *
-     * @param shell - the shell implementation to pass to the service
+     * @param shell
+     *            - the shell implementation to pass to the service
      * @return - LTTng Control Service implementation
-     * @throws ExecutionException If the command fails
+     * @throws ExecutionException
+     *             If the command fails
      */
     public ILttngControlService getLttngControlService(ICommandShell shell) throws ExecutionException {
         // get the version
+        boolean machineInterfaceMode = true;
         String command = LTTngControlServiceConstants.CONTROL_COMMAND + LTTngControlServiceConstants.COMMAND_VERSION;
+        String commandMi = LTTngControlServiceConstants.CONTROL_COMMAND_MI_XML + LTTngControlServiceConstants.COMMAND_VERSION;
 
+        // Logging
         if (ControlPreferences.getInstance().isLoggingEnabled()) {
-            ControlCommandLogger.log(command);
+            ControlCommandLogger.log(commandMi);
         }
+
         ICommandResult result = null;
 
+        // Looking for a machine interface on LTTng side
         try {
-            result = shell.executeCommand(command, new NullProgressMonitor());
+            result = shell.executeCommand(commandMi, new NullProgressMonitor());
         } catch (ExecutionException e) {
-            throw new ExecutionException(Messages.TraceControl_GettingVersionError + ": " + e); //$NON-NLS-1$
+            throw new ExecutionException(Messages.TraceControl_GettingVersionError, e);
         }
 
+        // Output logging
         if (ControlPreferences.getInstance().isLoggingEnabled()) {
             ControlCommandLogger.log(LTTngControlService.formatOutput(result));
         }
 
+        if (result.getResult() != 0) {
+            machineInterfaceMode = false;
+            // Fall back if no machine interface is present
+
+            // Logging
+            if (ControlPreferences.getInstance().isLoggingEnabled()) {
+                ControlCommandLogger.log(command);
+            }
+
+            try {
+                result = shell.executeCommand(command, new NullProgressMonitor());
+            } catch (ExecutionException e) {
+                throw new ExecutionException(Messages.TraceControl_GettingVersionError + ": " + e); //$NON-NLS-1$
+            }
+
+            // Output logging
+            if (ControlPreferences.getInstance().isLoggingEnabled()) {
+                ControlCommandLogger.log(LTTngControlService.formatOutput(result));
+            }
+        }
+
+
         if ((result != null) && (result.getResult() == 0) && (result.getOutput().length >= 1)) {
+            if (machineInterfaceMode) {
+                LTTngControlServiceMI service = new LTTngControlServiceMI(shell, LTTngControlService.class.getResource(LTTngControlServiceConstants.MI_XSD_FILENAME));
+                service.setVersion(result.getOutput());
+                return service;
+            }
             int index = 0;
             while (index < result.getOutput().length) {
                 String line = result.getOutput()[index];
diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/LTTngControlServiceMI.java
new file mode 100644 (file)
index 0000000..2c13046
--- /dev/null
@@ -0,0 +1,572 @@
+/**********************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Jonathan Rajotte - Initial support for machine interface lttng 2.6
+ **********************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.IBaseEventInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.IChannelInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.IDomainInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.IFieldInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISessionInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.IUstProviderInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.LogLevelType;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceLogLevel;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.BaseEventInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.FieldInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SessionInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SnapshotInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.UstProviderInfo;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.handlers.XmlMiValidationErrorHandler;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.messages.Messages;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandResult;
+import org.eclipse.linuxtools.internal.lttng2.control.ui.views.remote.ICommandShell;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * Service for sending LTTng trace control commands to remote host via machine
+ * interface mode.
+ *
+ * @author Jonathan Rajotte
+ */
+public class LTTngControlServiceMI extends LTTngControlService {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final DocumentBuilder fDocumentBuilder;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     *
+     * @param shell
+     *            the command shell implementation to use
+     * @param xsdUrl
+     *            the xsd schema file for validation
+     * @throws ExecutionException
+     *             if the creation of the Schema and DocumentBuilder objects
+     *             fails
+     */
+    public LTTngControlServiceMI(ICommandShell shell, URL xsdUrl) throws ExecutionException {
+        super(shell);
+
+        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
+        docBuilderFactory.setValidating(false);
+
+        // TODO: Add xsd validation for machine interface via mi_lttng.xsd from LTTng
+        try {
+            fDocumentBuilder = docBuilderFactory.newDocumentBuilder();
+        } catch (ParserConfigurationException e) {
+            throw new ExecutionException(Messages.TraceControl_XmlDocumentBuilderError, e);
+        }
+
+        fDocumentBuilder.setErrorHandler(new XmlMiValidationErrorHandler());
+
+    }
+
+    /**
+     * Generate a Document object from an array of String.
+     *
+     * @param xmlStrings
+     *            array of strings representing an xml input
+     * @return Document generated from strings input
+     * @throws ExecutionException
+     *             when parsing has failed
+     */
+    private Document getDocumentFromStrings(String[] xmlStrings) throws ExecutionException {
+        StringBuilder concatenedString = new StringBuilder();
+        for (String string : xmlStrings) {
+            concatenedString.append(string);
+        }
+        InputSource stream = new InputSource(new StringReader(concatenedString.toString()));
+
+        Document document;
+        try {
+            document = fDocumentBuilder.parse(stream);
+        } catch (SAXException | IOException e) {
+            throw new ExecutionException(Messages.TraceControl_XmlParsingError, e);
+        }
+        return document;
+
+    }
+
+    /**
+     * Parse, populate and set the internal LTTngVersion variable
+     *
+     * @param xmlOutput
+     *            the mi xml output of lttng version
+     * @throws ExecutionException
+     *             when xml extraction fail
+     */
+    public void setVersion(String[] xmlOutput) throws ExecutionException {
+        Document doc = getDocumentFromStrings(xmlOutput);
+        NodeList element = doc.getElementsByTagName(MIStrings.VERSION);
+        int major = 0;
+        int minor = 0;
+        int patchLevel = 0;
+        String license = ""; //$NON-NLS-1$
+        String commit = ""; //$NON-NLS-1$
+        String name = ""; //$NON-NLS-1$
+        String description = ""; //$NON-NLS-1$
+        String url = ""; //$NON-NLS-1$
+        String fullVersion = ""; //$NON-NLS-1$
+        if (element.getLength() == 1) {
+            NodeList child = element.item(0).getChildNodes();
+            // Get basic information
+            for (int i = 0; i < child.getLength(); i++) {
+                Node node = child.item(i);
+                switch (node.getNodeName()) {
+                case MIStrings.VERSION_MAJOR:
+                    major = Integer.parseInt(node.getTextContent());
+                    break;
+                case MIStrings.VERSION_MINOR:
+                    minor = Integer.parseInt(node.getTextContent());
+                    break;
+                case MIStrings.VERSION_PATCH_LEVEL:
+                    patchLevel = Integer.parseInt(node.getTextContent());
+                    break;
+                case MIStrings.VERSION_COMMIT:
+                    commit = node.getTextContent();
+                    break;
+                case MIStrings.VERSION_DESCRIPTION:
+                    description = node.getTextContent();
+                    break;
+                case MIStrings.VERSION_LICENSE:
+                    license = node.getTextContent();
+                    break;
+                case MIStrings.VERSION_NAME:
+                    name = node.getTextContent();
+                    break;
+                case MIStrings.VERSION_STR:
+                    fullVersion = node.getTextContent();
+                    break;
+                case MIStrings.VERSION_WEB:
+                    url = node.getTextContent();
+                    break;
+                default:
+                    break;
+                }
+            }
+            setVersion(new LttngVersion(major, minor, patchLevel, license, commit, name, description, url, fullVersion));
+        } else {
+            throw new ExecutionException(Messages.TraceControl_UnsupportedVersionError);
+        }
+    }
+
+    @Override
+    public String[] getSessionNames(IProgressMonitor monitor) throws ExecutionException {
+        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST);
+        ICommandResult result = executeCommand(command.toString(), monitor);
+
+        Document doc = getDocumentFromStrings(result.getOutput());
+
+        NodeList elements = doc.getElementsByTagName(MIStrings.NAME);
+
+        ArrayList<String> retArray = new ArrayList<>();
+        for (int i = 0; i < elements.getLength(); i++) {
+            Node node = elements.item(i);
+            if (node.getParentNode().getNodeName().equalsIgnoreCase(MIStrings.SESSION)) {
+                retArray.add(node.getTextContent());
+            }
+        }
+        return retArray.toArray(new String[retArray.size()]);
+    }
+
+    @Override
+    public ISessionInfo getSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST, sessionName);
+        ICommandResult result = executeCommand(command.toString(), monitor);
+
+        ISessionInfo sessionInfo = new SessionInfo(sessionName);
+        Document document = getDocumentFromStrings(result.getOutput());
+
+        NodeList sessionsNode = document.getElementsByTagName(MIStrings.SESSION);
+        // There should be only one session
+        if (sessionsNode.getLength() != 1) {
+            throw new ExecutionException(Messages.TraceControl_MiInvalidNumberOfElementError);
+        }
+
+        // Populate session information
+        NodeList rawSessionInfos = sessionsNode.item(0).getChildNodes();
+        for (int i = 0; i < rawSessionInfos.getLength(); i++) {
+            Node rawInfo = rawSessionInfos.item(i);
+            switch (rawInfo.getNodeName()) {
+            case MIStrings.PATH:
+                sessionInfo.setSessionPath(rawInfo.getTextContent());
+                break;
+            case MIStrings.ENABLED:
+                sessionInfo.setSessionState(rawInfo.getTextContent());
+                break;
+            case MIStrings.SNAPSHOT_MODE:
+                if (rawInfo.getTextContent().equals(LTTngControlServiceConstants.TRUE_NUMERICAL)) {
+                    // real name will be set later
+                    ISnapshotInfo snapshotInfo = new SnapshotInfo(""); //$NON-NLS-1$
+                    sessionInfo.setSnapshotInfo(snapshotInfo);
+                }
+                break;
+            case MIStrings.LIVE_TIMER_INTERVAL:
+                // TODO : live mode not supported yet in TMF:lttng-control
+                break;
+            case MIStrings.DOMAINS:
+                // Extract the domains node
+                NodeList rawDomains = rawInfo.getChildNodes();
+                IDomainInfo domain = null;
+                for (int j = 0; j < rawDomains.getLength(); j++) {
+                    if (rawDomains.item(j).getNodeName().equalsIgnoreCase(MIStrings.DOMAIN)) {
+                        domain = parseDomain(rawDomains.item(j));
+                        sessionInfo.addDomain(domain);
+                    }
+                }
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (!sessionInfo.isSnapshotSession()) {
+            Matcher matcher = LTTngControlServiceConstants.TRACE_NETWORK_PATTERN.matcher(sessionInfo.getSessionPath());
+            if (matcher.matches()) {
+                sessionInfo.setStreamedTrace(true);
+            }
+        }
+
+
+        // Fetch the snapshot info
+        if (sessionInfo.isSnapshotSession()) {
+            ISnapshotInfo snapshot = getSnapshotInfo(sessionName, monitor);
+            sessionInfo.setSnapshotInfo(snapshot);
+        }
+
+        return sessionInfo;
+    }
+
+    /**
+     * @param domain
+     *            a domain xml node
+     * @return {@link IDomainInfo}
+     */
+    protected IDomainInfo parseDomain(Node domain) {
+        // TODO JRJ - STUB
+        return null;
+    }
+
+    @Override
+    public ISnapshotInfo getSnapshotInfo(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO JRJ - STUB
+        return null;
+    }
+
+    @Override
+    public List<IBaseEventInfo> getKernelProvider(IProgressMonitor monitor) throws ExecutionException {
+        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_KERNEL);
+        ICommandResult result = executeCommand(command.toString(), monitor, false);
+        List<IBaseEventInfo> events = new ArrayList<>();
+
+        if (isError(result)) {
+            return events;
+        }
+
+        Document document = getDocumentFromStrings(result.getOutput());
+        NodeList rawEvents = document.getElementsByTagName(MIStrings.EVENT);
+        parseXmlEvents(rawEvents, events);
+        return events;
+    }
+
+    @Override
+    public List<IUstProviderInfo> getUstProvider(IProgressMonitor monitor) throws ExecutionException {
+        StringBuffer command = createCommand(LTTngControlServiceConstants.COMMAND_LIST_UST);
+        // Get the field to
+        command.append(LTTngControlServiceConstants.OPTION_FIELDS);
+
+        // Execute
+        ICommandResult result = executeCommand(command.toString(), monitor, false);
+        List<IUstProviderInfo> allProviders = new ArrayList<>();
+
+        if (isError(result)) {
+            return allProviders;
+        }
+
+        Document document = getDocumentFromStrings(result.getOutput());
+        NodeList rawProviders = document.getElementsByTagName(MIStrings.PID);
+
+        IUstProviderInfo providerInfo = null;
+
+        for (int i = 0; i < rawProviders.getLength(); i++) {
+            Node provider = rawProviders.item(i);
+            Node name = getFirstOf(provider.getChildNodes(), MIStrings.NAME);
+            if (name == null) {
+                throw new ExecutionException(Messages.TraceControl_MiInvalidProviderError);
+            }
+            providerInfo = new UstProviderInfo(name.getTextContent());
+
+            // Populate provider
+            NodeList infos = provider.getChildNodes();
+            for (int j = 0; j < infos.getLength(); j++) {
+                Node info = infos.item(j);
+                switch (info.getNodeName()) {
+                case MIStrings.PID_ID:
+                    providerInfo.setPid(Integer.parseInt(info.getTextContent()));
+                    break;
+                case MIStrings.EVENTS:
+                    List<IBaseEventInfo> events = new ArrayList<>();
+                    NodeList rawEvents = info.getChildNodes();
+                    parseXmlEvents(rawEvents, events);
+                    providerInfo.setEvents(events);
+                    break;
+                default:
+                    break;
+                }
+            }
+            allProviders.add(providerInfo);
+        }
+
+        return allProviders;
+    }
+
+    @Override
+    public ISessionInfo createSession(ISessionInfo sessionInfo, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void destroySession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void startSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void stopSession(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void enableChannels(String sessionName, List<String> channelNames, boolean isKernel, IChannelInfo info, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void disableChannels(String sessionName, List<String> channelNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void enableEvents(String sessionName, String channelName, List<String> eventNames, boolean isKernel, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void enableSyscalls(String sessionName, String channelName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void enableProbe(String sessionName, String channelName, String eventName, boolean isFunction, String probe, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void enableLogLevel(String sessionName, String channelName, String eventName, LogLevelType logLevelType, TraceLogLevel level, String filterExpression, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void calibrate(boolean isKernel, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void recordSnapshot(String sessionName, IProgressMonitor monitor) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void runCommands(IProgressMonitor monitor, List<String> commands) throws ExecutionException {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * @param strings
+     *            array of string that make up a command line
+     * @return string buffer with created command line
+     */
+    @Override
+    protected StringBuffer createCommand(String... strings) {
+        StringBuffer command = new StringBuffer();
+        command.append(LTTngControlServiceConstants.CONTROL_COMMAND_MI_XML);
+        command.append(getTracingGroupOption());
+        for (String string : strings) {
+            command.append(string);
+        }
+        return command;
+    }
+
+    /**
+     * @param xmlEvents
+     *            a Node list of xml event element
+     * @param events
+     *            list of event generated by the parsing of the xml event
+     *            element
+     * @throws ExecutionException
+     *             when a raw event is not a complete/valid xml event
+     */
+    protected void parseXmlEvents(NodeList xmlEvents, List<IBaseEventInfo> events) throws ExecutionException {
+        IBaseEventInfo eventInfo = null;
+        for (int i = 0; i < xmlEvents.getLength(); i++) {
+            NodeList rawInfos = xmlEvents.item(i).getChildNodes();
+            // Search for name
+            if (xmlEvents.item(i).getNodeName().equalsIgnoreCase(MIStrings.EVENT)) {
+                Node rawName = getFirstOf(rawInfos, MIStrings.NAME);
+                if (rawName == null) {
+                    throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
+                }
+                eventInfo = new BaseEventInfo(rawName.getTextContent());
+
+                // Populate the event
+                for (int j = 0; j < rawInfos.getLength(); j++) {
+                    Node infoNode = rawInfos.item(j);
+                    switch (infoNode.getNodeName()) {
+                    case MIStrings.TYPE:
+                        eventInfo.setEventType(infoNode.getTextContent());
+                        break;
+                    case MIStrings.LOGLEVEL:
+                        eventInfo.setLogLevel(infoNode.getTextContent());
+                        break;
+                    case MIStrings.EVENT_FIELDS:
+                        List<IFieldInfo> fields = new ArrayList<>();
+                        getFieldInfo(infoNode.getChildNodes(), fields);
+                        eventInfo.setFields(fields);
+                        break;
+                    default:
+                        break;
+                    }
+                }
+                events.add(eventInfo);
+            }
+        }
+    }
+
+    /**
+     * @param fieldsList
+     *            a list of xml event_field element
+     * @param fields
+     *            a list of field generated by xml parsing
+     * @throws ExecutionException
+     *             when parsing fail or required elements are missing
+     */
+    private static void getFieldInfo(NodeList fieldsList, List<IFieldInfo> fields) throws ExecutionException {
+        IFieldInfo fieldInfo = null;
+        for (int i = 0; i < fieldsList.getLength(); i++) {
+            Node field = fieldsList.item(i);
+            if (field.getNodeName().equalsIgnoreCase(MIStrings.EVENT_FIELD)) {
+                // Get name
+                Node name = getFirstOf(field.getChildNodes(), MIStrings.NAME);
+                if (name == null) {
+                    throw new ExecutionException(Messages.TraceControl_MiMissingRequiredError);
+                }
+                fieldInfo = new FieldInfo(name.getTextContent());
+
+                // Populate the field information
+                NodeList infos = field.getChildNodes();
+                for (int j = 0; j < infos.getLength(); j++) {
+                    Node info = infos.item(j);
+                    switch (info.getNodeName()) {
+                    case MIStrings.TYPE:
+                        fieldInfo.setFieldType(info.getTextContent());
+                        break;
+                    default:
+                        break;
+                    }
+                }
+                fields.add(fieldInfo);
+            }
+        }
+    }
+
+    /**
+     * Retrieve the fist instance of a given node with tag name equal to tagName
+     * parameter
+     *
+     * @param nodeList
+     *            the list of Node to search against
+     * @param tagName
+     *            the tag name of the desired node
+     * @return the first occurrence of a node with a tag name equals to tagName
+     */
+    private static Node getFirstOf(NodeList nodeList, String tagName) {
+        Node node = null;
+        for (int i = 0; i < nodeList.getLength(); i++) {
+            if (nodeList.item(i).getNodeName() == tagName) {
+                node = nodeList.item(i);
+                break;
+            }
+        }
+        return node;
+    }
+
+}
index a026267acbabfd80555c049b928e8b29a182896f..f992efb19e4f830652b520b0bd7adef9193e7f92 100644 (file)
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2013 Ericsson
+ * Copyright (c) 2013, 2014 Ericsson
  *
  * All rights reserved. This program and the accompanying materials are
  * made available under the terms of the Eclipse Public License v1.0 which
@@ -8,35 +8,81 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Jonathan Rajotte - Machine interface support and new information
  **********************************************************************/
+
 package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
 
 import org.osgi.framework.Version;
 
 /**
- * A version implementation with a special compareTo implementation
- * to bypass problems of older implementation of org.osgi.framework.Version.
+ * A version implementation with a special compareTo implementation to bypass
+ * problems of older implementation of org.osgi.framework.Version.
  *
  * @author Bernd Hufmann
  */
 public class LttngVersion extends Version {
 
+    private final String fLicense;
+    private final String fCommit;
+    private final String fName;
+    private final String fDescription;
+    private final String fUrl;
+    private final String fFullVersion;
+
     /**
      * Constructor
      *
      * @param version
-     *      The version string
+     *            The version string
      */
     public LttngVersion(String version) {
         super(version);
+        fLicense = ""; //$NON-NLS-1$
+        fCommit = ""; //$NON-NLS-1$
+        fName = ""; //$NON-NLS-1$
+        fDescription = ""; //$NON-NLS-1$
+        fUrl = ""; //$NON-NLS-1$
+        fFullVersion = ""; //$NON-NLS-1$
+    }
+
+    /**
+     * @param major
+     *            major version number
+     * @param minor
+     *            minor version number
+     * @param micro
+     *            micro version number
+     * @param license
+     *            licence text of LTTng
+     * @param commit
+     *            current git commit information about LTTng
+     * @param name
+     *            name of the version
+     * @param description
+     *            description of the version
+     * @param url
+     *            url to website
+     * @param fullVersion
+     *            complete string representation of the version
+     */
+    public LttngVersion(int major, int minor, int micro, String license, String commit, String name, String description, String url, String fullVersion) {
+        super(major, minor, micro);
+        fLicense = license;
+        fCommit = commit;
+        fName = name;
+        fDescription = description;
+        fUrl = url;
+        fFullVersion = fullVersion;
     }
 
     /**
-     * Special compareTo method to fix problem of older implementations of org.osgi.framework.Version
-     * where {@code Version.compareTo} takes an {@code Object} instead a {@code Version} as argument.
+     * Special compareTo method to fix problem of older implementations of
+     * org.osgi.framework.Version where {@code Version.compareTo} takes an
+     * {@code Object} instead a {@code Version} as argument.
      *
      * @param other
-     *      - Other version to compare
+     *            - Other version to compare
      * @return a negative integer, zero, or a positive integer if this version
      *         is less than, equal to, or greater than the specified
      *         {@code LttngVersion} object.
@@ -45,7 +91,6 @@ public class LttngVersion extends Version {
         if (other == this) { // quicktest
             return 0;
         }
-
         int result = getMajor() - other.getMajor();
         if (result != 0) {
             return result;
@@ -62,4 +107,46 @@ public class LttngVersion extends Version {
         }
         return getQualifier().compareTo(other.getQualifier());
     }
+
+    /**
+     * @return String representing the lttng license
+     */
+    public String getLicense() {
+        return fLicense;
+    }
+
+    /**
+     * @return commit id of lttng
+     */
+    public String getCommit() {
+        return fCommit;
+    }
+
+    /**
+     * @return name of lttng version
+     */
+    public String getName() {
+        return fName;
+    }
+
+    /**
+     * @return full description of lttng
+     */
+    public String getDescription() {
+        return fDescription;
+    }
+
+    /**
+     * @return url of lttng
+     */
+    public String getUrl() {
+        return fUrl;
+    }
+
+    /**
+     * @return the full_version
+     */
+    public String getFullVersion() {
+        return fFullVersion;
+    }
 }
diff --git a/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/MIStrings.java b/org.eclipse.linuxtools.lttng2.control.ui/src/org/eclipse/linuxtools/internal/lttng2/control/ui/views/service/MIStrings.java
new file mode 100644 (file)
index 0000000..61b352a
--- /dev/null
@@ -0,0 +1,576 @@
+/*******************************************************************************
+ * Copyright (c) 2014 Ericsson
+ *
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   Jonathan Rajotte Julien - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.internal.lttng2.control.ui.views.service;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Non-externalized strings for use with the LTTng Control services. This
+ * nformation is extracted from mi_lttng.xsd from lttng-tool libmi.
+ *
+ * @author Jonathan Rajotte
+ */
+@SuppressWarnings("nls")
+@NonNullByDefault
+public interface MIStrings {
+
+    /**
+     * Represent the command_action xml element
+     */
+     String COMMAND_ACTION = "snapshot_action";
+
+    /**
+     * Represent the command_add_context xml element
+     */
+     String COMMAND_ADD_CONTEXT = "add-context";
+
+    /**
+     * Represent the command_calibrate xml element
+     */
+     String COMMAND_CALIBRATE = "calibrate";
+
+    /**
+     * Represent the command_create xml element
+     */
+     String COMMAND_CREATE = "create";
+
+    /**
+     * Represent the command_destroy xml element
+     */
+     String COMMAND_DESTROY = "destroy";
+
+    /**
+     * Represent the command_disable_channel xml element
+     */
+     String COMMAND_DISABLE_CHANNEL = "disable-channel";
+
+    /**
+     * Represent the command_disable_event xml element
+     */
+     String COMMAND_DISABLE_EVENT = "disable-event";
+
+    /**
+     * Represent the command_enable_channels xml element
+     */
+     String COMMAND_ENABLE_CHANNELS = "enable-channel";
+
+    /**
+     * Represent the command_enable_event xml element
+     */
+     String COMMAND_ENABLE_EVENT = "enable-event";
+
+    /**
+     * Represent the command_list xml element
+     */
+     String COMMAND_LIST = "list";
+
+    /**
+     * Represent the command_load xml element
+     */
+     String COMMAND_LOAD = "load";
+
+    /**
+     * Represent the command_name xml element
+     */
+     String COMMAND_NAME = "name";
+
+    /**
+     * Represent the command_output xml element
+     */
+     String COMMAND_OUTPUT = "output";
+
+    /**
+     * Represent the command_save xml element
+     */
+     String COMMAND_SAVE = "save";
+
+    /**
+     * Represent the command_set_session xml element
+     */
+     String COMMAND_SET_SESSION = "set-session";
+
+    /**
+     * Represent the command_snapshot xml element
+     */
+     String COMMAND_SNAPSHOT = "snapshot";
+
+    /**
+     * Represent the command_snapshot_add xml element
+     */
+     String COMMAND_SNAPSHOT_ADD = "add_snapshot";
+
+    /**
+     * Represent the command_snapshot_del xml element
+     */
+     String COMMAND_SNAPSHOT_DEL = "del_snapshot";
+
+    /**
+     * Represent the command_snapshot_list xml element
+     */
+     String COMMAND_SNAPSHOT_LIST = "list_snapshot";
+
+    /**
+     * Represent the command_snapshot_record xml element
+     */
+     String COMMAND_SNAPSHOT_RECORD = "record_snapshot";
+
+    /**
+     * Represent the command_start xml element
+     */
+     String COMMAND_START = "start";
+
+    /**
+     * Represent the command_stop xml element
+     */
+     String COMMAND_STOP = "stop";
+
+    /**
+     * Represent the command_success xml element
+     */
+     String COMMAND_SUCCESS = "success";
+
+    /**
+     * Represent the command_version xml element
+     */
+     String COMMAND_VERSION = "version";
+
+    /**
+     * Represent the version xml element
+     */
+     String VERSION = "version";
+
+    /**
+     * Represent the version_commit xml element
+     */
+     String VERSION_COMMIT = "commit";
+
+    /**
+     * Represent the version_description xml element
+     */
+     String VERSION_DESCRIPTION = "description";
+
+    /**
+     * Represent the version_license xml element
+     */
+     String VERSION_LICENSE = "license";
+
+    /**
+     * Represent the version_major xml element
+     */
+     String VERSION_MAJOR = "major";
+
+    /**
+     * Represent the version_minor xml element
+     */
+     String VERSION_MINOR = "minor";
+
+    /**
+     * Represent the version_patch_level xml element
+     */
+     String VERSION_PATCH_LEVEL = "patchLevel";
+
+    /**
+     * Represent the version_str xml element
+     */
+     String VERSION_STR = "string";
+
+    /**
+     * Represent the version_web xml element
+     */
+     String VERSION_WEB = "url";
+
+    /**
+     * Represent the version_name xml element
+     */
+     String VERSION_NAME = "name";
+    /* String related to a lttng_event_field */
+
+    /**
+     * Represent the event_field xml element
+     */
+     String EVENT_FIELD = "event_field";
+
+    /**
+     * Represent the event_fields xml element
+     */
+     String EVENT_FIELDS = "event_fields";
+
+    /**
+     * Represent the perf_counter_context xml element
+     */
+     String PERF_COUNTER_CONTEXT = "perf_counter_context";
+
+     // ------------------------------------------------------------------------
+     // String related to pid
+     // ------------------------------------------------------------------------/
+
+    /**
+     * Represent the pids xml element
+     */
+     String PIDS = "pids";
+
+    /**
+     * Represent the pid xml element
+     */
+     String PID = "pid";
+
+    /**
+     * Represent the pid_id xml element
+     */
+     String PID_ID = "id";
+
+     // ------------------------------------------------------------------------
+     // String related to save command
+     // ------------------------------------------------------------------------
+    /**
+     * Represent the save xml element
+     */
+     String SAVE = "save";
+
+     // ------------------------------------------------------------------------
+     // String related to load command
+     // ------------------------------------------------------------------------
+    /**
+     * Represent the load xml element
+     */
+     String LOAD = "load";
+
+     // ------------------------------------------------------------------------
+     // String related to general element of mi_lttng
+     // ------------------------------------------------------------------------
+    /**
+     * Represent the empty xml element
+     */
+     String EMPTY = "";
+
+    /**
+     * Represent the id xml element
+     */
+     String ID = "id";
+
+    /**
+     * Represent the nowrite xml element
+     */
+     String NOWRITE = "nowrite";
+
+    /**
+     * Represent the success xml element
+     */
+     String SUCCESS = "success";
+
+    /**
+     * Represent the type_enum xml element
+     */
+     String TYPE_ENUM = "ENUM";
+
+    /**
+     * Represent the type_float xml element
+     */
+     String TYPE_FLOAT = "FLOAT";
+
+    /**
+     * Represent the type_integer xml element
+     */
+     String TYPE_INTEGER = "INTEGER";
+
+    /**
+     * Represent the type_other xml element
+     */
+     String TYPE_OTHER = "OTHER";
+
+    /**
+     * Represent the type_string xml element
+     */
+     String TYPE_STRING = "STRING";
+
+     // ------------------------------------------------------------------------
+     // String related to lttng_calibrate
+     // ------------------------------------------------------------------------
+    /**
+     * Represent the calibrate xml element
+     */
+     String CALIBRATE = "calibrate";
+
+    /**
+     * Represent the calibrate_function xml element
+     */
+     String CALIBRATE_FUNCTION = "FUNCTION";
+
+     // ------------------------------------------------------------------------
+     // String related to a lttng_snapshot_output
+     // ------------------------------------------------------------------------
+    /**
+     * Represent the snapshot_ctrl_url xml element
+     */
+     String SNAPSHOT_CTRL_URL = "ctrl_url";
+
+    /**
+     * Represent the snapshot_data_url xml element
+     */
+     String SNAPSHOT_DATA_URL = "data_url";
+
+    /**
+     * Represent the snapshot_max_size xml element
+     */
+
+     String SNAPSHOT_MAX_SIZE = "max_size";
+
+    /**
+     * Represent the snapshot_n_ptr xml element
+     */
+     String SNAPSHOT_N_PTR = "n_ptr";
+
+    /**
+     * Represent the snapshot_session_name xml element
+     */
+     String SNAPSHOT_SESSION_NAME = "session_name";
+
+    /**
+     * Represent the snapshots xml element
+     */
+     String SNAPSHOTS = "snapshots";
+    /**
+     * Represent the channel xml element
+     */
+     String CHANNEL = "channel";
+
+    /**
+     * Represent the channels xml element
+     */
+     String CHANNELS = "channels";
+
+    /**
+     * Represent the domain xml element
+     */
+     String DOMAIN = "domain";
+
+    /**
+     * Represent the domains xml element
+     */
+     String DOMAINS = "domains";
+
+    /**
+     * Represent the event xml element
+     */
+     String EVENT = "event";
+
+    /**
+     * Represent the events xml element
+     */
+     String EVENTS = "events";
+
+    /**
+     * Represent the context xml element
+     */
+     String CONTEXT = "context";
+
+    /**
+     * Represent the contexts xml element
+     */
+     String CONTEXTS = "contexts";
+
+    /**
+     * Represent the attributes xml element
+     */
+     String ATTRIBUTES = "attributes";
+
+    /**
+     * Represent the exclusion xml element
+     */
+     String EXCLUSION = "exclusion";
+
+    /**
+     * Represent the exclusions xml element
+     */
+     String EXCLUSIONS = "exclusions";
+
+    /**
+     * Represent the function_attributes xml element
+     */
+     String FUNCTION_ATTRIBUTES = "function_attributes";
+
+    /**
+     * Represent the probe_attributes xml element
+     */
+     String PROBE_ATTRIBUTES = "probe_attributes";
+
+    /**
+     * Represent the symbol_name xml element
+     */
+     String SYMBOL_NAME = "symbol_name";
+
+    /**
+     * Represent the address xml element
+     */
+     String ADDRESS = "address";
+
+    /**
+     * Represent the offset xml element
+     */
+     String OFFSET = "offset";
+
+    /**
+     * Represent the name xml element
+     */
+     String NAME = "name";
+
+    /**
+     * Represent the enabled xml element
+     */
+     String ENABLED = "enabled";
+
+    /**
+     * Represent the overwrite_mode xml element
+     */
+     String OVERWRITE_MODE = "overwrite_mode";
+
+    /**
+     * Represent the subbuf_size xml element
+     */
+     String SUBBUF_SIZE = "subbuffer_size";
+
+    /**
+     * Represent the num_subbuf xml element
+     */
+     String NUM_SUBBUF = "subbuffer_count";
+
+    /**
+     * Represent the switch_timer_interval xml element
+     */
+     String SWITCH_TIMER_INTERVAL = "switch_timer_interval";
+
+    /**
+     * Represent the read_timer_interval xml element
+     */
+     String READ_TIMER_INTERVAL = "read_timer_interval";
+
+    /**
+     * Represent the output xml element
+     */
+     String OUTPUT = "output";
+
+    /**
+     * Represent the output_type xml element
+     */
+     String OUTPUT_TYPE = "output_type";
+
+    /**
+     * Represent the tracefile_size xml element
+     */
+     String TRACEFILE_SIZE = "tracefile_size";
+
+    /**
+     * Represent the tracefile_count xml element
+     */
+     String TRACEFILE_COUNT = "tracefile_count";
+
+    /**
+     * Represent the live_timer_interval xml element
+     */
+     String LIVE_TIMER_INTERVAL = "live_timer_interval";
+
+    /**
+     * Represent the type xml element
+     */
+     String TYPE = "type";
+
+    /**
+     * Represent the buffer_type xml element
+     */
+     String BUFFER_TYPE = "buffer_type";
+
+    /**
+     * Represent the session xml element
+     */
+     String SESSION = "session";
+
+    /**
+     * Represent the sessions xml element
+     */
+     String SESSIONS = "sessions";
+
+    /**
+     * Represent the perf xml element
+     */
+     String PERF = "perf";
+
+    /**
+     * Represent the config xml element
+     */
+     String CONFIG = "config";
+
+    /**
+     * Represent the started xml element
+     */
+     String STARTED = "started";
+
+    /**
+     * Represent the snapshot_mode xml element
+     */
+     String SNAPSHOT_MODE = "snapshot_mode";
+
+    /**
+     * Represent the loglevel xml element
+     */
+     String LOGLEVEL = "loglevel";
+
+    /**
+     * Represent the loglevel_type xml element
+     */
+     String LOGLEVEL_TYPE = "loglevel_type";
+
+    /**
+     * Represent the filter xml element
+     */
+     String FILTER = "filter";
+
+    /**
+     * Represent the snapshot_outputs xml element
+     */
+     String SNAPSHOT_OUTPUTS = "snapshot_outputs";
+
+    /**
+     * Represent the consumer_output xml element
+     */
+     String CONSUMER_OUTPUT = "consumer_output";
+
+    /**
+     * Represent the destination xml element
+     */
+     String DESTINATION = "destination";
+
+    /**
+     * Represent the path xml element
+     */
+     String PATH = "path";
+
+    /**
+     * Represent the net_output xml element
+     */
+     String NET_OUTPUT = "net_output";
+
+    /**
+     * Represent the control_uri xml element
+     */
+     String CONTROL_URI = "control_uri";
+
+    /**
+     * Represent the data_uri xml element
+     */
+     String DATA_URI = "data_uri";
+
+    /**
+     * Represent the max_size xml element
+     */
+    String MAX_SIZE = "max_size";
+}
This page took 0.04931 seconds and 5 git commands to generate.