aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /src/input
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to 'src/input')
-rw-r--r--src/input/ArchiveInputPlugin.cxx7
-rw-r--r--src/input/CdioParanoiaInputPlugin.cxx44
-rw-r--r--src/input/CurlInputPlugin.cxx127
-rw-r--r--src/input/DespotifyInputPlugin.cxx4
-rw-r--r--src/input/FfmpegInputPlugin.cxx28
-rw-r--r--src/input/FileInputPlugin.cxx29
-rw-r--r--src/input/MmsInputPlugin.cxx21
-rw-r--r--src/input/RewindInputPlugin.cxx14
8 files changed, 122 insertions, 152 deletions
diff --git a/src/input/ArchiveInputPlugin.cxx b/src/input/ArchiveInputPlugin.cxx
index 0d856527f..025b25fef 100644
--- a/src/input/ArchiveInputPlugin.cxx
+++ b/src/input/ArchiveInputPlugin.cxx
@@ -24,6 +24,7 @@
#include "ArchivePlugin.hxx"
#include "ArchiveFile.hxx"
#include "InputPlugin.hxx"
+#include "util/Error.hxx"
#include <glib.h>
@@ -38,7 +39,7 @@
static struct input_stream *
input_archive_open(const char *pathname,
Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
const struct archive_plugin *arplug;
char *archive, *filename, *suffix, *pname;
@@ -63,14 +64,14 @@ input_archive_open(const char *pathname,
return NULL;
}
- auto file = archive_file_open(arplug, archive, error_r);
+ auto file = archive_file_open(arplug, archive, error);
if (file == NULL) {
g_free(pname);
return NULL;
}
//setup fileops
- is = file->OpenStream(filename, mutex, cond, error_r);
+ is = file->OpenStream(filename, mutex, cond, error);
g_free(pname);
file->Close();
diff --git a/src/input/CdioParanoiaInputPlugin.cxx b/src/input/CdioParanoiaInputPlugin.cxx
index f0fa835b3..660c157e8 100644
--- a/src/input/CdioParanoiaInputPlugin.cxx
+++ b/src/input/CdioParanoiaInputPlugin.cxx
@@ -26,6 +26,8 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <stdio.h>
#include <stdint.h>
@@ -71,11 +73,7 @@ struct CdioParanoiaInputStream {
}
};
-static inline GQuark
-cdio_quark(void)
-{
- return g_quark_from_static_string("cdio");
-}
+static constexpr Domain cdio_domain("cdio");
static void
input_cdio_close(struct input_stream *is)
@@ -91,7 +89,7 @@ struct cdio_uri {
};
static bool
-parse_cdio_uri(struct cdio_uri *dest, const char *src, GError **error_r)
+parse_cdio_uri(struct cdio_uri *dest, const char *src, Error &error)
{
if (!g_str_has_prefix(src, "cdda://"))
return false;
@@ -125,8 +123,7 @@ parse_cdio_uri(struct cdio_uri *dest, const char *src, GError **error_r)
char *endptr;
dest->track = strtoul(track, &endptr, 10);
if (*endptr != 0) {
- g_set_error(error_r, cdio_quark(), 0,
- "Malformed track number");
+ error.Set(cdio_domain, "Malformed track number");
return false;
}
@@ -154,10 +151,10 @@ cdio_detect_device(void)
static struct input_stream *
input_cdio_open(const char *uri,
Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
struct cdio_uri parsed_uri;
- if (!parse_cdio_uri(&parsed_uri, uri, error_r))
+ if (!parse_cdio_uri(&parsed_uri, uri, error))
return nullptr;
CdioParanoiaInputStream *i =
@@ -169,8 +166,8 @@ input_cdio_open(const char *uri,
? g_strdup(parsed_uri.device)
: cdio_detect_device();
if (device == nullptr) {
- g_set_error(error_r, cdio_quark(), 0,
- "Unable find or access a CD-ROM drive with an audio CD in it.");
+ error.Set(cdio_domain,
+ "Unable find or access a CD-ROM drive with an audio CD in it.");
delete i;
return nullptr;
}
@@ -182,8 +179,7 @@ input_cdio_open(const char *uri,
i->drv = cdio_cddap_identify_cdio(i->cdio, 1, nullptr);
if ( !i->drv ) {
- g_set_error(error_r, cdio_quark(), 0,
- "Unable to identify audio CD disc.");
+ error.Set(cdio_domain, "Unable to identify audio CD disc.");
delete i;
return nullptr;
}
@@ -191,7 +187,7 @@ input_cdio_open(const char *uri,
cdda_verbose_set(i->drv, CDDA_MESSAGE_FORGETIT, CDDA_MESSAGE_FORGETIT);
if ( 0 != cdio_cddap_open(i->drv) ) {
- g_set_error(error_r, cdio_quark(), 0, "Unable to open disc.");
+ error.Set(cdio_domain, "Unable to open disc.");
delete i;
return nullptr;
}
@@ -211,9 +207,8 @@ input_cdio_open(const char *uri,
reverse_endian = G_BYTE_ORDER == G_LITTLE_ENDIAN;
break;
default:
- g_set_error(error_r, cdio_quark(), 0,
- "Drive returns unknown data type %d",
- data_bigendianp(i->drv));
+ error.Format(cdio_domain, "Drive returns unknown data type %d",
+ data_bigendianp(i->drv));
delete i;
return nullptr;
}
@@ -250,7 +245,7 @@ input_cdio_open(const char *uri,
static bool
input_cdio_seek(struct input_stream *is,
- goffset offset, int whence, GError **error_r)
+ goffset offset, int whence, Error &error)
{
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
@@ -267,9 +262,8 @@ input_cdio_seek(struct input_stream *is,
}
if (offset < 0 || offset > cis->base.size) {
- g_set_error(error_r, cdio_quark(), 0,
- "Invalid offset to seek %ld (%ld)",
- (long int)offset, (long int)cis->base.size);
+ error.Format(cdio_domain, "Invalid offset to seek %ld (%ld)",
+ (long int)offset, (long int)cis->base.size);
return false;
}
@@ -288,7 +282,7 @@ input_cdio_seek(struct input_stream *is,
static size_t
input_cdio_read(struct input_stream *is, void *ptr, size_t length,
- GError **error_r)
+ Error &error)
{
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
size_t nbytes = 0;
@@ -319,8 +313,8 @@ input_cdio_read(struct input_stream *is, void *ptr, size_t length,
free(s_mess);
}
if (!rbuf) {
- g_set_error(error_r, cdio_quark(), 0,
- "paranoia read error. Stopping.");
+ error.Set(cdio_domain,
+ "paranoia read error. Stopping.");
return 0;
}
//store current buffer
diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx
index c5f524bc0..cbf5c6b83 100644
--- a/src/input/CurlInputPlugin.cxx
+++ b/src/input/CurlInputPlugin.cxx
@@ -28,6 +28,8 @@
#include "event/MultiSocketMonitor.hxx"
#include "event/Call.hxx"
#include "IOThread.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <assert.h>
@@ -162,16 +164,14 @@ struct input_curl {
input_stream_tag() */
Tag *tag;
- GError *postponed_error;
+ Error postponed_error;
input_curl(const char *url, Mutex &mutex, Cond &cond)
:base(input_plugin_curl, url, mutex, cond),
range(nullptr), request_headers(nullptr),
paused(false),
meta_name(nullptr),
- tag(nullptr),
- postponed_error(nullptr) {
- }
+ tag(nullptr) {}
~input_curl();
@@ -215,12 +215,9 @@ static struct {
CurlSockets *sockets;
} curl;
-gcc_const
-static inline GQuark
-curl_quark(void)
-{
- return g_quark_from_static_string("curl");
-}
+static constexpr Domain http_domain("http");
+static constexpr Domain curl_domain("curl");
+static constexpr Domain curlm_domain("curlm");
/**
* Find a request by its CURL "easy" handle.
@@ -319,7 +316,7 @@ CurlSockets::UpdateSockets()
* Runs in the I/O thread. No lock needed.
*/
static bool
-input_curl_easy_add(struct input_curl *c, GError **error_r)
+input_curl_easy_add(struct input_curl *c, Error &error)
{
assert(io_thread_inside());
assert(c != NULL);
@@ -330,9 +327,9 @@ input_curl_easy_add(struct input_curl *c, GError **error_r)
CURLMcode mcode = curl_multi_add_handle(curl.multi, c->easy);
if (mcode != CURLM_OK) {
- g_set_error(error_r, curl_quark(), mcode,
- "curl_multi_add_handle() failed: %s",
- curl_multi_strerror(mcode));
+ error.Format(curlm_domain, mcode,
+ "curl_multi_add_handle() failed: %s",
+ curl_multi_strerror(mcode));
return false;
}
@@ -346,14 +343,14 @@ input_curl_easy_add(struct input_curl *c, GError **error_r)
* any thread. Caller must not hold a mutex.
*/
static bool
-input_curl_easy_add_indirect(struct input_curl *c, GError **error_r)
+input_curl_easy_add_indirect(struct input_curl *c, Error &error)
{
assert(c != NULL);
assert(c->easy != NULL);
bool result;
- BlockingCall(io_thread_get(), [c, error_r, &result](){
- result = input_curl_easy_add(c, error_r);
+ BlockingCall(io_thread_get(), [c, &error, &result](){
+ result = input_curl_easy_add(c, error);
});
return result;
}
@@ -409,27 +406,25 @@ input_curl_easy_free_indirect(struct input_curl *c)
* Runs in the I/O thread. The caller must not hold locks.
*/
static void
-input_curl_abort_all_requests(GError *error)
+input_curl_abort_all_requests(const Error &error)
{
assert(io_thread_inside());
- assert(error != NULL);
+ assert(error.IsDefined());
while (!curl.requests.empty()) {
struct input_curl *c = curl.requests.front();
- assert(c->postponed_error == NULL);
+ assert(!c->postponed_error.IsDefined());
input_curl_easy_free(c);
const ScopeLock protect(c->base.mutex);
- c->postponed_error = g_error_copy(error);
+ c->postponed_error.Set(error);
c->base.ready = true;
c->base.cond.broadcast();
}
- g_error_free(error);
-
}
/**
@@ -443,18 +438,17 @@ input_curl_request_done(struct input_curl *c, CURLcode result, long status)
assert(io_thread_inside());
assert(c != NULL);
assert(c->easy == NULL);
- assert(c->postponed_error == NULL);
+ assert(!c->postponed_error.IsDefined());
const ScopeLock protect(c->base.mutex);
if (result != CURLE_OK) {
- c->postponed_error = g_error_new(curl_quark(), result,
- "curl failed: %s",
- c->error);
+ c->postponed_error.Format(curl_domain, result,
+ "curl failed: %s", c->error);
} else if (status < 200 || status >= 300) {
- c->postponed_error = g_error_new(curl_quark(), 0,
- "got HTTP status %ld",
- status);
+ c->postponed_error.Format(http_domain, status,
+ "got HTTP status %ld",
+ status);
}
c->base.ready = true;
@@ -513,9 +507,10 @@ input_curl_perform(void)
} while (mcode == CURLM_CALL_MULTI_PERFORM);
if (mcode != CURLM_OK && mcode != CURLM_CALL_MULTI_PERFORM) {
- GError *error = g_error_new(curl_quark(), mcode,
- "curl_multi_perform() failed: %s",
- curl_multi_strerror(mcode));
+ Error error;
+ error.Format(curlm_domain, mcode,
+ "curl_multi_perform() failed: %s",
+ curl_multi_strerror(mcode));
input_curl_abort_all_requests(error);
return false;
}
@@ -559,14 +554,13 @@ CurlSockets::DispatchSockets()
*/
static bool
-input_curl_init(const config_param &param,
- gcc_unused GError **error_r)
+input_curl_init(const config_param &param, Error &error)
{
CURLcode code = curl_global_init(CURL_GLOBAL_ALL);
if (code != CURLE_OK) {
- g_set_error(error_r, curl_quark(), code,
- "curl_global_init() failed: %s\n",
- curl_easy_strerror(code));
+ error.Format(curl_domain, code,
+ "curl_global_init() failed: %s",
+ curl_easy_strerror(code));
return false;
}
@@ -588,8 +582,7 @@ input_curl_init(const config_param &param,
curl.multi = curl_multi_init();
if (curl.multi == NULL) {
- g_set_error(error_r, curl_quark(), 0,
- "curl_multi_init() failed");
+ error.Set(curl_domain, 0, "curl_multi_init() failed");
return false;
}
@@ -639,20 +632,17 @@ input_curl::~input_curl()
g_free(meta_name);
input_curl_easy_free_indirect(this);
-
- if (postponed_error != NULL)
- g_error_free(postponed_error);
}
static bool
-input_curl_check(struct input_stream *is, GError **error_r)
+input_curl_check(struct input_stream *is, Error &error)
{
struct input_curl *c = (struct input_curl *)is;
- bool success = c->postponed_error == NULL;
+ bool success = !c->postponed_error.IsDefined();
if (!success) {
- g_propagate_error(error_r, c->postponed_error);
- c->postponed_error = NULL;
+ error = std::move(c->postponed_error);
+ c->postponed_error.Clear();
}
return success;
@@ -669,14 +659,14 @@ input_curl_tag(struct input_stream *is)
}
static bool
-fill_buffer(struct input_curl *c, GError **error_r)
+fill_buffer(struct input_curl *c, Error &error)
{
while (c->easy != NULL && c->buffers.empty())
c->base.cond.wait(c->base.mutex);
- if (c->postponed_error != NULL) {
- g_propagate_error(error_r, c->postponed_error);
- c->postponed_error = NULL;
+ if (c->postponed_error.IsDefined()) {
+ error = std::move(c->postponed_error);
+ c->postponed_error.Clear();
return false;
}
@@ -754,13 +744,13 @@ input_curl_available(struct input_stream *is)
{
struct input_curl *c = (struct input_curl *)is;
- return c->postponed_error != NULL || c->easy == NULL ||
+ return c->postponed_error.IsDefined() || c->easy == NULL ||
!c->buffers.empty();
}
static size_t
input_curl_read(struct input_stream *is, void *ptr, size_t size,
- GError **error_r)
+ Error &error)
{
struct input_curl *c = (struct input_curl *)is;
bool success;
@@ -770,7 +760,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size,
do {
/* fill the buffer */
- success = fill_buffer(c, error_r);
+ success = fill_buffer(c, error);
if (!success)
return 0;
@@ -927,14 +917,13 @@ input_curl_writefunction(void *ptr, size_t size, size_t nmemb, void *stream)
}
static bool
-input_curl_easy_init(struct input_curl *c, GError **error_r)
+input_curl_easy_init(struct input_curl *c, Error &error)
{
CURLcode code;
c->easy = curl_easy_init();
if (c->easy == NULL) {
- g_set_error(error_r, curl_quark(), 0,
- "curl_easy_init() failed");
+ error.Set(curl_domain, "curl_easy_init() failed");
return false;
}
@@ -971,9 +960,9 @@ input_curl_easy_init(struct input_curl *c, GError **error_r)
code = curl_easy_setopt(c->easy, CURLOPT_URL, c->base.uri.c_str());
if (code != CURLE_OK) {
- g_set_error(error_r, curl_quark(), code,
- "curl_easy_setopt() failed: %s",
- curl_easy_strerror(code));
+ error.Format(curl_domain, code,
+ "curl_easy_setopt() failed: %s",
+ curl_easy_strerror(code));
return false;
}
@@ -987,7 +976,7 @@ input_curl_easy_init(struct input_curl *c, GError **error_r)
static bool
input_curl_seek(struct input_stream *is, goffset offset, int whence,
- GError **error_r)
+ Error &error)
{
struct input_curl *c = (struct input_curl *)is;
bool ret;
@@ -1059,7 +1048,7 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
return true;
}
- ret = input_curl_easy_init(c, error_r);
+ ret = input_curl_easy_init(c, error);
if (!ret)
return false;
@@ -1072,7 +1061,7 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
c->base.ready = false;
- if (!input_curl_easy_add_indirect(c, error_r))
+ if (!input_curl_easy_add_indirect(c, error))
return false;
c->base.mutex.lock();
@@ -1080,9 +1069,9 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
while (!c->base.ready)
c->base.cond.wait(c->base.mutex);
- if (c->postponed_error != NULL) {
- g_propagate_error(error_r, c->postponed_error);
- c->postponed_error = NULL;
+ if (c->postponed_error.IsDefined()) {
+ error = std::move(c->postponed_error);
+ c->postponed_error.Clear();
return false;
}
@@ -1091,19 +1080,19 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
static struct input_stream *
input_curl_open(const char *url, Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
if (strncmp(url, "http://", 7) != 0)
return NULL;
struct input_curl *c = new input_curl(url, mutex, cond);
- if (!input_curl_easy_init(c, error_r)) {
+ if (!input_curl_easy_init(c, error)) {
delete c;
return NULL;
}
- if (!input_curl_easy_add_indirect(c, error_r)) {
+ if (!input_curl_easy_add_indirect(c, error)) {
delete c;
return NULL;
}
diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx
index 30ecceed7..f2b87dbcc 100644
--- a/src/input/DespotifyInputPlugin.cxx
+++ b/src/input/DespotifyInputPlugin.cxx
@@ -124,7 +124,7 @@ static void callback(gcc_unused struct despotify_session* ds,
static struct input_stream *
input_despotify_open(const char *url,
Mutex &mutex, Cond &cond,
- gcc_unused GError **error_r)
+ gcc_unused Error &error)
{
struct despotify_session *session;
struct ds_link *ds_link;
@@ -172,7 +172,7 @@ input_despotify_open(const char *url,
static size_t
input_despotify_read(struct input_stream *is, void *ptr, size_t size,
- gcc_unused GError **error_r)
+ gcc_unused Error &error)
{
DespotifyInputStream *ctx = (DespotifyInputStream *)is;
size_t to_cpy = size;
diff --git a/src/input/FfmpegInputPlugin.cxx b/src/input/FfmpegInputPlugin.cxx
index f27348b27..1837303bb 100644
--- a/src/input/FfmpegInputPlugin.cxx
+++ b/src/input/FfmpegInputPlugin.cxx
@@ -25,6 +25,8 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
extern "C" {
#include <libavutil/avutil.h>
@@ -62,11 +64,7 @@ struct FfmpegInputStream {
}
};
-static inline GQuark
-ffmpeg_quark(void)
-{
- return g_quark_from_static_string("ffmpeg");
-}
+static constexpr Domain ffmpeg_domain("ffmpeg");
static inline bool
input_ffmpeg_supported(void)
@@ -77,14 +75,13 @@ input_ffmpeg_supported(void)
static bool
input_ffmpeg_init(gcc_unused const config_param &param,
- gcc_unused GError **error_r)
+ Error &error)
{
av_register_all();
/* disable this plugin if there's no registered protocol */
if (!input_ffmpeg_supported()) {
- g_set_error(error_r, ffmpeg_quark(), 0,
- "No protocol");
+ error.Set(ffmpeg_domain, "No protocol");
return false;
}
@@ -94,7 +91,7 @@ input_ffmpeg_init(gcc_unused const config_param &param,
static struct input_stream *
input_ffmpeg_open(const char *uri,
Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
if (!g_str_has_prefix(uri, "gopher://") &&
!g_str_has_prefix(uri, "rtp://") &&
@@ -107,8 +104,8 @@ input_ffmpeg_open(const char *uri,
AVIOContext *h;
int ret = avio_open(&h, uri, AVIO_FLAG_READ);
if (ret != 0) {
- g_set_error(error_r, ffmpeg_quark(), ret,
- "libavformat failed to open the URI");
+ error.Set(ffmpeg_domain, ret,
+ "libavformat failed to open the URI");
return nullptr;
}
@@ -118,15 +115,14 @@ input_ffmpeg_open(const char *uri,
static size_t
input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size,
- GError **error_r)
+ Error &error)
{
FfmpegInputStream *i = (FfmpegInputStream *)is;
int ret = avio_read(i->h, (unsigned char *)ptr, size);
if (ret <= 0) {
if (ret < 0)
- g_set_error(error_r, ffmpeg_quark(), 0,
- "url_read() failed");
+ error.Set(ffmpeg_domain, "avio_read() failed");
i->eof = true;
return false;
@@ -154,7 +150,7 @@ input_ffmpeg_eof(struct input_stream *is)
static bool
input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence,
- gcc_unused GError **error_r)
+ Error &error)
{
FfmpegInputStream *i = (FfmpegInputStream *)is;
int64_t ret = avio_seek(i->h, offset, whence);
@@ -163,7 +159,7 @@ input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence,
i->eof = false;
return true;
} else {
- g_set_error(error_r, ffmpeg_quark(), 0, "url_seek() failed");
+ error.Set(ffmpeg_domain, "avio_seek() failed");
return false;
}
}
diff --git a/src/input/FileInputPlugin.cxx b/src/input/FileInputPlugin.cxx
index 6fd743179..7d1fc0a7f 100644
--- a/src/input/FileInputPlugin.cxx
+++ b/src/input/FileInputPlugin.cxx
@@ -22,9 +22,10 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include "system/fd_util.h"
#include "open.h"
-#include "io_error.h"
#include <sys/stat.h>
#include <unistd.h>
@@ -35,6 +36,8 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "input_file"
+static constexpr Domain file_domain("file");
+
struct FileInputStream {
struct input_stream base;
@@ -57,7 +60,7 @@ struct FileInputStream {
static struct input_stream *
input_file_open(const char *filename,
Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
int fd, ret;
struct stat st;
@@ -68,24 +71,20 @@ input_file_open(const char *filename,
fd = open_cloexec(filename, O_RDONLY|O_BINARY, 0);
if (fd < 0) {
if (errno != ENOENT && errno != ENOTDIR)
- g_set_error(error_r, errno_quark(), errno,
- "Failed to open \"%s\": %s",
- filename, g_strerror(errno));
+ error.FormatErrno("Failed to open \"%s\"",
+ filename);
return nullptr;
}
ret = fstat(fd, &st);
if (ret < 0) {
- g_set_error(error_r, errno_quark(), errno,
- "Failed to stat \"%s\": %s",
- filename, g_strerror(errno));
+ error.FormatErrno("Failed to stat \"%s\"", filename);
close(fd);
return nullptr;
}
if (!S_ISREG(st.st_mode)) {
- g_set_error(error_r, errno_quark(), 0,
- "Not a regular file: %s", filename);
+ error.Format(file_domain, "Not a regular file: %s", filename);
close(fd);
return nullptr;
}
@@ -101,14 +100,13 @@ input_file_open(const char *filename,
static bool
input_file_seek(struct input_stream *is, goffset offset, int whence,
- GError **error_r)
+ Error &error)
{
FileInputStream *fis = (FileInputStream *)is;
offset = (goffset)lseek(fis->fd, (off_t)offset, whence);
if (offset < 0) {
- g_set_error(error_r, errno_quark(), errno,
- "Failed to seek: %s", g_strerror(errno));
+ error.SetErrno("Failed to seek");
return false;
}
@@ -118,15 +116,14 @@ input_file_seek(struct input_stream *is, goffset offset, int whence,
static size_t
input_file_read(struct input_stream *is, void *ptr, size_t size,
- GError **error_r)
+ Error &error)
{
FileInputStream *fis = (FileInputStream *)is;
ssize_t nbytes;
nbytes = read(fis->fd, ptr, size);
if (nbytes < 0) {
- g_set_error(error_r, errno_quark(), errno,
- "Failed to read: %s", g_strerror(errno));
+ error.SetErrno("Failed to read");
return 0;
}
diff --git a/src/input/MmsInputPlugin.cxx b/src/input/MmsInputPlugin.cxx
index 80d479613..02810bb22 100644
--- a/src/input/MmsInputPlugin.cxx
+++ b/src/input/MmsInputPlugin.cxx
@@ -22,6 +22,8 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#include <glib.h>
#include <libmms/mmsx.h>
@@ -56,16 +58,12 @@ struct MmsInputStream {
}
};
-static inline GQuark
-mms_quark(void)
-{
- return g_quark_from_static_string("mms");
-}
+static constexpr Domain mms_domain("mms");
static struct input_stream *
input_mms_open(const char *url,
Mutex &mutex, Cond &cond,
- GError **error_r)
+ Error &error)
{
if (!g_str_has_prefix(url, "mms://") &&
!g_str_has_prefix(url, "mmsh://") &&
@@ -75,7 +73,7 @@ input_mms_open(const char *url,
const auto mms = mmsx_connect(nullptr, nullptr, url, 128 * 1024);
if (mms == nullptr) {
- g_set_error(error_r, mms_quark(), 0, "mmsx_connect() failed");
+ error.Set(mms_domain, "mmsx_connect() failed");
return nullptr;
}
@@ -85,18 +83,15 @@ input_mms_open(const char *url,
static size_t
input_mms_read(struct input_stream *is, void *ptr, size_t size,
- GError **error_r)
+ Error &error)
{
MmsInputStream *m = (MmsInputStream *)is;
int ret;
ret = mmsx_read(nullptr, m->mms, (char *)ptr, size);
if (ret <= 0) {
- if (ret < 0) {
- g_set_error(error_r, mms_quark(), errno,
- "mmsx_read() failed: %s",
- g_strerror(errno));
- }
+ if (ret < 0)
+ error.SetErrno("mmsx_read() failed");
m->eof = true;
return false;
diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx
index d68fd3d73..7a88d4f52 100644
--- a/src/input/RewindInputPlugin.cxx
+++ b/src/input/RewindInputPlugin.cxx
@@ -24,8 +24,6 @@
#include "InputPlugin.hxx"
#include "Tag.hxx"
-#include <glib.h>
-
#include <assert.h>
#include <string.h>
#include <stdio.h>
@@ -112,11 +110,11 @@ input_rewind_close(struct input_stream *is)
}
static bool
-input_rewind_check(struct input_stream *is, GError **error_r)
+input_rewind_check(struct input_stream *is, Error &error)
{
RewindInputStream *r = (RewindInputStream *)is;
- return input_stream_check(r->input, error_r);
+ return input_stream_check(r->input, error);
}
static void
@@ -146,7 +144,7 @@ input_rewind_available(struct input_stream *is)
static size_t
input_rewind_read(struct input_stream *is, void *ptr, size_t size,
- GError **error_r)
+ Error &error)
{
RewindInputStream *r = (RewindInputStream *)is;
@@ -167,7 +165,7 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size,
} else {
/* pass method call to underlying stream */
- size_t nbytes = input_stream_read(r->input, ptr, size, error_r);
+ size_t nbytes = input_stream_read(r->input, ptr, size, error);
if (r->input->offset > (goffset)sizeof(r->buffer))
/* disable buffering */
@@ -197,7 +195,7 @@ input_rewind_eof(struct input_stream *is)
static bool
input_rewind_seek(struct input_stream *is, goffset offset, int whence,
- GError **error_r)
+ Error &error)
{
RewindInputStream *r = (RewindInputStream *)is;
@@ -216,7 +214,7 @@ input_rewind_seek(struct input_stream *is, goffset offset, int whence,
return true;
} else {
bool success = input_stream_seek(r->input, offset, whence,
- error_r);
+ error);
r->CopyAttributes();
/* disable the buffer, because r->input has left the