Accept FS#9480 - centralise and organise the events in the apps/ layer.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18819 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2008-10-16 10:38:03 +00:00
parent 9e0ebcc4e6
commit 71898e5c54
11 changed files with 80 additions and 41 deletions

56
apps/appevents.h Normal file
View File

@ -0,0 +1,56 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id: events.h 17847 2008-06-28 18:10:04Z bagder $
*
* Copyright (C) 2008 by Jonathan Gordon
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#ifndef _APPEVENTS_H
#define _APPEVENTS_H
#include <stdbool.h>
#include "events.h"
/** Only app/ level events should be defined here.
* firmware/ level events and CLASS's are defined in firmware/export/events.h
*/
/** Playback events **/
enum {
PLAYBACK_EVENT_TRACK_BUFFER = (EVENT_CLASS_PLAYBACK|1),
PLAYBACK_EVENT_TRACK_FINISH,
PLAYBACK_EVENT_TRACK_CHANGE,
};
/** Buffering events **/
enum {
BUFFER_EVENT_BUFFER_LOW = (EVENT_CLASS_BUFFERING|1),
BUFFER_EVENT_REBUFFER,
BUFFER_EVENT_CLOSED,
BUFFER_EVENT_MOVED,
BUFFER_EVENT_FINISHED,
};
/** Generic GUI class events **/
enum {
GUI_EVENT_THEME_CHANGED = (EVENT_CLASS_GUI|1),
GUI_EVENT_STATUSBAR_TOGGLE,
};
#endif

View File

@ -50,7 +50,7 @@
#include "pcmbuf.h"
#include "buffer.h"
#include "bmp.h"
#include "events.h"
#include "appevents.h"
#include "metadata.h"
#if MEM > 1
@ -600,7 +600,7 @@ static bool buffer_handle(int handle_id)
h->filerem = 0;
h->available = sizeof(struct mp3entry);
h->widx += sizeof(struct mp3entry);
send_event(EVENT_HANDLE_FINISHED, &h->id);
send_event(BUFFER_EVENT_FINISHED, &h->id);
return true;
}
@ -673,7 +673,7 @@ static bool buffer_handle(int handle_id)
/* finished buffering the file */
close(h->fd);
h->fd = -1;
send_event(EVENT_HANDLE_FINISHED, &h->id);
send_event(BUFFER_EVENT_FINISHED, &h->id);
}
return true;
@ -729,7 +729,7 @@ static void rebuffer_handle(int handle_id, size_t newpos)
/* There isn't enough space to rebuffer all of the track from its new
offset, so we ask the user to free some */
DEBUGF("rebuffer_handle: space is needed\n");
send_event(EVENT_HANDLE_REBUFFER, &handle_id);
send_event(BUFFER_EVENT_REBUFFER, &handle_id);
}
/* Now we ask for a rebuffer */
@ -1339,7 +1339,7 @@ void buffering_thread(void)
LOGFQUEUE("buffering < Q_START_FILL %d", (int)ev.data);
/* Call buffer callbacks here because this is one of two ways
* to begin a full buffer fill */
send_event(EVENT_BUFFER_LOW, 0);
send_event(BUFFER_EVENT_BUFFER_LOW, 0);
shrink_buffer();
queue_reply(&buffering_queue, 1);
filling |= buffer_handle((int)ev.data);
@ -1401,7 +1401,7 @@ void buffering_thread(void)
/* If the buffer is low, call the callbacks to get new data */
if (num_handles > 0 && data_counters.useful <= conf_watermark)
send_event(EVENT_BUFFER_LOW, 0);
send_event(BUFFER_EVENT_BUFFER_LOW, 0);
#if 0
/* TODO: This needs to be fixed to use the idle callback, disable it
@ -1411,7 +1411,7 @@ void buffering_thread(void)
else if (ata_disk_is_active() && queue_empty(&buffering_queue))
{
if (num_handles > 0 && data_counters.useful <= high_watermark)
send_event(EVENT_BUFFER_LOW, 0);
send_event(BUFFER_EVENT_BUFFER_LOW, 0);
if (data_counters.remaining > 0 && BUF_USED <= high_watermark)
{

View File

@ -24,7 +24,7 @@
#include <sys/types.h>
#include <stdbool.h>
#include "events.h"
#include "appevents.h"
enum data_type {
@ -38,14 +38,6 @@ enum data_type {
TYPE_UNKNOWN,
};
enum callback_event {
EVENT_BUFFER_LOW = (EVENT_CLASS_BUFFERING|1),
EVENT_HANDLE_REBUFFER,
EVENT_HANDLE_CLOSED,
EVENT_HANDLE_MOVED,
EVENT_HANDLE_FINISHED,
};
/* Error return values */
#define ERR_HANDLE_NOT_FOUND -1
#define ERR_BUFFER_FULL -2

View File

