Re-structure LTTng sub-project as per the Linux Tools guidelines
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / histogram / HistogramRequest.java
index 3f3bc6c8e21db010f199055a19de89064f670f55..2b88329570eabb9bade5ffd75ecc725bf35c8357 100644 (file)
+/*******************************************************************************
+ * Copyright (c) 2009, 2011 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:
+ *   William Bourque - Initial API and implementation
+ *   Yuriy Vashchuk - Heritage correction.
+ *   Francois Chouinard - Cleanup and refactoring
+ *******************************************************************************/
+
 package org.eclipse.linuxtools.lttng.ui.views.histogram;
 
-import org.eclipse.linuxtools.lttng.event.LttngEvent;
-import org.eclipse.linuxtools.tmf.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
-import org.eclipse.linuxtools.tmf.request.TmfEventRequest;
-import org.eclipse.swt.widgets.Display;
+import org.eclipse.linuxtools.lttng.core.LttngConstants;
+import org.eclipse.linuxtools.lttng.core.event.LttngEvent;
+import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
+import org.eclipse.linuxtools.tmf.core.request.ITmfDataRequest;
+import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest;
 
+/**
+ * <b><u>HistogramRequest</u></b>
+ * <p>
+ */
 public class HistogramRequest extends TmfEventRequest<LttngEvent> {
-       
-       final static int MAX_EVENTS_PER_REQUEST = 1;
-       final static int REDRAW_EVERY_NB_EVENTS = 10000;
-       
-       private HistogramContent histogramContent = null;
-       
-       private int lastPos = 0;
-       private long lastRangeTime = 0L;
-       private long nbEventsInRange = 1;
-       
-       private int  nbPosNotEmpty = 1;
-       private int  nbEventRead = 0;
-       
-       private TraceCanvas parentCanvas = null;
-       
-       @SuppressWarnings("unchecked")
-       public HistogramRequest(Class<? extends TmfEvent> dataType, TmfTimeRange range, int nbRequested, HistogramContent newContent, TraceCanvas newParentCanvas) {
-        super((Class<LttngEvent>)dataType, range, nbRequested, MAX_EVENTS_PER_REQUEST);
-        
-        histogramContent = newContent;
-        parentCanvas = newParentCanvas;
-        
-        lastRangeTime = histogramContent.getStartTime();
-        
-        histogramContent.resetContentData();
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+
+    private final Histogram fHistogram;
+
+    // ------------------------------------------------------------------------
+    // Constructor
+    // ------------------------------------------------------------------------
+
+    public HistogramRequest(Histogram histogram, TmfTimeRange range, int rank, int nbEvents, ITmfDataRequest.ExecutionType execType) {
+        super(LttngEvent.class, range, rank, nbEvents, LttngConstants.DEFAULT_BLOCK_SIZE, execType);
+        fHistogram = histogram;
     }
 
-       @Override
-    public void handleData() {
-        TmfEvent[] result = getData();
-        TmfEvent[] evt = new TmfEvent[1];
-        
-        evt[0] = (result.length > 0) ? result[0] : null;
-        
-        if ( evt[0] != null ) {
-               LttngEvent tmpEvent = (LttngEvent)evt[0];
-               
-               long distance = ( tmpEvent.getTimestamp().getValue() - lastRangeTime );
-                       
-                       if  ( distance > histogramContent.getIntervalTime() ) {
-                               
-                               histogramContent.getElementByIndex(lastPos).intervalNbEvents = nbEventsInRange;
-                               lastRangeTime = tmpEvent.getTimestamp().getValue();
-                               
-                               lastPos = (int)((lastRangeTime - histogramContent.getStartTime()) / histogramContent.getIntervalTime() );
-                               histogramContent.getElementByIndex(lastPos).firstIntervalTimestamp = lastRangeTime;
-                               
-                               histogramContent.setReadyUpToPosition(lastPos);
-                               
-                               nbPosNotEmpty++;
-                               nbEventsInRange = 1;
-                       }
-                       else {
-                               nbEventsInRange++;
-                               if ( nbEventsInRange > histogramContent.getHeighestEventCount() ) {
-                                       histogramContent.setHeighestEventCount(nbEventsInRange);
-                               }
-                       }
-                       
-                       nbEventRead++;
-                       
-                       if ( nbEventRead % REDRAW_EVERY_NB_EVENTS == 0 ) {
-                               redrawAsyncronously();
-                       }
-                       
-               }
+    public HistogramRequest(Histogram histogram, TmfTimeRange range, ITmfDataRequest.ExecutionType execType) {
+        this(histogram, range, 0, ALL_DATA, execType);
     }
-       
-    @Override
-    public void handleCompleted() {
-               redrawAsyncronously();
+
+    public HistogramRequest(Histogram histogram, TmfTimeRange range, int rank, ITmfDataRequest.ExecutionType execType) {
+        this(histogram, range, rank, ALL_DATA, execType);
     }
-    
+
+    // ------------------------------------------------------------------------
+    // TmfEventRequest
+    // ------------------------------------------------------------------------
+
     @Override
-    public void handleSuccess() {
+    public void handleData(LttngEvent event) {
+        super.handleData(event);
+        if (event != null) {
+            long timestamp = event.getTimestamp().getValue();
+            fHistogram.countEvent(timestamp);
+        }
     }
-    
+
     @Override
-    public void handleFailure() {
+    public void handleCompleted() {
+        fHistogram.refresh();
+        super.handleCompleted();
     }
-    
+
     @Override
     public void handleCancel() {
+        fHistogram.refresh();
+        super.handleCancel();
     }
-       
-    
-    public void updateEventsInfo() {
-       int averageNumberOfEvents = nbEventRead / nbPosNotEmpty;
-               histogramContent.setAverageNumberOfEvents(averageNumberOfEvents);
-               histogramContent.recalculateEventHeight();
-    }
-    
-    public void redrawAsyncronously() {
-       updateEventsInfo();
-       
-       Display display = parentCanvas.getDisplay();
-               display.asyncExec(new Runnable() {
-                       public void run() {
-                               parentCanvas.redraw();
-                       }
-               });
-    }
-    
+
 }
This page took 0.026744 seconds and 5 git commands to generate.