summaryrefslogtreecommitdiffstats
path: root/apps/scrobbler.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:33 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:33 +0000
commitd0b72e25903574acb1cf9184a6052cdd646dbc37 (patch)
tree5be8db5ee00b2a727e4821cf51a5f7bcf3991073 /apps/scrobbler.c
parentc940811ade7d99a0e0d414df7c6509672413684a (diff)
downloadrockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.gz
rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.zip
GSoC/Buflib: Add buflib memory alocator to the core.
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/scrobbler.c')
-rw-r--r--apps/scrobbler.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/apps/scrobbler.c b/apps/scrobbler.c
index 6ed9bbb037..a6307d5dd7 100644
--- a/apps/scrobbler.c
+++ b/apps/scrobbler.c
@@ -30,7 +30,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging
#include "metadata.h"
#include "kernel.h"
#include "audio.h"
-#include "buffer.h"
+#include "core_alloc.h"
#include "settings.h"
#include "ata_idle_notify.h"
#include "filefuncs.h"
@@ -52,7 +52,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging
/* longest entry I've had is 323, add a safety margin */
#define SCROBBLER_CACHE_LEN 512
-static char* scrobbler_cache;
+static int scrobbler_cache;
static int cache_pos;
static struct mp3entry scrobbler_entry;
@@ -139,11 +139,16 @@ static void write_cache(void)
if(fd >= 0)
{
logf("SCROBBLER: writing %d entries", cache_pos);
-
+ /* copy data to temporary storage in case data moves during I/O */
+ char temp_buf[SCROBBLER_CACHE_LEN];
for ( i=0; i < cache_pos; i++ )
{
logf("SCROBBLER: write %d", i);
- fdprintf(fd, "%s", scrobbler_cache+(SCROBBLER_CACHE_LEN*i));
+ char* scrobbler_buf = core_get_data(scrobbler_cache);
+ ssize_t len = strlcpy(temp_buf, scrobbler_buf+(SCROBBLER_CACHE_LEN*i),
+ sizeof(temp_buf));
+ if (write(fd, temp_buf, len) != len)
+ break;
}
close(fd);
}
@@ -170,6 +175,7 @@ static void add_to_cache(unsigned long play_length)
int ret;
char rating = 'S'; /* Skipped */
+ char* scrobbler_buf = core_get_data(scrobbler_cache);
logf("SCROBBLER: add_to_cache[%d]", cache_pos);
@@ -178,7 +184,7 @@ static void add_to_cache(unsigned long play_length)
if (scrobbler_entry.tracknum > 0)
{
- ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos),
+ ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos),
SCROBBLER_CACHE_LEN,
"%s\t%s\t%s\t%d\t%d\t%c\t%ld\t%s\n",
scrobbler_entry.artist,
@@ -190,7 +196,7 @@ static void add_to_cache(unsigned long play_length)
(long)timestamp,
scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:"");
} else {
- ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos),
+ ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos),
SCROBBLER_CACHE_LEN,
"%s\t%s\t%s\t\t%d\t%c\t%ld\t%s\n",
scrobbler_entry.artist,
@@ -248,7 +254,7 @@ int scrobbler_init(void)
if(!global_settings.audioscrobbler)
return -1;
- scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN);
+ scrobbler_cache = core_alloc("scrobbler", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN);
add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event);
cache_pos = 0;