AuroraRuntime/Source/Console/Console.cpp
Reece e5e36bd887 Large Commit
[*] Fix deadlock in the async subsystem (NoLockShutdown vs Shutdown in exception handler)
[+] Added ProccessMap NT variant
[+] Added ToolHelp image profiling
[*] Improved exception awareness
[*] Delegated SpawnThread to isolated TU, ready for reuse for RunAs and XNU Open - now with horrible evil alloc that could fail
[+] Added header for future api 'UtilRun'
[*] Improve NT core detection
[*] Changed small affinity bitmap to AuUInt64 instead of AuUInt32
[+] Added data structure to hold cpuids/affinity masks
[+] Implemented logger sinks
[+] Implemented logger glue logic
[*] Began migrating older loggers to sink-based default devices
[*] Minor refactors
[*] Improved internal exception discarding, not yet nothrow capable
[*] Minor create directory fix
2022-01-24 18:43:53 +00:00

139 lines
3.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Console.cpp
Date: 2021-6-8
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Console.hpp"
#include "Commands/Commands.hpp"
#include "Hooks/Hooks.hpp"
#include "Logging/Logger.hpp"
#include "ConsoleStd/ConsoleStd.hpp"
#include "ConsoleWxWidgets/ConsoleWxWidgets.hpp"
#include "ConsoleFIO/ConsoleFIO.hpp"
#include "Flusher.hpp"
namespace Aurora::Console
{
static AuList<AuSPtr<IBasicSink>> gDefaultSinks;
static AuSPtr<ILogger> gDefaultLogger;
static AuSPtr<ILogger> gUserLogger;
static AuSPtr<ILogger> CreateDefaultLogger()
{
return Logging::NewLoggerShared(gDefaultSinks);
}
AUKN_SYM void WriteLine(AuUInt8 level, const ConsoleMessage &msg)
{
Hooks::WriteLine(msg);
if (gUserLogger)
{
gUserLogger->WriteMessage(level, msg);
}
else if (!gDefaultLogger)
{
auto tmp = CreateDefaultLogger();
if (tmp)
{
tmp->WriteMessage(level, msg);
}
}
else
{
gDefaultLogger->WriteMessage(level, msg);
}
}
void AddDefaultLogger(const AuSPtr<IBasicSink> &logger)
{
gDefaultSinks.push_back(logger);
}
static void FinailizeDefaultLogger()
{
gDefaultLogger = CreateDefaultLogger();
//gDefaultSinks.clear();
}
AUKN_SYM void SetGlobalLogger(const AuSPtr<Logging::ILogger> &defaultGlobalLogger)
{
gUserLogger = defaultGlobalLogger;
}
AUKN_SYM AuSPtr<Logging::ILogger> GetDefaultLogInterface()
{
return gDefaultLogger;
}
AUKN_SYM AuUInt32 ReadStdIn(void *buffer, AuUInt32 length)
{
return ConsoleStd::ReadStdIn(buffer, length);
}
AUKN_SYM AuUInt32 WriteStdOut(const void *buffer, AuUInt32 length)
{
return ConsoleStd::WriteStdOut(buffer, length);
}
AUKN_SYM bool DispatchRawLine(const AuString &string)
{
if (Hooks::gExternalLineProcessor)
{
Hooks::gExternalLineProcessor->OnProcessedLineUTF8(string);
return true;
}
return Commands::DispatchCommand(string);
}
void Init()
{
Hooks::Init();
ConsoleStd::Init();
ConsoleWxWidgets::Init();
}
void Init2()
{
ConsoleFIO::Init();
InitFlusher();
FinailizeDefaultLogger();
Logging::InitLoggers();
}
void Pump()
{
Commands::PumpCommands();
ConsoleStd::Pump();
ConsoleWxWidgets::Pump();
ConsoleFIO::Pump();
}
void Exit()
{
gDefaultSinks.clear();
gDefaultLogger.reset();
gUserLogger.reset();
DeinitFlusher();
Logging::DeinitLoggers();
ConsoleFIO::Exit();
ConsoleWxWidgets::Exit();
ConsoleStd::Exit();
Hooks::Deinit();
}
AUKN_SYM void OpenLateStd()
{
ConsoleStd::Start();
FinailizeDefaultLogger();
}
AUKN_SYM void OpenLateGUI()
{
ConsoleWxWidgets::Start();
}
}