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>
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;
assertNotNull(ed.toString());
}
- EventDeclaration e1;
- EventDeclaration e2;
+ IEventDeclaration e1;
+ IEventDeclaration e2;
@Test
public void testEquals1() {
@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));
}
*/
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.
*
--- /dev/null
+/*******************************************************************************
+ * 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;
+ }
+
+}
* 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$
* 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$
}
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;
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;
/**
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);
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;
*/
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
// ------------------------------------------------------------------------
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
// ------------------------------------------------------------------------