src/Pure/Tools/print_operation.scala
author wenzelm
Mon May 05 15:17:07 2014 +0200 (2014-05-05)
changeset 56864 0446c7ac2e32
child 59366 e94df7f6b608
permissions -rw-r--r--
support print operations as asynchronous query;
wenzelm@56864
     1
/*  Title:      Pure/System/print_operation.scala
wenzelm@56864
     2
    Author:     Makarius
wenzelm@56864
     3
wenzelm@56864
     4
Print operations as asynchronous query.
wenzelm@56864
     5
*/
wenzelm@56864
     6
wenzelm@56864
     7
package isabelle
wenzelm@56864
     8
wenzelm@56864
     9
wenzelm@56864
    10
object Print_Operation
wenzelm@56864
    11
{
wenzelm@56864
    12
  def print_operations(session: Session): List[(String, String)] =
wenzelm@56864
    13
    session.protocol_handler("isabelle.Print_Operation$Handler") match {
wenzelm@56864
    14
      case Some(handler: Handler) => handler.get
wenzelm@56864
    15
      case _ => Nil
wenzelm@56864
    16
    }
wenzelm@56864
    17
wenzelm@56864
    18
wenzelm@56864
    19
  /* protocol handler */
wenzelm@56864
    20
wenzelm@56864
    21
  class Handler extends Session.Protocol_Handler
wenzelm@56864
    22
  {
wenzelm@56864
    23
    private val print_operations = Synchronized(Nil: List[(String, String)])
wenzelm@56864
    24
wenzelm@56864
    25
    def get: List[(String, String)] = print_operations.value
wenzelm@56864
    26
wenzelm@56864
    27
    private def put(prover: Prover, msg: Prover.Protocol_Output): Boolean =
wenzelm@56864
    28
    {
wenzelm@56864
    29
      val ops =
wenzelm@56864
    30
      {
wenzelm@56864
    31
        import XML.Decode._
wenzelm@56864
    32
        list(pair(string, string))(YXML.parse_body(msg.text))
wenzelm@56864
    33
      }
wenzelm@56864
    34
      print_operations.change(_ => ops)
wenzelm@56864
    35
      true
wenzelm@56864
    36
    }
wenzelm@56864
    37
wenzelm@56864
    38
    override def start(prover: Prover): Unit =
wenzelm@56864
    39
      prover.protocol_command(Markup.PRINT_OPERATIONS)
wenzelm@56864
    40
wenzelm@56864
    41
    val functions = Map(Markup.PRINT_OPERATIONS -> put _)
wenzelm@56864
    42
  }
wenzelm@56864
    43
}