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 43d27025e6a719a98ee572da483014d024c33c6f..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.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;
-       
-       private boolean requestCompleted = false;
-       
-       @SuppressWarnings("unchecked")
-       public HistogramRequest(Class<? extends TmfEvent> dataType, TmfTimeRange range, int nbRequested, HistogramContent newContent, TraceCanvas newParentCanvas, Long timeInterval) {
-        super((Class<LttngEvent>)dataType, range, nbRequested, MAX_EVENTS_PER_REQUEST);
-        
-        // *** FIXME ***
-        // This does not work! The request won't be processed or the number of events returned is wrong!
-        // We cannot use this !
-               //super((Class<LttngEvent>)dataType, range);
-               
-        histogramContent = newContent;
-        parentCanvas = newParentCanvas;
-        
-        histogramContent.resetContentData();
-        histogramContent.setStartTime(range.getStartTime().getValue());
-        histogramContent.setEndTime(range.getEndTime().getValue());
-        histogramContent.setIntervalTime(timeInterval);
-        histogramContent.resetTable();
-        
-        lastRangeTime = histogramContent.getStartTime();
+
+    // ------------------------------------------------------------------------
+    // 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;
-        
-        // *** FIXME ***
-       // *** EVIL BUG ***
-        // The request by timerange only does not work! (see constructor above) 
-       //      However, the request with number of events will loop until it reach its number or EOF
-       //  We have to filter out ourself the extra useless events!
-       //
-        if ( (evt[0] != null) && (requestCompleted == false) ) {
-               LttngEvent tmpEvent = (LttngEvent)evt[0];
-               
-               // This check is linked to the evil fix mentionned above
-               if ( tmpEvent.getTimestamp().getValue() <= histogramContent.getEndTime() ) {
-               
-                       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() );
-                                       
-                                       // *** HACK ***
-                                       // Because of the threads, weird phenomenons seem to happen here, like a position after the 
-                                       //       element range because another request was issued.
-                                       // This enforce the position but may result in slightly inconsistent result (i.e. a weird misplaced bar sometime).
-                                       if ( lastPos < 0 ) {
-                                               lastPos = 0;
-                                       }
-                                       else if ( lastPos >= histogramContent.getNbElement() ) {
-                                               lastPos = (histogramContent.getNbElement()-1);
-                                       }
-                                       
-                                       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();
-                               }
-               }
-               else {
-                       // *** FIXME ***
-               // *** EVIL FIX ***
-                // Because of the other evil bug (see above), we have to ignore extra useless events we will get
-                       // However, we might be far away from the end so we better start a redraw now
-                       redrawAsyncronously();
-                       requestCompleted = true;
-                       
-                       // Althought it won't do anything, try to call control functions to stop the request
-                       done();
-                       cancel();
-                       fail();
-               }
-               }
+    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() {
-       // Nothing different from completed.
+    public void handleData(LttngEvent event) {
+        super.handleData(event);
+        if (event != null) {
+            long timestamp = event.getTimestamp().getValue();
+            fHistogram.countEvent(timestamp);
+        }
     }
-    
+
     @Override
-    public void handleFailure() {
-       // Nothing different from cancel.
+    public void handleCompleted() {
+        fHistogram.refresh();
+        super.handleCompleted();
     }
-    
+
     @Override
     public void handleCancel() {
-       redrawAsyncronously();
-               requestCompleted = true;
-    }
-       
-    
-    public void updateEventsInfo() {
-       int averageNumberOfEvents = nbEventRead / nbPosNotEmpty;
-               histogramContent.setAverageNumberOfEvents(averageNumberOfEvents);
-               histogramContent.recalculateEventHeight();
+        fHistogram.refresh();
+        super.handleCancel();
     }
-    
-    public void redrawAsyncronously() {
-       updateEventsInfo();
-       // canvas redraw is already asynchronous
-       parentCanvas.redrawAsynchronously();
-    }
-    
+
 }
This page took 0.025763 seconds and 5 git commands to generate.