summaryrefslogtreecommitdiffstats
path: root/common/msg_control.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-01-16 21:26:31 +0100
committerwm4 <wm4@nowhere>2014-01-16 23:06:40 +0100
commit738dfbb2fe650d4157f3f123dd1358fb1c12af24 (patch)
tree775e46f6bc5e55555430ed77519f62658c2186fc /common/msg_control.h
parent49eb3c4025bbb225620f58d69f6d9365910b25c6 (diff)
downloadmpv-738dfbb2fe650d4157f3f123dd1358fb1c12af24.tar.bz2
mpv-738dfbb2fe650d4157f3f123dd1358fb1c12af24.tar.xz
msg: add a mechanism to output messages to a ringbuffer
Until now, mp_msg output always went to the terminal. There was no way to grab the stream of output messages. But this will be needed by various future changes: Lua scripts, slave mode, client library... This commit allows registering a ring buffer. A callback would be more straight-forward, but since msg.c sits at the bottom of the lock hierarchy (it's used by virtually everything), this would probably be a nightmare. A ring buffer will be simpler and more predictable in the long run. We allocate new memory for each ringbuffer entry, which is probably a bit expensive. We could try to be clever and somehow pack the data directly into the buffer, but I felt like this wouldn't be worth the complexity. You'd have to copy the data a bunch of times anyway. I'm hoping that we can get away with using the ringbuffer mechanism for low frequency important messages only (and not e.g. for high volume debug messages), so the cost doesn't matter that much. A ringbuffer has a simple, single log level. I considered allowing --msglevel style per-prefix configuration for each ringbuffer, but that would have been pretty complicated to implement, and wouldn't have been that useful either.
Diffstat (limited to 'common/msg_control.h')
-rw-r--r--common/msg_control.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/common/msg_control.h b/common/msg_control.h
index 3ff53971b7..65b64eff5e 100644
--- a/common/msg_control.h
+++ b/common/msg_control.h
@@ -12,6 +12,18 @@ void mp_msg_force_stderr(struct mpv_global *global, bool force_stderr);
void mp_msg_flush_status_line(struct mpv_global *global);
bool mp_msg_has_status_line(struct mpv_global *global);
+struct mp_log_buffer_entry {
+ char *prefix;
+ int level;
+ char *text;
+};
+
+struct mp_log_buffer;
+struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global,
+ int size, int level);
+void mp_msg_log_buffer_destroy(struct mp_log_buffer *buffer);
+struct mp_log_buffer_entry *mp_msg_log_buffer_read(struct mp_log_buffer *buffer);
+
struct bstr;
int mp_msg_split_msglevel(struct bstr *s, struct bstr *out_mod, int *out_level);