2 * This file is part of DisOrder.
3 * Copyright (C) 2006, 2007 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 #include "disobedience.h"
23 /* State monitoring -------------------------------------------------------- */
25 static void log_connected(void *v
);
26 static void log_completed(void *v
, const char *track
);
27 static void log_failed(void *v
, const char *track
, const char *status
);
28 static void log_moved(void *v
, const char *user
);
29 static void log_playing(void *v
, const char *track
, const char *user
);
30 static void log_queue(void *v
, struct queue_entry
*q
);
31 static void log_recent_added(void *v
, struct queue_entry
*q
);
32 static void log_recent_removed(void *v
, const char *id
);
33 static void log_removed(void *v
, const char *id
, const char *user
);
34 static void log_scratched(void *v
, const char *track
, const char *user
);
35 static void log_state(void *v
, unsigned long state
);
36 static void log_volume(void *v
, int l
, int r
);
38 /** @brief Callbacks for server state monitoring */
39 const disorder_eclient_log_callbacks log_callbacks
= {
57 monitor_callback
*callback
;
61 static struct monitor
*monitors
;
63 void all_update(void) {
70 static void log_connected(void attribute((unused
)) *v
) {
71 struct callbackdata
*cbd
;
73 /* Don't know what we might have missed while disconnected so update
74 * everything. We get this at startup too and this is how we do the initial
77 /* Re-get the volume */
78 cbd
= xmalloc(sizeof *cbd
);
80 disorder_eclient_volume(client
, log_volume
, -1, -1, cbd
);
83 static void log_completed(void attribute((unused
)) *v
,
84 const char attribute((unused
)) *track
) {
90 static void log_failed(void attribute((unused
)) *v
,
91 const char attribute((unused
)) *track
,
92 const char attribute((unused
)) *status
) {
98 static void log_moved(void attribute((unused
)) *v
,
99 const char attribute((unused
)) *user
) {
103 static void log_playing(void attribute((unused
)) *v
,
104 const char attribute((unused
)) *track
,
105 const char attribute((unused
)) *user
) {
109 /* we get a log_removed() anyway so we don't need to update_queue() from
113 static void log_queue(void attribute((unused
)) *v
,
114 struct queue_entry
attribute((unused
)) *q
) {
118 static void log_recent_added(void attribute((unused
)) *v
,
119 struct queue_entry
attribute((unused
)) *q
) {
123 static void log_recent_removed(void attribute((unused
)) *v
,
124 const char attribute((unused
)) *id
) {
125 /* nothing - log_recent_added() will trigger the relevant update */
128 static void log_removed(void attribute((unused
)) *v
,
129 const char attribute((unused
)) *id
,
130 const char attribute((unused
)) *user
) {
134 static void log_scratched(void attribute((unused
)) *v
,
135 const char attribute((unused
)) *track
,
136 const char attribute((unused
)) *user
) {
142 static void log_state(void attribute((unused
)) *v
,
143 unsigned long state
) {
144 const struct monitor
*m
;
145 const unsigned long changes
= state
^ last_state
;
147 info("log_state %s", disorder_eclient_interpret_state(state
));
149 /* Tell anything that cares about the state change */
150 for(m
= monitors
; m
; m
= m
->next
) {
151 if(changes
& m
->mask
)
154 /* If the track is paused or resume then the currently playing track is
155 * refetched so that we can continue to correctly calculate the played so-far
160 static void log_volume(void attribute((unused
)) *v
,
162 if(volume_l
!= l
|| volume_r
!= r
) {
169 void register_monitor(monitor_callback
*callback
,
171 unsigned long mask
) {
172 struct monitor
*m
= xmalloc(sizeof *m
);
176 m
->callback
= callback
;