src/Pure/System/session.scala
author wenzelm
Mon Sep 05 23:26:41 2011 +0200 (2011-09-05 ago)
changeset 44722 a8331fb5c959
parent 44721 ba478c3f7255
child 44732 c58b69d888ac
permissions -rw-r--r--
commands_change_delay within main actor -- prevents overloading of commands_change_buffer input channel;
wenzelm@36676
     1
/*  Title:      Pure/System/session.scala
wenzelm@36676
     2
    Author:     Makarius
wenzelm@38221
     3
    Options:    :folding=explicit:collapseFolds=1:
wenzelm@36676
     4
wenzelm@43651
     5
Main Isabelle/Scala session, potentially with running prover process.
wenzelm@36676
     6
*/
wenzelm@34777
     7
wenzelm@34871
     8
package isabelle
wenzelm@34777
     9
wenzelm@43520
    10
import java.lang.System
wenzelm@34777
    11
wenzelm@34820
    12
import scala.actors.TIMEOUT
wenzelm@34777
    13
import scala.actors.Actor._
wenzelm@34777
    14
wenzelm@34815
    15
wenzelm@34791
    16
object Session
wenzelm@34791
    17
{
wenzelm@34813
    18
  /* events */
wenzelm@34813
    19
wenzelm@43716
    20
  //{{{
wenzelm@34791
    21
  case object Global_Settings
wenzelm@37849
    22
  case object Perspective
wenzelm@38849
    23
  case object Assignment
wenzelm@44615
    24
  case class Commands_Changed(nodes: Set[Document.Node.Name], commands: Set[Command])
wenzelm@39630
    25
wenzelm@39630
    26
  sealed abstract class Phase
wenzelm@39630
    27
  case object Inactive extends Phase
wenzelm@39701
    28
  case object Startup extends Phase  // transient
wenzelm@39701
    29
  case object Failed extends Phase
wenzelm@39630
    30
  case object Ready extends Phase
wenzelm@39701
    31
  case object Shutdown extends Phase  // transient
wenzelm@43716
    32
  //}}}
wenzelm@34791
    33
}
wenzelm@34791
    34
wenzelm@34777
    35
wenzelm@44574
    36
