src/Pure/PIDE/session.scala
changeset 59366 e94df7f6b608
parent 59364 3b5da177ae6b
child 59367 6193bbbbe564
equal deleted inserted replaced
59365:b5d43b01a6b3 59366:e94df7f6b608
   103     def start(prover: Prover): Unit = {}
   103     def start(prover: Prover): Unit = {}
   104     def stop(prover: Prover): Unit = {}
   104     def stop(prover: Prover): Unit = {}
   105     val functions: Map[String, (Prover, Prover.Protocol_Output) => Boolean]
   105     val functions: Map[String, (Prover, Prover.Protocol_Output) => Boolean]
   106   }
   106   }
   107 
   107 
   108   class Protocol_Handlers(
   108   private class Protocol_Handlers(
   109     handlers: Map[String, Session.Protocol_Handler] = Map.empty,
   109     handlers: Map[String, Session.Protocol_Handler] = Map.empty,
   110     functions: Map[String, Prover.Protocol_Output => Boolean] = Map.empty)
   110     functions: Map[String, Prover.Protocol_Output => Boolean] = Map.empty)
   111   {
   111   {
   112     def get(name: String): Option[Protocol_Handler] = handlers.get(name)
   112     def get(name: String): Option[Protocol_Handler] = handlers.get(name)
   113 
   113 
   235   def recent_syntax(name: Document.Node.Name): Prover.Syntax =
   235   def recent_syntax(name: Document.Node.Name): Prover.Syntax =
   236     current_state().recent_finished.version.get_finished.nodes(name).syntax getOrElse
   236     current_state().recent_finished.version.get_finished.nodes(name).syntax getOrElse
   237     resources.base_syntax
   237     resources.base_syntax
   238 
   238 
   239 
   239 
   240   /* protocol handlers */
       
   241 
       
   242   @volatile private var _protocol_handlers = new Session.Protocol_Handlers()
       
   243 
       
   244   def protocol_handler(name: String): Option[Session.Protocol_Handler] =
       
   245     _protocol_handlers.get(name)
       
   246 
       
   247 
       
   248   /* theory files */
   240   /* theory files */
   249 
   241 
   250   def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text =
   242   def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text =
   251   {
   243   {
   252     val header1 =
   244     val header1 =
   339     def get: Prover = variable.value.get
   331     def get: Prover = variable.value.get
   340     def set(p: Prover) { variable.change(_ => Some(p)) }
   332     def set(p: Prover) { variable.change(_ => Some(p)) }
   341     def reset { variable.change(_ => None) }
   333     def reset { variable.change(_ => None) }
   342     def await_reset() { variable.guarded_access({ case None => Some((), None) case _ => None }) }
   334     def await_reset() { variable.guarded_access({ case None => Some((), None) case _ => None }) }
   343   }
   335   }
       
   336 
       
   337 
       
   338   /* protocol handlers */
       
   339 
       
   340   private val _protocol_handlers = Synchronized(new Session.Protocol_Handlers)
       
   341 
       
   342   def get_protocol_handler(name: String): Option[Session.Protocol_Handler] =
       
   343     _protocol_handlers.value.get(name)
       
   344 
       
   345   def add_protocol_handler(name: String): Unit =
       
   346     _protocol_handlers.change(_.add(prover.get, name))
   344 
   347 
   345 
   348 
   346   /* manager thread */
   349   /* manager thread */
   347 
   350 
   348   private val delay_prune = Simple_Thread.delay_first(prune_delay) { manager.send(Prune_History) }
   351   private val delay_prune = Simple_Thread.delay_first(prune_delay) { manager.send(Prune_History) }
   430         }
   433         }
   431       }
   434       }
   432 
   435 
   433       output match {
   436       output match {
   434         case msg: Prover.Protocol_Output =>
   437         case msg: Prover.Protocol_Output =>
   435           val handled = _protocol_handlers.invoke(msg)
   438           val handled = _protocol_handlers.value.invoke(msg)
   436           if (!handled) {
   439           if (!handled) {
   437             msg.properties match {
   440             msg.properties match {
   438               case Markup.Protocol_Handler(name) if prover.defined =>
   441               case Markup.Protocol_Handler(name) if prover.defined =>
   439                 _protocol_handlers = _protocol_handlers.add(prover.get, name)
   442                 add_protocol_handler(name)
   440 
   443 
   441               case Protocol.Command_Timing(state_id, timing) if prover.defined =>
   444               case Protocol.Command_Timing(state_id, timing) if prover.defined =>
   442                 val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))
   445                 val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))
   443                 accumulate(state_id, prover.get.xml_cache.elem(message))
   446                 accumulate(state_id, prover.get.xml_cache.elem(message))
   444 
   447 
   523               prover.set(resources.start_prover(manager.send(_), name, args))
   526               prover.set(resources.start_prover(manager.send(_), name, args))
   524             }
   527             }
   525 
   528 
   526           case Stop =>
   529           case Stop =>
   527             if (prover.defined && is_ready) {
   530             if (prover.defined && is_ready) {
   528               _protocol_handlers = _protocol_handlers.stop(prover.get)
   531               _protocol_handlers.change(_.stop(prover.get))
   529               global_state.change(_ => Document.State.init)
   532               global_state.change(_ => Document.State.init)
   530               phase = Session.Shutdown
   533               phase = Session.Shutdown
   531               prover.get.terminate
   534               prover.get.terminate
   532             }
   535             }
   533 
   536