From: Richard Kettlewell Date: Sun, 6 Jun 2010 09:27:29 +0000 (+0100) Subject: More commands. X-Git-Tag: branchpoint-5.1~22^2~16 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/ec9c046264b6c4ee76e2d08cf46ee928b026fe74 More commands. --- diff --git a/lib/client-stubs.c b/lib/client-stubs.c index d0c3103..68d041d 100644 --- a/lib/client-stubs.c +++ b/lib/client-stubs.c @@ -139,6 +139,10 @@ int disorder_playafter(disorder_client *c, const char *target, char **tracks, in return disorder_simple(c, 0, "playafter", target, disorder_list, tracks, ntracks, (char *)0); } +int disorder_playing(disorder_client *c, struct queue_entry **playingp) { + return onequeue(c, "playing", playingp); +} + int disorder_playlist_delete(disorder_client *c, const char *playlist) { return disorder_simple(c, 0, "playlist-delete", playlist, (char *)0); } @@ -172,7 +176,7 @@ int disorder_playlists(disorder_client *c, char ***playlistsp, int *nplaylistsp) } int disorder_queue(disorder_client *c, struct queue_entry **queuep) { - return disorder_somequeue(c, "queue", queuep); + return somequeue(c, "queue", queuep); } int disorder_random_disable(disorder_client *c) { @@ -192,7 +196,7 @@ int disorder_random_enabled(disorder_client *c, int *enabledp) { } int disorder_recent(disorder_client *c, struct queue_entry **recentp) { - return disorder_somequeue(c, "recent", recentp); + return somequeue(c, "recent", recentp); } int disorder_reconfigure(disorder_client *c) { diff --git a/lib/client-stubs.h b/lib/client-stubs.h index 19649ac..8a4ece5 100644 --- a/lib/client-stubs.h +++ b/lib/client-stubs.h @@ -281,6 +281,16 @@ int disorder_play(disorder_client *c, const char *track, char **idp); */ int disorder_playafter(disorder_client *c, const char *target, char **tracks, int ntracks); +/** @brief Retrieve the playing track + * + * + * + * @param c Client + * @param playingp Details of the playing track + * @return 0 on success, non-0 on error + */ +int disorder_playing(disorder_client *c, struct queue_entry **playingp); + /** @brief Delete a playlist * * Requires the 'play' right and permission to modify the playlist. diff --git a/lib/client.c b/lib/client.c index c96e2f3..c907e7c 100644 --- a/lib/client.c +++ b/lib/client.c @@ -532,19 +532,19 @@ static void client_error(const char *msg, disorder_error(0, "error parsing reply: %s", msg); } -/** @brief Get currently playing track +/** @brief Get a single queue entry * @param c Client + * @param cmd Command * @param qp Where to store track information * @return 0 on success, non-0 on error - * - * @p qp gets NULL if no track is playing. */ -int disorder_playing(disorder_client *c, struct queue_entry **qp) { +static int onequeue(disorder_client *c, const char *cmd, + struct queue_entry **qp) { char *r; struct queue_entry *q; int rc; - if((rc = disorder_simple(c, &r, "playing", (char *)0))) + if((rc = disorder_simple(c, &r, cmd, (char *)0))) return rc; if(r) { q = xmalloc(sizeof *q); @@ -557,8 +557,8 @@ int disorder_playing(disorder_client *c, struct queue_entry **qp) { } /** @brief Fetch the queue, recent list, etc */ -static int disorder_somequeue(disorder_client *c, - const char *cmd, struct queue_entry **qp) { +static int somequeue(disorder_client *c, + const char *cmd, struct queue_entry **qp) { struct queue_entry *qh, **qt = &qh, *q; char *l; int rc; diff --git a/scripts/protocol b/scripts/protocol index 7d4bbad..ea28966 100755 --- a/scripts/protocol +++ b/scripts/protocol @@ -18,6 +18,25 @@ # use strict; +# This file contains the definition of the disorder protocol, plus +# code to generates stubs for it in the various supported languages. +# +# At the time of writing it is a work in progress! + +# +# Types: +# +# string A (Unicode) string. +# integer An integer. 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. +# body In commands: a list of strings as a command body. +# 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. +# + # Variables and utilities ----------------------------------------------------- our @h = (); @@ -48,7 +67,7 @@ sub c_in_decl { return ("char **$name", "int n$name"); } else { - die "$0: unknown type '$type'\n"; + die "$0: c_in_decl: unknown type '$type'\n"; } } @@ -64,15 +83,15 @@ sub c_out_decl { return ("long *${name}p"); } elsif($type eq 'boolean') { return ("int *${name}p"); - } elsif($type eq 'list') { + } elsif($type eq 'list' or $type eq 'body') { return ("char ***${name}p", "int *n${name}p"); - } elsif($type eq 'queue') { + } elsif($type eq 'queue' or $type eq 'queue-one') { return ("struct queue_entry **${name}p"); } elsif($type eq 'user') { return (); } else { - die "$0: unknown type '$type'\n"; + die "$0: c_out_decl: unknown type '$type'\n"; } } @@ -101,15 +120,15 @@ sub c_return_docs { or $type eq 'integer' or $type eq 'boolean') { return (" * \@param ${name}p $descr\n"); - } elsif($type eq 'list') { + } elsif($type eq 'list' or $type eq 'body') { return (" * \@param ${name}p $descr\n", " * \@param n${name}p Number of elements in ${name}p\n"); - } elsif($type eq 'queue') { + } elsif($type eq 'queue' or $type eq 'queue-one') { return (" * \@param ${name}p $descr\n"); } elsif($type eq 'user') { return (); } else { - die "$0: unknown return type '$type'\n"; + die "$0: c_return_docs: unknown type '$type'\n"; } } @@ -123,9 +142,11 @@ sub simple { my $args = shift; my $return = shift; + print STDERR "Processing $cmd... "; my $cmdc = $cmd; $cmdc =~ s/-/_/g; # Synchronous C API + print STDERR "H "; push(@h, "/** \@brief $summary\n", " *\n", " * $detail\n", @@ -140,6 +161,7 @@ sub simple { map(c_in_decl($_), @$args), c_out_decl($return)), ");\n\n"); + print STDERR "C "; push(@c, "int disorder_$cmdc(", join(", ", "disorder_client *c", map(c_in_decl($_), @$args), @@ -195,14 +217,16 @@ sub simple { " return rc;\n", " c->user = u;\n", " return 0;\n"); - } elsif($return->[0] eq 'list') { + } elsif($return->[0] eq 'body') { push(@c, " return disorder_simple_list(c, $return->[1]p, n$return->[1]p, \"$cmd\"", map(", $_->[1]", @$args), ", (char *)0);\n"); } elsif($return->[0] eq 'queue') { - push(@c, " return disorder_somequeue(c, \"$cmd\", $return->[1]p);\n"); + push(@c, " return somequeue(c, \"$cmd\", $return->[1]p);\n"); + } elsif($return->[0] eq 'queue-one') { + push(@c, " return onequeue(c, \"$cmd\", $return->[1]p);\n"); } else { - die "$0: unknown return type '$return->[0]' for '$cmd'\n"; + die "$0: C API: unknown type '$return->[0]' for '$cmd'\n"; } push(@c, "}\n\n"); @@ -214,6 +238,7 @@ sub simple { # Java API # TODO + print STDERR "\n"; } # TODO other command classes @@ -266,7 +291,7 @@ simple("allfiles", "See 'files' and 'dirs' for more specific lists.", [["string", "dir", "Directory to list (optional)"], ["string", "re", "Regexp that results must match (optional)"]], - ["list", "files", "List of matching files and directories"]); + ["body", "files", "List of matching files and directories"]); simple("confirm", "Confirm registration", @@ -290,7 +315,7 @@ simple("dirs", "", [["string", "dir", "Directory to list (optional)"], ["string", "re", "Regexp that results must match (optional)"]], - ["list", "files", "List of matching directories"]); + ["body", "files", "List of matching directories"]); simple("disable", "Disable play", @@ -326,7 +351,7 @@ simple("files", "", [["string", "dir", "Directory to list (optional)"], ["string", "re", "Regexp that results must match (optional)"]], - ["list", "files", "List of matching files"]); + ["body", "files", "List of matching files"]); simple("get", "Get a track preference", @@ -399,7 +424,11 @@ simple("playafter", [["string", "target", "Insert into queue after this track, or at head if \"\""], ["list", "tracks", "List of track names to play"]]); -# TODO playing +simple("playing", + "Retrieve the playing track", + "", + [], + ["queue-one", "playing", "Details of the playing track"]); simple("playlist-delete", "Delete a playlist", @@ -410,7 +439,7 @@ simple("playlist-get", "List the contents of a playlist", "Requires the 'read' right and oermission to read the playlist.", [["string", "playlist", "Playlist name"]], - ["list", "tracks", "List of tracks in playlist"]); + ["body", "tracks", "List of tracks in playlist"]); simple("playlist-get-share", "Get a playlist's sharing status", @@ -444,7 +473,7 @@ simple("playlists", "List playlists", "Requires the 'read' right. Only playlists that you have permission to read are returned.", [], - ["list", "playlists", "Playlist names"]); + ["body", "playlists", "Playlist names"]); # TODO prefs @@ -540,13 +569,13 @@ simple("schedule-list", "List scheduled events", "This just lists IDs. Use 'schedule-get' to retrieve more detail", [], - ["list", "ids", "List of event IDs"]); + ["body", "ids", "List of event IDs"]); simple("search", "Search for tracks", "Terms are either keywords or tags formatted as 'tag:TAG-NAME'.", [["string", "terms", "List of search terms"]], - ["list", "tracks", "List of matching tracks"]); + ["body", "tracks", "List of matching tracks"]); simple("set", "Set a track preference", @@ -570,13 +599,13 @@ simple("stats", "Get server statistics", "The details of what the server reports are not really defined. The returned strings are intended to be printed out one to a line..", [], - ["list", "stats", "List of server information strings."]); + ["body", "stats", "List of server information strings."]); simple("tags", "Get a list of known tags", "Only tags which apply to at least one track are returned.", [], - ["list", "tags", "List of tags"]); + ["body", "tags", "List of tags"]); simple("unset", "Unset a track preference", @@ -602,7 +631,7 @@ simple("users", "Get a list of users", "", [], - ["list", "users", "List of users"]); + ["body", "users", "List of users"]); simple("version", "Get the server version",