From 8ee4056bf819402aa4225e73bbe0a66e24294581 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sat, 10 Mar 2012 12:22:39 +0000 Subject: [PATCH] daemon: Implement 'get_job_names' call to list all loaded jobs. --- daemon/daemon.ml | 4 ++++ lib/whenproto.x | 3 +++ lib/whenstate.ml | 3 +++ lib/whenstate.mli | 3 +++ 4 files changed, 13 insertions(+) diff --git a/daemon/daemon.ml b/daemon/daemon.ml index 8929cfa..a4993a8 100644 --- a/daemon/daemon.ml +++ b/daemon/daemon.ml @@ -80,6 +80,7 @@ let rec init j d = ~proc_start_job ~proc_get_job ~proc_set_variables + ~proc_get_job_names (Rpc_server.Unix addr) Rpc.Tcp (* not TCP, this is the same as SOCK_STREAM *) Rpc.Socket @@ -213,6 +214,9 @@ and proc_set_variables vars = with Failure msg -> `error msg +and proc_get_job_names () = + Array.of_list (Whenstate.get_job_names !state) + (* 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 a1407fb..93173cf 100644 --- a/lib/whenproto.x +++ b/lib/whenproto.x @@ -85,6 +85,8 @@ struct job { typedef job job_list<>; +typedef job_name job_name_list<>; + /* The API of the daemon. */ program When { version V1 { @@ -98,5 +100,6 @@ program When { status start_job (job_name) = 8; job get_job (string_big_int) = 9; status set_variables (set_variable_list) = 10; + job_name_list get_job_names (void) = 11; } = 1; } = 0x20008081; diff --git a/lib/whenstate.ml b/lib/whenstate.ml index 2bb030d..b5784db 100644 --- a/lib/whenstate.ml +++ b/lib/whenstate.ml @@ -160,6 +160,9 @@ let get_everyjobs t = let get_job t jobname = StringMap.find jobname t.jobmap +let get_job_names t = + List.map (function { job_name = name } -> name) t.jobs + let evaluate_whenjob ?(onload = false) t job = match job with | { job_cond = Every_job _ } -> assert false diff --git a/lib/whenstate.mli b/lib/whenstate.mli index d9df5a9..f056c44 100644 --- a/lib/whenstate.mli +++ b/lib/whenstate.mli @@ -83,6 +83,9 @@ val get_everyjobs : t -> Whenexpr.job list val get_job : t -> string -> Whenexpr.job (** Return the named job, or raise [Not_found]. *) +val get_job_names : t -> string list +(** Return the names of all jobs (running or not). *) + val evaluate_whenjob : ?onload:bool -> t -> Whenexpr.job -> bool * t (** This evaluates the whenjob and returns [true] iff the whenjob should be run now. -- 1.8.3.1