From: Jérémie D. <Ba...@us...> - 2010-02-17 20:49:48
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 6745156ed1597623b6b73cb4da513875f04a357c (commit) from 8a7d0ca23efcdaef4335200e175fbe686a52c23a (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 6745156ed1597623b6b73cb4da513875f04a357c Author: Jérémie Dimino <je...@di...> Date: Wed Feb 17 21:49:14 2010 +0100 [controller] print logs on abnormal termination ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/clients/controller.ml b/PC_Mainboard/clients/controller.ml index 469f514..5b1d480 100644 --- a/PC_Mainboard/clients/controller.ml +++ b/PC_Mainboard/clients/controller.ml @@ -216,6 +216,17 @@ let () = (React.S.map (fun state -> state.Engine.mode) engine_state) let logs, set_logs = React.S.create [] +let log line = + let rec truncate n = function + | [] -> + [] + | line :: rest -> + if n = 1024 then + [] + else + line :: truncate (n + 1) rest + in + set_logs (line :: truncate 0 (React.S.value logs)) let history_file_name = Filename.concat (try Unix.getenv "HOME" with _ -> "") ".krobot-controller-history" @@ -256,7 +267,7 @@ let rec loop krobot history = let rec copy_logs ic = lwt line = Lwt_io.read_line ic in - set_logs (line :: React.S.value logs); + log line; copy_logs ic let redirect_stderr () = @@ -275,7 +286,7 @@ let redirect_stderr () = Lwt_log.render ~buffer ~level ~message:line ~template:"$(date): $(message)"; Buffer.contents buffer) lines in - set_logs (lines @ React.S.value logs); + List.iter log lines; return ()) ~close:return () @@ -283,35 +294,41 @@ let redirect_stderr () = lwt () = Log#notice "connecting to the krobot bus..."; lwt krobot = Krobot.create () in - try_lwt - lwt () = save_state () in - lwt () = hide_cursor () in - redirect_stderr (); - let signal = - React.S.l5 draw - Lwt_term.size - (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) - (Krobot.compass krobot) - (Krobot.logic_sensors krobot) - (Krobot.range_finders krobot) - (Krobot.team krobot) - (Krobot.jack krobot)) - (React.S.l2 (fun a b -> (a, b)) - (Krobot.inhibited_forward_until krobot) - (Krobot.inhibited_backward_until krobot)) - (React.S.l3 (fun a b c -> (a, b, c)) - engine_state - box - logs) - (React.S.l3 (fun a b c -> (a, b, c)) - (Krobot.Card.state krobot `Interface) - (Krobot.Card.state krobot `Sensor) - (Krobot.Card.state krobot `Motor)) - in - (* Make the compiler happy: *) - ignore signal; - lwt history = Lwt_read_line.load_history history_file_name in - set_engine_state (Engine.init history); - Lwt_term.with_raw_mode (fun () -> loop krobot history) - finally - restore_state () + lwt () = save_state () in + lwt () = hide_cursor () in + let node = + Lwt_sequence.add_l + (fun () -> + (* Dump logs on abnormal exit: *) + lwt () = restore_state () in + Lwt_list.iter_s Lwt_io.printl (React.S.value logs)) + Lwt_main.exit_hooks + in + redirect_stderr (); + let signal = + React.S.l5 draw + Lwt_term.size + (React.S.l5 (fun a b c d e -> (a, b, c, d, e)) + (Krobot.compass krobot) + (Krobot.logic_sensors krobot) + (Krobot.range_finders krobot) + (Krobot.team krobot) + (Krobot.jack krobot)) + (React.S.l2 (fun a b -> (a, b)) + (Krobot.inhibited_forward_until krobot) + (Krobot.inhibited_backward_until krobot)) + (React.S.l3 (fun a b c -> (a, b, c)) + engine_state + box + logs) + (React.S.l3 (fun a b c -> (a, b, c)) + (Krobot.Card.state krobot `Interface) + (Krobot.Card.state krobot `Sensor) + (Krobot.Card.state krobot `Motor)) + in + lwt history = Lwt_read_line.load_history history_file_name in + set_engine_state (Engine.init history); + lwt () = Lwt_term.with_raw_mode (fun () -> loop krobot history) in + React.S.stop signal; + Lwt_sequence.remove node; + restore_state () hooks/post-receive -- krobot |