mirror of
https://github.com/libretro/dolphin
synced 2024-11-09 06:53:01 -05:00
c792961000
Previously the logging was a in a little bit of a disarray. Some things were in namespaces, and other things were not. Given this code will feature a bit of restructuring during the transition over to fmt, this is a good time to unify it under a single namespace and also remove functions and types from the global namespace. Now, all functions and types are under the Common::Log namespace. The only outliers being, of course, the preprocessor macros.
76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
// Copyright 2017 Dolphin Emulator Project
|
|
// Licensed under GPLv2+
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <cstdarg>
|
|
#include <cstddef>
|
|
#include <cstring>
|
|
|
|
#include "AudioCommon/CubebUtils.h"
|
|
#include "Common/CommonPaths.h"
|
|
#include "Common/Logging/Log.h"
|
|
#include "Common/Logging/LogManager.h"
|
|
#include "Common/StringUtil.h"
|
|
|
|
#include <cubeb/cubeb.h>
|
|
|
|
static ptrdiff_t s_path_cutoff_point = 0;
|
|
|
|
static void LogCallback(const char* format, ...)
|
|
{
|
|
if (!Common::Log::LogManager::GetInstance())
|
|
return;
|
|
|
|
va_list args;
|
|
va_start(args, format);
|
|
|
|
const char* filename = va_arg(args, const char*) + s_path_cutoff_point;
|
|
int lineno = va_arg(args, int);
|
|
std::string adapted_format(StripSpaces(format + strlen("%s:%d:")));
|
|
|
|
Common::Log::LogManager::GetInstance()->LogWithFullPath(
|
|
Common::Log::LNOTICE, Common::Log::AUDIO, filename, lineno, adapted_format.c_str(), args);
|
|
va_end(args);
|
|
}
|
|
|
|
static void DestroyContext(cubeb* ctx)
|
|
{
|
|
cubeb_destroy(ctx);
|
|
if (cubeb_set_log_callback(CUBEB_LOG_DISABLED, nullptr) != CUBEB_OK)
|
|
{
|
|
ERROR_LOG(AUDIO, "Error removing cubeb log callback");
|
|
}
|
|
}
|
|
|
|
std::shared_ptr<cubeb> CubebUtils::GetContext()
|
|
{
|
|
static std::weak_ptr<cubeb> weak;
|
|
|
|
std::shared_ptr<cubeb> shared = weak.lock();
|
|
// Already initialized
|
|
if (shared)
|
|
return shared;
|
|
|
|
const char* filename = __FILE__;
|
|
const char* match_point = strstr(filename, DIR_SEP "Source" DIR_SEP "Core" DIR_SEP);
|
|
if (match_point)
|
|
{
|
|
s_path_cutoff_point = match_point - filename + strlen(DIR_SEP "Externals" DIR_SEP);
|
|
}
|
|
if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, LogCallback) != CUBEB_OK)
|
|
{
|
|
ERROR_LOG(AUDIO, "Error setting cubeb log callback");
|
|
}
|
|
|
|
cubeb* ctx;
|
|
if (cubeb_init(&ctx, "Dolphin", nullptr) != CUBEB_OK)
|
|
{
|
|
ERROR_LOG(AUDIO, "Error initializing cubeb library");
|
|
return nullptr;
|
|
}
|
|
INFO_LOG(AUDIO, "Cubeb initialized using %s backend", cubeb_get_backend_id(ctx));
|
|
|
|
weak = shared = {ctx, DestroyContext};
|
|
return shared;
|
|
}
|