summaryrefslogtreecommitdiff
path: root/src/cache
diff options
context:
space:
mode:
Diffstat (limited to 'src/cache')
-rw-r--r--src/cache/backings/file.c4
-rw-r--r--src/cache/backings/file.h2
-rw-r--r--src/cache/backings/file_common.h (renamed from src/cache/backings/file_common.c)15
-rw-r--r--src/cache/backings/file_mapped.c4
-rw-r--r--src/cache/handle.c2
-rw-r--r--src/cache/handlers/cdio.c23
-rw-r--r--src/cache/handlers/http.c11
-rw-r--r--src/cache/range.h2
8 files changed, 38 insertions, 25 deletions
diff --git a/src/cache/backings/file.c b/src/cache/backings/file.c
index f421623..9b905ac 100644
--- a/src/cache/backings/file.c
+++ b/src/cache/backings/file.c
@@ -1,7 +1,5 @@
-#include "../range.h"
-
#include "file.h"
-#include "file_common.c"
+#include "file_common.h"
static void file_backing_lock(struct cch_backing *backing)
{
diff --git a/src/cache/backings/file.h b/src/cache/backings/file.h
index 9ffd650..06daac9 100644
--- a/src/cache/backings/file.h
+++ b/src/cache/backings/file.h
@@ -12,8 +12,8 @@ struct cch_backing_file {
struct nn_file file;
off_t size;
union {
- void *map; // CACHE_BACKING_MAPPED
off_t pointer; // CACHE_BACKING_READ
+ void *map; // CACHE_BACKING_MAPPED
} u;
struct nn_mutex mutex;
};
diff --git a/src/cache/backings/file_common.c b/src/cache/backings/file_common.h
index e8bd2ca..98bd420 100644
--- a/src/cache/backings/file_common.c
+++ b/src/cache/backings/file_common.h
@@ -1,3 +1,12 @@
+#pragma once
+
+#include "../backing.h"
+#include "../range.h"
+
+#include "file.h"
+
+AL_UNUSED_FUNCTION_PUSH
+
static off_t file_backing_get_size_estimate(struct cch_backing *backing)
{
struct cch_backing_file *file = (struct cch_backing_file *)backing;
@@ -10,7 +19,9 @@ static off_t file_backing_get_size_estimate(struct cch_backing *backing)
static bool file_open_internal(struct cch_backing_file *file, str *path, size_t size)
{
s32 flags = size != 0 ? NNWT_FILE_CREATE : NNWT_FILE_READONLY;
- if (!nn_file_open(&file->file, path, flags)) return false;
+ if (!nn_file_open(&file->file, path, flags)) {
+ return false;
+ }
if (!size) {
file->size = file->file.size;
cch_backing_fill_range(&file->backing, 0, file->size);
@@ -22,3 +33,5 @@ static bool file_open_internal(struct cch_backing_file *file, str *path, size_t
}
return true;
}
+
+AL_UNUSED_FUNCTION_POP
diff --git a/src/cache/backings/file_mapped.c b/src/cache/backings/file_mapped.c
index e13d602..17620d0 100644
--- a/src/cache/backings/file_mapped.c
+++ b/src/cache/backings/file_mapped.c
@@ -1,7 +1,5 @@
-#include "../range.h"
-
#include "file.h"
-#include "file_common.c"
+#include "file_common.h"
static void file_backing_lock(struct cch_backing *backing)
{
diff --git a/src/cache/handle.c b/src/cache/handle.c
index 1b351a2..b6bbea0 100644
--- a/src/cache/handle.c
+++ b/src/cache/handle.c
@@ -53,7 +53,7 @@ s32 cch_handle_read(struct cch_handle *handle, u8 *buf, s32 size)
}
handle->pointer += available;
trace("read(%u), pointer: %zd.", size, handle->pointer);
- return available > 0 ? (s32)available : CAMU_ERR_EOF;
+ return (available > 0) ? (s32)available : CAMU_ERR_EOF;
}
off_t cch_handle_seek(struct cch_handle *handle, off_t offset, s32 whence)
diff --git a/src/cache/handlers/cdio.c b/src/cache/handlers/cdio.c
index 1b4c44b..3eae813 100644
--- a/src/cache/handlers/cdio.c
+++ b/src/cache/handlers/cdio.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "cache_cdio"
#include <al/log.h>
#include "../backings/file.h"
@@ -15,13 +16,13 @@ static void cdio_log_messages(struct cch_handler_cdio *cdio)
{
char *error_messages = cdio_cddap_errors(cdio->drive);
if (error_messages) {
- al_log_error("cdio", "\n%s", error_messages);
+ error("\n%s", error_messages);
cdio_cddap_free_messages(error_messages);
}
char *messages = cdio_cddap_messages(cdio->drive);
if (messages) {
- al_log_info("cdio", "\n%s", messages);
+ info("\n%s", messages);
cdio_cddap_free_messages(messages);
}
}
@@ -50,18 +51,18 @@ static nn_thread_result NNWT_THREADCALL cd_read_thread(void *userdata)
size_t size;
u8 *ptr = cdio->backing->get_ptr(cdio->backing, pointer, &size);
if (size < BYTES_PER_STEP) {
- al_log_error("cdio", "Tried to write over expected size during normal operation.");
+ error("Tried to write over expected size during normal operation.");
cdio->backing->unlock(cdio->backing);
break;
}
if (ret == SECTORS_PER_STEP) {
al_memcpy(ptr, nn_buffer_get_ptr(&cdio->buffer, 0), BYTES_PER_STEP);
} else if (ret == -10) {
- al_log_error("cdio", "I/O error, skipping sector.");
+ error("I/O error, skipping sector.");
al_memset(ptr, 0, BYTES_PER_STEP);
ret = SECTORS_PER_STEP;
} else if (ret < 0) {
- al_log_error("cdio", "Fatal error (%d).", ret);
+ error("Fatal error (%d).", ret);
cdio->backing->unlock(cdio->backing);
break;
}
@@ -70,13 +71,13 @@ static nn_thread_result NNWT_THREADCALL cd_read_thread(void *userdata)
cdio->backing->unlock(cdio->backing);
cch_threaded_waits_evaluate(&cdio->waits, cdio->backing);
if (ret < SECTORS_PER_STEP || cdio->sector > cdio->end) {
- al_log_debug("cdio", "Normal CD EOF.");
+ debug("Normal CD EOF.");
break;
}
}
if (cdio->sector <= cdio->end) {
- al_log_warn("cdio", "Disc read cut short (sectors: %zd, end: %zd).", cdio->sector, cdio->end);
+ warn("Disc read cut short (sectors: %zd, end: %zd).", cdio->sector, cdio->end);
// We didn't read the full disc, disable waiters.
cch_threaded_waits_disable_all(&cdio->waits);
}
@@ -134,7 +135,7 @@ static bool open_cd_drive(struct cch_handler_cdio *cdio)
cdio_handle = cdio_open(*cd_drives, DRIVER_UNKNOWN);
drive = cdio_cddap_identify_cdio(cdio_handle, CDDA_MESSAGE_LOGIT, NULL);
} else {
- al_log_error("cdio", "No compatible disc found.");
+ error("No compatible disc found.");
return false;
}
cdio_free_device_list(cd_drives);
@@ -143,19 +144,19 @@ static bool open_cd_drive(struct cch_handler_cdio *cdio)
s32 ret = cdio_cddap_open(drive);
if (ret != 0) {
- al_log_error("cdio", "Unable to open disc (%d).", ret);
+ error("Unable to open disc (%d).", ret);
return false;
}
ret = cdio_cddap_speed_set(drive, 4);
if (ret != 0) {
- al_log_warn("cdio", "Failed to set drive speed (%d).", ret);
+ warn("Failed to set drive speed (%d).", ret);
}
track_t tracks = cdio_cddap_tracks(drive);
track_t first_track = cdio_get_first_track_num(drive->p_cdio);
track_t last_track = cdio_get_last_track_num(drive->p_cdio);
- al_log_info("cdio", "CD with %d tracks loaded (%d-%d).", tracks, first_track, last_track);
+ info("CD with %d tracks loaded (%d-%d).", tracks, first_track, last_track);
al_array_reserve(cdio->handler.entry->chapters, tracks);
lsn_t start = cdio_cddap_disc_firstsector(drive);
diff --git a/src/cache/handlers/http.c b/src/cache/handlers/http.c
index 1856014..d5c06dc 100644
--- a/src/cache/handlers/http.c
+++ b/src/cache/handlers/http.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "cache_http"
#include <al/log.h>
#include "../backings/memory.h"
@@ -35,23 +36,23 @@ static void http_callback(void *userdata, u8 op, u8 *buf, void *opaque)
}
case NNWT_HTTP_RESPONSE_CODE: {
long response_code = *(long *)opaque;
- al_log_debug("cache_handler_http", "HTTP %ld.", response_code);
+ debug("HTTP %ld.", response_code);
break;
}
case NNWT_HTTP_CONTENT_LENGTH: {
curl_off_t length = *(curl_off_t *)opaque;
- al_log_debug("cache_handler_http", "Content-Length: %"CURL_FORMAT_CURL_OFF_T".", length);
+ debug("Content-Length: %"CURL_FORMAT_CURL_OFF_T".", length);
cch_entry_set_size(http->handler.entry, length);
cch_threaded_waits_signal_any(&http->waits);
break;
}
case NNWT_HTTP_REDIRECT: {
long response_code = *(long *)opaque;
- al_log_debug("cache_handler_http", "Redirect %ld.", response_code);
+ debug("Redirect %ld.", response_code);
break;
}
case NNWT_HTTP_FINISHED:
- al_log_debug("cache_handler_http", "Transfer finished.");
+ debug("Transfer finished.");
break;
case NNWT_HTTP_ERROR:
cch_threaded_waits_disable_all(&http->waits);
@@ -71,7 +72,7 @@ static void handler_http_maybe_spawn_worker(struct cch_handler *handler, size_t
nn_http_set_url(request, &http->url);
nn_http_set_user_agent(request, &USER_AGENT);
nn_http_request_stream(request, NNWT_HTTP_GET, http->loop, http_callback, http);
- al_log_debug("cache_handler_http", "Spawning worker for %.*s.", al_str_fmt(&http->url));
+ debug("Spawning worker for %.*s.", al_str_fmt(&http->url));
}
static bool handler_http_wait_for_range(struct cch_handler *handler, struct cch_handler_wait *wait)
diff --git a/src/cache/range.h b/src/cache/range.h
index d6c7539..2a95953 100644
--- a/src/cache/range.h
+++ b/src/cache/range.h
@@ -1,3 +1,5 @@
+#pragma once
+
#include <al/types.h>
#include "backing.h"