From ff75e16ea3fc8406f49fc8aa1f00407bb0391368 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sat, 6 Aug 2011 15:17:59 +0100 Subject: [PATCH] protogen: disorder_new_tracks(). Organization: Straylight/Edgeware From: Richard Kettlewell --- clients/disorder.c | 2 +- lib/client-stubs.c | 13 +++++++- lib/client-stubs.h | 19 +++++++++++- lib/client.c | 16 ---------- lib/client.h | 3 -- scripts/protocol | 74 +++++++++++++++++++++++++++++----------------- 6 files changed, 78 insertions(+), 49 deletions(-) diff --git a/clients/disorder.c b/clients/disorder.c index 6e2ec14..6d2c823 100644 --- a/clients/disorder.c +++ b/clients/disorder.c @@ -416,7 +416,7 @@ static int isarg_integer(const char *s) { static void cf_new(char **argv) { char **vec; - if(disorder_new_tracks(getclient(), &vec, 0, argv[0] ? atoi(argv[0]) : 0)) + if(disorder_new_tracks(getclient(), argv[0] ? atol(argv[0]) : 0, &vec, 0)) exit(EXIT_FAILURE); while(*vec) xprintf("%s\n", nullcheck(utf82mb(*vec++))); diff --git a/lib/client-stubs.c b/lib/client-stubs.c index 1661a0c..f995043 100644 --- a/lib/client-stubs.c +++ b/lib/client-stubs.c @@ -1,6 +1,11 @@ +/* + * Automatically generated file, see scripts/protocol + * + * DO NOT EDIT. + */ /* * This file is part of DisOrder. - * Copyright (C) 2010 Richard Kettlewell + * Copyright (C) 2010-11 Richard Kettlewell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -119,6 +124,12 @@ int disorder_moveafter(disorder_client *c, const char *target, char **ids, int n return disorder_simple(c, 0, "moveafter", target, disorder_list, ids, nids, (char *)0); } +int disorder_new_tracks(disorder_client *c, long max, char ***tracksp, int *ntracksp) { + char buf_max[16]; + byte_snprintf(buf_max, sizeof buf_max, "%ld", max); + return disorder_simple_list(c, tracksp, ntracksp, "new", buf_max, (char *)0); +} + int disorder_nop(disorder_client *c) { return disorder_simple(c, 0, "nop", (char *)0); } diff --git a/lib/client-stubs.h b/lib/client-stubs.h index 0d3d727..fd85670 100644 --- a/lib/client-stubs.h +++ b/lib/client-stubs.h @@ -1,6 +1,11 @@ +/* + * Automatically generated file, see scripts/protocol + * + * DO NOT EDIT. + */ /* * This file is part of DisOrder. - * Copyright (C) 2010 Richard Kettlewell + * Copyright (C) 2010-11 Richard Kettlewell * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -227,6 +232,18 @@ int disorder_move(disorder_client *c, const char *track, long delta); */ int disorder_moveafter(disorder_client *c, const char *target, char **ids, int nids); +/** @brief List recently added tracks + * + * + * + * @param c Client + * @param max Maximum tracks to fetch, or 0 for all available + * @param tracksp Recently added tracks + * @param ntracksp Number of elements in tracksp + * @return 0 on success, non-0 on error + */ +int disorder_new_tracks(disorder_client *c, long max, char ***tracksp, int *ntracksp); + /** @brief Do nothing * * Used as a keepalive. No authentication required. diff --git a/lib/client.c b/lib/client.c index 0fc4827..5884e48 100644 --- a/lib/client.c +++ b/lib/client.c @@ -775,22 +775,6 @@ int disorder_log(disorder_client *c, struct sink *s) { return 0; } -/** @brief Get recently added tracks - * @param c Client - * @param vecp Where to store pointer to list (UTF-8) - * @param nvecp Where to store count - * @param max Maximum tracks to fetch, or 0 for all available - * @return 0 on success, non-0 on error - */ -int disorder_new_tracks(disorder_client *c, - char ***vecp, int *nvecp, - int max) { - char limit[32]; - - sprintf(limit, "%d", max); - return disorder_simple_list(c, vecp, nvecp, "new", limit, (char *)0); -} - /** @brief Get server's RTP address information * @param c Client * @param addressp Where to store address (UTF-8) diff --git a/lib/client.h b/lib/client.h index 6db0eb8..e41ea00 100644 --- a/lib/client.h +++ b/lib/client.h @@ -54,9 +54,6 @@ int disorder_prefs(disorder_client *c, const char *track, int disorder_set_volume(disorder_client *c, int left, int right); int disorder_get_volume(disorder_client *c, int *left, int *right); int disorder_log(disorder_client *c, struct sink *s); -int disorder_new_tracks(disorder_client *c, - char ***vecp, int *nvecp, - int max); int disorder_rtp_address(disorder_client *c, char **addressp, char **portp); const char *disorder_last(disorder_client *c); int disorder_schedule_get(disorder_client *c, const char *id, diff --git a/scripts/protocol b/scripts/protocol index a7b36ed..c3eb6f3 100755 --- a/scripts/protocol +++ b/scripts/protocol @@ -1,7 +1,7 @@ #! /usr/bin/perl -w # # This file is part of DisOrder. -# Copyright (C) 2010 Richard Kettlewell +# Copyright (C) 2010-11 Richard Kettlewell # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -140,6 +140,10 @@ sub c_return_docs { # simple(CMD, SUMMARY, DETAIL, # [[TYPE,NAME,DESCR], [TYPE,NAME,DESCR], ...], # [RETURN-TYPE, RETURN-NAME, RETURN_DESCR]) +# +# CMD is normally just the name of the command, but can +# be [COMMAND,FUNCTION] if the function name should differ +# from the protocol command. sub simple { my $cmd = shift; my $summary = shift; @@ -147,9 +151,15 @@ sub simple { my $args = shift; my $return = shift; + my $cmdc; + if(ref $cmd eq 'ARRAY') { + $cmdc = $$cmd[1]; + $cmd = $$cmd[0]; + } else { + $cmdc = $cmd; + $cmdc =~ s/-/_/g; + } print STDERR "Processing $cmd... "; - my $cmdc = $cmd; - $cmdc =~ s/-/_/g; # Synchronous C API print STDERR "H "; push(@h, "/** \@brief $summary\n", @@ -172,33 +182,33 @@ sub simple { map(c_in_decl($_), @$args), c_out_decl($return)), ") {\n"); + my @cargs = (); + for my $arg (@$args) { + if($arg->[0] eq 'body' or $arg->[0] eq 'list') { + push(@cargs, "disorder_$arg->[0]", $arg->[1], "n$arg->[1]"); + } elsif($arg->[0] eq 'string') { + push(@cargs, $arg->[1]); + } elsif($arg->[0] eq 'integer') { + 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"); + } else { + die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n"; + } + } if(!defined $return) { - my @cargs = (); - for my $arg (@$args) { - if($arg->[0] eq 'body' or $arg->[0] eq 'list') { - push(@cargs, "disorder_$arg->[0]", $arg->[1], "n$arg->[1]"); - } elsif($arg->[0] eq 'string') { - push(@cargs, $arg->[1]); - } elsif($arg->[0] eq 'integer') { - 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"); - } else { - die "$0: unsupported arg type '$arg->[0]' for '$cmd'\n"; - } - } push(@c, " return disorder_simple(", join(", ", "c", 0, "\"$cmd\"", @cargs, "(char *)0"), ");\n"); } elsif($return->[0] eq 'string') { push(@c, " return dequote(disorder_simple(c, $return->[1]p, \"$cmd\"", - map(", $_->[1]", @$args), + map(", $_", @cargs), ", (char *)0), $return->[1]p);\n"); } elsif($return->[0] eq 'boolean') { push(@c, " char *v;\n", " int rc;\n", " if((rc = disorder_simple(c, &v, \"$cmd\"", - map(", $_->[1]", @$args), + map(", $_", @cargs), ", (char *)0)))\n", " return rc;\n", " return boolean(\"$cmd\", v, $return->[1]p);\n"); @@ -207,7 +217,7 @@ sub simple { " int rc;\n", "\n", " if((rc = disorder_simple(c, &v, \"$cmd\"", - map(", $_->[1]", @$args), + map(", $_", @cargs), ", (char *)0)))\n", " return rc;\n", " *$return->[1]p = atol(v);\n", @@ -217,14 +227,14 @@ sub simple { push(@c, " char *u;\n", " int rc;\n", " if((rc = disorder_simple(c, &u, \"$cmd\"", - map(", $_->[1]", @$args), + map(", $_", @cargs), " )))\n", " return rc;\n", " c->user = u;\n", " return 0;\n"); } elsif($return->[0] eq 'body') { push(@c, " return disorder_simple_list(c, $return->[1]p, n$return->[1]p, \"$cmd\"", - map(", $_->[1]", @$args), + map(", $_", @cargs), ", (char *)0);\n"); } elsif($return->[0] eq 'queue') { push(@c, " return somequeue(c, \"$cmd\", $return->[1]p);\n"); @@ -232,7 +242,7 @@ sub simple { push(@c, " return onequeue(c, \"$cmd\", $return->[1]p);\n"); } elsif($return->[0] eq 'pair-list') { push(@c, " return pairlist(c, $return->[1]p, \"$cmd\"", - map(", $_->[1]", @$args), ", (char *)0);\n"); + map(", $_", @cargs), ", (char *)0);\n"); } else { die "$0: C API: unknown type '$return->[0]' for '$cmd'\n"; } @@ -253,9 +263,15 @@ sub simple { # Front matter ---------------------------------------------------------------- +our @generated = ("/*\n", + " * Automatically generated file, see scripts/protocol\n", + " *\n", + " * DO NOT EDIT.\n", + " */\n"); + our @gpl = ("/*\n", " * This file is part of DisOrder.\n", - " * Copyright (C) 2010 Richard Kettlewell\n", + " * Copyright (C) 2010-11 Richard Kettlewell\n", " *\n", " * This program is free software: you can redistribute it and/or modify\n", " * it under the terms of the GNU General Public License as published by\n", @@ -272,12 +288,12 @@ our @gpl = ("/*\n", " */\n"); -push(@h, @gpl, +push(@h, @generated, @gpl, "#ifndef CLIENT_STUBS_H\n", "#define CLIENT_STUBS_H\n", "\n"); -push(@c, @gpl, +push(@c, @generated, @gpl, "\n"); # The protocol ---------------------------------------------------------------- @@ -400,7 +416,11 @@ simple("moveafter", [["string", "target", "Move after this track, or to head if \"\""], ["list", "ids", "List of tracks to move by ID"]]); -# TODO new +simple(["new", "new_tracks"], + "List recently added tracks", + "", + [["integer", "max", "Maximum tracks to fetch, or 0 for all available"]], + ["body", "tracks", "Recently added tracks"]); simple("nop", "Do nothing", -- [mdw]