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 / controlflow / model / FlowProcessContainer.java
index 65e0f369a0e5a99072074e2db9cc00e03d9d01b0..f3b0053f8fabd64016a69a25c00590d749e013d0 100644 (file)
@@ -8,13 +8,15 @@
  * 
  * Contributors:
  *   Alvaro Sanchez-Leon - Initial API and implementation
+ *      Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
  *******************************************************************************/
 package org.eclipse.linuxtools.lttng.ui.views.controlflow.model;
 
 import java.util.HashMap;
 import java.util.Iterator;
 
-import org.eclipse.linuxtools.lttng.TraceDebug;
+import org.eclipse.linuxtools.lttng.core.TraceDebug;
+import org.eclipse.linuxtools.lttng.ui.model.trange.ItemContainer;
 import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
 
 /**
@@ -23,7 +25,7 @@ import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventProcess;
  * @author alvaro
  * 
  */
-public class FlowProcessContainer {
+public class FlowProcessContainer implements ItemContainer<TimeRangeEventProcess> {
        // ========================================================================
        // Data
        // ========================================================================
@@ -51,9 +53,10 @@ public class FlowProcessContainer {
         * 
         * @param newProcess   The process to add
         */
-       public void addProcess(TimeRangeEventProcess newProcess) {
-               if (newProcess != null) {
-                       allProcesses.put(new ProcessKey(newProcess), newProcess);
+       @Override
+       public void addItem(TimeRangeEventProcess newItem) {
+               if (newItem != null) {
+                       allProcesses.put(new ProcessKey(newItem), newItem);
                }
        }
        
@@ -62,7 +65,8 @@ public class FlowProcessContainer {
      * 
      * @return Integer
      */
-    public Integer getUniqueId() {
+    @Override
+       public Integer getUniqueId() {
         return uniqueId++;
     }
     
@@ -72,37 +76,33 @@ public class FlowProcessContainer {
      * 
      * @return TimeRangeEventProcess[]
      */
-       public TimeRangeEventProcess[] readProcesses() {
+       @Override
+       public TimeRangeEventProcess[] readItems() {
                
            // This allow us to return an Array of the correct type of the exact correct dimension, without looping
                return allProcesses.values().toArray(new TimeRangeEventProcess[allProcesses.size()]);
        }
        
        /**
-     * Clear the children information for processes related to a specific trace
-     * e.g. just before refreshing data with a new time range
-     * 
-     * @param traceId   The trace unique id (trace name?) on which we need to eliminate children.
-     */
-       public void clearChildren(String traceId) {
+        * Clear the children information for processes e.g. just before refreshing
+        * data with a new time range
+        */
+       @Override
+       public void clearChildren() {
            TimeRangeEventProcess process = null;
         Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
         
         while (iterator.hasNext()) {
             process = allProcesses.get(iterator.next());
-            
-            if (process.getTraceID().equals(traceId)) {
-                // Reset clear childEventComposites() and traceEvents()
-                // Also restore the nextGoodTime to the insertionTime for the drawing
-                process.reset();
-            }
+                       process.reset();
         }
        }
        
        /**
      * Clear all process items
      */
-    public void clearProcesses() {
+    @Override
+       public void clearItems() {
         allProcesses.clear();
     }
        
@@ -112,7 +112,8 @@ public class FlowProcessContainer {
      * 
      * @param traceId   The trace unique id (trace name?) on which we want to remove process
      */
-       public void removeProcesses(String traceId) {
+       @Override
+       public void removeItems(String traceId) {
            ProcessKey iterKey = null;
 
         Iterator<ProcessKey> iterator = allProcesses.keySet().iterator();
@@ -176,27 +177,31 @@ class ProcessKey {
         if ( obj instanceof ProcessKey ) {
                ProcessKey procKey = (ProcessKey) obj;
                
-               if ( valueRef != null ) {
-                   if ( (procKey.getPid().equals(valueRef.getPid()) ) &&
-                        (procKey.getTraceId().equals(valueRef.getTraceID()) ) &&
-                        (procKey.getCpuId().equals(valueRef.getCpu()) ) &&
-                        (procKey.getCreationtime().equals(valueRef.getCreationTime()) )  )
-                   {
-                       isSame = true;
-                   }
-               }
-               else {
-                       if ( (procKey.getPid().equals(this.pid ) ) &&
-                        (procKey.getTraceId().equals(this.traceId ) ) &&
-                        (procKey.getCpuId().equals(this.cpuId ) ) &&
-                        (procKey.getCreationtime().equals(this.creationtime ) )  )
-                   {
-                       isSame = true;
-                   }
-               }
+                       if (valueRef != null) {
+                               if ((procKey.getPid().equals(valueRef.getPid()))
+                                               && (procKey.getTraceId().equals(valueRef.getTraceID()))
+                                               && (procKey.getCreationtime().equals(valueRef.getCreationTime()))) {
+                                       // use the cpu value to validate pid 0
+                                       if (valueRef.getPid().longValue() == 0L && !procKey.getCpuId().equals(valueRef.getCpu())) {
+                                               isSame = false;
+                                       } else {
+                                               isSame = true;
+                                       }
+                               }
+                       } else {
+                               if ((procKey.getPid().equals(this.pid)) && (procKey.getTraceId().equals(this.traceId))
+                                               && (procKey.getCreationtime().equals(this.creationtime))) {
+                                       // use the cpu value to validate pid 0
+                                       if (this.pid.longValue() == 0L && !procKey.getCpuId().equals(this.cpuId)) {
+                                               isSame = false;
+                                       } else {
+                                               isSame = true;
+                                       }
+                               }
+                       }
         }
         else {
-               TraceDebug.debug("ERROR : The given key is not of the type ProcessKey!" + obj.getClass().toString());
+               TraceDebug.debug("ERROR : The given key is not of the type ProcessKey!" + obj.getClass().toString()); //$NON-NLS-1$
         }
         
         return isSame;
@@ -246,12 +251,21 @@ class ProcessKey {
     }
     
     
-    @Override
+       @Override
+    @SuppressWarnings("nls")
     public String toString() {
         if ( valueRef != null ) {
-            return (valueRef.getPid().toString() + ":" + valueRef.getCpu().toString() + ":" + valueRef.getTraceID().toString() + ":" + valueRef.getCreationTime().toString());
+                       // return (valueRef.getPid().toString() + ":" +
+                       // valueRef.getCpu().toString() + ":"
+                       // + valueRef.getTraceID().toString() + ":" +
+                       // valueRef.getCreationTime().toString());
+                       return (valueRef.getPid().toString() + ":" + valueRef.getTraceID().toString() + ":" + valueRef
+                                       .getCreationTime().toString());
         } 
         
-        return (pid.toString() + ":" + cpuId.toString() + ":" + traceId.toString() + ":" + creationtime.toString());
+               // return (pid.toString() + ":" + cpuId.toString() + ":" +
+               // traceId.toString() + ":" + creationtime.toString());
+
+               return (pid.toString() + ":" + traceId.toString() + ":" + creationtime.toString());
     }
 }
This page took 0.025584 seconds and 5 git commands to generate.