26 |
26 |
27 class Outlet[A](dispatcher: Consumer_Thread[() => Unit]) |
27 class Outlet[A](dispatcher: Consumer_Thread[() => Unit]) |
28 { |
28 { |
29 private val consumers = Synchronized[List[Consumer[A]]](Nil) |
29 private val consumers = Synchronized[List[Consumer[A]]](Nil) |
30 |
30 |
31 def += (c: Consumer[A]) { consumers.change(Library.update(c)) } |
31 def += (c: Consumer[A]): Unit = consumers.change(Library.update(c)) |
32 def -= (c: Consumer[A]) { consumers.change(Library.remove(c)) } |
32 def -= (c: Consumer[A]): Unit = consumers.change(Library.remove(c)) |
33 |
33 |
34 def post(a: A) |
34 def post(a: A): Unit = |
35 { |
35 { |
36 for (c <- consumers.value.iterator) { |
36 for (c <- consumers.value.iterator) { |
37 dispatcher.send(() => |
37 dispatcher.send(() => |
38 try { c.consume(a) } |
38 try { c.consume(a) } |
39 catch { |
39 catch { |
322 Delay.first(consolidate_delay) { manager.send(Consolidate_Execution) } |
322 Delay.first(consolidate_delay) { manager.send(Consolidate_Execution) } |
323 |
323 |
324 private val init_state: Option[Set[Document.Node.Name]] = Some(Set.empty) |
324 private val init_state: Option[Set[Document.Node.Name]] = Some(Set.empty) |
325 private val state = Synchronized(init_state) |
325 private val state = Synchronized(init_state) |
326 |
326 |
327 def exit() |
327 def exit(): Unit = |
328 { |
328 { |
329 delay.revoke() |
329 delay.revoke() |
330 state.change(_ => None) |
330 state.change(_ => None) |
331 } |
331 } |
332 |
332 |
333 def update(new_nodes: Set[Document.Node.Name] = Set.empty) |
333 def update(new_nodes: Set[Document.Node.Name] = Set.empty): Unit = |
334 { |
334 { |
335 val active = |
335 val active = |
336 state.change_result(st => |
336 state.change_result(st => |
337 (st.isDefined, st.map(nodes => if (nodes.isEmpty) new_nodes else nodes ++ new_nodes))) |
337 (st.isDefined, st.map(nodes => if (nodes.isEmpty) new_nodes else nodes ++ new_nodes))) |
338 if (active) delay.invoke() |
338 if (active) delay.invoke() |
349 { |
349 { |
350 private val variable = Synchronized[Option[Prover]](None) |
350 private val variable = Synchronized[Option[Prover]](None) |
351 |
351 |
352 def defined: Boolean = variable.value.isDefined |
352 def defined: Boolean = variable.value.isDefined |
353 def get: Prover = variable.value.get |
353 def get: Prover = variable.value.get |
354 def set(p: Prover) { variable.change(_ => Some(p)) } |
354 def set(p: Prover): Unit = variable.change(_ => Some(p)) |
355 def reset { variable.change(_ => None) } |
355 def reset: Unit = variable.change(_ => None) |
356 def await_reset() { variable.guarded_access({ case None => Some((), None) case _ => None }) } |
356 def await_reset(): Unit = variable.guarded_access({ case None => Some((), None) case _ => None }) |
357 } |
357 } |
358 |
358 |
359 |
359 |
360 /* file formats and protocol handlers */ |
360 /* file formats and protocol handlers */ |
361 |
361 |
399 /* raw edits */ |
399 /* raw edits */ |
400 |
400 |
401 def handle_raw_edits( |
401 def handle_raw_edits( |
402 doc_blobs: Document.Blobs = Document.Blobs.empty, |
402 doc_blobs: Document.Blobs = Document.Blobs.empty, |
403 edits: List[Document.Edit_Text] = Nil, |
403 edits: List[Document.Edit_Text] = Nil, |
404 consolidate: List[Document.Node.Name] = Nil) |
404 consolidate: List[Document.Node.Name] = Nil): Unit = |
405 //{{{ |
405 //{{{ |
406 { |
406 { |
407 require(prover.defined, "prover process not defined (handle_raw_edits)") |
407 require(prover.defined, "prover process not defined (handle_raw_edits)") |
408 |
408 |
409 if (edits.nonEmpty) prover.get.discontinue_execution() |
409 if (edits.nonEmpty) prover.get.discontinue_execution() |
418 //}}} |
418 //}}} |
419 |
419 |
420 |
420 |
421 /* resulting changes */ |
421 /* resulting changes */ |
422 |
422 |
423 def handle_change(change: Session.Change) |
423 def handle_change(change: Session.Change): Unit = |
424 //{{{ |
424 //{{{ |
425 { |
425 { |
426 require(prover.defined, "prover process not defined (handle_change)") |
426 require(prover.defined, "prover process not defined (handle_change)") |
427 |
427 |
428 // define commands |
428 // define commands |
429 { |
429 { |
430 val id_commands = new mutable.ListBuffer[Command] |
430 val id_commands = new mutable.ListBuffer[Command] |
431 def id_command(command: Command) |
431 def id_command(command: Command): Unit = |
432 { |
432 { |
433 for { |
433 for { |
434 (name, digest) <- command.blobs_defined |
434 (name, digest) <- command.blobs_defined |
435 if !global_state.value.defined_blob(digest) |
435 if !global_state.value.defined_blob(digest) |
436 } { |
436 } { |
465 //}}} |
465 //}}} |
466 |
466 |
467 |
467 |
468 /* prover output */ |
468 /* prover output */ |
469 |
469 |
470 def handle_output(output: Prover.Output) |
470 def handle_output(output: Prover.Output): Unit = |
471 //{{{ |
471 //{{{ |
472 { |
472 { |
473 def bad_output() |
473 def bad_output(): Unit = |
474 { |
474 { |
475 if (verbose) |
475 if (verbose) |
476 Output.warning("Ignoring bad prover output: " + output.message.toString) |
476 Output.warning("Ignoring bad prover output: " + output.message.toString) |
477 } |
477 } |
478 |
478 |
479 def change_command(f: Document.State => (Command.State, Document.State)) |
479 def change_command(f: Document.State => (Command.State, Document.State)): Unit = |
480 { |
480 { |
481 try { |
481 try { |
482 val st = global_state.change_result(f) |
482 val st = global_state.change_result(f) |
483 if (!st.command.span.is_theory) { |
483 if (!st.command.span.is_theory) { |
484 change_buffer.invoke(false, Nil, List(st.command)) |
484 change_buffer.invoke(false, Nil, List(st.command)) |
755 case Session.Terminated(result) => result |
755 case Session.Terminated(result) => result |
756 case phase => error("Bad session phase after shutdown: " + quote(phase.print)) |
756 case phase => error("Bad session phase after shutdown: " + quote(phase.print)) |
757 } |
757 } |
758 } |
758 } |
759 |
759 |
760 def protocol_command(name: String, args: String*) |
760 def protocol_command(name: String, args: String*): Unit = |
761 { manager.send(Protocol_Command(name, args.toList)) } |
761 manager.send(Protocol_Command(name, args.toList)) |
762 |
762 |
763 def cancel_exec(exec_id: Document_ID.Exec) |
763 def cancel_exec(exec_id: Document_ID.Exec): Unit = |
764 { manager.send(Cancel_Exec(exec_id)) } |
764 manager.send(Cancel_Exec(exec_id)) |
765 |
765 |
766 def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]) |
766 def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text]): Unit = |
767 { |
|
768 if (edits.nonEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits)) |
767 if (edits.nonEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits)) |
769 } |
768 |
770 |
769 def update_options(options: Options): Unit = |
771 def update_options(options: Options) |
770 manager.send_wait(Update_Options(options)) |
772 { manager.send_wait(Update_Options(options)) } |
771 |
773 |
772 def dialog_result(id: Document_ID.Generic, serial: Long, result: String): Unit = |
774 def dialog_result(id: Document_ID.Generic, serial: Long, result: String) |
773 manager.send(Session.Dialog_Result(id, serial, result)) |
775 { manager.send(Session.Dialog_Result(id, serial, result)) } |
|
776 } |
774 } |