|
From: Jérémie D. <Ba...@us...> - 2010-01-30 17:01:36
|
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 aa454675ff1f8c9a040ffbb6bf8d67edc1296e6f (commit)
from 4895e2f16c55d98053d1849d4ae9a7c7711b89d2 (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 aa454675ff1f8c9a040ffbb6bf8d67edc1296e6f
Author: Jérémie Dimino <je...@di...>
Date: Sat Jan 30 18:01:00 2010 +0100
do not open cards if we just want to kill the dirver
-----------------------------------------------------------------------
Changes:
diff --git a/PC_Mainboard/driver/src/driver.ml b/PC_Mainboard/driver/src/driver.ml
index 2bcb781..7b5b7ff 100644
--- a/PC_Mainboard/driver/src/driver.ml
+++ b/PC_Mainboard/driver/src/driver.ml
@@ -12,6 +12,37 @@
open OBus_pervasives
open Lwt
+(* Kill a running driver *)
+let kill bus =
+ OBus_connection.method_call bus
+ ~path:["fr"; "krobot"; "Manager"]
+ ~interface:"fr.krobot.Manager"
+ ~member:"Shutdown"
+ ~destination:"fr.krobot"
+ <:obus_func< unit >>
+
+(* +-----------------------------------------------------------------+
+ | Command line options |
+ +-----------------------------------------------------------------+ *)
+
+let foreground = ref false
+let kill_and_exit = ref false
+
+let () =
+ let args = [
+ "-n", Arg.Set foreground, "do not daemonize";
+ "-k", Arg.Set kill_and_exit, "kill any running driver and exit";
+ ] in
+ let usage_msg = Printf.sprintf "Usage: %s [-n]\n\noptions are:" (Filename.basename (Sys.argv.(0))) in
+ Arg.parse args ignore usage_msg;
+
+ if !kill_and_exit then
+ Lwt_main.run begin
+ lwt bus = Lazy.force OBus_bus.system in
+ lwt () = kill bus in
+ exit 0
+ end
+
(* +-----------------------------------------------------------------+
| Cards |
+-----------------------------------------------------------------+ *)
@@ -397,6 +428,7 @@ struct
include OBus.MakeInterface(struct let name = "fr.krobot.Manager" end)
OL_method Shutdown : unit = fun () ->
+ Log#info "exiting";
lwt bus = Lazy.force OBus_bus.system in
lwt () = Card.close card_interface
and () = Card.close card_sensor
@@ -410,84 +442,58 @@ end
| Entry point |
+-----------------------------------------------------------------+ *)
-(* Kill a running driver *)
-let kill bus =
- OBus_connection.method_call bus
- ~path:["fr"; "krobot"; "Manager"]
- ~interface:"fr.krobot.Manager"
- ~member:"Shutdown"
- ~destination:"fr.krobot"
- <:obus_func< unit >>
-
lwt () =
- (* Command line options *)
- let foreground = ref false and kill_and_exit = ref false in
- let args = [
- "-n", Arg.Set foreground, "do not daemonize";
- "-k", Arg.Set kill_and_exit, "kill any running driver and exit";
- ] in
- let usage_msg = Printf.sprintf "Usage: %s [-n]\n\noptions are:" (Filename.basename (Sys.argv.(0))) in
- Arg.parse args ignore usage_msg;
-
(* Be verbose: *)
Lwt_log.set_level !Lwt_log.default Lwt_log.Info;
lwt bus = Lazy.force OBus_bus.system in
- if !kill_and_exit then
- try_lwt
- kill bus
- with exn ->
- return ()
+ lwt () = OBus_bus.name_has_owner bus "fr.krobot" >>= function
+ | true ->
+ (* If a daemon is already running, kill it: *)
+ Log#info "killing the currently running driver";
+ kill bus
+ | false ->
+ return ()
+ in
+
+ (* Request the bus name for the driver: *)
+ lwt () = OBus_bus.request_name bus "fr.krobot" >>= function
+ | `primary_owner ->
+ return ()
+ | _ ->
+ fail (Failure "cannot obtain the name 'fr.krobot'")
+ in
+ if !foreground then
+ (* Running foreground, prints message on stderr: *)
+ Log#info "starting krobot driver in foreground mode"
else begin
- lwt () = OBus_bus.name_has_owner bus "fr.krobot" >>= function
- | true ->
- (* If a daemon is already running, kill it: *)
- Log#info "killing the currently running driver";
- kill bus
- | false ->
- return ()
- in
-
- (* Request the bus name for the driver: *)
- lwt () = OBus_bus.request_name bus "fr.krobot" >>= function
- | `primary_owner ->
- return ()
- | _ ->
- fail (Failure "cannot obtain the name 'fr.krobot'")
- in
-
- if !foreground then
- (* Running foreground, prints message on stderr: *)
- Log#info "starting krobot driver in foreground mode"
- else begin
- Log#info "starting krobot driver in daemon mode";
- (* In daemon mode, send messages to syslog: *)
- Lwt_log.default := Lwt_log.syslog ~level:Lwt_log.Info ~facility:`Daemon ();
- (* Become a daemon. Keep stderr for possible error messages of
- libusb. *)
- Lwt_unix.daemonize ~keep_stderr:true ()
- end;
-
- Log#info "creating and exporting objects";
-
- (* Interface card *)
- Compass.OBus.export bus (Compass.make card_interface ["fr"; "krobot"; "Devices"; "Compass"]);
- AX12.OBus.export bus (AX12.make card_interface ["fr"; "krobot"; "Devices"; "AX12"]);
- Elevator.OBus.export bus (Elevator.make card_interface ["fr"; "krobot"; "Devices"; "Elevator"]);
- Grip.OBus.export bus (Grip.make card_interface ["fr"; "krobot"; "Devices"; "Grip"]);
-
- (* Sensor card *)
- LogicSensors.OBus.export bus (LogicSensors.make card_sensor ["fr"; "krobot"; "Devices"; "LogicSensors"]);
- RangeFinders.OBus.export bus (RangeFinders.make card_sensor ["fr"; "krobot"; "Devices"; "RangeFinders"]);
-
- (* Motor card *)
- Motors.OBus.export bus (Motors.make card_motor ["fr"; "krobot"; "Devices"; "Motors"]);
-
- (* Internal objects *)
- Manager.OBus.export bus ();
-
- Log#info "ready, waiting for requests";
- done_waiter
- end
+ Log#info "starting krobot driver in daemon mode";
+ (* In daemon mode, send messages to syslog: *)
+ Lwt_log.default := Lwt_log.syslog ~level:Lwt_log.Info ~facility:`Daemon ();
+ (* Become a daemon. Keep stderr for possible error messages of
+ libusb. *)
+ Lwt_unix.daemonize ~keep_stderr:true ()
+ end;
+
+ Log#info "creating and exporting objects";
+
+ (* Interface card *)
+ Compass.OBus.export bus (Compass.make card_interface ["fr"; "krobot"; "Devices"; "Compass"]);
+ AX12.OBus.export bus (AX12.make card_interface ["fr"; "krobot"; "Devices"; "AX12"]);
+ Elevator.OBus.export bus (Elevator.make card_interface ["fr"; "krobot"; "Devices"; "Elevator"]);
+ Grip.OBus.export bus (Grip.make card_interface ["fr"; "krobot"; "Devices"; "Grip"]);
+
+ (* Sensor card *)
+ LogicSensors.OBus.export bus (LogicSensors.make card_sensor ["fr"; "krobot"; "Devices"; "LogicSensors"]);
+ RangeFinders.OBus.export bus (RangeFinders.make card_sensor ["fr"; "krobot"; "Devices"; "RangeFinders"]);
+
+ (* Motor card *)
+ Motors.OBus.export bus (Motors.make card_motor ["fr"; "krobot"; "Devices"; "Motors"]);
+
+ (* Internal objects *)
+ Manager.OBus.export bus ();
+
+ Log#info "ready, waiting for requests";
+ done_waiter
hooks/post-receive
--
krobot
|