aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder_control.h
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-08-08 21:54:54 +0200
committerMax Kellermann <max@duempel.org>2012-08-08 22:38:16 +0200
commit8c425c758c9217b3388ca5bc1ea2883a1c3c2bc6 (patch)
tree9ecf8a7652966be4f0655f8a377d6c2613ec88db /src/decoder_control.h
parent0b9e91229791e143d5da79f14cf7012ead9c3bc7 (diff)
downloadmpd-8c425c758c9217b3388ca5bc1ea2883a1c3c2bc6.tar.gz
mpd-8c425c758c9217b3388ca5bc1ea2883a1c3c2bc6.tar.xz
mpd-8c425c758c9217b3388ca5bc1ea2883a1c3c2bc6.zip
decoder_control: add GError attribute
Diffstat (limited to '')
-rw-r--r--src/decoder_control.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/decoder_control.h b/src/decoder_control.h
index 566b153ee..164875ae0 100644
--- a/src/decoder_control.h
+++ b/src/decoder_control.h
@@ -67,6 +67,14 @@ struct decoder_control {
enum decoder_state state;
enum decoder_command command;
+ /**
+ * The error that occurred in the decoder thread. This
+ * attribute is only valid if #state is #DECODE_STATE_ERROR.
+ * The object must be freed when this object transitions to
+ * any other state (usually #DECODE_STATE_START).
+ */
+ GError *error;
+
bool quit;
bool seek_error;
bool seekable;
@@ -188,6 +196,49 @@ decoder_has_failed(const struct decoder_control *dc)
return dc->state == DECODE_STATE_ERROR;
}
+/**
+ * Checks whether an error has occurred, and if so, returns a newly
+ * allocated copy of the #GError object.
+ *
+ * Caller must lock the object.
+ */
+static inline GError *
+dc_get_error(const struct decoder_control *dc)
+{
+ assert(dc != NULL);
+ assert(dc->command == DECODE_COMMAND_NONE);
+
+ return dc->state == DECODE_STATE_ERROR
+ ? g_error_copy(dc->error)
+ : NULL;
+}
+
+/**
+ * Like dc_get_error(), but locks and unlocks the object.
+ */
+static inline GError *
+dc_lock_get_error(struct decoder_control *dc)
+{
+ decoder_lock(dc);
+ GError *error = dc_get_error(dc);
+ decoder_unlock(dc);
+ return error;
+}
+
+/**
+ * Clear the error condition and free the #GError object (if any).
+ *
+ * Caller must lock the object.
+ */
+static inline void
+dc_clear_error(struct decoder_control *dc)
+{
+ if (dc->state == DECODE_STATE_ERROR) {
+ g_error_free(dc->error);
+ dc->state = DECODE_STATE_STOP;
+ }
+}
+
static inline bool
decoder_lock_is_idle(struct decoder_control *dc)
{