LTTng: CPU usage analysis from the LTTng kernel trace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / ctfadaptor / CtfLocation.java
index 4c7ebb1d047b8beea24d0d48f19a23e136c249f5..e59a2d35c35079a00b0bc19b1bdd4f73bf6f0b96 100644 (file)
+/*******************************************************************************
+ * Copyright (c) 2012, 2013 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
+ *   Alexandre Montplaisir - Extends TmfLocation
+ *******************************************************************************/
 package org.eclipse.linuxtools.tmf.core.ctfadaptor;
 
-import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp;
-import org.eclipse.linuxtools.tmf.core.trace.ITmfLocation;
+import java.nio.ByteBuffer;
 
-public class CtfLocation implements ITmfLocation<Long> {
+import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.trace.location.TmfLocation;
 
-    public static final Long INVALID_LOCATION = -1L;
+/**
+ * The nugget of information that is unique to a location in a CTF trace.
+ *
+ * It can be copied and used to restore a position in a given trace.
+ *
+ * @version 1.0
+ * @author Matthew Khouzam
+ */
+public final class CtfLocation extends TmfLocation {
 
-    public CtfLocation(Long location) {
-        setLocation(location);
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    /**
+     * An invalid location
+     */
+    public static final CtfLocationInfo INVALID_LOCATION = new CtfLocationInfo(-1, -1);
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Basic constructor for CtfLocation. Uses a default index of 0.
+     *
+     * @param timestamp
+     *            The timestamp of this location
+     * @since 2.0
+     */
+    public CtfLocation(final ITmfTimestamp timestamp) {
+        this(timestamp.getValue(), 0);
+    }
+
+    /**
+     * Constructor using timestamp object and index
+     *
+     * @param timestamp
+     *            The timestamp of this location
+     * @param index
+     *            The index of this location for this timestamp
+     * @since 2.0
+     */
+    public CtfLocation(final ITmfTimestamp timestamp, long index) {
+        this(timestamp.getValue(), index);
+    }
+
+    /**
+     * Constructor using a long value for the timestamp, and an index
+     *
+     * @param timestampValue
+     *            The new timestamp
+     * @param index
+     *            The new index
+     * @since 2.0
+     */
+    public CtfLocation(final long timestampValue, final long index) {
+       super(new CtfLocationInfo(timestampValue, index));
+    }
+
+    /**
+     * Constructor using a pre-made locationInfo object
+     *
+     * @param locationInfo
+     *            The locationInfo object to use
+     * @since 2.0
+     */
+    public CtfLocation(CtfLocationInfo locationInfo) {
+        super(locationInfo);
     }
 
-    public CtfLocation(ITmfTimestamp timestamp) {
-        setLocation(timestamp.getValue());
+    /**
+     * Copy constructor
+     *
+     * @param location
+     *            Other location to copy
+     * @since 2.0
+     */
+    public CtfLocation(final CtfLocation location) {
+        super(location);
     }
 
-    private Long fTimestamp;
+    // ------------------------------------------------------------------------
+    // TmfLocation
+    // ------------------------------------------------------------------------
 
-//    @Override
-    public void setLocation(Long location) {
-        this.fTimestamp = location;
+    /**
+     * Construct the location from the ByteBuffer.
+     *
+     * @param bufferIn
+     *            the buffer to read from
+     *
+     * @since 3.0
+     */
+    public CtfLocation(ByteBuffer bufferIn) {
+        super(new CtfLocationInfo(bufferIn));
     }
 
+    /**
+     * @since 2.0
+     */
     @Override
-    public Long getLocation() {
-        return this.fTimestamp;
+    public CtfLocationInfo getLocationInfo() {
+        return (CtfLocationInfo) super.getLocationInfo();
     }
 
+    // ------------------------------------------------------------------------
+    // Object
+    // ------------------------------------------------------------------------
+
     @Override
-    public CtfLocation clone() {
-        return new CtfLocation(getLocation());
+    public String toString() {
+        if (getLocationInfo().equals(CtfLocation.INVALID_LOCATION )) {
+            return getClass().getSimpleName() + " [INVALID]"; //$NON-NLS-1$
+        }
+        return super.toString();
     }
 
+    /**
+     * Constructs the location from the ByteBuffer. This typically happens when reading from disk.
+     *
+     * @since 3.0
+     */
+    @Override
+    public void serialize(ByteBuffer bufferOut) {
+        getLocationInfo().serialize(bufferOut);
+    }
 }
This page took 0.030035 seconds and 5 git commands to generate.