2017-10-26 12:33:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2024-06-08 21:32:17 +00:00
|
|
|
#include "format.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2022-08-30 16:48:46 +00:00
|
|
|
|
|
|
|
#if !defined(Q_OS_ANDROID) && !defined(__ANDROID__)
|
2024-06-08 21:32:17 +00:00
|
|
|
#define LOG_MSG(fmt, s) fprintf(stderr, fmt, s)
|
2022-08-30 16:48:46 +00:00
|
|
|
#else
|
|
|
|
#include <android/log.h>
|
2024-06-08 21:32:17 +00:00
|
|
|
#define LOG_MSG(fmt, s) __android_log_print(ANDROID_LOG_INFO, "Subsurface", fmt, s);
|
2022-08-30 16:48:46 +00:00
|
|
|
#endif
|
2017-10-26 12:33:02 +00:00
|
|
|
|
2019-08-05 17:41:15 +00:00
|
|
|
int verbose;
|
|
|
|
|
2022-08-30 16:48:46 +00:00
|
|
|
void report_info(const char *fmt, ...)
|
|
|
|
{
|
2024-06-08 21:32:17 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
std::string s = vformat_string_std(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
LOG_MSG("INFO: %s\n", s.c_str());
|
2022-08-30 16:48:46 +00:00
|
|
|
}
|
|
|
|
|
2024-06-08 21:32:17 +00:00
|
|
|
static void (*error_cb)(std::string) = NULL;
|
2017-10-26 12:33:02 +00:00
|
|
|
|
|
|
|
int report_error(const char *fmt, ...)
|
|
|
|
{
|
2024-06-08 21:32:17 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
std::string s = vformat_string_std(fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
LOG_MSG("ERROR: %s\n", s.c_str());
|
2022-08-30 16:48:46 +00:00
|
|
|
|
2018-01-26 09:40:04 +00:00
|
|
|
/* if there is no error callback registered, don't produce errors */
|
2024-06-08 21:32:17 +00:00
|
|
|
if (error_cb)
|
|
|
|
error_cb(std::move(s));
|
2017-10-26 12:33:02 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2024-06-08 21:32:17 +00:00
|
|
|
void set_error_cb(void(*cb)(std::string))
|
2019-02-23 17:31:02 +00:00
|
|
|
{
|
2017-10-26 12:37:29 +00:00
|
|
|
error_cb = cb;
|
|
|
|
}
|