add back fused gui log classes, this needs to be redone another way

also, add back wx requirement for strfmt
This commit is contained in:
Peter Tissen 2014-06-08 23:02:20 +02:00
parent 10e10de98d
commit ed10ea7544
12 changed files with 332 additions and 333 deletions

View file

@ -4,91 +4,94 @@
#include "Emu/System.h"
#include "DbgConsole.h"
LogWriter ConLog;
class LogFrame;
extern LogFrame* ConLogFrame;
BEGIN_EVENT_TABLE(DbgConsole, FrameBase)
EVT_CLOSE(DbgConsole::OnQuit)
END_EVENT_TABLE()
_LogBuffer LogBuffer;
std::mutex g_cs_conlog;
const uint max_item_count = 500;
const uint buffer_size = 1024 * 64;
static const std::string g_log_colors[] =
DbgConsole::DbgConsole()
: FrameBase(nullptr, wxID_ANY, "Debug Console", "", wxDefaultSize, wxDefaultPosition, wxDEFAULT_FRAME_STYLE, true)
, ThreadBase("DbgConsole thread")
, m_output(nullptr)
{
"Black", "Green", "White", "Yellow", "Red",
};
m_console = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition,
wxSize(500, 500), wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
m_console->SetBackgroundColour(wxColor("Black"));
m_console->SetFont(wxFont(8, wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
LogWriter::LogWriter()
{
if (!m_logfile.Open(_PRGNAME_ ".log", rFile::write))
{
rMessageBox("Can't create log file! (" _PRGNAME_ ".log)", rMessageBoxCaptionStr, rICON_ERROR);
}
m_color_white = new wxTextAttr(wxColour(255, 255, 255));
m_color_red = new wxTextAttr(wxColour(255, 0, 0));
if (Ini.HLESaveTTY.GetValue())
m_output = new wxFile("tty.log", wxFile::write);
}
void LogWriter::WriteToLog(const std::string& prefix, const std::string& value, u8 lvl/*, wxColour bgcolour*/)
DbgConsole::~DbgConsole()
{
std::string new_prefix = prefix;
if (!prefix.empty())
ThreadBase::Stop();
m_dbg_buffer.Flush();
safe_delete(m_console);
safe_delete(m_color_white);
safe_delete(m_color_red);
safe_delete(m_output);
}
void DbgConsole::Write(int ch, const std::string& text)
{
while (m_dbg_buffer.IsBusy())
{
if (NamedThreadBase* thr = GetCurrentNamedThread())
if (Emu.IsStopped())
{
new_prefix += " : " + thr->GetThreadName();
return;
}
Sleep(1);
}
m_dbg_buffer.Push(DbgPacket(ch, text));
if (m_logfile.IsOpened() && !new_prefix.empty())
m_logfile.Write("[" + new_prefix + "]: " + value + "\n");
if (!IsAlive()) Start();
}
if (!ConLogFrame || Ini.HLELogLvl.GetValue() == 4 || (lvl != 0 && lvl <= Ini.HLELogLvl.GetValue()))
return;
void DbgConsole::Clear()
{
m_console->Clear();
}
std::lock_guard<std::mutex> lock(g_cs_conlog);
// TODO: Use ThreadBase instead, track main thread id
if (rThread::IsMain())
void DbgConsole::Task()
{
while (!TestDestroy())
{
while (LogBuffer.IsBusy())
{
// need extra break condition?
rYieldIfNeeded();
}
}
else
{
while (LogBuffer.IsBusy())
if (!m_dbg_buffer.HasNewPacket())
{
if (Emu.IsStopped())
{
break;
}
Sleep(1);
continue;
}
DbgPacket packet = m_dbg_buffer.Pop();
m_console->SetDefaultStyle(packet.m_ch == 1 ? *m_color_red : *m_color_white);
m_console->SetInsertionPointEnd();
m_console->WriteText(fmt::FromUTF8(packet.m_text));
if (m_output && Ini.HLESaveTTY.GetValue())
m_output->Write(fmt::FromUTF8(packet.m_text));
if (!DbgConsole::IsShown()) Show();
}
}
void DbgConsole::OnQuit(wxCloseEvent& event)
{
ThreadBase::Stop(false);
Hide();
if (m_output)
{
m_output->Close();
m_output = nullptr;
}
//if(LogBuffer.put == LogBuffer.get) LogBuffer.Flush();
LogBuffer.Push(LogPacket(new_prefix, value, g_log_colors[lvl]));
}
void LogWriter::SkipLn()
{
WriteToLog("", "", 0);
}
void DbgConsole::Close()
{
i = 1;
}
void DbgConsole::Clear()
{
i = 2;
}
void DbgConsole::Write(int ch, const std::string &msg)
{
//event.Skip();
}