@ -61,6 +61,7 @@
#include "backdrop.h"
#include "quickscreen.h"
#include "pitchscreen.h"
#include "appevents.h"
/* currently only on wps_state is needed */
struct wps_state wps_state;
@ -820,7 +821,7 @@ void gui_sync_wps_init(void)
gui_wps_set_statusbar(&gui_wps[i], &statusbars.statusbars[i]);
}
#ifdef HAVE_LCD_BITMAP
add_event(STATUSBAR_TOGGLE_EVENT, false, statusbar_toggle_handler);
add_event(GUI_EVENT_STATUSBAR_TOGGLE, false, statusbar_toggle_handler);
#endif
#if LCD_DEPTH > 1
unload_wps_backdrop();

View File

@ -30,10 +30,6 @@
#define STATUSBAR_Y_POS 0 /* MUST be a multiple of 8 */
#define STATUSBAR_HEIGHT 8
/* possibly a horrible misuse of the event system.
This is triggered when the statusbar setting changes */
#define STATUSBAR_TOGGLE_EVENT (EVENT_CLASS_GUI|1)
struct status_info {
int battlevel;
int batt_charge_step;

View File

@ -23,7 +23,7 @@
#include <stddef.h>
#include <limits.h>
#include "config.h"
#include "events.h"
#include "appevents.h"
#include "lang.h"
#include "action.h"
#include "settings.h"
@ -304,7 +304,7 @@ static int statusbar_callback(int action,const struct menu_item_ex *this_item)
switch (action)
{
case ACTION_EXIT_MENUITEM:
send_event(STATUSBAR_TOGGLE_EVENT, NULL);
send_event(GUI_EVENT_STATUSBAR_TOGGLE, NULL);
/* this should be changed so only the viewports are reloaded */
settings_apply(false);
break;

View File

@ -39,7 +39,7 @@
#include "mp3_playback.h"
#include "sound.h"
#include "bitswap.h"
#include "events.h"
#include "appevents.h"
#ifndef SIMULATOR
#include "i2c.h"
#include "mas.h"

View File

@ -44,7 +44,7 @@
#include "codecs.h"
#include "audio.h"
#include "buffering.h"
#include "events.h"
#include "appevents.h"
#include "voice_thread.h"
#include "mp3_playback.h"
#include "usb.h"
@ -2134,7 +2134,7 @@ static void audio_stop_playback(void)
prev_track_elapsed = curtrack_id3.elapsed;
remove_event(EVENT_BUFFER_LOW, buffering_low_buffer_callback);
remove_event(BUFFER_EVENT_BUFFER_LOW, buffering_low_buffer_callback);
}
paused = false;
@ -2194,7 +2194,7 @@ static void audio_play_start(size_t offset)
audio_fill_file_buffer(true, offset);
add_event(EVENT_BUFFER_LOW, false, buffering_low_buffer_callback);
add_event(BUFFER_EVENT_BUFFER_LOW, false, buffering_low_buffer_callback);
LOGFQUEUE("audio > audio Q_AUDIO_TRACK_CHANGED");
queue_post(&audio_queue, Q_AUDIO_TRACK_CHANGED, 0);
@ -2578,8 +2578,8 @@ void audio_init(void)
#endif
}
add_event(EVENT_HANDLE_REBUFFER, false, buffering_handle_rebuffer_callback);
add_event(EVENT_HANDLE_FINISHED, false, buffering_handle_finished_callback);
add_event(BUFFER_EVENT_REBUFFER, false, buffering_handle_rebuffer_callback);
add_event(BUFFER_EVENT_FINISHED, false, buffering_handle_finished_callback);
/* Probably safe to say */
audio_is_initialized = true;

View File

@ -34,6 +34,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging
#include "settings.h"
#include "ata_idle_notify.h"
#include "misc.h"
#include "appevents.h"
#if CONFIG_RTC
#include "time.h"

View File

@ -47,7 +47,7 @@
#include "misc.h"
#include "filetypes.h"
#include "audio.h"
#include "events.h"
#include "appevents.h"
#define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config"

View File

@ -24,6 +24,10 @@
#include <stdbool.h>
/** Only CLASS defines and firmware/ level events should be defined here.
* apps/ level events are defined in apps/appevents.h
*/
/**
* High byte = Event class definition
* Low byte = Event ID
@ -34,17 +38,6 @@
#define EVENT_CLASS_BUFFERING 0x0400
#define EVENT_CLASS_GUI 0x0800
/**
* Because same playback events are used in mpeg.c and playback.c, define
* them here to prevent cluttering and ifdefs.
*/
enum {
PLAYBACK_EVENT_TRACK_BUFFER = (EVENT_CLASS_PLAYBACK|1),
PLAYBACK_EVENT_TRACK_FINISH,
PLAYBACK_EVENT_TRACK_CHANGE,
};
bool add_event(unsigned short id, bool oneshot, void (*handler));
void remove_event(unsigned short id, void (*handler));
void send_event(unsigned short id, void *data);