From: Richard Kettlewell Date: Sat, 6 Aug 2011 20:19:37 +0000 (+0100) Subject: protogen: support schedule-add. X-Git-Tag: branchpoint-5.1~22^2~9 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/4d80373d26cd9ce5da4cbf5b0ddbf36650f25b11 protogen: support schedule-add. --- diff --git a/clients/disorder.c b/clients/disorder.c index 6d2c823..5d47bb1 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -317,10 +317,10 @@ static void cf_stats(char attribute((unused)) **argv) { } static void cf_get_volume(char attribute((unused)) **argv) { - int l, r; + long l, r; if(disorder_get_volume(getclient(), &l, &r)) exit(EXIT_FAILURE); - xprintf("%d %d\n", l, r); + xprintf("%ld %ld\n", l, r); } static void cf_set_volume(char **argv) { @@ -581,31 +581,27 @@ static void cf_schedule_del(char **argv) { } static void cf_schedule_play(char **argv) { - if(disorder_schedule_add(getclient(), - dateparse(argv[0]), - argv[1], - "play", - argv[2])) + if(disorder_schedule_add_play(getclient(), + dateparse(argv[0]), + argv[1], + argv[2])) exit(EXIT_FAILURE); } static void cf_schedule_set_global(char **argv) { - if(disorder_schedule_add(getclient(), - dateparse(argv[0]), - argv[1], - "set-global", - argv[2], - argv[3])) + if(disorder_schedule_add_set_global(getclient(), + dateparse(argv[0]), + argv[1], + argv[2], + argv[3])) exit(EXIT_FAILURE); } static void cf_schedule_unset_global(char **argv) { - if(disorder_schedule_add(getclient(), - dateparse(argv[0]), - argv[1], - "set-global", - argv[2], - (char *)0)) + if(disorder_schedule_add_unset_global(getclient(), + dateparse(argv[0]), + argv[1], + argv[2])) exit(EXIT_FAILURE); } diff --git a/lib/client-stubs.c b/lib/client-stubs.c index 310505a..cf5916f 100644 --- a/lib/client-stubs.c +++ b/lib/client-stubs.c @@ -412,6 +412,24 @@ int disorder_scratch(disorder_client *c, const char *id) { return disorder_simple(c, NULL, "scratch", id, (char *)NULL); } +int disorder_schedule_add_play(disorder_client *c, time_t when, const char *priority, const char *track) { + char buf_when[16]; + byte_snprintf(buf_when, sizeof buf_when, "%lld", (long long)when); + return disorder_simple(c, NULL, "schedule-add", buf_when, priority, "play", track, (char *)NULL); +} + +int disorder_schedule_add_set_global(disorder_client *c, time_t when, const char *priority, const char *pref, const char *value) { + char buf_when[16]; + byte_snprintf(buf_when, sizeof buf_when, "%lld", (long long)when); + return disorder_simple(c, NULL, "schedule-add", buf_when, priority, "set-global", pref, value, (char *)NULL); +} + +int disorder_schedule_add_unset_global(disorder_client *c, time_t when, const char *priority, const char *pref) { + char buf_when[16]; + byte_snprintf(buf_when, sizeof buf_when, "%lld", (long long)when); + return disorder_simple(c, NULL, "schedule-add", buf_when, priority, "set-global", pref, (char *)NULL); +} + int disorder_schedule_del(disorder_client *c, const char *event) { return disorder_simple(c, NULL, "schedule-del", event, (char *)NULL); } diff --git a/lib/client-stubs.h b/lib/client-stubs.h index 153b082..8b0f4c5 100644 --- a/lib/client-stubs.h +++ b/lib/client-stubs.h @@ -553,6 +553,43 @@ int disorder_rtp_address(disorder_client *c, char **addressp, char **portp); */ int disorder_scratch(disorder_client *c, const char *id); +/** @brief Schedule a track to play in the future + * + * + * + * @param c Client + * @param when When to play the track + * @param priority Event priority ("normal" or "junk") + * @param track Track to play + * @return 0 on success, non-0 on error + */ +int disorder_schedule_add_play(disorder_client *c, time_t when, const char *priority, const char *track); + +/** @brief Schedule a global setting to be changed in the future + * + * + * + * @param c Client + * @param when When to change the setting + * @param priority Event priority ("normal" or "junk") + * @param pref Global preference to set + * @param value New value of global preference + * @return 0 on success, non-0 on error + */ +int disorder_schedule_add_set_global(disorder_client *c, time_t when, const char *priority, const char *pref, const char *value); + +/** @brief Schedule a global setting to be unset in the future + * + * + * + * @param c Client + * @param when When to change the setting + * @param priority Event priority ("normal" or "junk") + * @param pref Global preference to set + * @return 0 on success, non-0 on error + */ +int disorder_schedule_add_unset_global(disorder_client *c, time_t when, const char *priority, const char *pref); + /** @brief Delete a scheduled event. * * Users can always delete their own scheduled events; with the admin right you can delete any event. diff --git a/lib/client.c b/lib/client.c index 521a4c7..0fdb8be 100644 --- a/lib/client.c +++ b/lib/client.c @@ -709,46 +709,6 @@ int disorder_log(disorder_client *c, struct sink *s) { return 0; } -/** @brief Add a scheduled event - * @param c Client - * @param when When to trigger the event - * @param priority Event priority ("normal" or "junk") - * @param action What action to perform - * @param ... Action-specific arguments - * @return 0 on success, non-0 on error - * - * For action @c "play" the next argument is the track. - * - * For action @c "set-global" next argument is the global preference name - * and the final argument the value to set it to, or (char *)0 to unset it. - */ -int disorder_schedule_add(disorder_client *c, - time_t when, - const char *priority, - const char *action, - ...) { - va_list ap; - char when_str[64]; - int rc; - - snprintf(when_str, sizeof when_str, "%lld", (long long)when); - va_start(ap, action); - if(!strcmp(action, "play")) - rc = disorder_simple(c, 0, "schedule-add", when_str, priority, - action, va_arg(ap, char *), - (char *)0); - else if(!strcmp(action, "set-global")) { - const char *key = va_arg(ap, char *); - const char *value = va_arg(ap, char *); - rc = disorder_simple(c, 0,"schedule-add", when_str, priority, - action, key, value, - (char *)0); - } else - disorder_fatal(0, "unknown action '%s'", action); - va_end(ap); - return rc; -} - #include "client-stubs.c" /* diff --git a/lib/client.h b/lib/client.h index 9bc6fec..4210b60 100644 --- a/lib/client.h +++ b/lib/client.h @@ -47,19 +47,9 @@ int disorder_connect_generic(struct config *conf, const char *password, const char *cookie); int disorder_close(disorder_client *c); -int disorder_playing(disorder_client *c, struct queue_entry **qp); char *disorder_user(disorder_client *c); -int disorder_prefs(disorder_client *c, const char *track, - struct kvp **kp); int disorder_log(disorder_client *c, struct sink *s); const char *disorder_last(disorder_client *c); -int disorder_schedule_get(disorder_client *c, const char *id, - struct kvp **actiondatap); -int disorder_schedule_add(disorder_client *c, - time_t when, - const char *priority, - const char *action, - ...); #include "client-stubs.h" diff --git a/scripts/protocol b/scripts/protocol index 610656b..13c9f3c 100755 --- a/scripts/protocol +++ b/scripts/protocol @@ -29,6 +29,7 @@ use strict; # string A (Unicode) string. # string-raw A string that is not subject to de-quoting (return only) # integer An integer. Decimal on the wire. +# time A timestamp. Decimal on the wire. # boolean True or false. "yes" or "no" on the wire. # list In commands: a list of strings in the command. # In returns: a list of lines in the response. @@ -37,6 +38,7 @@ use strict; # In returns: a list of strings as a response body. # queue In returns: a list of queue entries in a response body. # queue-one In returns: a queue entry in the response. +# literal Constant string sent in sequence # # Variables and utilities ----------------------------------------------------- @@ -72,9 +74,13 @@ sub c_in_decl { return "const char *$name"; } elsif($type eq 'integer') { return "long $name"; + } elsif($type eq 'time') { + return "time_t $name"; } elsif($type eq 'list' or $type eq 'body') { return ("char **$name", "int n$name"); + } elsif($type eq 'literal') { + return (); } else { die "$0: c_in_decl: unknown type '$type'\n"; } @@ -94,6 +100,8 @@ sub c_out_decl { return ("char **${name}p"); } elsif($type eq 'integer') { return ("long *${name}p"); + } elsif($type eq 'time') { + return ("time_t *${name}p"); } elsif($type eq 'boolean') { return ("int *${name}p"); } elsif($type eq 'list' or $type eq 'body') { @@ -117,12 +125,15 @@ sub c_param_docs { my $args = shift; my @d = (); for my $arg (@$args) { - if($arg->[0] eq 'body' or $arg->[0] eq 'list') { + my $type = $arg->[0]; + my $name = $arg->[1]; + my $description = $arg->[2]; + if($type eq 'body' or $type eq 'list') { push(@d, - " * \@param $arg->[1] $arg->[2]\n", - " * \@param n$arg->[1] Length of $arg->[1]\n"); - } else { - push(@d, " * \@param $arg->[1] $arg->[2]\n"); + " * \@param $name $description\n", + " * \@param n$name Length of $name\n"); + } elsif($type ne 'literal') { + push(@d, " * \@param $name $description\n"); } } return @d; @@ -141,6 +152,7 @@ sub c_return_docs { if($type eq 'string' or $type eq 'string-raw' or $type eq 'integer' + or $type eq 'time' or $type eq 'boolean') { return (" * \@param ${name}p $descr\n"); } elsif($type eq 'list' or $type eq 'body') { @@ -213,6 +225,12 @@ sub simple { push(@cargs, "buf_$arg->[1]"); push(@c, " char buf_$arg->[1]\[16];\n", " byte_snprintf(buf_$arg->[1], sizeof buf_$arg->[1], \"%ld\", $arg->[1]);\n"); + } elsif($arg->[0] eq 'time') { + push(@cargs, "buf_$arg->[1]"); + push(@c, " char buf_$arg->[1]\[16];\n", + " byte_snprintf(buf_$arg->[1], sizeof buf_$arg->[1], \"%lld\", (long long)$arg->[1]);\n"); + } elsif($arg->[0] eq 'literal') { + push(@cargs, "\"$arg->[1]\""); } else { die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n"; } @@ -252,6 +270,7 @@ sub simple { if($type eq 'string' or $type eq 'boolean' or $type eq 'integer' + or $type eq 'time' or $type eq 'user') { $split = 1; } @@ -293,6 +312,9 @@ sub simple { } elsif($type eq 'integer') { push(@c, " *${name}p = atol(v[$n]);\n"); + } elsif($type eq 'time') { + push(@c, + " *${name}p = atoll(v[$n]);\n"); } elsif($type eq 'user') { push(@c, " c->user = v[$n];\n"); @@ -658,7 +680,30 @@ simple("scratch", "Requires one of the 'scratch mine', 'scratch random' or 'scratch any' rights depending on how the track came to be added to the queue.", [["string", "id", "Track ID (optional)"]]); -# TODO schedule-add +simple(["schedule-add", "schedule_add_play"], + "Schedule a track to play in the future", + "", + [["time", "when", "When to play the track"], + ["string", "priority", "Event priority (\"normal\" or \"junk\")"], + ["literal", "play", ""], + ["string", "track", "Track to play"]]); + +simple(["schedule-add", "schedule_add_set_global"], + "Schedule a global setting to be changed in the future", + "", + [["time", "when", "When to change the setting"], + ["string", "priority", "Event priority (\"normal\" or \"junk\")"], + ["literal", "set-global", ""], + ["string", "pref", "Global preference to set"], + ["string", "value", "New value of global preference"]]); + +simple(["schedule-add", "schedule_add_unset_global"], + "Schedule a global setting to be unset in the future", + "", + [["time", "when", "When to change the setting"], + ["string", "priority", "Event priority (\"normal\" or \"junk\")"], + ["literal", "set-global", ""], + ["string", "pref", "Global preference to set"]]); simple("schedule-del", "Delete a scheduled event.",