9 |
9 |
10 object Server_Commands |
10 object Server_Commands |
11 { |
11 { |
12 def default_preferences: String = Options.read_prefs() |
12 def default_preferences: String = Options.read_prefs() |
13 |
13 |
14 object Cancel |
14 object Help extends Server.Command("help") |
|
15 { |
|
16 override val command_body: Server.Command_Body = |
|
17 { case (context, ()) => context.command_list } |
|
18 } |
|
19 |
|
20 object Echo extends Server.Command("echo") |
|
21 { |
|
22 override val command_body: Server.Command_Body = |
|
23 { case (_, t) => t } |
|
24 } |
|
25 |
|
26 object Cancel extends Server.Command("cancel") |
15 { |
27 { |
16 sealed case class Args(task: UUID.T) |
28 sealed case class Args(task: UUID.T) |
17 |
29 |
18 def unapply(json: JSON.T): Option[Args] = |
30 def unapply(json: JSON.T): Option[Args] = |
19 for { task <- JSON.uuid(json, "task") } |
31 for { task <- JSON.uuid(json, "task") } |
20 yield Args(task) |
32 yield Args(task) |
21 } |
33 |
22 |
34 override val command_body: Server.Command_Body = |
23 |
35 { case (context, Cancel(args)) => context.cancel_task(args.task) } |
24 object Session_Build |
36 } |
|
37 |
|
38 object Shutdown extends Server.Command("shutdown") |
|
39 { |
|
40 override val command_body: Server.Command_Body = |
|
41 { case (context, ()) => context.server.shutdown() } |
|
42 } |
|
43 |
|
44 object Session_Build extends Server.Command("session_build") |
25 { |
45 { |
26 sealed case class Args( |
46 sealed case class Args( |
27 session: String, |
47 session: String, |
28 preferences: String = default_preferences, |
48 preferences: String = default_preferences, |
29 options: List[String] = Nil, |
49 options: List[String] = Nil, |
89 else { |
109 else { |
90 throw new Server.Error("Session build failed: " + Process_Result.print_rc(results.rc), |
110 throw new Server.Error("Session build failed: " + Process_Result.print_rc(results.rc), |
91 results_json) |
111 results_json) |
92 } |
112 } |
93 } |
113 } |
94 } |
114 |
95 |
115 override val command_body: Server.Command_Body = |
96 object Session_Start |
116 { case (context, Session_Build(args)) => |
|
117 context.make_task(task => Session_Build.command(args, progress = task.progress)._1) } |
|
118 } |
|
119 |
|
120 object Session_Start extends Server.Command("session_start") |
97 { |
121 { |
98 sealed case class Args( |
122 sealed case class Args( |
99 build: Session_Build.Args, |
123 build: Session_Build.Args, |
100 print_mode: List[String] = Nil) |
124 print_mode: List[String] = Nil) |
101 |
125 |
124 "session_id" -> id.toString, |
148 "session_id" -> id.toString, |
125 "tmp_dir" -> File.path(session.tmp_dir).implode) |
149 "tmp_dir" -> File.path(session.tmp_dir).implode) |
126 |
150 |
127 (res, id -> session) |
151 (res, id -> session) |
128 } |
152 } |
129 } |
153 |
130 |
154 override val command_body: Server.Command_Body = |
131 object Session_Stop |
155 { case (context, Session_Start(args)) => |
|
156 context.make_task(task => |
|
157 { |
|
158 val (res, entry) = |
|
159 Session_Start.command(args, progress = task.progress, log = context.server.log) |
|
160 context.server.add_session(entry) |
|
161 res |
|
162 }) |
|
163 } |
|
164 } |
|
165 |
|
166 object Session_Stop extends Server.Command("session_stop") |
132 { |
167 { |
133 def unapply(json: JSON.T): Option[UUID.T] = |
168 def unapply(json: JSON.T): Option[UUID.T] = |
134 JSON.uuid(json, "session_id") |
169 JSON.uuid(json, "session_id") |
135 |
170 |
136 def command(session: Headless.Session): (JSON.Object.T, Process_Result) = |
171 def command(session: Headless.Session): (JSON.Object.T, Process_Result) = |
139 val result_json = JSON.Object("ok" -> result.ok, "return_code" -> result.rc) |
174 val result_json = JSON.Object("ok" -> result.ok, "return_code" -> result.rc) |
140 |
175 |
141 if (result.ok) (result_json, result) |
176 if (result.ok) (result_json, result) |
142 else throw new Server.Error("Session shutdown failed: " + result.print_rc, result_json) |
177 else throw new Server.Error("Session shutdown failed: " + result.print_rc, result_json) |
143 } |
178 } |
144 } |
179 |
145 |
180 override val command_body: Server.Command_Body = |
146 object Use_Theories |
181 { case (context, Session_Stop(id)) => |
|
182 context.make_task(_ => |
|
183 { |
|
184 val session = context.server.remove_session(id) |
|
185 Session_Stop.command(session)._1 |
|
186 }) |
|
187 } |
|
188 } |
|
189 |
|
190 object Use_Theories extends Server.Command("use_theories") |
147 { |
191 { |
148 sealed case class Args( |
192 sealed case class Args( |
149 session_id: UUID.T, |
193 session_id: UUID.T, |
150 theories: List[String], |
194 theories: List[String], |
151 master_dir: String = "", |
195 master_dir: String = "", |
239 })) |
283 })) |
240 })) |
284 })) |
241 |
285 |
242 (result_json, result) |
286 (result_json, result) |
243 } |
287 } |
244 } |
288 |
245 |
289 override val command_body: Server.Command_Body = |
246 object Purge_Theories |
290 { case (context, Use_Theories(args)) => |
|
291 context.make_task(task => |
|
292 { |
|
293 val session = context.server.the_session(args.session_id) |
|
294 Use_Theories.command(args, session, id = task.id, progress = task.progress)._1 |
|
295 }) |
|
296 } |
|
297 } |
|
298 |
|
299 object Purge_Theories extends Server.Command("purge_theories") |
247 { |
300 { |
248 sealed case class Args( |
301 sealed case class Args( |
249 session_id: UUID.T, |
302 session_id: UUID.T, |
250 theories: List[String] = Nil, |
303 theories: List[String] = Nil, |
251 master_dir: String = "", |
304 master_dir: String = "", |
270 val result_json = |
323 val result_json = |
271 JSON.Object("purged" -> purged.map(_.json), "retained" -> retained.map(_.json)) |
324 JSON.Object("purged" -> purged.map(_.json), "retained" -> retained.map(_.json)) |
272 |
325 |
273 (result_json, (purged, retained)) |
326 (result_json, (purged, retained)) |
274 } |
327 } |
|
328 |
|
329 override val command_body: Server.Command_Body = |
|
330 { case (context, Purge_Theories(args)) => |
|
331 val session = context.server.the_session(args.session_id) |
|
332 command(args, session)._1 |
|
333 } |
275 } |
334 } |
276 } |
335 } |
|
336 |
|
337 class Server_Commands extends Server.Commands( |
|
338 Server_Commands.Help, |
|
339 Server_Commands.Echo, |
|
340 Server_Commands.Cancel, |
|
341 Server_Commands.Shutdown, |
|
342 Server_Commands.Session_Build, |
|
343 Server_Commands.Session_Start, |
|
344 Server_Commands.Session_Stop, |
|
345 Server_Commands.Use_Theories, |
|
346 Server_Commands.Purge_Theories) |