94b0a9fb6d303c21c1b17272860740bd0e48335b
[tlb/tomd.git] / guile / tomd / job.scm
1 ;; Copyright (C) 2018 Thomas Balzer
2
3 ;; This file is part of tomd.
4
5 ;; tomd is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, either version 3 of the License, or
8 ;; (at your option) any later version.
9
10 ;; tomd is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with tomd. If not, see <http://www.gnu.org/licenses/>.
17
18 (define-module (tomd job)
19 #:use-module (srfi srfi-9)
20 #:export (create-job make-job
21 job-command-line c-job-cmd
22 job-args c-job-args
23 job-start-trigger c-job-start-trigger
24 job-end-trigger c-job-end-trigger
25 c-check-job))
26
27 ;;; records
28 (define-record-type <job>
29 (make-job command-line args start-trigger end-trigger)
30 job?
31 (command-line job-command-line)
32 (args job-args)
33 (start-trigger job-start-trigger)
34 (end-trigger job-end-trigger))
35
36 ;;; this sillyness is because i'm not sure how to expand macros in scm_call
37 (define (c-check-job obj)
38 (job? obj))
39
40 (define (c-job-cmd obj)
41 (job-command-line obj))
42
43 (define (c-job-args obj)
44 (job-args obj))
45
46 (define (c-job-start-trigger obj)
47 (job-start-trigger obj))
48
49 (define (c-job-end-trigger obj)
50 (job-end-trigger obj))
51
52 ;;; functions
53 (define (get-keyword-value args keyword default)
54 (let ((keyword-value (memq keyword args)))
55 (if (and keyword-value (>= (length keyword-value) 2))
56 (cadr keyword-value)
57 default)))
58
59 (define (create-job . rest)
60 (let ((command-line (get-keyword-value rest #:command-line #f))
61 (args (get-keyword-value rest #:args (list)))
62 (start-trigger (get-keyword-value rest #:start-trigger 'login))
63 (end-trigger (get-keyword-value rest #:end-trigger #f)))
64 ;; do thing with keyword-ed variables
65 ;; (display "settings:") (newline)
66 ;; (format (current-output-port)
67 ;; "command-line:~a" command-line)
68 ;; (newline)
69 ;; (format (current-output-port)
70 ;; "args:~a" args)
71 ;; (newline)
72 ;; (format (current-output-port)
73 ;; "start-trigger:~a" start-trigger)
74 ;; (newline)
75 ;; (format (current-output-port)
76 ;; "end-trigger:~a" end-trigger)
77 ;; (newline)
78
79 ;; create a new object that represents the args given.
80 (make-job command-line
81 args
82 start-trigger
83 end-trigger)
84 ))