summaryrefslogtreecommitdiffstats
path: root/core/mp_msg.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-07-31 21:40:30 +0200
committerwm4 <wm4@nowhere>2013-07-31 21:46:40 +0200
commit88d79fc00df39dc0180de86c758697f5ab3e56cb (patch)
tree5764f1067cae79dad6a01dccfb241db894b67683 /core/mp_msg.h
parentd1de1e090f91a254f066505ee5811feda4d93dde (diff)
downloadmpv-88d79fc00df39dc0180de86c758697f5ab3e56cb.tar.bz2
mpv-88d79fc00df39dc0180de86c758697f5ab3e56cb.tar.xz
mp_msg: introduce new log functions and macros
This has two goals: 1. Getting rid of global variables to make the core library-safe. 2. Getting rid of all the MSGT_* constants and the inconsistent prefixes spread throughout the source code. Both goals are not immediately reached with this commit. It's a huge transition that will take time. There are over >2500 mp_msg calls in the source, which all have to be replaced for this to work. The inconsistent prefixes are in particular annoying. Lots of code manually prefixes messages, e.g. mp_msg(MSGT_VO, MSGL_V, "[vo] ..."). Sometimes the prefixes don't even follow this convention (for example vo_direct3d.c uses "<vo_direct3d>" as prefix). This commit allows automatically adding prefixes on request, so consistency will hopefully improve. For now, this commit adds unused stuff, and behavior should not change. In mplayer.c, move the GetCpuCaps() call, because that used mp_msg() before mp_msg_init() was run.
Diffstat (limited to 'core/mp_msg.h')
-rw-r--r--core/mp_msg.h35
1 files changed, 33 insertions, 2 deletions
diff --git a/core/mp_msg.h b/core/mp_msg.h
index 392adcf01f..4685668f01 100644
--- a/core/mp_msg.h
+++ b/core/mp_msg.h
@@ -20,6 +20,9 @@
#define MPLAYER_MP_MSG_H
#include <stdarg.h>
+#include <stdbool.h>
+
+struct mp_log;
// defined in mplayer.c
extern int verbose;
@@ -126,10 +129,10 @@ extern int verbose;
#define MSGT_TELETEXT 46 // Teletext decoder
-#define MSGT_MAX 64
+#define MSGT_MAX 47
-void mp_msg_init(void);
int mp_msg_test(int mod, int lev);
+bool mp_msg_test_log(struct mp_log *log, int lev);
#include "config.h"
#include "core/mp_common.h"
@@ -142,6 +145,34 @@ void mp_msg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
void mp_tmsg(int mod, int lev, const char *format, ... ) PRINTF_ATTRIBUTE(3, 4);
#define mp_dbg mp_msg
+struct mp_log *mp_log_new(void *talloc_ctx, struct mp_log *parent,
+ const char *name);
+
+void mp_msg_log(struct mp_log *log, int lev, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4);
+void mp_tmsg_log(struct mp_log *log, int lev, const char *format, ...)
+ PRINTF_ATTRIBUTE(3, 4);
+
+// Convenience macros, typically called with a pointer to a context struct
+// as first argument, which has a "struct mp_log log;" member.
+
+#define MP_MSG(obj, lev, ...) mp_msg_log((obj)->log, lev, __VA_ARGS__)
+#define MP_MSGT(obj, lev, ...) mp_msgt_log((obj)->log, lev, __VA_ARGS__)
+
+#define MP_FATAL(obj, ...) MP_MSG(obj, MSGL_FATAL, __VA_ARGS__)
+#define MP_ERR(obj, ...) MP_MSG(obj, MSGL_ERR, __VA_ARGS__)
+#define MP_WARN(obj, ...) MP_MSG(obj, MSGL_WARN, __VA_ARGS__)
+#define MP_INFO(obj, ...) MP_MSG(obj, MSGL_INFO, __VA_ARGS__)
+#define MP_VERBOSE(obj, ...) MP_MSG(obj, MSGL_V, __VA_ARGS__)
+#define MP_DBG(obj, ...) MP_MSG(obj, MSGL_DGB2, __VA_ARGS__)
+#define MP_TRACE(obj, ...) MP_MSG(obj, MSGL_DGB5, __VA_ARGS__)
+
+struct mpv_global;
+void mp_msg_init(struct mpv_global *global);
+void mp_msg_uninit(struct mpv_global *global);
+
+struct mpv_global *mp_log_get_global(struct mp_log *log);
+
extern bool mp_msg_stdout_in_use;
#endif /* MPLAYER_MP_MSG_H */