class Session(thy_load: Thy_Load)
wenzelm@34777
    37
{
wenzelm@37849
    38
  /* real time parameters */  // FIXME properties or settings (!?)
wenzelm@37849
    39
wenzelm@43716
    40
  val input_delay = Time.seconds(0.3)  // user input (e.g. text edits, cursor movement)
wenzelm@43716
    41
  val output_delay = Time.seconds(0.1)  // prover output (markup, common messages)
wenzelm@43716
    42
  val update_delay = Time.seconds(0.5)  // GUI layout updates
wenzelm@44573
    43
  val load_delay = Time.seconds(0.5)  // file load operations (new buffers etc.)
wenzelm@44676
    44
  val prune_delay = Time.seconds(60.0)  // prune history -- delete old versions
wenzelm@44676
    45
  val prune_size = 0  // size of retained history
wenzelm@37849
    46
wenzelm@37849
    47
wenzelm@34809
    48
  /* pervasive event buses */
wenzelm@34809
    49
wenzelm@34809
    50
  val global_settings = new Event_Bus[Session.Global_Settings.type]
wenzelm@37849
    51
  val perspective = new Event_Bus[Session.Perspective.type]
wenzelm@38849
    52
  val assignments = new Event_Bus[Session.Assignment.type]
wenzelm@43716
    53
  val commands_changed = new Event_Bus[Session.Commands_Changed]
wenzelm@43716
    54
  val phase_changed = new Event_Bus[Session.Phase]
wenzelm@43721
    55
  val raw_messages = new Event_Bus[Isabelle_Process.Message]
wenzelm@43716
    56
wenzelm@34809
    57
wenzelm@34809
    58
wenzelm@38841
    59
  /** buffered command changes (delay_first discipline) **/
wenzelm@38841
    60
wenzelm@43716
    61
  //{{{
wenzelm@38841
    62
  private case object Stop
wenzelm@38841
    63
wenzelm@44722
    64
  private val (_, commands_changed_buffer) =
wenzelm@44722
    65
    Simple_Thread.actor("commands_changed_buffer", daemon = true)
wenzelm@38841
    66
  {
wenzelm@38841
    67
    var finished = false
wenzelm@38841
    68
    while (!finished) {
wenzelm@44722
    69
      receive {
wenzelm@39630
    70
        case Stop => finished = true; reply(())
wenzelm@44722
    71
        case changed: Session.Commands_Changed => commands_changed.event(changed)
wenzelm@44722
    72
        case bad => System.err.println("commands_changed_buffer: ignoring bad message " + bad)
wenzelm@38841
    73
      }
wenzelm@38841
    74
    }
wenzelm@38841
    75
  }
wenzelm@38841
    76
  //}}}
wenzelm@38841
    77
wenzelm@38841
    78
wenzelm@38841
    79
wenzelm@38841
    80
  /** main protocol actor **/
wenzelm@34809
    81
wenzelm@43651
    82
  /* global state */
wenzelm@43644
    83
wenzelm@43716
    84
  @volatile var verbose: Boolean = false
wenzelm@43716
    85
wenzelm@43695
    86
  @volatile private var syntax = new Outer_Syntax
wenzelm@38569
    87
  def current_syntax(): Outer_Syntax = syntax
wenzelm@34809
    88
wenzelm@39626
    89
  @volatile private var reverse_syslog = List[XML.Elem]()
wenzelm@39629
    90
  def syslog(): String = reverse_syslog.reverse.map(msg => XML.content(msg).mkString).mkString("\n")
wenzelm@39626
    91
wenzelm@39630
    92
  @volatile private var _phase: Session.Phase = Session.Inactive
wenzelm@39633
    93
  private def phase_=(new_phase: Session.Phase)
wenzelm@39630
    94
  {
wenzelm@39630
    95
    _phase = new_phase
wenzelm@39701
    96
    phase_changed.event(new_phase)
wenzelm@39630
    97
  }
wenzelm@43716
    98
  def phase = _phase
wenzelm@43553
    99
  def is_ready: Boolean = phase == Session.Ready
wenzelm@39630
   100
wenzelm@38841
   101
  private val global_state = new Volatile(Document.State.init)
wenzelm@43719
   102
  def current_state(): Document.State = global_state()
wenzelm@34816
   103
wenzelm@44615
   104
  def snapshot(name: Document.Node.Name, pending_edits: List[Text.Edit]): Document.Snapshot =
wenzelm@43719
   105
    global_state().snapshot(name, pending_edits)
wenzelm@43716
   106
wenzelm@43651
   107
wenzelm@43651
   108
  /* theory files */
wenzelm@43651
   109
wenzelm@44615
   110
  def header_edit(name: Document.Node.Name, header: Document.Node_Header): Document.Edit_Text =
wenzelm@44442
   111
  {
wenzelm@44442
   112
    def norm_import(s: String): String =
wenzelm@44442
   113
    {
wenzelm@44442
   114
      val thy_name = Thy_Header.base_name(s)
wenzelm@44442
   115
      if (thy_load.is_loaded(thy_name)) thy_name
wenzelm@44616
   116
      else thy_load.append(name.dir, Thy_Header.thy_path(Path.explode(s)))
wenzelm@44442
   117
    }
wenzelm@44616
   118
    def norm_use(s: String): String = thy_load.append(name.dir, Path.explode(s))
wenzelm@44442
   119
wenzelm@44442
   120
    val header1: Document.Node_Header =
wenzelm@44442
   121
      header match {
wenzelm@44442
   122
        case Exn.Res(Thy_Header(thy_name, _, _))
wenzelm@44442
   123
        if (thy_load.is_loaded(thy_name)) =>
wenzelm@44442
   124
          Exn.Exn(ERROR("Attempt to update loaded theory " + quote(thy_name)))
wenzelm@44442
   125
        case _ => Document.Node.norm_header(norm_import, norm_use, header)
wenzelm@44442
   126
      }
wenzelm@44442
   127
    (name, Document.Node.Header(header1))
wenzelm@44442
   128
  }
wenzelm@44442
   129
wenzelm@43651
   130
wenzelm@43651
   131
  /* actor messages */
wenzelm@43651
   132
wenzelm@43716
   133
  private case class Start(timeout: Time, args: List[String])
wenzelm@43716
   134
  private case object Interrupt
wenzelm@44615
   135
  private case class Init_Node(name: Document.Node.Name,
wenzelm@44385
   136
    header: Document.Node_Header, perspective: Text.Perspective, text: String)
wenzelm@44615
   137
  private case class Edit_Node(name: Document.Node.Name,
wenzelm@44385
   138
    header: Document.Node_Header, perspective: Text.Perspective, edits: List[Text.Edit])
wenzelm@43722
   139
  private case class Change_Node(
wenzelm@44615
   140
    name: Document.Node.Name,
wenzelm@43722
   141
    doc_edits: List[Document.Edit_Command],
wenzelm@43722
   142
    previous: Document.Version,
wenzelm@43722
   143
    version: Document.Version)
wenzelm@41534
   144
wenzelm@39572
   145
  private val (_, session_actor) = Simple_Thread.actor("session_actor", daemon = true)
wenzelm@38639
   146
  {
wenzelm@43648
   147
    val this_actor = self
wenzelm@43649
   148
    var prover: Option[Isabelle_Process with Isar_Document] = None
wenzelm@34809
   149
wenzelm@44676
   150
    var prune_next = System.currentTimeMillis() + prune_delay.ms
wenzelm@44676
   151
wenzelm@34809
   152
wenzelm@44722
   153
    /* delayed command changes */
wenzelm@44722
   154
wenzelm@44722
   155
    object commands_changed_delay
wenzelm@44722
   156
    {
wenzelm@44722
   157
      private var changed_nodes: Set[Document.Node.Name] = Set.empty
wenzelm@44722
   158
      private var changed_commands: Set[Command] = Set.empty
wenzelm@44722
   159
      private def changed: Boolean = !changed_nodes.isEmpty || !changed_commands.isEmpty
wenzelm@44722
   160
wenzelm@44722
   161
      private var flush_time: Option[Long] = None
wenzelm@44722
   162
wenzelm@44722
   163
      def flush_timeout: Long =
wenzelm@44722
   164
        flush_time match {
wenzelm@44722
   165
          case None => 5000L
wenzelm@44722
   166
          case Some(time) => (time - System.currentTimeMillis()) max 0
wenzelm@44722
   167
        }
wenzelm@44722
   168
wenzelm@44722
   169
      def flush()
wenzelm@44722
   170
      {
wenzelm@44722
   171
        if (changed)
wenzelm@44722
   172
          commands_changed_buffer ! Session.Commands_Changed(changed_nodes, changed_commands)
wenzelm@44722
   173
        changed_nodes = Set.empty
wenzelm@44722
   174
        changed_commands = Set.empty
wenzelm@44722
   175
        flush_time = None
wenzelm@44722
   176
      }
wenzelm@44722
   177
wenzelm@44722
   178
      def invoke(command: Command)
wenzelm@44722
   179
      {
wenzelm@44722
   180
        changed_nodes += command.node_name
wenzelm@44722
   181
        changed_commands += command
wenzelm@44722
   182
        val now = System.currentTimeMillis()
wenzelm@44722
   183
        flush_time match {
wenzelm@44722
   184
          case None => flush_time = Some(now + output_delay.ms)
wenzelm@44722
   185
          case Some(time) => if (now >= time) flush()
wenzelm@44722
   186
        }
wenzelm@44722
   187
      }
wenzelm@44722
   188
    }
wenzelm@44722
   189
wenzelm@44722
   190
wenzelm@44436
   191
    /* perspective */
wenzelm@44436
   192
wenzelm@44615
   193
    def update_perspective(name: Document.Node.Name, text_perspective: Text.Perspective)
wenzelm@44436
   194
    {
wenzelm@44475
   195
      val previous = global_state().tip_version
wenzelm@44436
   196
      val (perspective, version) = Thy_Syntax.edit_perspective(previous, name, text_perspective)
wenzelm@44436
   197
wenzelm@44436
   198
      val text_edits: List[Document.Edit_Text] =
wenzelm@44436
   199
        List((name, Document.Node.Perspective(text_perspective)))
wenzelm@44436
   200
      val change =
wenzelm@44436
   201
        global_state.change_yield(
wenzelm@44446
   202
          _.continue_history(Future.value(previous), text_edits, Future.value(version)))
wenzelm@44436
   203
wenzelm@44477
   204
      val assignment = global_state().the_assignment(previous).check_finished
wenzelm@44479
   205
      global_state.change(_.define_version(version, assignment))
wenzelm@44476
   206
      global_state.change_yield(_.assign(version.id, Document.no_assign))
wenzelm@44436
   207
wenzelm@44436
   208
      prover.get.update_perspective(previous.id, version.id, name, perspective)
wenzelm@44436
   209
    }
wenzelm@44436
   210
wenzelm@44436
   211
wenzelm@43716
   212
    /* incoming edits */
wenzelm@43716
   213
wenzelm@44615
   214
    def handle_edits(name: Document.Node.Name,
wenzelm@44384
   215
        header: Document.Node_Header, edits: List[Document.Node.Edit[Text.Edit, Text.Perspective]])
wenzelm@43716
   216
    //{{{
wenzelm@43716
   217
    {
wenzelm@43716
   218
      val syntax = current_syntax()
wenzelm@43719
   219
      val previous = global_state().history.tip.version
wenzelm@44185
   220
wenzelm@44612
   221
      prover.get.cancel_execution()
wenzelm@44612
   222
wenzelm@44615
   223
      val text_edits = header_edit(name, header) :: edits.map(edit => (name, edit))
wenzelm@44185
   224
      val result = Future.fork { Thy_Syntax.text_edits(syntax, previous.join, text_edits) }
wenzelm@43722
   225
      val change =
wenzelm@44446
   226
        global_state.change_yield(_.continue_history(previous, text_edits, result.map(_._2)))
wenzelm@43716
   227
wenzelm@43722
   228
      result.map {
wenzelm@44157
   229
        case (doc_edits, _) =>
wenzelm@43722
   230
          assignments.await { global_state().is_assigned(previous.get_finished) }
wenzelm@44157
   231
          this_actor ! Change_Node(name, doc_edits, previous.join, change.version.join)
wenzelm@43722
   232
      }
wenzelm@43716
   233
    }
wenzelm@43716
   234
    //}}}
wenzelm@43716
   235
wenzelm@43716
   236
wenzelm@44436
   237
    /* exec state assignment */
wenzelm@44436
   238
wenzelm@44476
   239
    def handle_assign(id: Document.Version_ID, assign: Document.Assign)
wenzelm@44436
   240
    //{{{
wenzelm@44436
   241
    {
wenzelm@44476
   242
      val cmds = global_state.change_yield(_.assign(id, assign))
wenzelm@44722
   243
      for (cmd <- cmds) commands_changed_delay.invoke(cmd)
wenzelm@44436
   244
      assignments.event(Session.Assignment)
wenzelm@44436
   245
    }
wenzelm@44436
   246
    //}}}
wenzelm@44436
   247
wenzelm@44436
   248
wenzelm@44676
   249
    /* removed versions */
wenzelm@44676
   250
wenzelm@44676
   251
    def handle_removed(removed: List[Document.Version_ID])
wenzelm@44676
   252
    //{{{
wenzelm@44676
   253
    {
wenzelm@44676
   254
      global_state.change(_.removed_versions(removed))
wenzelm@44676
   255
    }
wenzelm@44676
   256
    //}}}
wenzelm@44676
   257
wenzelm@44676
   258
wenzelm@43716
   259
    /* resulting changes */
wenzelm@34809
   260
wenzelm@43722
   261
    def handle_change(change: Change_Node)
wenzelm@38221
   262
    //{{{
wenzelm@34809
   263
    {
wenzelm@43722
   264
      val previous = change.previous
wenzelm@43722
   265
      val version = change.version
wenzelm@43722
   266
      val name = change.name
wenzelm@43722
   267
      val doc_edits = change.doc_edits
wenzelm@38366
   268
wenzelm@44383
   269
      def id_command(command: Command)
wenzelm@43720
   270
      {
wenzelm@44582
   271
        if (!global_state().defined_command(command.id)) {
wenzelm@43720
   272
          global_state.change(_.define_command(command))
wenzelm@44644
   273
          prover.get.define_command(command)
wenzelm@43720
   274
        }
wenzelm@43720
   275
      }
wenzelm@44383
   276
      doc_edits foreach {
wenzelm@44383
   277
        case (_, edit) =>
wenzelm@44383
   278
          edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
wenzelm@44383
   279
      }
wenzelm@43722
   280
wenzelm@44479
   281
      val assignment = global_state().the_assignment(previous).check_finished
wenzelm@44479
   282
      global_state.change(_.define_version(version, assignment))
wenzelm@44481
   283
      prover.get.update(previous.id, version.id, doc_edits)
wenzelm@34809
   284
    }
wenzelm@38221
   285
    //}}}
wenzelm@34809
   286
wenzelm@34809
   287
wenzelm@34809
   288
    /* prover results */
wenzelm@34809
   289
wenzelm@34809
   290
    def handle_result(result: Isabelle_Process.Result)
wenzelm@38221
   291
    //{{{
wenzelm@34809
   292
    {
wenzelm@43716
   293
      def bad_result(result: Isabelle_Process.Result)
wenzelm@43716
   294
      {
wenzelm@43716
   295
        if (verbose)
wenzelm@43716
   296
          System.err.println("Ignoring prover result: " + result.message.toString)
wenzelm@43716
   297
      }
wenzelm@43716
   298
wenzelm@38722
   299
      result.properties match {
wenzelm@43748
   300
        case Position.Id(state_id) if !result.is_raw =>
wenzelm@38370
   301
          try {
wenzelm@38841
   302
            val st = global_state.change_yield(_.accumulate(state_id, result.message))
wenzelm@44722
   303
            commands_changed_delay.invoke(st.command)
wenzelm@38370
   304
          }
wenzelm@43748
   305
          catch {
wenzelm@43748
   306
            case _: Document.State.Fail => bad_result(result)
wenzelm@43748
   307
          }
wenzelm@44661
   308
        case Markup.Assign_Execs if result.is_raw =>
wenzelm@44661
   309
          XML.content(result.body).mkString match {
wenzelm@44661
   310
            case Isar_Document.Assign(id, assign) =>
wenzelm@44661
   311
              try { handle_assign(id, assign) }
wenzelm@44661
   312
              catch { case _: Document.State.Fail => bad_result(result) }
wenzelm@44661
   313
            case _ => bad_result(result)
wenzelm@44661
   314
          }
wenzelm@44676
   315
          // FIXME separate timeout event/message!?
wenzelm@44676
   316
          if (prover.isDefined && System.currentTimeMillis() > prune_next) {
wenzelm@44676
   317
            val old_versions = global_state.change_yield(_.prune_history(prune_size))
wenzelm@44676
   318
            if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
wenzelm@44676
   319
            prune_next = System.currentTimeMillis() + prune_delay.ms
wenzelm@44676
   320
          }
wenzelm@44676
   321
        case Markup.Removed_Versions if result.is_raw =>
wenzelm@44676
   322
          XML.content(result.body).mkString match {
wenzelm@44676
   323
            case Isar_Document.Removed(removed) =>
wenzelm@44676
   324
              try { handle_removed(removed) }
wenzelm@44676
   325
              catch { case _: Document.State.Fail => bad_result(result) }
wenzelm@44676
   326
            case _ => bad_result(result)
wenzelm@44676
   327
          }
wenzelm@43748
   328
        case Markup.Invoke_Scala(name, id) if result.is_raw =>
wenzelm@43748
   329
          Future.fork {
wenzelm@43748
   330
            val arg = XML.content(result.body).mkString
wenzelm@43748
   331
            val (tag, res) = Invoke_Scala.method(name, arg)
wenzelm@43748
   332
            prover.get.invoke_scala(id, tag, res)
wenzelm@43748
   333
          }
wenzelm@44298
   334
        case Markup.Cancel_Scala(id) =>
wenzelm@44298
   335
          System.err.println("cancel_scala " + id)  // FIXME cancel JVM task
wenzelm@38722
   336
        case _ =>
wenzelm@39630
   337
          if (result.is_syslog) {
wenzelm@39630
   338
            reverse_syslog ::= result.message
wenzelm@40533
   339
            if (result.is_ready) {
wenzelm@43716
   340
              // FIXME move to ML side (!?)
wenzelm@40533
   341
              syntax += ("hence", Keyword.PRF_ASM_GOAL, "then have")
wenzelm@40533
   342
              syntax += ("thus", Keyword.PRF_ASM_GOAL, "then show")
wenzelm@40533
   343
              phase = Session.Ready
wenzelm@40533
   344
            }
wenzelm@39701
   345
            else if (result.is_exit && phase == Session.Startup) phase = Session.Failed
wenzelm@39696
   346
            else if (result.is_exit) phase = Session.Inactive
wenzelm@39630
   347
          }
wenzelm@39626
   348
          else if (result.is_stdout) { }
wenzelm@39625
   349
          else if (result.is_status) {
wenzelm@38370
   350
            result.body match {
wenzelm@38370
   351
              case List(Keyword.Command_Decl(name, kind)) => syntax += (name, kind)
wenzelm@38370
   352
              case List(Keyword.Keyword_Decl(name)) => syntax += name
wenzelm@44574
   353
              case List(Thy_Info.Loaded_Theory(name)) => thy_load.register_thy(name)
wenzelm@39625
   354
              case _ => bad_result(result)
wenzelm@38370
   355
            }
wenzelm@38370
   356
          }
wenzelm@39625
   357
          else bad_result(result)
wenzelm@43748
   358
      }
wenzelm@34809
   359
    }
wenzelm@38221
   360
    //}}}
wenzelm@34809
   361
wenzelm@34820
   362
wenzelm@39630
   363
    /* main loop */
wenzelm@34809
   364
wenzelm@43716
   365
    //{{{
wenzelm@38639
   366
    var finished = false
wenzelm@38639
   367
    while (!finished) {
wenzelm@44722
   368
      receiveWithin(commands_changed_delay.flush_timeout) {
wenzelm@44722
   369
        case TIMEOUT => commands_changed_delay.flush()
wenzelm@44722
   370
wenzelm@43649
   371
        case Start(timeout, args) if prover.isEmpty =>
wenzelm@39701
   372
          if (phase == Session.Inactive || phase == Session.Failed) {
wenzelm@39701
   373
            phase = Session.Startup
wenzelm@43661
   374
            prover = Some(new Isabelle_Process(timeout, this_actor, args:_*) with Isar_Document)
wenzelm@39701
   375
          }
wenzelm@38841
   376
wenzelm@39701
   377
        case Stop =>
wenzelm@39701
   378
          if (phase == Session.Ready) {
wenzelm@39701
   379
            global_state.change(_ => Document.State.init)  // FIXME event bus!?
wenzelm@39701
   380
            phase = Session.Shutdown
wenzelm@43649
   381
            prover.get.terminate
wenzelm@43717
   382
            prover = None
wenzelm@39701
   383
            phase = Session.Inactive
wenzelm@39701
   384
          }
wenzelm@39630
   385
          finished = true
wenzelm@39630
   386
          reply(())
wenzelm@38850
   387
wenzelm@43717
   388
        case Interrupt if prover.isDefined =>
wenzelm@43717
   389
          prover.get.interrupt
wenzelm@43716
   390
wenzelm@44615
   391
        case Init_Node(name, header, perspective, text) if prover.isDefined =>
wenzelm@43716
   392
          // FIXME compare with existing node
wenzelm@44615
   393
          handle_edits(name, header,
wenzelm@44385
   394
            List(Document.Node.Clear(),
wenzelm@44385
   395
              Document.Node.Edits(List(Text.Edit.insert(0, text))),
wenzelm@44385
   396
              Document.Node.Perspective(perspective)))
wenzelm@43716
   397
          reply(())
wenzelm@43716
   398
wenzelm@44615
   399
        case Edit_Node(name, header, perspective, text_edits) if prover.isDefined =>
wenzelm@44484
   400
          if (text_edits.isEmpty && global_state().tip_stable &&
wenzelm@44484
   401
              perspective.range.stop <= global_state().last_exec_offset(name))
wenzelm@44484
   402
            update_perspective(name, perspective)
wenzelm@44484
   403
          else
wenzelm@44615
   404
            handle_edits(name, header,
wenzelm@44436
   405
              List(Document.Node.Edits(text_edits), Document.Node.Perspective(perspective)))
wenzelm@43718
   406
          reply(())
wenzelm@43718
   407
wenzelm@43722
   408
        case change: Change_Node if prover.isDefined =>
wenzelm@43722
   409
          handle_change(change)
wenzelm@43716
   410
wenzelm@43721
   411
        case input: Isabelle_Process.Input =>
wenzelm@43721
   412
          raw_messages.event(input)
wenzelm@43721
   413
wenzelm@43716
   414
        case result: Isabelle_Process.Result =>
wenzelm@43716
   415
          handle_result(result)
wenzelm@43721
   416
          raw_messages.event(result)
wenzelm@43716
   417
wenzelm@43717
   418
        case bad => System.err.println("session_actor: ignoring bad message " + bad)
wenzelm@34777
   419
      }
wenzelm@34777
   420
    }
wenzelm@43716
   421
    //}}}
wenzelm@34777
   422
  }
wenzelm@34777
   423
wenzelm@34809
   424
wenzelm@43716
   425
  /* actions */
wenzelm@34809
   426
wenzelm@40848
   427
  def start(timeout: Time, args: List[String]) { session_actor ! Start(timeout, args) }
wenzelm@34820
   428
wenzelm@44722
   429
  def stop() { commands_changed_buffer !? Stop; session_actor !? Stop }
wenzelm@38841
   430
wenzelm@43716
   431
  def interrupt() { session_actor ! Interrupt }
wenzelm@43648
   432
wenzelm@44615
   433
  def init_node(name: Document.Node.Name,
wenzelm@44385
   434
    header: Document.Node_Header, perspective: Text.Perspective, text: String)
wenzelm@44615
   435
  { session_actor !? Init_Node(name, header, perspective, text) }
wenzelm@38221
   436
wenzelm@44615
   437
  def edit_node(name: Document.Node.Name,
wenzelm@44615
   438
    header: Document.Node_Header, perspective: Text.Perspective, edits: List[Text.Edit])
wenzelm@44615
   439
  { session_actor !? Edit_Node(name, header, perspective, edits) }
wenzelm@34777
   440
}