Browse Source

Extends Controller & Packet Manager

* Controller notifies other relevant Panels on change
* Packet Manager does not call inactive collectors
Andreas T. Meyer-Berg 4 years ago
parent
commit
2f3a5df553

+ 43 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/PacketCaptureController.java

@@ -163,7 +163,49 @@ public class PacketCaptureController {
 			notifyObservers();
 		}
 	}
-	
+	/**
+	 * Returns training or testing mode of the algorithm.
+	 * @param collector Collector which is used
+	 * @return true if testing or false if training the algorithm.
+	 */
+	public boolean getMode(PacketCollector collector) {
+		if(collector == null) 
+			return false;
+		return collector.getMode();
+	}
+
+	/**
+	 * Sets the training or testing mode
+	 * @param collector Collector which is used
+	 * @param mode true if testing or false if training the algorithm.
+	 */
+	public void setMode(PacketCollector collector, boolean mode) {
+		if(collector == null) return;
+		collector.setMode(mode);
+		notifyObservers();
+	}
+
+	/**
+	 * Whether the algorithm should run
+	 * @param collector Collector which is used
+	 * @return true if algorithm will be executed
+	 */
+	public boolean isActive(PacketCollector collector) {
+		if(collector == null) 
+			return false;
+		return collector.isActive();
+	}
+
+	/**
+	 * Set to true, if it should run
+	 * @param collector Collector which is used
+	 * @param active true if it should be active
+	 */
+	public void setActive(PacketCollector collector, boolean active) {
+		if(collector == null)return;
+		collector.setActive(active);
+		notifyObservers();
+	}
 	/**
 	 * Notify all observers of the packet collection managers
 	 */

+ 2 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/PacketCollectionManager.java

@@ -38,6 +38,7 @@ public class PacketCollectionManager extends Observable {
 		 */
 		for(PacketCollector col: collectors){
 			col.resetPackets();
+			if(!col.isActive())continue;
 			/**
 			 * Add all links, which packets should be collected
 			 */
@@ -74,7 +75,7 @@ public class PacketCollectionManager extends Observable {
 	 */
 	public void runPacketAlgorithms(){
 		for(PacketCollector collector:collectors){
-			if(collector.getPacketAlgorithm()!=null){
+			if(collector.isActive() && collector.getPacketAlgorithm()!=null){
 				collector.getPacketAlgorithm().processPackets(collector.getPackets());
 			}
 		}