From 52fd86ab718439b6be29b8807dc52c71bc1567a6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 25 Dec 2015 21:45:21 +0100 Subject: improve send_command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/client.c | 13 ++++--------- src/client.h | 39 ++++++++++++++++++++++++++++++--------- src/satq.c | 2 +- src/satr.c | 2 +- src/satrm.c | 2 +- 5 files changed, 37 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/client.c b/src/client.c index 5f4ad00..fb08c49 100644 --- a/src/client.c +++ b/src/client.c @@ -33,21 +33,16 @@ extern char *argv0; /** * Send a command to satd. Start satd if it is not running. * - * If `n` is 0 but `msg` is not `NULL`, `msg` is a - * NUL-terminated string with the ID of the job to - * remove for the queue. `msg` should otherwise, - * unless it is `NULL` be the command the run, followed - * by its environment. - * - * @param n The length of the message, or a number - * number to send if `msg` is `NULL`. + * @param cmd Command type. + * @param n The length of the message, 0 if `msg` is + * `NULL` or NUL-terminated. * @param msg The message to send. * @return Zero on success. * * @throws 0 Error at the daemon-side. */ int -send_command(size_t n, const char *restrict msg) +send_command(enum command cmd, size_t n, const char *restrict msg) { return 0 /* TODO */ } diff --git a/src/client.h b/src/client.h index f64da2c..2e5cf9d 100644 --- a/src/client.h +++ b/src/client.h @@ -22,22 +22,43 @@ #include +/** + * Commands for `send_command`. + */ +enum command + { + /** + * Queue a job. + */ + SAT_QUEUE = 0, + + /** + * Remove jobs. + */ + SAT_REMOVE = 1, + + /** + * Print job queue. + */ + SAT_PRINT = 2, + + /** + * Run jobs + */ + SAT_RUN = 3 + }; + /** * Send a command to satd. Start satd if it is not running. * - * If `n` is 0 but `msg` is not `NULL`, `msg` is a - * NUL-terminated string with the ID of the job to - * remove for the queue. `msg` should otherwise, - * unless it is `NULL` be the command the run, followed - * by its environment. - * - * @param n The length of the message, or a number - * number to send if `msg` is `NULL`. + * @param cmd Command type. + * @param n The length of the message, 0 if `msg` is + * `NULL` or NUL-terminated. * @param msg The message to send. * @return Zero on success. * * @throws 0 Error at the daemon-side. */ -int send_command(size_t n, const char *restrict msg); +int send_command(enum command cmd, size_t n, const char *restrict msg); diff --git a/src/satq.c b/src/satq.c index f1c29b2..73b61ac 100644 --- a/src/satq.c +++ b/src/satq.c @@ -62,7 +62,7 @@ main(int argc, char *argv[]) if (argc > 0) argv0 = argv[0]; if (argc > 1) usage(); - if (send_command(0, NULL)) + if (send_command(SAT_PRINT, 0, NULL)) return errno ? (perror(argv0), 1) : 3; return 0; } diff --git a/src/satr.c b/src/satr.c index 11317c7..df85ee2 100644 --- a/src/satr.c +++ b/src/satr.c @@ -62,7 +62,7 @@ main(int argc, char *argv[]) if (argc > 0) argv0 = argv[0]; if (argc > 1) usage(); /* TODO possibility to select job */ - if (send_command(1, NULL)) + if (send_command(SAT_RUN, 0, NULL)) return errno ? (perror(argv0), 1) : 3; return 0; } diff --git a/src/satrm.c b/src/satrm.c index e1280bc..b3dafcd 100644 --- a/src/satrm.c +++ b/src/satrm.c @@ -63,7 +63,7 @@ main(int argc, char *argv[]) if (argc > 0) argv0 = argv[0]; if (argc != 2) usage(); - if (send_command(0, argv[1])) + if (send_command(SAT_REMOVE, 0, argv[1])) return errno ? (perror(argv0), 1) : 3; return 0; } -- cgit v1.2.3-70-g09d2