Pass log levels from emugl layer

This commit is contained in:
Simon Fels 2017-01-26 09:21:53 +01:00
commit 1b1b2c35a1
9 changed files with 54 additions and 25 deletions

View file

@ -823,12 +823,7 @@ int ApiGen::genDecoderImpl(const std::string &filename)
fprintf(fp, "typedef unsigned int tsize_t; // Target \"size_t\", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.\n\n"); fprintf(fp, "typedef unsigned int tsize_t; // Target \"size_t\", which is 32-bit for now. It may or may not be the same as host's size_t when emugen is compiled.\n\n");
// helper macros // helper macros
fprintf(fp, fprintf(fp, "# define DEBUG(...) do { if (emugl_cxt_logger) { emugl_cxt_logger(LogLevel::TRACE, __VA_ARGS__); } } while(0)\n\n");
"#ifdef OPENGL_DEBUG_PRINTOUT\n"
"# define DEBUG(...) do { if (emugl_cxt_logger) { emugl_cxt_logger(__VA_ARGS__); } } while(0)\n"
"#else\n"
"# define DEBUG(...) ((void)0)\n"
"#endif\n\n");
fprintf(fp, fprintf(fp,
"#ifdef CHECK_GLERROR\n" "#ifdef CHECK_GLERROR\n"
@ -913,7 +908,7 @@ int ApiGen::genDecoderImpl(const std::string &filename)
} }
} else if (pass == PASS_DebugPrint) { } else if (pass == PASS_DebugPrint) {
fprintf(fp, fprintf(fp,
"\t\t\tDEBUG(\"%s(%%p): %s(%s)\\n\", stream", "\t\t\tDEBUG(\"%s(%%p): %s(%s)\", stream",
m_basename.c_str(), m_basename.c_str(),
e->name().c_str(), e->name().c_str(),
printString.c_str()); printString.c_str());

View file

@ -98,6 +98,6 @@ void ChecksumCalculatorThreadInfo::validOrDie(void* buf,
// We should actually call crashhandler_die(message), but I don't think we // We should actually call crashhandler_die(message), but I don't think we
// can link to that library from here // can link to that library from here
if (!validate(buf, bufLen, checksum, checksumLen)) { if (!validate(buf, bufLen, checksum, checksumLen)) {
emugl_crash_reporter(message); emugl_crash_reporter(emugl::LogLevel::FATAL, message);
} }
} }

View file

