tmf: lttngControl: TraceEnablement: mi support + utility function
authorJonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Fri, 15 Aug 2014 17:57:21 +0000 (13:57 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 27 Aug 2014 15:31:15 +0000 (11:31 -0400)
Change-Id: Ib2cdddaaf37fa3ef0c8fa4ccfaa6d79ef4ee3714
Signed-off-by: Jonathan Rajotte Julien <jonathan.rajotte-julien@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/30976
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>
org.eclipse.linuxtools.lttng2.control.core.tests/src/org/eclipse/linuxtools/lttng2/control/core/tests/model/impl/EventInfoTest.java
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/TraceEnablement.java
org.eclipse.linuxtools.lttng2.control.core/src/org/eclipse/linuxtools/internal/lttng2/control/core/model/impl/EventInfo.java

index bc15edd028291d600cb03d7e47f89fb75284b095..e0c5212a352b5bb73dd2401876897fe131970a58 100644 (file)
@@ -168,6 +168,13 @@ public class EventInfoTest {
         assertEquals("DISABLED", state.toString());
         assertEquals(0, state.ordinal());
 
+        fixture.setState("false");
+        state = fixture.getState();
+        assertEquals("false", state.getInMiName());
+        assertEquals("DISABLED", state.name());
+        assertEquals("DISABLED", state.toString());
+        assertEquals(0, state.ordinal());
+
         fixture.setState("bla");
         state = fixture.getState();
         assertEquals("disabled", state.getInName());
@@ -182,6 +189,13 @@ public class EventInfoTest {
         assertEquals("ENABLED", state.toString());
         assertEquals(1, state.ordinal());
 
+        fixture.setState("true");
+        state = fixture.getState();
+        assertEquals("true", state.getInMiName());
+        assertEquals("ENABLED", state.name());
+        assertEquals("ENABLED", state.toString());
+        assertEquals(1, state.ordinal());
+
         // setState(TraceEnablement state)
         fixture.setState(TraceEnablement.DISABLED);
         state = fixture.getState();
index 77e15c2b23fecb8c1645f521c8129cc28c841992..a9583e3f29d1bc2027f680d61f6e71e65593955f 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,14 @@
  *
  * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Jonathan Rajotte - Machine interface support and utility function
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.control.core.model;
 
+import java.security.InvalidParameterException;
+
 /**
- * <p>
  * Enumeration for enabled/disabled states.
- * </p>
  *
  * @author Bernd Hufmann
  */
@@ -24,9 +25,9 @@ public enum TraceEnablement {
     // Enum definition
     // ------------------------------------------------------------------------
     /** Tracing is disabled */
-    DISABLED("disabled"), //$NON-NLS-1$
+    DISABLED("disabled", "false"), //$NON-NLS-1$ //$NON-NLS-2$
     /** Tracing is enabled */
-    ENABLED("enabled"); //$NON-NLS-1$
+    ENABLED("enabled", "true"); //$NON-NLS-1$ //$NON-NLS-2$
 
     // ------------------------------------------------------------------------
     // Attributes
@@ -35,6 +36,7 @@ public enum TraceEnablement {
      * Name of enum
      */
     private final String fInName;
+    private final String fInMiName;
 
     // ------------------------------------------------------------------------
     // Constuctors
@@ -42,10 +44,13 @@ public enum TraceEnablement {
 
     /**
      * Private constructor
-     * @param name the name of state
+     *
+     * @param name
+     *            the name of state
      */
-    private TraceEnablement(String name) {
+    private TraceEnablement(String name, String miName) {
         fInName = name;
+        fInMiName = miName;
     }
 
     // ------------------------------------------------------------------------
@@ -57,4 +62,30 @@ public enum TraceEnablement {
     public String getInName() {
         return fInName;
     }
+
+    /**
+     * @return state name
+     */
+    public String getInMiName() {
+        return fInMiName;
+    }
+
+    /**
+     * @param name
+     *            name of the desired enum
+     * @return the corresponding {@link TraceEnablement} matching name
+     */
+    public static TraceEnablement valueOfString(String name) {
+        if (name == null) {
+            throw new InvalidParameterException();
+        }
+        for (TraceEnablement enablementType : TraceEnablement.values()) {
+            boolean exist = enablementType.fInName.equalsIgnoreCase(name) || enablementType.fInMiName.equalsIgnoreCase(name);
+            if (exist) {
+                return enablementType;
+            }
+        }
+        return DISABLED;
+    }
+
 }
index 7da1b6b3fab0112ce1204d1a9ee7384272869165..1de851095fc9822cb3a8eb1463c758251cdcfdba 100644 (file)
@@ -74,12 +74,7 @@ public class EventInfo extends BaseEventInfo implements IEventInfo {
 
     @Override
     public void setState(String stateName) {
-        fState = TraceEnablement.DISABLED;
-        if (TraceEnablement.DISABLED.getInName().equals(stateName)) {
-            fState = TraceEnablement.DISABLED;
-        } else if (TraceEnablement.ENABLED.getInName().equals(stateName)) {
-            fState = TraceEnablement.ENABLED;
-        }
+        fState = TraceEnablement.valueOfString(stateName);
     }
 
     @Override
This page took 0.028657 seconds and 5 git commands to generate.