summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/player.c23
-rw-r--r--src/util.c9
-rw-r--r--src/util.h3
3 files changed, 33 insertions, 2 deletions
diff --git a/src/player.c b/src/player.c
index 612172c..1a281a5 100644
--- a/src/player.c
+++ b/src/player.c
@@ -22,6 +22,25 @@
static struct player player_static;
struct player *player;
+static void
+handle_mpd_status(struct mpd_connection *conn, int status)
+{
+ switch (status) {
+ case MPD_ERROR_SYSTEM:
+ PLAYER_STATUS(PLAYER_MSG_ERR, "%s",
+ mpd_connection_get_error_message(conn));
+ break;
+ case MPD_ERROR_SERVER:
+ case MPD_ERROR_ARGUMENT:
+ if (!mpd_connection_clear_error(conn))
+ PANIC("Player failed to recover from error");
+ break;
+ case MPD_ERROR_CLOSED:
+ PANIC("Player encountered non-recoverable error");
+ break;
+ }
+}
+
void
player_init(void)
{
@@ -92,7 +111,7 @@ player_update(void)
ref_free(ref);
break;
default:
- ASSERT(0);
+ PANIC();
}
player->action = PLAYER_ACTION_NONE;
}
@@ -111,7 +130,7 @@ player_update(void)
player->state = PLAYER_STATE_STOPPED;
break;
default:
- ASSERT(0);
+ PANIC();
}
player->volume = mpd_status_get_volume(status);
diff --git a/src/util.c b/src/util.c
index e8c0935..c91f944 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2,6 +2,7 @@
#include "util.h"
+#include "execinfo.h"
#include "ncurses.h"
#include <stdarg.h>
@@ -40,6 +41,14 @@ done:
}
void
+panic(const char *msg, const char *file, int line)
+{
+ endwin();
+ fprintf(stderr, "Panic at %s:%i (%s)\n", file, line, msg);
+ exit(1);
+}
+
+void
assert(int cond, const char *file, int line, const char *condstr)
{
if (cond) return;
diff --git a/src/util.h b/src/util.h
index b9f45f4..248b442 100644
--- a/src/util.h
+++ b/src/util.h
@@ -6,9 +6,12 @@
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define ARRLEN(x) (sizeof(x)/sizeof((x)[0]))
+#define PANIC(...) panic("" __VA_ARGS__, __FILE__, __LINE__)
#define ASSERT(x) assert((x), __FILE__, __LINE__, #x)
int strnwidth(const char *s, int n);
+
+void panic(const char *msg, const char *file, int line);
void assert(int cond, const char *file, int line, const char *condstr);
char *aprintf(const char *fmtstr, ...);