chiark / gitweb /
length command stub
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 5 Jun 2010 14:40:10 +0000 (15:40 +0100)
committerRichard Kettlewell <rjk@terraraq.org.uk>
Sat, 6 Aug 2011 17:19:07 +0000 (18:19 +0100)
lib/client-stubs.c
lib/client-stubs.h
lib/client.c
scripts/protocol

index 3d021396b6a7bf137687b174c85cf6bd29a54b3e..9d8edf7208e116fe4b3253400dee711866feedb5 100644 (file)
@@ -94,6 +94,17 @@ int disorder_get_global(disorder_client *c, const char *pref, char **valuep) {
   return dequote(disorder_simple(c, valuep, "get-global", pref, (char *)0), valuep);
 }
 
+int disorder_length(disorder_client *c, const char *track, long *lengthp) {
+  char *v;
+  int rc;
+
+  if((rc = disorder_simple(c, &v, "length", track, (char *)0)))
+    return rc;
+  *lengthp = atol(v);
+  xfree(v);
+  return 0;
+}
+
 int disorder_make_cookie(disorder_client *c, char **cookiep) {
   return dequote(disorder_simple(c, cookiep, "make-cookie", (char *)0), cookiep);
 }
index 13f0724f58979f1100693714eced68540ed589d0..f7a9dbbd03e44b35ad013a6a0605767bedc81ba9 100644 (file)
@@ -166,6 +166,16 @@ int disorder_get(disorder_client *c, const char *track, const char *pref, char *
  */
 int disorder_get_global(disorder_client *c, const char *pref, char **valuep);
 
+/** @brief Get a track's length
+ *
+ * If the track does not exist an error is returned.
+ *
+ * @param track Track name
+ * @param lengthp Track length in seconds
+ * @return 0 on success, non-0 on error
+ */
+int disorder_length(disorder_client *c, const char *track, long *lengthp);
+
 /** @brief Create a login cookie for this user
  *
  * The cookie may be redeemed via the 'cookie' command
index 1cb73a456010e5fd038b9ecc8fc7b6b3109e61e0..e7a1acc6161f498b24099af191ac5793a4f96be3 100644 (file)
@@ -742,25 +742,6 @@ static int boolean(const char *cmd, const char *value,
   return 0;
 }
 
-/** @brief Get the length of a track
- * @param c Client
- * @param track Track name (UTF-8)
- * @param valuep Where to store length in seconds
- * @return 0 on success, non-0 on error
- *
- * If the length is unknown 0 is returned.
- */
-int disorder_length(disorder_client *c, const char *track,
-                   long *valuep) {
-  char *value;
-  int rc;
-
-  if((rc = disorder_simple(c, &value, "length", track, (char *)0)))
-    return rc;
-  *valuep = atol(value);
-  return 0;
-}
-
 /** @brief Set volume
  * @param c Client
  * @param left New left channel value
index 2cfa644ff61ffaf0f826ff5c26d837cd95a145f0..b623632c1538122b73e111d5fcd64a982b01444f 100755 (executable)
@@ -211,6 +211,56 @@ sub boolean {
     # TODO
 }
 
+# integer(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
+#
+# Response is an integer, or failure
+sub integer {
+    my $cmd = shift;
+    my $summary = shift;
+    my $detail = shift;
+    my $args = shift;
+    my $return = shift;
+
+    my $cmdc = $cmd;
+    $cmdc =~ s/-/_/g;
+    # Synchronous C API
+    push(@h, "/** \@brief $summary\n",
+         " *\n",
+         " * $detail\n",
+         " *\n",
+         map(" * \@param $_->[0] $_->[1]\n", @$args),
+         " * \@param $return->[0]p $return->[1]\n",
+         " * \@return 0 on success, non-0 on error\n",
+         " */\n",
+         "int disorder_$cmdc(disorder_client *c",
+         map(", const char *$_->[0]", @$args),
+         ", long *$return->[0]p);\n",
+         "\n");
+    push(@c, "int disorder_$cmdc(disorder_client *c",
+         map(", const char *$_->[0]", @$args),
+         ", long *$return->[0]p) {\n",
+         "  char *v;\n",
+        "  int rc;\n",
+        "\n",
+        "  if((rc = disorder_simple(c, &v, \"$cmd\"",
+         map(", $_->[0]", @$args),
+         ", (char *)0)))\n",
+        "    return rc;\n",
+        "  *$return->[0]p = atol(v);\n",
+        "  xfree(v);\n",
+        "  return 0;\n",
+         "}\n\n");
+
+    # Asynchronous C API
+    # TODO
+
+    # Python API
+    # TODO
+
+    # Java API
+    # TODO
+}
+
 # list(CMD, SUMMARY, DETAIL, [[NAME,DESCR], [NAME,DESCR], ...], [RETURN, DESCR])
 #
 # Response is a a list of strings in a dot-stuffed body
@@ -378,7 +428,11 @@ string("get-global",
        [["pref", "Global preference name"]],
        ["value", "Preference value"]);
 
-# TODO length
+integer("length",
+       "Get a track's length",
+       "If the track does not exist an error is returned.",
+       [["track", "Track name"]],
+       ["length", "Track length in seconds"]);
 
 # TODO log