ctf: Introduce LostEventDeclaration singleton
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Mon, 18 May 2015 02:49:24 +0000 (22:49 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Tue, 19 May 2015 20:12:27 +0000 (16:12 -0400)
Move constants from EventDeclaration to IEventDeclaration.
this removes some package cycles but breaks the API.

Change-Id: If20f7927dd878f2719e84fec6656dd7f55bc72e7
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/48040
Reviewed-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
Reviewed-by: Hudson CI
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.tracecompass.ctf.core.tests/src/org/eclipse/tracecompass/ctf/core/tests/types/EventDeclarationTest.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/IEventDeclaration.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/LostEventDeclaration.java [new file with mode: 0644]
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStream.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/trace/CTFStreamInputPacketReader.java
org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/EventDeclaration.java

index 7545050c98395097c1573c8d20884ae421ea27e3..1d20b241532998d8e00f0bfe95dc105a716df754 100644 (file)
@@ -20,6 +20,8 @@ import static org.junit.Assume.assumeTrue;
 
 import org.eclipse.tracecompass.ctf.core.CTFException;
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
+import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
 import org.eclipse.tracecompass.ctf.core.tests.shared.CtfTestTrace;
 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
@@ -336,8 +338,8 @@ public class EventDeclarationTest {
         assertNotNull(ed.toString());
     }
 
-    EventDeclaration e1;
-    EventDeclaration e2;
+    IEventDeclaration e1;
+    IEventDeclaration e2;
 
     @Test
     public void testEquals1() {
@@ -347,26 +349,26 @@ public class EventDeclarationTest {
 
     @Test
     public void testEquals2() {
-        e1 = EventDeclaration.getLostEventDeclaration();
+        e1 = LostEventDeclaration.INSTANCE;
         assertFalse(e1.equals(new Long(23L)));
     }
 
     @Test
     public void testEquals3() {
-        e1 = EventDeclaration.getLostEventDeclaration();
+        e1 = LostEventDeclaration.INSTANCE;
         assertEquals(e1, e1);
     }
 
     @Test
     public void testEquals4() {
-        e1 = EventDeclaration.getLostEventDeclaration();
-        e2 = EventDeclaration.getLostEventDeclaration();
+        e1 = LostEventDeclaration.INSTANCE;
+        e2 = LostEventDeclaration.INSTANCE;
         assertEquals(e1, e2);
     }
 
     @Test
     public void testEquals5() {
-        e1 = EventDeclaration.getLostEventDeclaration();
+        e1 = LostEventDeclaration.INSTANCE;
         e2 = new EventDeclaration();
         assertFalse(e1.equals(e2));
     }
index f29856bf1968e6abe3f4d18f8dfa279f2f217ee4..bb2392fc086d7c8276149cb8169de3cf1e087066 100644 (file)
@@ -28,6 +28,13 @@ import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
  */
 public interface IEventDeclaration {
 
+    /**
+     * Id of events when not set
+     *
+     * @since 1.0
+     */
+    public static final long UNSET_EVENT_ID = -2L;
+
     /**
      * Creates an instance of EventDefinition corresponding to this declaration.
      *
diff --git a/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/LostEventDeclaration.java b/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/LostEventDeclaration.java
new file mode 100644 (file)
index 0000000..1ffddc4
--- /dev/null
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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: Matthew Khouzam - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.ctf.core.event;
+
+import java.util.Collections;
+import java.util.Set;
+
+import org.eclipse.tracecompass.ctf.core.CTFException;
+import org.eclipse.tracecompass.ctf.core.CTFStrings;
+import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
+import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
+import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
+import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
+
+/**
+ * A lost event definition
+ *
+ * @author Matthew Khouzam
+ * @since 1.0
+ */
+public class LostEventDeclaration implements IEventDeclaration {
+
+    /**
+     * Id of lost events
+     *
+     * @since 1.0
+     */
+    public static final long LOST_EVENT_ID = -1L;
+
+    /**
+     * Gets a "lost" event. This is a synthetic event that is there to show that
+     * there should be something there.
+     */
+    public static final LostEventDeclaration INSTANCE = new LostEventDeclaration();
+
+    private final StructDeclaration fFields = new StructDeclaration(0);
+
+    private LostEventDeclaration() {
+        getFields().addField(CTFStrings.LOST_EVENTS_FIELD, IntegerDeclaration.UINT_32B_DECL);
+        getFields().addField(CTFStrings.LOST_EVENTS_DURATION, IntegerDeclaration.UINT_64B_DECL);
+    }
+
+    @Override
+    public EventDefinition createDefinition(CTFStreamInputReader streamInputReader, BitBuffer input, long timestamp) throws CTFException {
+        return null;
+    }
+
+    @Override
+    public String getName() {
+        return CTFStrings.LOST_EVENT_NAME;
+    }
+
+    @Override
+    public StructDeclaration getFields() {
+        return fFields;
+    }
+
+    @Override
+    public StructDeclaration getContext() {
+        return null;
+    }
+
+    @Override
+    public Long getId() {
+        return LOST_EVENT_ID;
+    }
+
+    @Override
+    public CTFStream getStream() {
+        return null;
+    }
+
+    @Override
+    public long getLogLevel() {
+        return 0;
+    }
+
+    @Override
+    public Set<String> getCustomAttributes() {
+        return Collections.<String> emptySet();
+    }
+
+    @Override
+    public String getCustomAttribute(String key) {
+        return null;
+    }
+
+}
index f09b1bf8e237dd7d98db5f4039675419763eab86..22e2232e9c4e8d9ec981ae04d8d70d11dacc7a2f 100644 (file)
@@ -244,7 +244,7 @@ public class CTFStream {
      *             If the passed ID is invalid
      */
     public @Nullable IEventDeclaration getEventDeclaration(int eventId) {
-        int eventIndex = (eventId == EventDeclaration.UNSET_EVENT_ID) ? 0 : eventId;
+        int eventIndex = (eventId == IEventDeclaration.UNSET_EVENT_ID) ? 0 : eventId;
         if (eventIndex < 0) {
             /* Any negative value other than UNSET_EVENT_ID is invalid */
             throw new IllegalArgumentException("Event ID cannot be negative."); //$NON-NLS-1$
@@ -285,7 +285,7 @@ public class CTFStream {
          * If there is an event without id (the null key), it must be the only
          * one
          */
-        if (id == EventDeclaration.UNSET_EVENT_ID) {
+        if (id == IEventDeclaration.UNSET_EVENT_ID) {
             if (!fEvents.isEmpty()) {
                 throw new ParseException("Event without id with multiple events in a stream"); //$NON-NLS-1$
             }
index 5456f77d18498af03dca89fe39960f53f4b7e1fb..765250ca8d49d1a0a2b492870a1778b39e479648 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.tracecompass.ctf.core.CTFException;
 import org.eclipse.tracecompass.ctf.core.CTFStrings;
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
+import org.eclipse.tracecompass.ctf.core.event.LostEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
 import org.eclipse.tracecompass.ctf.core.event.scope.IDefinitionScope;
 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
@@ -37,7 +38,6 @@ import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
 import org.eclipse.tracecompass.ctf.core.event.types.VariantDefinition;
 import org.eclipse.tracecompass.internal.ctf.core.SafeMappedByteBuffer;
-import org.eclipse.tracecompass.internal.ctf.core.event.EventDeclaration;
 import org.eclipse.tracecompass.internal.ctf.core.event.types.composite.EventHeaderDefinition;
 
 /**
@@ -311,11 +311,11 @@ public class CTFStreamInputPacketReader implements IDefinitionScope, AutoCloseab
     public EventDefinition readNextEvent() throws CTFException {
         /* Default values for those fields */
         // compromise since we cannot have 64 bit addressing of arrays yet.
-        int eventID = (int) EventDeclaration.UNSET_EVENT_ID;
+        int eventID = (int) IEventDeclaration.UNSET_EVENT_ID;
         long timestamp = 0;
         if (fHasLost) {
             fHasLost = false;
-            EventDeclaration lostEventDeclaration = EventDeclaration.getLostEventDeclaration();
+            IEventDeclaration lostEventDeclaration = LostEventDeclaration.INSTANCE;
             StructDeclaration lostFields = lostEventDeclaration.getFields();
             // this is a hard coded map, we know it's not null
             IntegerDeclaration lostFieldsDecl = (IntegerDeclaration) lostFields.getField(CTFStrings.LOST_EVENTS_FIELD);
index c519e94f077c74e3df1e6c3d7ea6c67b16ee3fdb..6167586ad399bbd90359957a08d26e9ad5d9e007 100644 (file)
@@ -18,13 +18,11 @@ import java.util.Set;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.tracecompass.ctf.core.CTFException;
-import org.eclipse.tracecompass.ctf.core.CTFStrings;
 import org.eclipse.tracecompass.ctf.core.event.EventDefinition;
 import org.eclipse.tracecompass.ctf.core.event.IEventDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.io.BitBuffer;
 import org.eclipse.tracecompass.ctf.core.event.scope.ILexicalScope;
 import org.eclipse.tracecompass.ctf.core.event.types.ICompositeDefinition;
-import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDeclaration;
 import org.eclipse.tracecompass.ctf.core.event.types.StructDefinition;
 import org.eclipse.tracecompass.ctf.core.trace.CTFStream;
@@ -36,12 +34,6 @@ import org.eclipse.tracecompass.ctf.core.trace.CTFStreamInputReader;
  */
 public class EventDeclaration implements IEventDeclaration {
 
-    /** Id of lost events */
-    public static final long LOST_EVENT_ID = -1L;
-
-    /** Id of events when not set */
-    public static final long UNSET_EVENT_ID = -2L;
-
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -108,22 +100,6 @@ public class EventDeclaration implements IEventDeclaration {
                 eventPayload);
     }
 
-    /**
-     * Creates a "lost" event. This is a synthetic event that is there to show
-     * that there should be something there.
-     *
-     * @return the lost event
-     */
-    public static synchronized EventDeclaration getLostEventDeclaration() {
-        EventDeclaration lostEvent = new EventDeclaration();
-        lostEvent.fFields = new StructDeclaration(0);
-        lostEvent.fId = (int) LOST_EVENT_ID;
-        lostEvent.fName = CTFStrings.LOST_EVENT_NAME;
-        lostEvent.getFields().addField(CTFStrings.LOST_EVENTS_FIELD, IntegerDeclaration.UINT_32B_DECL);
-        lostEvent.getFields().addField(CTFStrings.LOST_EVENTS_DURATION, IntegerDeclaration.UINT_64B_DECL);
-        return lostEvent;
-    }
-
     // ------------------------------------------------------------------------
     // Getters/Setters/Predicates
     // ------------------------------------------------------------------------
This page took 0.033501 seconds and 5 git commands to generate.