63 val continue = Answer("continue", "Continue") |
63 val continue = Answer("continue", "Continue") |
64 val continue_trace = Answer("continue_trace", "Continue (with full trace)") |
64 val continue_trace = Answer("continue_trace", "Continue (with full trace)") |
65 val continue_passive = Answer("continue_passive", "Continue (without asking)") |
65 val continue_passive = Answer("continue_passive", "Continue (without asking)") |
66 val continue_disable = Answer("continue_disable", "Continue (without any trace)") |
66 val continue_disable = Answer("continue_disable", "Continue (without any trace)") |
67 |
67 |
68 val default = skip |
|
69 val all = List(continue, continue_trace, continue_passive, continue_disable, skip) |
68 val all = List(continue, continue_trace, continue_passive, continue_disable, skip) |
70 } |
69 } |
71 |
70 |
72 object hint_fail |
71 object hint_fail |
73 { |
72 { |
74 val exit = Answer("exit", "Exit") |
73 val exit = Answer("exit", "Exit") |
75 val redo = Answer("redo", "Redo") |
74 val redo = Answer("redo", "Redo") |
76 |
75 |
77 val default = exit |
|
78 val all = List(redo, exit) |
76 val all = List(redo, exit) |
79 } |
77 } |
80 } |
78 } |
81 |
79 |
82 val all_answers: List[Answer] = Answer.step.all ::: Answer.hint_fail.all |
80 val all_answers: List[Answer] = Answer.step.all ::: Answer.hint_fail.all |
83 |
|
84 object Active |
|
85 { |
|
86 def unapply(tree: XML.Tree): Option[(Long, Answer)] = |
|
87 tree match { |
|
88 case XML.Elem(Markup(Markup.SIMP_TRACE, props), _) => |
|
89 (props, props) match { |
|
90 case (Markup.Serial(serial), Markup.Name(name)) => |
|
91 all_answers.find(_.name == name).map((serial, _)) |
|
92 case _ => None |
|
93 } |
|
94 case _ => None |
|
95 } |
|
96 } |
|
97 |
81 |
98 |
82 |
99 /* GUI interaction */ |
83 /* GUI interaction */ |
100 |
84 |
101 case object Event |
85 case object Event |
108 private case class Generate_Trace(results: Command.Results, slot: Promise[Trace]) |
92 private case class Generate_Trace(results: Command.Results, slot: Promise[Trace]) |
109 private case class Cancel(serial: Long) |
93 private case class Cancel(serial: Long) |
110 private object Clear_Memory |
94 private object Clear_Memory |
111 case class Reply(session: Session, serial: Long, answer: Answer) |
95 case class Reply(session: Session, serial: Long, answer: Answer) |
112 |
96 |
113 case class Question(data: Item.Data, answers: List[Answer], default_answer: Answer) |
97 case class Question(data: Item.Data, answers: List[Answer]) |
114 |
98 |
115 case class Context( |
99 case class Context( |
116 last_serial: Long = 0L, |
100 last_serial: Long = 0L, |
117 questions: SortedMap[Long, Question] = SortedMap.empty) |
101 questions: SortedMap[Long, Question] = SortedMap.empty) |
118 { |
102 { |
205 val index = Index.of_data(data) |
189 val index = Index.of_data(data) |
206 memory.get(index) match { |
190 memory.get(index) match { |
207 case Some(answer) if data.memory => |
191 case Some(answer) if data.memory => |
208 do_reply(session, serial, answer) |
192 do_reply(session, serial, answer) |
209 case _ => |
193 case _ => |
210 new_context += Question(data, Answer.step.all, Answer.step.default) |
194 new_context += Question(data, Answer.step.all) |
211 } |
195 } |
212 |
196 |
213 case Markup.SIMP_TRACE_HINT => |
197 case Markup.SIMP_TRACE_HINT => |
214 data.props match { |
198 data.props match { |
215 case Success(false) => |
199 case Success(false) => |
216 results.get(data.parent) match { |
200 results.get(data.parent) match { |
217 case Some(Item(Markup.SIMP_TRACE_STEP, _)) => |
201 case Some(Item(Markup.SIMP_TRACE_STEP, _)) => |
218 new_context += |
202 new_context += Question(data, Answer.hint_fail.all) |
219 Question(data, Answer.hint_fail.all, Answer.hint_fail.default) |
|
220 case _ => |
203 case _ => |
221 // unknown, better send a default reply |
204 // unknown, better send a default reply |
222 do_reply(session, data.serial, Answer.hint_fail.default) |
205 do_reply(session, data.serial, Answer.hint_fail.exit) |
223 } |
206 } |
224 case _ => |
207 case _ => |
225 } |
208 } |
226 |
209 |
227 case Markup.SIMP_TRACE_IGNORE => |
210 case Markup.SIMP_TRACE_IGNORE => |
261 // Since there are potentially lots of trace messages, we do not cache them here again. |
244 // Since there are potentially lots of trace messages, we do not cache them here again. |
262 // Instead, everytime the trace is being requested, we re-assemble it based on the |
245 // Instead, everytime the trace is being requested, we re-assemble it based on the |
263 // current results. |
246 // current results. |
264 |
247 |
265 val items = |
248 val items = |
266 (for { (_, Item(_, data)) <- results.iterator } |
249 results.iterator.collect { case (_, Item(_, data)) => data }.toList |
267 yield data).toList |
|
268 |
250 |
269 slot.fulfill(Trace(items)) |
251 slot.fulfill(Trace(items)) |
270 |
252 |
271 case Cancel(serial) => |
253 case Cancel(serial) => |
272 find_question(serial) match { |
254 find_question(serial) match { |
279 memory_children = Map.empty |
261 memory_children = Map.empty |
280 memory = Map.empty |
262 memory = Map.empty |
281 |
263 |
282 case Reply(session, serial, answer) => |
264 case Reply(session, serial, answer) => |
283 find_question(serial) match { |
265 find_question(serial) match { |
284 case Some((id, Question(data, _, _))) => |
266 case Some((id, Question(data, _))) => |
285 if (data.markup == Markup.SIMP_TRACE_STEP && data.memory) |
267 if (data.markup == Markup.SIMP_TRACE_STEP && data.memory) |
286 { |
268 { |
287 val index = Index.of_data(data) |
269 val index = Index.of_data(data) |
288 memory += (index -> answer) |
270 memory += (index -> answer) |
289 } |
271 } |