2017-10-26 12:33:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifdef __clang__
|
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
|
|
|
#endif
|
2019-03-03 21:55:18 +00:00
|
|
|
#include <stdarg.h>
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2017-10-26 12:33:02 +00:00
|
|
|
#include "membuffer.h"
|
2022-08-30 16:48:46 +00:00
|
|
|
#include "qthelper.h"
|
|
|
|
|
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(__ANDROID__)
|
|
|
|
#define LOG_MSG(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#include <android/log.h>
|
|
|
|
#define LOG_MSG(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "Subsurface", fmt, ##__VA_ARGS__);
|
|
|
|
#endif
|
2017-10-26 12:33:02 +00:00
|
|
|
|
|
|
|
#define VA_BUF(b, fmt) do { va_list args; va_start(args, fmt); put_vformat(b, fmt, args); va_end(args); } while (0)
|
|
|
|
|
2019-08-05 17:41:15 +00:00
|
|
|
int verbose;
|
|
|
|
|
2022-08-30 16:48:46 +00:00
|
|
|
void report_info(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct membuffer buf = { 0 };
|
|
|
|
|
|
|
|
VA_BUF(&buf, fmt);
|
|
|
|
strip_mb(&buf);
|
|
|
|
LOG_MSG("INFO: %s\n", mb_cstring(&buf));
|
|
|
|
}
|
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
static void (*error_cb)(char *) = NULL;
|
2017-10-26 12:33:02 +00:00
|
|
|
|
|
|
|
int report_error(const char *fmt, ...)
|
|
|
|
{
|
2018-01-26 09:40:04 +00:00
|
|
|
struct membuffer buf = { 0 };
|
2017-10-26 12:33:02 +00:00
|
|
|
|
2022-08-30 16:48:46 +00:00
|
|
|
VA_BUF(&buf, fmt);
|
|
|
|
strip_mb(&buf);
|
|
|
|
LOG_MSG("ERROR: %s\n", mb_cstring(&buf));
|
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
/* if there is no error callback registered, don't produce errors */
|
|
|
|
if (!error_cb)
|
|
|
|
return -1;
|
2019-10-27 18:24:10 +00:00
|
|
|
error_cb(detach_cstring(&buf));
|
2017-10-26 12:33:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-02-23 17:31:02 +00:00
|
|
|
void set_error_cb(void(*cb)(char *))
|
|
|
|
{
|
2017-10-26 12:37:29 +00:00
|
|
|
error_cb = cb;
|
|
|
|
}
|