From a67e5d89efe6c3fcf5a2eaf27aac1c14f024ee27 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 17 Mar 2008 05:22:53 +0000 Subject: [PATCH] It makes more sense for the callback registrar to decide if its a "oneshot" then the callback caller. (Doing it this way means playback could(/should?) registar a disk spinup callback at init which is called every spinup without needing to be reregistered) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16685 a1c6a512-1295-4272-9138-f99709370657 --- apps/playback.c | 6 +++--- apps/scrobbler.c | 2 +- apps/tagtree.c | 4 ++-- firmware/ata_idle_notify.c | 4 ++-- firmware/events.c | 8 +++++--- firmware/export/events.h | 4 ++-- firmware/mpeg.c | 8 ++++---- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/apps/playback.c b/apps/playback.c index ee1787e612..7eecd23e35 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -1731,7 +1731,7 @@ static bool audio_load_track(int offset, bool start_play) { if (get_metadata(&id3, fd, trackname)) { - send_event(PLAYBACK_EVENT_TRACK_BUFFER, false, &id3); + send_event(PLAYBACK_EVENT_TRACK_BUFFER, &id3); tracks[track_widx].id3_hid = bufalloc(&id3, sizeof(struct mp3entry), TYPE_ID3); @@ -1968,7 +1968,7 @@ static int audio_check_new_track(void) bool end_of_playlist; /* Temporary flag, not the same as playlist_end */ /* Now it's good time to send track unbuffer events. */ - send_event(PLAYBACK_EVENT_TRACK_FINISH, false, &curtrack_id3); + send_event(PLAYBACK_EVENT_TRACK_FINISH, &curtrack_id3); if (dir_skip) { @@ -2339,7 +2339,7 @@ static void audio_finalise_track_change(void) bufgetid3(prev_ti->id3_hid)->elapsed = 0; } - send_event(PLAYBACK_EVENT_TRACK_CHANGE, false, &curtrack_id3); + send_event(PLAYBACK_EVENT_TRACK_CHANGE, &curtrack_id3); track_changed = true; playlist_update_resume_info(audio_current_track()); diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 2f60e858e1..85285cb911 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c @@ -227,7 +227,7 @@ int scrobbler_init(void) scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); - add_event(PLAYBACK_EVENT_TRACK_CHANGE, scrobbler_change_event); + add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); cache_pos = 0; pending = false; scrobbler_initialised = true; diff --git a/apps/tagtree.c b/apps/tagtree.c index 4572204ae5..faffb0053d 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -925,8 +925,8 @@ void tagtree_init(void) uniqbuf = buffer_alloc(UNIQBUF_SIZE); - add_event(PLAYBACK_EVENT_TRACK_BUFFER, tagtree_buffer_event); - add_event(PLAYBACK_EVENT_TRACK_FINISH, tagtree_track_finish_event); + add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); + add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); } static bool show_search_progress(bool init, int count) diff --git a/firmware/ata_idle_notify.c b/firmware/ata_idle_notify.c index a97c3538da..ab2233da1f 100644 --- a/firmware/ata_idle_notify.c +++ b/firmware/ata_idle_notify.c @@ -26,7 +26,7 @@ void register_ata_idle_func(ata_idle_notify function) { #if USING_ATA_CALLBACK - add_event(DISK_EVENT_SPINUP, function); + add_event(DISK_EVENT_SPINUP, true, function); #else function(); /* just call the function now */ /* this _may_ cause problems later if the calling function @@ -55,7 +55,7 @@ bool call_ata_idle_notifys(bool force) } lock_until = current_tick + 30*HZ; - send_event(DISK_EVENT_SPINUP, true, NULL); + send_event(DISK_EVENT_SPINUP, NULL); return true; } diff --git a/firmware/events.c b/firmware/events.c index eaf2e5c352..00c0099bb9 100644 --- a/firmware/events.c +++ b/firmware/events.c @@ -23,12 +23,13 @@ struct sysevent { unsigned short id; + bool oneshot; void (*callback)(void *data); }; struct sysevent events[MAX_SYS_EVENTS]; -bool add_event(unsigned short id, void (*handler)) +bool add_event(unsigned short id, bool oneshot, void (*handler)) { int i; @@ -45,6 +46,7 @@ bool add_event(unsigned short id, void (*handler)) if (events[i].callback == NULL) { events[i].id = id; + events[i].oneshot = oneshot; events[i].callback = handler; return true; } @@ -70,7 +72,7 @@ void remove_event(unsigned short id, void (*handler)) panicf("event not found"); } -void send_event(unsigned short id, bool oneshot, void *data) +void send_event(unsigned short id, void *data) { int i; @@ -80,7 +82,7 @@ void send_event(unsigned short id, bool oneshot, void *data) { events[i].callback(data); - if (oneshot) + if (events[i].oneshot) events[i].callback = NULL; } } diff --git a/firmware/export/events.h b/firmware/export/events.h index b27b5dee4c..c7935dbc74 100644 --- a/firmware/export/events.h +++ b/firmware/export/events.h @@ -43,9 +43,9 @@ enum { }; -bool add_event(unsigned short id, void (*handler)); +bool add_event(unsigned short id, bool oneshot, void (*handler)); void remove_event(unsigned short id, void (*handler)); -void send_event(unsigned short id, bool oneshot, void *data); +void send_event(unsigned short id, void *data); #endif diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 9023c304d2..f2322e563b 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -485,7 +485,7 @@ static void generate_unbuffer_events(void) for (i = 0; i < numentries; i++) { /* Send an event to notify that track has finished. */ - send_event(PLAYBACK_EVENT_TRACK_FINISH, false, &trackdata[cur_idx].id3); + send_event(PLAYBACK_EVENT_TRACK_FINISH, &trackdata[cur_idx].id3); cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; } } @@ -499,7 +499,7 @@ static void generate_postbuffer_events(void) for (i = 0; i < numentries; i++) { - send_event(PLAYBACK_EVENT_TRACK_BUFFER, false, &trackdata[cur_idx].id3); + send_event(PLAYBACK_EVENT_TRACK_BUFFER, &trackdata[cur_idx].id3); cur_idx = (cur_idx + 1) & MAX_TRACK_ENTRIES_MASK; } } @@ -1049,7 +1049,7 @@ static void track_change(void) if (num_tracks_in_memory() > 0) { remove_current_tag(); - send_event(PLAYBACK_EVENT_TRACK_CHANGE, false, audio_current_track()); + send_event(PLAYBACK_EVENT_TRACK_CHANGE, audio_current_track()); update_playlist(); } @@ -1102,7 +1102,7 @@ static void start_playback_if_ready(void) if (play_pending_track_change) { play_pending_track_change = false; - send_event(PLAYBACK_EVENT_TRACK_CHANGE, false, audio_current_track()); + send_event(PLAYBACK_EVENT_TRACK_CHANGE, audio_current_track()); } play_pending = false; }