chiark / gitweb /
Add 'adopt' command. This adopts a randomly picked track by changing
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 13 Dec 2008 15:48:31 +0000 (15:48 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 13 Dec 2008 15:48:31 +0000 (15:48 +0000)
its origin to 'adopted' and its submitter to the calling user.  The
nice UIs don't support this yet but you can access it from the command
line.

Document 'origin' and update 'state' in disorder_protocol(5).

clients/disorder.c
doc/disorder_protocol.5.in
lib/client.c
lib/client.h
lib/eclient.c
lib/eclient.h
lib/queue.h
python/disorder.py.in
server/server.c

index 4afc5680eca18a39b5535937a0e277c4d9d25164..8dc6d7fda7f35baa96bc38f0c78ddbbc1a93f13f 100644 (file)
@@ -577,6 +577,11 @@ static void cf_schedule_unset_global(char **argv) {
     exit(EXIT_FAILURE);
 }
 
+static void cf_adopt(char **argv) {
+  if(disorder_adopt(getclient(), argv[0]))
+    exit(EXIT_FAILURE);
+}
+
 static const struct command {
   const char *name;
   int min, max;
@@ -586,6 +591,8 @@ static const struct command {
 } commands[] = {
   { "adduser",        2, 3, cf_adduser, isarg_rights, "USERNAME PASSWORD [RIGHTS]",
                       "Create a new user" },
+  { "adopt",          1, 1, cf_adopt, 0, "ID",
+                      "Adopt a randomly picked track" },
   { "allfiles",       1, 2, cf_allfiles, isarg_regexp, "DIR [~REGEXP]",
                       "List all files and directories in DIR" },
   { "authorize",      1, 2, cf_authorize, isarg_rights, "USERNAME [RIGHTS]",
index a35e7f7d192e77ce1f5609d1eb00f3ea5b560cd9..ba37e67120e11444f16d3a650126af66296663ae 100644 (file)
@@ -57,6 +57,10 @@ then the \fBdefault_rights\fR setting applies instead.
 Requires the \fBadmin\fR right, and only works on local
 connections.
 .TP
+.B adopt \fIID\fR
+Adopts a randomly picked track, leaving it in a similar state to if it was
+picked by this user.  Requires the \fBplay\fR right.
+.TP
 .B allfiles \fIDIRECTORY\fR [\fIREGEXP\fR]
 List all the files and directories in \fIDIRECTORY\fR in a response body.
 If \fIREGEXP\fR is present only matching files and directories are returned.
@@ -495,6 +499,26 @@ The time the track was played at.
 .B scratched
 The user that scratched the track.
 .TP
+.B origin
+The origin of the track.  Valid origins are:
+.RS
+.TP 12
+.B adopted
+The track was originally randomly picked but has been adopted by a user.
+.TP
+.B picked
+The track was picked by a user.
+.TP
+.B random
+The track was randomly picked.
+.TP
+.B scheduled
+The track was played from a scheduled action.
+.TP
+.B scratch
+The track is a scratch sound.
+.RE
+.TP
 .B state
 The current track state.
 Valid states are:
@@ -503,12 +527,6 @@ Valid states are:
 .B failed
 The player failed (exited with nonzero status but wasn't scratched).
 .TP
-.B isscratch
-The track is actually a scratch.
-.TP
-.B no_player
-No player could be found for the track.
-.TP
 .B ok
 The track was played without any problems.
 .TP
@@ -518,6 +536,9 @@ The track was scratched.
 .B started
 The track is currently playing.
 .TP
+.B paused
+Track is playing but paused.
+.TP
 .B unplayed
 In the queue, hasn't been played yet.
 .TP
@@ -536,6 +557,9 @@ The time the track was added to the queue.
 .TP
 .B wstat
 The wait status of the player in decimal.
+.PP
+Note that \fBorigin\fR is new with DisOrder 4.3, and obsoletes some old
+\fBstate\fR values.
 .SH NOTES
 Times are decimal integers using the server's \fBtime_t\fR.
 .PP
@@ -553,6 +577,9 @@ keyword followed by (optionally) parameters.
 The parameters are quoted in the usual DisOrder way.
 Currently the following keywords are used:
 .TP
+.B adopted \fIID\fR \fIUSERNAME\fR
+\fIUSERNAME\fR adopted track \fIID\fR.
+.TP
 .B completed \fITRACK\fR
 Completed playing \fITRACK\fR
 .TP
index 9a676c9a6b0205ae539d3f58c001fed74a8fd0be..00d7cf51b0b804a7bb29e92f674a9579a6a36b80 100644 (file)
@@ -1302,6 +1302,15 @@ int disorder_schedule_add(disorder_client *c,
   return rc;
 }
 
+/** @brief Adopt a track
+ * @param c Client
+ * @param id Track ID to adopt
+ * @return 0 on success, non-0 on error
+ */
+int disorder_adopt(disorder_client *c, const char *id) {
+  return disorder_simple(c, 0, "adopt", id, (char *)0);
+}
+
 /*
 Local Variables:
 c-basic-offset:2
index 746daed01e919aca2a60851a75906dedaee3d8cb..89f30377c3aecbf74db17105dfaa7265813f19e8 100644 (file)
@@ -131,6 +131,7 @@ int disorder_schedule_add(disorder_client *c,
                          const char *priority,
                          const char *action,
                          ...);
+int disorder_adopt(disorder_client *c, const char *id);
 
 #endif /* CLIENT_H */
 
index 19d8d7c04b3393bc07f8ec184fa78cd6fc9d55fd..b7b502b960ebbdba113310866c1d2dc05a484266 100644 (file)
@@ -1404,6 +1404,20 @@ int disorder_eclient_adduser(disorder_eclient *c,
                 "adduser", user, password, rights, (char *)0);
 }
 
+/** @brief Adopt a track
+ * @param c Client
+ * @param completed Called on completion
+ * @param id Track ID
+ * @param v Passed to @p completed
+ */
+int disorder_eclient_adopt(disorder_eclient *c,
+                           disorder_eclient_no_response *completed,
+                           const char *id,
+                           void *v) {
+  return simple(c, no_response_opcallback, (void (*)())completed, v, 
+                "adopt", id, (char *)0);
+}
+
 /* Log clients ***************************************************************/
 
 /** @brief Monitor the server log
index 6578a759892a08df9e14dea6f7e0047d0c93a13a..359a71b38b59d4faed28b341363f09f8b27a3e90 100644 (file)
@@ -483,7 +483,10 @@ int disorder_eclient_adduser(disorder_eclient *c,
                              void *v);
 void disorder_eclient_enable_connect(disorder_eclient *c);
 void disorder_eclient_disable_connect(disorder_eclient *c);
-  
+int disorder_eclient_adopt(disorder_eclient *c,
+                           disorder_eclient_no_response *completed,
+                           const char *id,
+                           void *v);  
 #endif
 
 /*
index 17a6d2270c0af3114364977a520e260915bbf9c0..1c70cfde8ffe2a22fcb6c63e02f2aad0ae00e4c2 100644 (file)
@@ -94,8 +94,7 @@ extern const char *const playing_states[];
 enum track_origin {
   /** @brief Track was picked at random and then adopted by a user
    *
-   * @c submitter identifies who adopted it.  This isn't implemented
-   * yet.
+   * @c submitter identifies who adopted it.
    */
   origin_adopted,
 
index e99f18b7d51d478752105e7456cd14e41d60d033..e873e49c76387ba627cd7d5db5bb92748530996c 100644 (file)
@@ -905,6 +905,10 @@ class client:
     """Add a scheduled event"""
     self._simple("schedule-add", str(when), priority, action, *rest)
 
+  def adopt(self, id):
+    """Adopt a randomly picked track"""
+    self._simple("adopt", id)
+
   ########################################################################
   # I/O infrastructure
 
index 0b2458d80e6859f4b0303e1951f2b65a7139a9b5..18f6851ff6f741556b6b257f3dae529113369ab8 100644 (file)
@@ -1573,6 +1573,31 @@ static int c_schedule_add(struct conn *c,
   return 1;
 }
 
+static int c_adopt(struct conn *c,
+                  char **vec,
+                  int attribute((unused)) nvec) {
+  struct queue_entry *q;
+
+  if(!c->who) {
+    sink_writes(ev_writer_sink(c->w), "550 no identity\n");
+    return 1;
+  }
+  if(!(q = queue_find(vec[0]))) {
+    sink_writes(ev_writer_sink(c->w), "550 no such track on the queue\n");
+    return 1;
+  }
+  if(q->origin != origin_random) {
+    sink_writes(ev_writer_sink(c->w), "550 not a random track\n");
+    return 1;
+  }
+  q->origin = origin_adopted;
+  q->submitter = xstrdup(c->who);
+  eventlog("adopted", q->id, q->submitter, (char *)0);
+  queue_write();
+  sink_writes(ev_writer_sink(c->w), "250 OK\n");
+  return 1;
+}
+
 static const struct command {
   /** @brief Command name */
   const char *name;
@@ -1594,6 +1619,7 @@ static const struct command {
   rights_type rights;
 } commands[] = {
   { "adduser",        2, 3,       c_adduser,        RIGHT_ADMIN|RIGHT__LOCAL },
+  { "adopt",          1, 1,       c_adopt,          RIGHT_PLAY },
   { "allfiles",       0, 2,       c_allfiles,       RIGHT_READ },
   { "confirm",        1, 1,       c_confirm,        0 },
   { "cookie",         1, 1,       c_cookie,         0 },