From 928f6dc758f4c76f798117ae4e40aa477cccb680 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 10 Mar 2012 12:09:13 +0000 Subject: [PATCH] daemon: Implement 'set_variables' (atomic set multiple variables) call. --- daemon/daemon.ml | 33 +++++++++++++++++++++++++++++++++ lib/whenproto.x | 7 +++++++ 2 files changed, 40 insertions(+) diff --git a/daemon/daemon.ml b/daemon/daemon.ml index ed5e067..8929cfa 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -79,6 +79,7 @@ let rec init j d = ~proc_cancel_job ~proc_start_job ~proc_get_job + ~proc_set_variables (Rpc_server.Unix addr) Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *) Rpc.Socket @@ -180,6 +181,38 @@ and proc_get_job serial = | Not_found -> failwith "job not found" | exn -> failwith (Printexc.to_string exn) +and proc_set_variables vars = + try + let vars = Array.map ( + fun { Whenproto_aux.sv_name = name; sv_value = value } -> + name, variable_of_rpc value + ) vars in + let vars = Array.to_list vars in + + if !debug then + Syslog.notice "remote call: set_variables (%s)" + (String.concat " " + (List.map ( + fun (name, value) -> + sprintf "%s=%s" name (string_of_variable value) + ) vars)); + + List.iter (fun (name, _) -> check_valid_variable_name name) vars; + + (* Update all the variables atomically. *) + let s = List.fold_left ( + fun s (name, value) -> Whenstate.set_variable s name value + ) !state vars in + state := s; + + (* Which jobs need to be re-evaluated? *) + let jobs = Whenstate.get_dependencies !state (List.map fst vars) in + reevaluate_whenjobs jobs; + + `ok + with + Failure msg -> `error msg + (* Reload the jobs file. *) and reload_file () = let file = sprintf "%s/jobs.cmo" !jobsdir in diff --git a/lib/whenproto.x b/lib/whenproto.x index 5754821..f7ea513 100644 --- a/lib/whenproto.x +++ b/lib/whenproto.x @@ -70,6 +70,12 @@ union variable switch (variable_type t) { double f; /* C 'double' maps to an OCaml 'float' */ }; +struct set_variable { + variable_name sv_name; + variable sv_value; +}; +typedef set_variable set_variable_list<>; + struct job { job_name job_name; string_big_int job_serial; @@ -91,5 +97,6 @@ program When { status cancel_job (string_big_int) = 7; status start_job (job_name) = 8; job get_job (string_big_int) = 9; + status set_variables (set_variable_list) = 10; } = 1; } = 0x20008081; -- 1.8.3.1