summaryrefslogtreecommitdiff
path: root/apps/scrobbler.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2014-03-14 23:15:16 +0100
committerThomas Martitz <kugel@rockbox.org>2014-03-14 23:36:30 +0100
commit470989bd708d9a425dbbf2d83b8fcbd0a8d0f488 (patch)
treef3bef37bc0f8ff7da4beddad9903209ced1bc25a /apps/scrobbler.c
parent50f0dd80d660b332a1739e07a630c2cef1b678c6 (diff)
downloadrockbox-470989bd708d9a425dbbf2d83b8fcbd0a8d0f488.tar.gz
rockbox-470989bd708d9a425dbbf2d83b8fcbd0a8d0f488.zip
events: Rework event subsystem (add_event, send_event) to be more versatile.
add_event_ex is added that takes an extra user_data pointer. This pointer is passed to the callback (add_event and add_event_ex have slightly different callbacks types). All callbacks also get the event id passed. Events added with add_event_ex must be removed with remove_event_ex because the user_data pointer must match in addition to the callback pointer. On the other add_event is simplified to omit the oneshort parameter which was almost always false (still there with add_event_ex). As a side effect the ata_idle_notify callbacks are changed as well, they do not take a data parameter anymore which was always NULL anyway. This commit also adds some documentation to events.h Change-Id: I13e29a0f88ef908f175b376d83550f9e0231f772
Diffstat (limited to 'apps/scrobbler.c')
-rw-r--r--apps/scrobbler.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/apps/scrobbler.c b/apps/scrobbler.c
index efd028327c..b8a95f85cb 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -150,9 +150,8 @@ static void write_cache(void)
150 cache_pos = 0; 150 cache_pos = 0;
151} 151}
152 152
153static void scrobbler_flush_callback(void *data) 153static void scrobbler_flush_callback(void)
154{ 154{
155 (void)data;
156 if (scrobbler_initialised && cache_pos) 155 if (scrobbler_initialised && cache_pos)
157 write_cache(); 156 write_cache();
158} 157}
@@ -200,16 +199,17 @@ static void add_to_cache(const struct mp3entry *id)
200 199
201} 200}
202 201
203static void scrobbler_change_event(void *data) 202static void scrobbler_change_event(unsigned short id, void *ev_data)
204{ 203{
205 struct mp3entry *id = ((struct track_event *)data)->id3; 204 (void)id;
205 struct mp3entry *id3 = ((struct track_event *)ev_data)->id3;
206 206
207 /* check if track was resumed > %50 played 207 /* check if track was resumed > %50 played
208 check for blank artist or track name */ 208 check for blank artist or track name */
209 if (id->elapsed > id->length / 2 || !id->artist || !id->title) 209 if (id3->elapsed > id3->length / 2 || !id3->artist || !id3->title)
210 { 210 {
211 pending = false; 211 pending = false;
212 logf("SCROBBLER: skipping file %s", id->path); 212 logf("SCROBBLER: skipping file %s", id3->path);
213 } 213 }
214 else 214 else
215 { 215 {
@@ -219,8 +219,9 @@ static void scrobbler_change_event(void *data)
219 } 219 }
220} 220}
221 221
222static void scrobbler_finish_event(void *data) 222static void scrobbler_finish_event(unsigned short id, void *data)
223{ 223{
224 (void)id;
224 struct track_event *te = (struct track_event *)data; 225 struct track_event *te = (struct track_event *)data;
225 226
226 /* add entry using the currently ending track */ 227 /* add entry using the currently ending track */
@@ -254,8 +255,8 @@ int scrobbler_init(void)
254 255
255 scrobbler_initialised = true; 256 scrobbler_initialised = true;
256 257
257 add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); 258 add_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event);
258 add_event(PLAYBACK_EVENT_TRACK_FINISH, false, scrobbler_finish_event); 259 add_event(PLAYBACK_EVENT_TRACK_FINISH, scrobbler_finish_event);
259 260
260 return 1; 261 return 1;
261} 262}