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 📥

Pipeline.scala 2.48 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
package de.bbisping.coupledsim.tool.control

import de.bbisping.coupledsim.tool.arch.Action
import de.bbisping.coupledsim.tool.arch.Control

class Pipeline(val main: Control) extends ModelComponent {
  
  var pipelineSource = Array[String]()
  var operations = Map[String, StructureOperation]()
  var currentStep = 0
  
  def changePipeline(code: String) = {
    pipelineSource = code.split("\n")
  }
  
  def runPipeline() = {
  }
  
  def stepPipeline() = {
    println("pipeline step")
    if (pipelineSource.length <= currentStep) {
      false
    } else {
      val currentLine = pipelineSource(currentStep).trim()
      val operation = operations.get(currentLine)
      
      for (
        op <- operation
      ) {
        main.dispatchAction(Structure.StructureCallOperation(op.slug))
      }
      
      setStep(currentStep + 1)
      
      operation.isDefined
    }
  }
  
  def resetPipeline() = {
    setStep(0)
  }
  
  def setStep(step: Int) = {
    currentStep = step
    broadcast(Pipeline.PipelineStatusChange(List(Pipeline.CurrentLine(currentStep))))
  }
  
  def notify(change: ModelComponent.Change) = change match {
    case Structure.StructureOperationsChanged(ops) =>
      operations = ops toMap
    case Structure.StructureChange(_) =>
      resetPipeline()
    case _ => 
  }
}

object Pipeline {
  
  abstract class LineInfo(line: Int)
  case class CurrentLine(line: Int) extends LineInfo(line)
  
  case class PipelineStatusChange(pipelineStatus: List[LineInfo]) extends ModelComponent.Change
  
  abstract sealed class PipelineAction extends Action {
    override def implement(target: ModelComponent): Boolean = target match {
      case s: Pipeline => 
        implementPipeline(s)
      case _ =>
        false
    }
    
    def implementPipeline(pipeline: Pipeline): Boolean
  }
  
  case class LoadPipeline(code: String) extends PipelineAction {
    override def implementPipeline(pipeline: Pipeline) = {
      println("pipeline: "+code)
      pipeline.changePipeline(code)
      true
    }
  }
  
  case class StepPipeline() extends PipelineAction {
    override def implementPipeline(pipeline: Pipeline) = {
      pipeline.stepPipeline()
      true
    }
  }
  
  case class RunPipeline() extends PipelineAction {
    override def implementPipeline(pipeline: Pipeline) = {
      pipeline.runPipeline()
      true
    }
  }
  
  case class ResetPipeline() extends PipelineAction {
    override def implementPipeline(pipeline: Pipeline) = {
      pipeline.resetPipeline()
      true
    }
  }
  
}