@ -18,13 +18,13 @@
#include <cstdlib> #include <cstdlib>
void default_crash_reporter(const char* format, ...) { void default_crash_reporter(const emugl::LogLevel &level, const char* format, ...) {
abort(); abort();
} }
crash_reporter_t emugl_crash_reporter = default_crash_reporter; logger_t emugl_crash_reporter = default_crash_reporter;
void set_emugl_crash_reporter(crash_reporter_t crash_reporter) { void set_emugl_crash_reporter(logger_t crash_reporter) {
if (crash_reporter) { if (crash_reporter) {
emugl_crash_reporter = crash_reporter; emugl_crash_reporter = crash_reporter;
} else { } else {

View file

@ -16,7 +16,7 @@
#pragma once #pragma once
typedef void (*crash_reporter_t)(const char* format, ...); #include "emugl/common/logging.h"
extern crash_reporter_t emugl_crash_reporter; extern logger_t emugl_crash_reporter;
void set_emugl_crash_reporter(crash_reporter_t crash_reporter); void set_emugl_crash_reporter(logger_t crash_reporter);

View file

@ -16,7 +16,7 @@
#include "emugl/common/logging.h" #include "emugl/common/logging.h"
void default_logger(const char* fmt, ...) { } void default_logger(const emugl::LogLevel &level, const char* fmt, ...) { }
logger_t emugl_logger = default_logger; logger_t emugl_logger = default_logger;
logger_t emugl_cxt_logger = default_logger; logger_t emugl_cxt_logger = default_logger;

View file

@ -14,10 +14,24 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef EMUGL_COMMON_LOGGING_H_
#define EMUGL_COMMON_LOGGING_H_
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls" #pragma GCC diagnostic ignored "-Wredundant-decls"
typedef void (*logger_t)(const char* fmt, ...); namespace emugl {
enum class LogLevel {
TRACE,
DEBUG,
INFO,
WARNING,
ERROR,
FATAL,
};
} // namespace emugl
typedef void (*logger_t)(const emugl::LogLevel &level, const char* fmt, ...);
extern logger_t emugl_logger; extern logger_t emugl_logger;
extern logger_t emugl_cxt_logger; extern logger_t emugl_cxt_logger;
void set_emugl_logger(logger_t f); void set_emugl_logger(logger_t f);
@ -40,3 +54,5 @@ void set_emugl_cxt_logger(logger_t f);
#endif #endif
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
#endif

View file

@ -23,7 +23,6 @@
#include "OpenGLESDispatch/GLESv2Dispatch.h" #include "OpenGLESDispatch/GLESv2Dispatch.h"
#include "emugl/common/crash_reporter.h" #include "emugl/common/crash_reporter.h"
#include "emugl/common/logging.h"
#include <string.h> #include <string.h>
@ -50,7 +49,7 @@ std::vector<GLLibrary> default_gl_libraries(bool no_glesv1) {
}; };
} }
bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct log_funcs, emugl_crash_func_t crash_func) { bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct log_funcs, logger_t crash_func) {
set_emugl_crash_reporter(crash_func); set_emugl_crash_reporter(crash_func);
set_emugl_logger(log_funcs.coarse); set_emugl_logger(log_funcs.coarse);
set_emugl_cxt_logger(log_funcs.fine); set_emugl_cxt_logger(log_funcs.fine);

View file

@ -21,12 +21,11 @@
#include <boost/filesystem/path.hpp> #include <boost/filesystem/path.hpp>
typedef void (*emugl_logger_func_t)(const char* fmt, ...); #include "emugl/common/logging.h"
typedef void (*emugl_crash_func_t)(const char* format, ...);
typedef struct { typedef struct {
emugl_logger_func_t coarse; logger_t coarse;
emugl_logger_func_t fine; logger_t fine;
} emugl_logger_struct; } emugl_logger_struct;
namespace anbox { namespace anbox {
@ -40,7 +39,7 @@ struct GLLibrary {
std::vector<GLLibrary> default_gl_libraries(bool no_glesv1 = false); std::vector<GLLibrary> default_gl_libraries(bool no_glesv1 = false);
bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct log_funcs, emugl_crash_func_t crash_func); bool initialize(const std::vector<GLLibrary> &libs, emugl_logger_struct log_funcs, logger_t crash_func);
} // namespace emugl } // namespace emugl
} // namespace graphics } // namespace graphics
} // namespace anbox } // namespace anbox

View file

@ -29,7 +29,9 @@
#include <stdexcept> #include <stdexcept>
namespace { namespace {
void logger_write(const char *format, ...) { void logger_write(const emugl::LogLevel &level, const char *format, ...) {
(void)level;
char message[2048]; char message[2048];
va_list args; va_list args;
@ -37,7 +39,25 @@ void logger_write(const char *format, ...) {
vsnprintf(message, sizeof(message) - 1, format, args); vsnprintf(message, sizeof(message) - 1, format, args);
va_end(args); va_end(args);
switch (level) {
case emugl::LogLevel::WARNING:
WARNING("%s", message);
break;
case emugl::LogLevel::ERROR:
ERROR("%s", message);
break;
case emugl::LogLevel::FATAL:
FATAL("%s", message);
break;
case emugl::LogLevel::DEBUG:
DEBUG("%s", message); DEBUG("%s", message);
break;
case emugl::LogLevel::TRACE:
TRACE("%s", message);
break;
default:
break;
}
} }
} }