This GitLab instance reached the end of its service life. It won't be possible to create new users or projects.

Please read the deprecation notice for more information concerning the deprecation timeline

Visit migration.git.tu-berlin.de (internal network only) to import your old projects to the new GitLab platform 📥

Control.scala 1.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
package de.bbisping.coupledsim.tool.arch

import scala.collection.mutable.Queue
import de.bbisping.coupledsim.tool.view.ViewComponent
import de.bbisping.coupledsim.tool.control.ModelComponent

trait Control extends ActionDispatcher {
  
  val pendingChanges = Queue[ModelComponent.Change]()
  var changeDeliveryRunning: Boolean = false
  
  /**
   * mutable list of registered view components
   */
  val viewComponents = Queue[ViewComponent]()
  
  /**
   * mutable list of registered model components
   */
  val modelComponents = Queue[ModelComponent]()
  
  def broadcastChange(change: ModelComponent.Change) {
    pendingChanges.enqueue(change)
    
    if (!changeDeliveryRunning) {
      changeDeliveryRunning = true
      while(pendingChanges.nonEmpty) {
        val ch = pendingChanges.dequeue()
        println("processing " + ch)
        modelComponents.foreach(_.notify(ch))
        viewComponents.foreach(_.notify(ch))
      }
      changeDeliveryRunning = false
    }
  }
  
  def registerViewComponent(component: ViewComponent) {
    viewComponents.enqueue(component)
  }
  
  def registerModelComponent(component: ModelComponent) {
    modelComponents.enqueue(component)
  }
}