}
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) {
}
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);
}
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);
}
*/
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.
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"
/*
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"
# 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.
# 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 -----------------------------------------------------
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";
}
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') {
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;
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') {
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";
}
if($type eq 'string'
or $type eq 'boolean'
or $type eq 'integer'
+ or $type eq 'time'
or $type eq 'user') {
$split = 1;
}
} 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");
"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.",