Replace CLogger::Write() calls with macros

This commit is contained in:
Dale Whinham
2023-03-05 16:30:36 +00:00
parent 919696b41d
commit 52b85b7027
16 changed files with 200 additions and 223 deletions

View File

@@ -140,7 +140,6 @@ private:
void LEDOn();
void LCDLog(TLCDLogType Type, const char* pFormat...);
CLogger* volatile m_pLogger;
CConfig* volatile m_pConfig;
CTimer* m_pTimer;

View File

@@ -30,6 +30,10 @@
#include "config.h"
#include "utility.h"
LOGMODULE("config");
const char* TrueStrings[] = {"true", "on", "1"};
const char* FalseStrings[] = {"false", "off", "0"};
// Templated function that converts a string to an enum
template <class T, const char* pEnumStrings[], size_t N> static bool ParseEnum(const char* pString, T* pOut)
{
@@ -52,10 +56,6 @@ template <class T, const char* pEnumStrings[], size_t N> static bool ParseEnum(c
return ParseEnum<ENUM_NAME, ENUM_NAME##Strings, Utility::ArraySize(ENUM_NAME##Strings)>(pString, pOut); \
}
const char ConfigName[] = "config";
const char* TrueStrings[] = {"true", "on", "1"};
const char* FalseStrings[] = {"false", "off", "0"};
// Enum string tables
CONFIG_ENUM_STRINGS(TSystemDefaultSynth, ENUM_SYSTEMDEFAULTSYNTH);
CONFIG_ENUM_STRINGS(TAudioOutputDevice, ENUM_AUDIOOUTPUTDEVICE);
@@ -85,7 +85,7 @@ bool CConfig::Initialize(const char* pPath)
FIL File;
if (f_open(&File, pPath, FA_READ) != FR_OK)
{
CLogger::Get()->Write(ConfigName, LogError, "Couldn't open '%s' for reading", pPath);
LOGERR("Couldn't open '%s' for reading", pPath);
return false;
}
@@ -96,7 +96,7 @@ bool CConfig::Initialize(const char* pPath)
if (f_read(&File, Buffer, nSize, &nRead) != FR_OK)
{
CLogger::Get()->Write(ConfigName, LogError, "Error reading config file", pPath);
LOGERR("Error reading config file", pPath);
f_close(&File);
return false;
}
@@ -106,7 +106,7 @@ bool CConfig::Initialize(const char* pPath)
const int nResult = ini_parse_string(Buffer, INIHandler, this);
if (nResult > 0)
CLogger::Get()->Write(ConfigName, LogWarning, "Config parse error on line %d", nResult);
LOGWARN("Config parse error on line %d", nResult);
f_close(&File);
return nResult >= 0;
@@ -117,7 +117,7 @@ int CConfig::INIHandler(void* pUser, const char* pSection, const char* pName, co
{
CConfig* const pConfig = static_cast<CConfig*>(pUser);
//CLogger::Get()->Write(ConfigName, LogDebug, "'%s', '%s', '%s'", pSection, pName, pValue);
//LOGDBG("'%s', '%s', '%s'", pSection, pName, pValue);
// Automatically generate ParseOption() calls from macro definition file
#define BEGIN_SECTION(SECTION) \

View File

@@ -24,7 +24,7 @@
#include "control/mister.h"
const char MisterControlName[] = "mistercontrol";
LOGMODULE("mistercontrol");
constexpr u8 MisterI2CAddress = 0x45;
@@ -50,12 +50,12 @@ void CMisterControl::Update(const TMisterStatus& SystemStatus)
return;
}
//CLogger::Get()->Write(MisterControlName, LogDebug, "MiSTer Rx: 0x%02x 0x%02x 0x%02x", static_cast<u8>(MisterStatus.Synth), MisterStatus.MT32ROMSet, MisterStatus.SoundFontIndex);
//LOGDBG("MiSTer Rx: 0x%02x 0x%02x 0x%02x", static_cast<u8>(MisterStatus.Synth), MisterStatus.MT32ROMSet, MisterStatus.SoundFontIndex);
// Core was reset or "Reset Hanging Notes" was selected from OSD; turn off all sound
if (MisterStatus.Synth == TMisterSynth::Mute)
{
CLogger::Get()->Write(MisterControlName, LogNotice, "Stopping synth activity");
LOGNOTE("Stopping synth activity");
EnqueueAllSoundOffEvent();
WriteConfigToMister(SystemStatus);
return;
@@ -138,11 +138,11 @@ bool CMisterControl::WriteConfigToMister(const TMisterStatus& NewStatus)
// Write config back to MiSTer
if (m_pI2CMaster->Write(MisterI2CAddress, &NewStatus, sizeof(NewStatus)) < 0)
{
CLogger::Get()->Write(MisterControlName, LogError, "MiSTer write failed");
LOGERR("MiSTer write failed");
return false;
}
//CLogger::Get()->Write(MisterControlName, LogDebug, "MiSTer Tx: 0x%02x 0x%02x 0x%02x", static_cast<u8>(NewStatus.Synth), NewStatus.MT32ROMSet, NewStatus.SoundFontIndex);
//LOGDBG("MiSTer Tx: 0x%02x 0x%02x 0x%02x", static_cast<u8>(NewStatus.Synth), NewStatus.MT32ROMSet, NewStatus.SoundFontIndex);
return true;
}
@@ -151,7 +151,7 @@ void CMisterControl::ResetState()
if (bMisterActive)
{
// MiSTer has just stopped responding; dispatch an All Sound Off event
CLogger::Get()->Write(MisterControlName, LogNotice, "MiSTer stopped responding; turning notes off");
LOGNOTE("MiSTer stopped responding; turning notes off");
EnqueueAllSoundOffEvent();
bMisterActive = false;
m_LastSystemStatus = {TMisterSynth::Unknown, 0xFF, 0xFF};

View File

@@ -24,7 +24,7 @@
#include "midiparser.h"
const char MIDIParserName[] = "midiparser";
LOGMODULE("midiparser");
CMIDIParser::CMIDIParser()
: m_State(TState::StatusByte),
@@ -111,14 +111,14 @@ void CMIDIParser::ParseMIDIBytes(const u8* pData, size_t nSize, bool bIgnoreNote
void CMIDIParser::OnUnexpectedStatus()
{
if (m_State == TState::SysExByte)
CLogger::Get()->Write(MIDIParserName, LogWarning, "Received illegal status byte during SysEx message; SysEx ignored");
LOGWARN("Received illegal status byte during SysEx message; SysEx ignored");
else
CLogger::Get()->Write(MIDIParserName, LogWarning, "Received illegal status byte when data expected");
LOGWARN("Received illegal status byte when data expected");
}
void CMIDIParser::OnSysExOverflow()
{
CLogger::Get()->Write(MIDIParserName, LogWarning, "Buffer overrun when receiving SysEx message; SysEx ignored");
LOGWARN("Buffer overrun when receiving SysEx message; SysEx ignored");
}
void CMIDIParser::ParseStatusByte(u8 nByte)

View File

@@ -34,7 +34,7 @@
#include "mt32pi.h"
#define MT32_PI_NAME "mt32-pi"
const char MT32PiName[] = MT32_PI_NAME;
LOGMODULE(MT32_PI_NAME);
const char MT32PiFullName[] = MT32_PI_NAME " " MT32_PI_VERSION;
const char WLANFirmwarePath[] = "SD:firmware/";
@@ -62,7 +62,6 @@ CMT32Pi::CMT32Pi(CI2CMaster* pI2CMaster, CSPIMaster* pSPIMaster, CInterruptSyste
: CMultiCoreSupport(CMemorySystem::Get()),
CMIDIParser(),
m_pLogger(CLogger::Get()),
m_pConfig(CConfig::Get()),
m_pTimer(CTimer::Get()),
@@ -160,7 +159,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
{
if (m_pLCD->Initialize())
{
m_pLogger->RegisterPanicHandler(PanicHandler);
CLogger::Get()->RegisterPanicHandler(PanicHandler);
// Splash screen
if (m_pLCD->GetType() == CLCD::TType::Graphical && !m_pConfig->SystemVerbose)
@@ -173,7 +172,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
}
else
{
m_pLogger->Write(MT32PiName, LogWarning, "LCD init failed; invalid dimensions?");
LOGWARN("LCD init failed; invalid dimensions?");
delete m_pLCD;
m_pLCD = nullptr;
}
@@ -202,7 +201,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
m_pPisound = new CPisound(m_pSPIMaster, m_pGPIOManager, m_pConfig->AudioSampleRate);
if (m_pPisound->Initialize())
{
m_pLogger->Write(MT32PiName, LogWarning, "Blokas Pisound detected");
LOGWARN("Blokas Pisound detected");
m_pPisound->RegisterMIDIReceiveHandler(IRQMIDIReceiveHandler);
m_bSerialMIDIEnabled = false;
}
@@ -255,7 +254,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
m_pSound->SetWriteFormat(Format);
if (!m_pSound->AllocateQueueFrames(nQueueSize))
m_pLogger->Write(MT32PiName, LogPanic, "Failed to allocate sound queue");
LOGPANIC("Failed to allocate sound queue");
LCDLog(TLCDLogType::Startup, "Init controls");
if (m_pConfig->ControlScheme == CConfig::TControlScheme::SimpleButtons)
@@ -265,7 +264,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
if (m_pControl && !m_pControl->Initialize())
{
m_pLogger->Write(MT32PiName, LogWarning, "Control init failed");
LOGWARN("Control init failed");
delete m_pControl;
m_pControl = nullptr;
}
@@ -284,7 +283,7 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
if (!m_pCurrentSynth)
{
m_pLogger->Write(MT32PiName, LogError, "Preferred synth failed to initialize successfully");
LOGERR("Preferred synth failed to initialize successfully");
// Activate any working synth
if (m_pMT32Synth)
@@ -293,15 +292,15 @@ bool CMT32Pi::Initialize(bool bSerialMIDIAvailable)
m_pCurrentSynth = m_pSoundFontSynth;
else
{
m_pLogger->Write(MT32PiName, LogPanic, "No synths available; ROMs/SoundFonts not found");
LOGPANIC("No synths available; ROMs/SoundFonts not found");
return false;
}
}
if (m_pPisound)
m_pLogger->Write(MT32PiName, LogNotice, "Using Pisound MIDI interface");
LOGNOTE("Using Pisound MIDI interface");
else if (m_bSerialMIDIEnabled)
m_pLogger->Write(MT32PiName, LogNotice, "Using serial MIDI interface");
LOGNOTE("Using serial MIDI interface");
CCPUThrottle::Get()->DumpStatus();
SetPowerSaveTimeout(m_pConfig->SystemPowerSaveTimeout);
@@ -328,16 +327,16 @@ bool CMT32Pi::InitNetwork()
if (m_pConfig->NetworkMode == CConfig::TNetworkMode::WiFi)
{
m_pLogger->Write(MT32PiName, LogNotice, "Initializing Wi-Fi");
LOGNOTE("Initializing Wi-Fi");
if (m_WLAN.Initialize() && m_WPASupplicant.Initialize())
NetDeviceType = NetDeviceTypeWLAN;
else
m_pLogger->Write(MT32PiName, LogError, "Failed to initialize Wi-Fi");
LOGERR("Failed to initialize Wi-Fi");
}
else if (m_pConfig->NetworkMode == CConfig::TNetworkMode::Ethernet)
{
m_pLogger->Write(MT32PiName, LogNotice, "Initializing Ethernet");
LOGNOTE("Initializing Ethernet");
NetDeviceType = NetDeviceTypeEthernet;
}
@@ -357,7 +356,7 @@ bool CMT32Pi::InitNetwork()
if (!m_pNet->Initialize(false))
{
m_pLogger->Write(MT32PiName, LogError, "Failed to initialize network subsystem");
LOGERR("Failed to initialize network subsystem");
delete m_pNet;
m_pNet = nullptr;
}
@@ -375,7 +374,7 @@ bool CMT32Pi::InitMT32Synth()
m_pMT32Synth = new CMT32Synth(m_pConfig->AudioSampleRate, m_pConfig->MT32EmuGain, m_pConfig->MT32EmuReverbGain, m_pConfig->MT32EmuResamplerQuality);
if (!m_pMT32Synth->Initialize())
{
m_pLogger->Write(MT32PiName, LogWarning, "mt32emu init failed; no ROMs present?");
LOGWARN("mt32emu init failed; no ROMs present?");
delete m_pMT32Synth;
m_pMT32Synth = nullptr;
return false;
@@ -400,7 +399,7 @@ bool CMT32Pi::InitSoundFontSynth()
m_pSoundFontSynth = new CSoundFontSynth(m_pConfig->AudioSampleRate);
if (!m_pSoundFontSynth->Initialize())
{
m_pLogger->Write(MT32PiName, LogWarning, "FluidSynth init failed; no SoundFonts present?");
LOGWARN("FluidSynth init failed; no SoundFonts present?");
delete m_pSoundFontSynth;
m_pSoundFontSynth = nullptr;
return false;
@@ -415,7 +414,7 @@ void CMT32Pi::MainTask()
{
CScheduler* const pScheduler = CScheduler::Get();
m_pLogger->Write(MT32PiName, LogNotice, "Main task on Core 0 starting up");
LOGNOTE("Main task on Core 0 starting up");
Awaken();
@@ -448,7 +447,7 @@ void CMT32Pi::MainTask()
{
m_pCurrentSynth->AllSoundOff();
m_bActiveSenseFlag = false;
m_pLogger->Write(MT32PiName, LogNotice, "Active sense timeout - turning notes off");
LOGNOTE("Active sense timeout - turning notes off");
}
// Update power management
@@ -459,7 +458,7 @@ void CMT32Pi::MainTask()
if (nTicks - m_nTempUpdateTime >= MSEC2HZ(5000))
{
const unsigned int nTemp = CCPUThrottle::Get()->GetTemperature();
m_pLogger->Write(MT32PiName, LogDebug, "Temperature: %dC", nTemp);
LOGDBG("Temperature: %dC", nTemp);
LCDLog(TLCDLogType::Notice, "Temp: %dC", nTemp);
m_nTempUpdateTime = nTicks;
}
@@ -501,7 +500,7 @@ void CMT32Pi::MainTask()
void CMT32Pi::UITask()
{
m_pLogger->Write(MT32PiName, LogNotice, "UI task on Core 1 starting up");
LOGNOTE("UI task on Core 1 starting up");
const bool bMisterEnabled = m_pConfig->ControlMister;
@@ -556,7 +555,7 @@ void CMT32Pi::UITask()
void CMT32Pi::AudioTask()
{
m_pLogger->Write(MT32PiName, LogNotice, "Audio task on Core 2 starting up");
LOGNOTE("Audio task on Core 2 starting up");
constexpr u8 nChannels = 2;
@@ -602,7 +601,7 @@ void CMT32Pi::AudioTask()
const int nResult = m_pSound->Write(IntBuffer, nWriteBytes);
if (nResult != static_cast<int>(nWriteBytes))
m_pLogger->Write(MT32PiName, LogError, "Sound data dropped");
LOGERR("Sound data dropped");
}
}
@@ -726,7 +725,7 @@ bool CMT32Pi::ParseCustomSysEx(const u8* pData, size_t nSize)
// Reboot (F0 7D 00 F7)
if (nSize == 4 && Command == TCustomSysExCommand::Reboot)
{
m_pLogger->Write(MT32PiName, LogNotice, "Reboot command received");
LOGNOTE("Reboot command received");
m_bRunning = false;
return true;
}
@@ -783,10 +782,10 @@ void CMT32Pi::UpdateUSB(bool bStartup)
if (!m_pUSBMassStorageDevice && pUSBMassStorageDevice)
{
// USB disk was attached
m_pLogger->Write(MT32PiName, LogNotice, "USB mass storage device attached");
LOGNOTE("USB mass storage device attached");
if (f_mount(&m_USBFileSystem, "USB:", 1) != FR_OK)
m_pLogger->Write(MT32PiName, LogError, "Failed to mount USB mass storage device");
LOGERR("Failed to mount USB mass storage device");
else
{
if (!bStartup)
@@ -811,7 +810,7 @@ void CMT32Pi::UpdateUSB(bool bStartup)
else if (m_pUSBMassStorageDevice && !pUSBMassStorageDevice)
{
// USB disk was removed
m_pLogger->Write(MT32PiName, LogNotice, "USB mass storage device removed");
LOGNOTE("USB mass storage device removed");
f_unmount("USB:");
@@ -829,7 +828,7 @@ void CMT32Pi::UpdateUSB(bool bStartup)
{
m_pUSBMIDIDevice->RegisterRemovedHandler(USBMIDIDeviceRemovedHandler, &m_pUSBMIDIDevice);
m_pUSBMIDIDevice->RegisterPacketHandler(USBMIDIPacketHandler);
m_pLogger->Write(MT32PiName, LogNotice, "Using USB MIDI interface");
LOGNOTE("Using USB MIDI interface");
m_bSerialMIDIEnabled = false;
}
@@ -837,7 +836,7 @@ void CMT32Pi::UpdateUSB(bool bStartup)
{
m_pUSBSerialDevice->SetBaudRate(m_pConfig->MIDIUSBSerialBaudRate);
m_pUSBSerialDevice->RegisterRemovedHandler(USBMIDIDeviceRemovedHandler, &m_pUSBSerialDevice);
m_pLogger->Write(MT32PiName, LogNotice, "Using USB serial interface");
LOGNOTE("Using USB serial interface");
m_bSerialMIDIEnabled = false;
}
}
@@ -860,7 +859,7 @@ void CMT32Pi::UpdateNetwork()
CString IPString;
m_pNet->GetConfig()->GetIPAddress()->Format(&IPString);
m_pLogger->Write(MT32PiName, LogNotice, "Network up and running at: %s", static_cast<const char *>(IPString));
LOGNOTE("Network up and running at: %s", static_cast<const char *>(IPString));
LCDLog(TLCDLogType::Notice, "%s: %s", GetNetworkDeviceShortName(), static_cast<const char*>(IPString));
if (m_pConfig->NetworkRTPMIDI && !m_pAppleMIDIParticipant)
@@ -868,12 +867,12 @@ void CMT32Pi::UpdateNetwork()
m_pAppleMIDIParticipant = new CAppleMIDIParticipant(&m_Random, this);
if (!m_pAppleMIDIParticipant->Initialize())
{
m_pLogger->Write(MT32PiName, LogError, "Failed to init AppleMIDI receiver");
LOGERR("Failed to init AppleMIDI receiver");
delete m_pAppleMIDIParticipant;
m_pAppleMIDIParticipant = nullptr;
}
else
m_pLogger->Write(MT32PiName, LogNotice, "AppleMIDI receiver initialized");
LOGNOTE("AppleMIDI receiver initialized");
}
if (m_pConfig->NetworkUDPMIDI && !m_pUDPMIDIReceiver)
@@ -881,12 +880,12 @@ void CMT32Pi::UpdateNetwork()
m_pUDPMIDIReceiver = new CUDPMIDIReceiver(this);
if (!m_pUDPMIDIReceiver->Initialize())
{
m_pLogger->Write(MT32PiName, LogError, "Failed to init UDP MIDI receiver");
LOGERR("Failed to init UDP MIDI receiver");
delete m_pUDPMIDIReceiver;
m_pUDPMIDIReceiver = nullptr;
}
else
m_pLogger->Write(MT32PiName, LogNotice, "UDP MIDI receiver initialized");
LOGNOTE("UDP MIDI receiver initialized");
}
if (m_pConfig->NetworkFTPServer && !m_pFTPDaemon)
@@ -894,18 +893,18 @@ void CMT32Pi::UpdateNetwork()
m_pFTPDaemon = new CFTPDaemon(m_pConfig->NetworkFTPUsername, m_pConfig->NetworkFTPPassword);
if (!m_pFTPDaemon->Initialize())
{
m_pLogger->Write(MT32PiName, LogError, "Failed to init FTP daemon");
LOGERR("Failed to init FTP daemon");
delete m_pFTPDaemon;
m_pFTPDaemon = nullptr;
}
else
m_pLogger->Write(MT32PiName, LogNotice, "FTP daemon initialized");
LOGNOTE("FTP daemon initialized");
}
}
else if (m_bNetworkReady && !bNetIsRunning)
{
m_bNetworkReady = false;
m_pLogger->Write(MT32PiName, LogNotice, "Network disconnected.");
LOGNOTE("Network disconnected.");
LCDLog(TLCDLogType::Notice, "%s disconnected!", GetNetworkDeviceShortName());
}
@@ -987,7 +986,7 @@ size_t CMT32Pi::ReceiveSerialMIDI(u8* pOutData, size_t nSize)
break;
}
m_pLogger->Write(MT32PiName, LogWarning, pErrorString);
LOGWARN(pErrorString);
LCDLog(TLCDLogType::Warning, pErrorString);
}
@@ -1000,7 +999,7 @@ size_t CMT32Pi::ReceiveSerialMIDI(u8* pOutData, size_t nSize)
int nSendResult = m_pSerial->Write(pOutData, nResult);
if (nSendResult != nResult)
{
m_pLogger->Write(MT32PiName, LogError, "received %d bytes, but only sent %d bytes", nResult, nSendResult);
LOGERR("received %d bytes, but only sent %d bytes", nResult, nSendResult);
LCDLog(TLCDLogType::Error, "UART TX error!");
}
}
@@ -1140,7 +1139,7 @@ void CMT32Pi::SwitchSynth(TSynth NewSynth)
m_pCurrentSynth->AllSoundOff();
m_pCurrentSynth = pNewSynth;
const char* pMode = NewSynth == TSynth::MT32 ? "MT-32 mode" : "SoundFont mode";
m_pLogger->Write(MT32PiName, LogNotice, "Switching to %s", pMode);
LOGNOTE("Switching to %s", pMode);
LCDLog(TLCDLogType::Notice, pMode);
}
@@ -1149,7 +1148,7 @@ void CMT32Pi::SwitchMT32ROMSet(TMT32ROMSet ROMSet)
if (m_pMT32Synth == nullptr)
return;
m_pLogger->Write(MT32PiName, LogNotice, "Switching to ROM set %d", static_cast<u8>(ROMSet));
LOGNOTE("Switching to ROM set %d", static_cast<u8>(ROMSet));
if (m_pMT32Synth->SwitchROMSet(ROMSet) && m_pCurrentSynth == m_pMT32Synth)
m_pMT32Synth->ReportStatus();
}
@@ -1159,7 +1158,7 @@ void CMT32Pi::NextMT32ROMSet()
if (m_pMT32Synth == nullptr)
return;
m_pLogger->Write(MT32PiName, LogNotice, "Switching to next ROM set");
LOGNOTE("Switching to next ROM set");
if (m_pMT32Synth->NextROMSet() && m_pCurrentSynth == m_pMT32Synth)
m_pMT32Synth->ReportStatus();
@@ -1170,7 +1169,7 @@ void CMT32Pi::SwitchSoundFont(size_t nIndex)
if (m_pSoundFontSynth == nullptr)
return;
m_pLogger->Write(MT32PiName, LogNotice, "Switching to SoundFont %d", nIndex);
LOGNOTE("Switching to SoundFont %d", nIndex);
if (m_pSoundFontSynth->SwitchSoundFont(nIndex))
{
// Handle any MIDI data that has been queued up while busy
@@ -1268,7 +1267,7 @@ void CMT32Pi::USBMIDIDeviceRemovedHandler(CDevice* pDevice, void* pContext)
// Re-enable serial MIDI if not in-use by logger and no other MIDI devices available
if (s_pThis->m_bSerialMIDIAvailable && !(s_pThis->m_pUSBMIDIDevice || s_pThis->m_pUSBSerialDevice || s_pThis->m_pPisound))
{
s_pThis->m_pLogger->Write(MT32PiName, LogNotice, "Using serial MIDI interface");
LOGNOTE("Using serial MIDI interface");
s_pThis->m_bSerialMIDIEnabled = true;
}
}
@@ -1287,7 +1286,7 @@ void CMT32Pi::IRQMIDIReceiveHandler(const u8* pData, size_t nSize)
if (s_pThis->m_MIDIRxBuffer.Enqueue(pData, nSize) != nSize)
{
static const char* pErrorString = "MIDI overrun error!";
s_pThis->m_pLogger->Write(MT32PiName, LogWarning, pErrorString);
LOGWARN(pErrorString);
s_pThis->LCDLog(TLCDLogType::Error, pErrorString);
}
}
@@ -1308,7 +1307,7 @@ void CMT32Pi::PanicHandler()
s_pThis->m_pLCD->Print(pGuru, nOffsetX, 0, true, true);
char Buffer[LOGGER_BUFSIZE];
s_pThis->m_pLogger->Read(Buffer, sizeof(Buffer), false);
CLogger::Get()->Read(Buffer, sizeof(Buffer), false);
// Find last newline
char* pMessageStart = strrchr(Buffer, '\n');

View File

@@ -33,6 +33,8 @@
// #define APPLEMIDI_DEBUG
LOGMODULE("applemidi");
constexpr u16 ControlPort = 5004;
constexpr u16 MIDIPort = ControlPort + 1;
@@ -54,8 +56,6 @@ constexpr unsigned int SyncTimeout = 60 * 10000;
// Receiver feedback packet frequency (1 second in 100 microsecond units)
constexpr unsigned int ReceiverFeedbackPeriod = 1 * 10000;
const char AppleMIDIName[] = "applemidi";
constexpr u16 CommandWord(const char Command[2]) { return Command[0] << 8 | Command[1]; }
enum TAppleMIDICommand : u16
@@ -240,7 +240,7 @@ size_t ParseSysExCommand(const u8* pBuffer, size_t nSize, CAppleMIDIHandler* pHa
if (nHead == 0xF0 && nTail == 0xF0)
{
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "Received segmented SysEx (first)");
LOGNOTE("Received segmented SysEx (first)");
#endif
--nReceiveLength;
}
@@ -249,7 +249,7 @@ size_t ParseSysExCommand(const u8* pBuffer, size_t nSize, CAppleMIDIHandler* pHa
else if (nHead == 0xF7 && nTail == 0xF0)
{
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "Received segmented SysEx (middle)");
LOGNOTE("Received segmented SysEx (middle)");
#endif
++pBuffer;
nBytesParsed -= 2;
@@ -259,7 +259,7 @@ size_t ParseSysExCommand(const u8* pBuffer, size_t nSize, CAppleMIDIHandler* pHa
else if (nHead == 0xF7 && nTail == 0xF7)
{
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "Received segmented SysEx (last)");
LOGNOTE("Received segmented SysEx (last)");
#endif
++pBuffer;
--nReceiveLength;
@@ -269,7 +269,7 @@ size_t ParseSysExCommand(const u8* pBuffer, size_t nSize, CAppleMIDIHandler* pHa
else if (nHead == 0xF7 && nTail == 0xF4)
{
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "Received cancelled SysEx");
LOGNOTE("Received cancelled SysEx");
#endif
nReceiveLength = 1;
}
@@ -277,7 +277,7 @@ size_t ParseSysExCommand(const u8* pBuffer, size_t nSize, CAppleMIDIHandler* pHa
#ifdef APPLEMIDI_DEBUG
else
{
CLogger::Get()->Write(AppleMIDIName, LogNotice, "Received complete SysEx");
LOGNOTE("Received complete SysEx");
}
#endif
@@ -396,7 +396,7 @@ bool ParseMIDICommandSection(const u8* pBuffer, size_t nSize, CAppleMIDIHandler*
if (nMIDICommandLength > nBytesRemaining)
{
CLogger::Get()->Write(AppleMIDIName, LogError, "Invalid MIDI command length");
LOGERR("Invalid MIDI command length");
return false;
}
@@ -507,7 +507,6 @@ bool CAppleMIDIParticipant::Initialize()
assert(m_pControlSocket == nullptr);
assert(m_pMIDISocket == nullptr);
CLogger* const pLogger = CLogger::Get();
CNetSubSystem* const pNet = CNetSubSystem::Get();
if ((m_pControlSocket = new CSocket(pNet, IPPROTO_UDP)) == nullptr)
@@ -518,13 +517,13 @@ bool CAppleMIDIParticipant::Initialize()
if (m_pControlSocket->Bind(ControlPort) != 0)
{
pLogger->Write(AppleMIDIName, LogError, "Couldn't bind to port %d", ControlPort);
LOGERR("Couldn't bind to port %d", ControlPort);
return false;
}
if (m_pMIDISocket->Bind(MIDIPort) != 0)
{
pLogger->Write(AppleMIDIName, LogError, "Couldn't bind to port %d", MIDIPort);
LOGERR("Couldn't bind to port %d", MIDIPort);
return false;
}
@@ -539,16 +538,15 @@ void CAppleMIDIParticipant::Run()
assert(m_pControlSocket != nullptr);
assert(m_pMIDISocket != nullptr);
CLogger* const pLogger = CLogger::Get();
CScheduler* const pScheduler = CScheduler::Get();
while (true)
{
if ((m_nControlResult = m_pControlSocket->ReceiveFrom(m_ControlBuffer, sizeof(m_ControlBuffer), MSG_DONTWAIT, &m_ForeignControlIPAddress, &m_nForeignControlPort)) < 0)
pLogger->Write(AppleMIDIName, LogError, "Control socket receive error: %d", m_nControlResult);
LOGERR("Control socket receive error: %d", m_nControlResult);
if ((m_nMIDIResult = m_pMIDISocket->ReceiveFrom(m_MIDIBuffer, sizeof(m_MIDIBuffer), MSG_DONTWAIT, &m_ForeignMIDIIPAddress, &m_nForeignMIDIPort)) < 0)
pLogger->Write(AppleMIDIName, LogError, "MIDI socket receive error: %d", m_nMIDIResult);
LOGERR("MIDI socket receive error: %d", m_nMIDIResult);
switch (m_State)
{
@@ -572,7 +570,6 @@ void CAppleMIDIParticipant::Run()
void CAppleMIDIParticipant::ControlInvitationState()
{
CLogger* const pLogger = CLogger::Get();
TAppleMIDISession SessionPacket;
if (m_nControlResult == 0)
@@ -580,12 +577,12 @@ void CAppleMIDIParticipant::ControlInvitationState()
if (!ParseInvitationPacket(m_ControlBuffer, m_nControlResult, &SessionPacket))
{
pLogger->Write(AppleMIDIName, LogError, "Unexpected packet");
LOGERR("Unexpected packet");
return;
}
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "<-- Control invitation");
LOGNOTE("<-- Control invitation");
#endif
// Store initiator details
@@ -598,7 +595,7 @@ void CAppleMIDIParticipant::ControlInvitationState()
m_nSSRC = m_pRandom->GetNumber();
if (!SendAcceptInvitationPacket(m_pControlSocket, &m_InitiatorIPAddress, m_nInitiatorControlPort))
{
pLogger->Write(AppleMIDIName, LogError, "Couldn't accept control invitation");
LOGERR("Couldn't accept control invitation");
return;
}
@@ -608,7 +605,6 @@ void CAppleMIDIParticipant::ControlInvitationState()
void CAppleMIDIParticipant::MIDIInvitationState()
{
CLogger* const pLogger = CLogger::Get();
TAppleMIDISession SessionPacket;
if (m_nControlResult > 0)
@@ -619,7 +615,7 @@ void CAppleMIDIParticipant::MIDIInvitationState()
if (m_ForeignControlIPAddress != m_InitiatorIPAddress || m_nForeignControlPort != m_nInitiatorControlPort)
SendRejectInvitationPacket(m_pControlSocket, &m_ForeignControlIPAddress, m_nForeignControlPort, SessionPacket.nInitiatorToken);
else
pLogger->Write(AppleMIDIName, LogError, "Unexpected packet");
LOGERR("Unexpected packet");
}
}
@@ -627,7 +623,7 @@ void CAppleMIDIParticipant::MIDIInvitationState()
{
if (!ParseInvitationPacket(m_MIDIBuffer, m_nMIDIResult, &SessionPacket))
{
pLogger->Write(AppleMIDIName, LogError, "Unexpected packet");
LOGERR("Unexpected packet");
return;
}
@@ -639,7 +635,7 @@ void CAppleMIDIParticipant::MIDIInvitationState()
}
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "<-- MIDI invitation");
LOGNOTE("<-- MIDI invitation");
#endif
m_nInitiatorMIDIPort = m_nForeignMIDIPort;
@@ -648,14 +644,14 @@ void CAppleMIDIParticipant::MIDIInvitationState()
{
CString IPAddressString;
m_InitiatorIPAddress.Format(&IPAddressString);
pLogger->Write(AppleMIDIName, LogNotice, "Connection to %s (%s) established", SessionPacket.Name, static_cast<const char*>(IPAddressString));
LOGNOTE("Connection to %s (%s) established", SessionPacket.Name, static_cast<const char*>(IPAddressString));
m_nLastSyncTime = GetSyncClock();
m_State = TState::Connected;
m_pHandler->OnAppleMIDIConnect(&m_InitiatorIPAddress, SessionPacket.Name);
}
else
{
pLogger->Write(AppleMIDIName, LogError, "Couldn't accept MIDI invitation");
LOGERR("Couldn't accept MIDI invitation");
Reset();
}
}
@@ -663,15 +659,13 @@ void CAppleMIDIParticipant::MIDIInvitationState()
// Timeout
else if ((GetSyncClock() - m_nLastSyncTime) > InvitationTimeout)
{
pLogger->Write(AppleMIDIName, LogError, "MIDI port invitation timed out");
LOGERR("MIDI port invitation timed out");
Reset();
}
}
void CAppleMIDIParticipant::ConnectedState()
{
CLogger* const pLogger = CLogger::Get();
TAppleMIDISession SessionPacket;
TRTPMIDI MIDIPacket;
TAppleMIDISync SyncPacket;
@@ -681,14 +675,14 @@ void CAppleMIDIParticipant::ConnectedState()
if (ParseEndSessionPacket(m_ControlBuffer, m_nControlResult, &SessionPacket))
{
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "<-- End session");
LOGNOTE("<-- End session");
#endif
if (m_ForeignControlIPAddress == m_InitiatorIPAddress &&
m_nForeignControlPort == m_nInitiatorControlPort &&
SessionPacket.nSSRC == m_nInitiatorSSRC)
{
pLogger->Write(AppleMIDIName, LogNotice, "Initiator ended session");
LOGNOTE("Initiator ended session");
m_pHandler->OnAppleMIDIDisconnect(&m_InitiatorIPAddress, SessionPacket.Name);
Reset();
return;
@@ -700,20 +694,20 @@ void CAppleMIDIParticipant::ConnectedState()
if (m_ForeignControlIPAddress != m_InitiatorIPAddress || m_nForeignControlPort != m_nInitiatorControlPort)
SendRejectInvitationPacket(m_pControlSocket, &m_ForeignControlIPAddress, m_nForeignControlPort, SessionPacket.nInitiatorToken);
else
pLogger->Write(AppleMIDIName, LogError, "Unexpected packet");
LOGERR("Unexpected packet");
}
}
if (m_nMIDIResult > 0)
{
if (m_ForeignMIDIIPAddress != m_InitiatorIPAddress || m_nForeignMIDIPort != m_nInitiatorMIDIPort)
pLogger->Write(AppleMIDIName, LogError, "Unexpected packet");
LOGERR("Unexpected packet");
else if (ParseMIDIPacket(m_MIDIBuffer, m_nMIDIResult, &MIDIPacket, m_pHandler))
m_nSequence = MIDIPacket.nSequence;
else if (ParseSyncPacket(m_MIDIBuffer, m_nMIDIResult, &SyncPacket))
{
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "<-- Sync %d", SyncPacket.nCount);
LOGNOTE("<-- Sync %d", SyncPacket.nCount);
#endif
if (SyncPacket.nSSRC == m_nInitiatorSSRC && (SyncPacket.nCount == 0 || SyncPacket.nCount == 2))
@@ -724,7 +718,7 @@ void CAppleMIDIParticipant::ConnectedState()
{
m_nOffsetEstimate = ((SyncPacket.Timestamps[2] + SyncPacket.Timestamps[0]) / 2) - SyncPacket.Timestamps[1];
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "Offset estimate: %llu", m_nOffsetEstimate);
LOGNOTE("Offset estimate: %llu", m_nOffsetEstimate);
#endif
}
@@ -732,7 +726,7 @@ void CAppleMIDIParticipant::ConnectedState()
}
else
{
pLogger->Write(AppleMIDIName, LogError, "Unexpected sync packet");
LOGERR("Unexpected sync packet");
}
}
}
@@ -751,7 +745,7 @@ void CAppleMIDIParticipant::ConnectedState()
if ((nTicks - m_nLastSyncTime) > SyncTimeout)
{
pLogger->Write(AppleMIDIName, LogError, "Initiator timed out");
LOGERR("Initiator timed out");
Reset();
}
}
@@ -775,24 +769,22 @@ void CAppleMIDIParticipant::Reset()
bool CAppleMIDIParticipant::SendPacket(CSocket* pSocket, CIPAddress* pIPAddress, u16 nPort, const void* pData, size_t nSize)
{
CLogger* const pLogger = CLogger::Get();
const int nResult = pSocket->SendTo(pData, nSize, MSG_DONTWAIT, *pIPAddress, nPort);
if (nResult < 0)
{
pLogger->Write(AppleMIDIName, LogError, "Send failure, error code: %d", nResult);
LOGERR("Send failure, error code: %d", nResult);
return false;
}
if (static_cast<size_t>(nResult) != nSize)
{
pLogger->Write(AppleMIDIName, LogError, "Send failure, only %d/%d bytes sent", nResult, nSize);
LOGERR("Send failure, only %d/%d bytes sent", nResult, nSize);
return false;
}
#ifdef APPLEMIDI_DEBUG
pLogger->Write(AppleMIDIName, LogNotice, "Sent %d bytes to port %d", nResult, nPort);
LOGNOTE("Sent %d bytes to port %d", nResult, nPort);
#endif
return true;
@@ -814,7 +806,7 @@ bool CAppleMIDIParticipant::SendAcceptInvitationPacket(CSocket* pSocket, CIPAddr
strncpy(AcceptPacket.Name, "mt32-pi", sizeof(AcceptPacket.Name));
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "--> Accept invitation");
LOGNOTE("--> Accept invitation");
#endif
const size_t nSendSize = NamelessSessionPacketSize + strlen(AcceptPacket.Name) + 1;
@@ -834,7 +826,7 @@ bool CAppleMIDIParticipant::SendRejectInvitationPacket(CSocket* pSocket, CIPAddr
};
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "--> Reject invitation");
LOGNOTE("--> Reject invitation");
#endif
// Send without name
@@ -858,7 +850,7 @@ bool CAppleMIDIParticipant::SendSyncPacket(u64 nTimestamp1, u64 nTimestamp2)
};
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "--> Sync 1");
LOGNOTE("--> Sync 1");
#endif
return SendPacket(m_pMIDISocket, &m_InitiatorIPAddress, m_nInitiatorMIDIPort, &SyncPacket, sizeof(SyncPacket));
@@ -875,7 +867,7 @@ bool CAppleMIDIParticipant::SendFeedbackPacket()
};
#ifdef APPLEMIDI_DEBUG
CLogger::Get()->Write(AppleMIDIName, LogNotice, "--> Feedback");
LOGNOTE("--> Feedback");
#endif
return SendPacket(m_pControlSocket, &m_InitiatorIPAddress, m_nInitiatorControlPort, &FeedbackPacket, sizeof(FeedbackPacket));

View File

@@ -29,7 +29,7 @@
#include "net/ftpdaemon.h"
#include "net/ftpworker.h"
const char FTPDaemonName[] = "ftpd";
LOGMODULE("ftpd");
constexpr u16 ListenPort = 21;
constexpr u8 MaxConnections = 1;
@@ -50,7 +50,6 @@ CFTPDaemon::~CFTPDaemon()
bool CFTPDaemon::Initialize()
{
CLogger* const pLogger = CLogger::Get();
CNetSubSystem* const pNet = CNetSubSystem::Get();
if ((m_pListenSocket = new CSocket(pNet, IPPROTO_TCP)) == nullptr)
@@ -58,13 +57,13 @@ bool CFTPDaemon::Initialize()
if (m_pListenSocket->Bind(ListenPort) != 0)
{
pLogger->Write(FTPDaemonName, LogError, "Couldn't bind to port %d", ListenPort);
LOGERR("Couldn't bind to port %d", ListenPort);
return false;
}
if (m_pListenSocket->Listen() != 0)
{
pLogger->Write(FTPDaemonName, LogError, "Failed to listen on control socket");
LOGERR("Failed to listen on control socket");
return false;
}
@@ -78,32 +77,31 @@ void CFTPDaemon::Run()
{
assert(m_pListenSocket != nullptr);
CLogger* const pLogger = CLogger::Get();
pLogger->Write(FTPDaemonName, LogNotice, "Listener task spawned");
LOGNOTE("Listener task spawned");
while (true)
{
CIPAddress ClientIPAddress;
u16 nClientPort;
pLogger->Write(FTPDaemonName, LogDebug, "Listener: waiting for connection");
LOGDBG("Listener: waiting for connection");
CSocket* pConnection = m_pListenSocket->Accept(&ClientIPAddress, &nClientPort);
if (pConnection == nullptr)
{
pLogger->Write(FTPDaemonName, LogError, "Unable to accept connection");
LOGERR("Unable to accept connection");
continue;
}
CString IPAddressString;
ClientIPAddress.Format(&IPAddressString);
pLogger->Write(FTPDaemonName, LogNotice, "Incoming connection from %s:%d", static_cast<const char*>(IPAddressString), nClientPort);
LOGNOTE("Incoming connection from %s:%d", static_cast<const char*>(IPAddressString), nClientPort);
if (CFTPWorker::GetInstanceCount() >= MaxConnections)
{
pConnection->Send("421 Maximum number of connections reached.\r\n", 45, 0);
delete pConnection;
pLogger->Write(FTPDaemonName, LogWarning, "Maximum number of connections reached");
LOGWARN("Maximum number of connections reached");
continue;
}

View File

@@ -34,6 +34,9 @@
#include "net/ftpworker.h"
#include "utility.h"
// Use a per-instance name for the log macros
#define From m_LogName
constexpr u16 PassivePortBase = 9000;
constexpr size_t TextBufferSize = 512;
constexpr unsigned int SocketTimeout = 20;
@@ -153,7 +156,7 @@ CFTPWorker::~CFTPWorker()
--s_nInstanceCount;
CLogger::Get()->Write(m_LogName, LogNotice, "Instance count is now %d", s_nInstanceCount);
LOGNOTE("Instance count is now %d", s_nInstanceCount);
}
void CFTPWorker::Run()
@@ -161,10 +164,9 @@ void CFTPWorker::Run()
assert(m_pControlSocket != nullptr);
const size_t nWorkerNumber = s_nInstanceCount;
CLogger* const pLogger = CLogger::Get();
CScheduler* const pScheduler = CScheduler::Get();
pLogger->Write(m_LogName, LogNotice, "Worker task %d spawned", nWorkerNumber);
LOGNOTE("Worker task %d spawned", nWorkerNumber);
if (!SendStatus(TFTPStatus::ReadyForNewUser, MOTDBanner))
return;
@@ -176,7 +178,7 @@ void CFTPWorker::Run()
{
// Block while waiting to receive
#ifdef FTPDAEMON_DEBUG
pLogger->Write(m_LogName, LogDebug, "Waiting for command");
LOGDBG("Waiting for command");
#endif
const int nReceiveBytes = m_pControlSocket->Receive(m_CommandBuffer, sizeof(m_CommandBuffer), MSG_DONTWAIT);
@@ -184,7 +186,7 @@ void CFTPWorker::Run()
{
if (pTimer->GetTicks() - nTimeout >= SocketTimeout * HZ)
{
CLogger::Get()->Write(m_LogName, LogError, "Socket timed out");
LOGERR("Socket timed out");
break;
}
@@ -194,7 +196,7 @@ void CFTPWorker::Run()
if (nReceiveBytes < 0)
{
pLogger->Write(m_LogName, LogNotice, "Connection closed");
LOGNOTE("Connection closed");
break;
}
@@ -203,7 +205,7 @@ void CFTPWorker::Run()
#ifdef FTPDAEMON_DEBUG
const u8* pIPAddress = m_pControlSocket->GetForeignIP();
pLogger->Write(m_LogName, LogDebug, "<-- Received %d bytes from %d.%d.%d.%d: '%s'", nReceiveBytes, pIPAddress[0], pIPAddress[1], pIPAddress[2], pIPAddress[3], m_CommandBuffer);
LOGDBG("<-- Received %d bytes from %d.%d.%d.%d: '%s'", nReceiveBytes, pIPAddress[0], pIPAddress[1], pIPAddress[2], pIPAddress[3], m_CommandBuffer);
#endif
char* pSavePtr;
@@ -211,7 +213,7 @@ void CFTPWorker::Run()
if (!pToken)
{
pLogger->Write(m_LogName, LogError, "String tokenization error (received: '%s')", m_CommandBuffer);
LOGERR("String tokenization error (received: '%s')", m_CommandBuffer);
continue;
}
@@ -233,7 +235,7 @@ void CFTPWorker::Run()
nTimeout = pTimer->GetTicks();
}
pLogger->Write(m_LogName, LogNotice, "Worker task %d shutting down", nWorkerNumber);
LOGNOTE("Worker task %d shutting down", nWorkerNumber);
delete m_pControlSocket;
m_pControlSocket = nullptr;
@@ -279,7 +281,7 @@ CSocket* CFTPWorker::OpenDataConnection()
if (pDataSocket == nullptr)
{
CLogger::Get()->Write(m_LogName, LogError, "Unable to open data socket after %d attempts", NumRetries);
LOGERR("Unable to open data socket after %d attempts", NumRetries);
SendStatus(TFTPStatus::DataConnectionFailed, "Couldn't open data connection.");
}
@@ -289,19 +291,18 @@ CSocket* CFTPWorker::OpenDataConnection()
bool CFTPWorker::SendStatus(TFTPStatus StatusCode, const char* pMessage)
{
assert(m_pControlSocket != nullptr);
CLogger* pLogger = CLogger::Get();
const int nLength = snprintf(m_CommandBuffer, sizeof(m_CommandBuffer), "%d %s\r\n", StatusCode, pMessage);
if (m_pControlSocket->Send(m_CommandBuffer, nLength, 0) < 0)
{
pLogger->Write(m_LogName, LogError, "Failed to send status");
LOGERR("Failed to send status");
return false;
}
#ifdef FTPDAEMON_DEBUG
else
{
m_CommandBuffer[nLength - 2] = '\0';
pLogger->Write(m_LogName, LogDebug, "--> Sent: '%s'", m_CommandBuffer);
LOGDBG("--> Sent: '%s'", m_CommandBuffer);
}
#endif
@@ -311,9 +312,8 @@ bool CFTPWorker::SendStatus(TFTPStatus StatusCode, const char* pMessage)
bool CFTPWorker::CheckLoggedIn()
{
#ifdef FTPDAEMON_DEBUG
CLogger* pLogger = CLogger::Get();
pLogger->Write(m_LogName, LogDebug, "Username compare: expected '%s', actual '%s'", static_cast<const char*>(m_pExpectedUser), static_cast<const char*>(m_User));
pLogger->Write(m_LogName, LogDebug, "Password compare: expected '%s', actual '%s'", static_cast<const char*>(m_pExpectedPassword), static_cast<const char*>(m_Password));
LOGDBG("Username compare: expected '%s', actual '%s'", static_cast<const char*>(m_pExpectedUser), static_cast<const char*>(m_User));
LOGDBG("Password compare: expected '%s', actual '%s'", static_cast<const char*>(m_pExpectedPassword), static_cast<const char*>(m_Password));
#endif
if (m_User.Compare(m_pExpectedUser) == 0 && m_Password.Compare(m_pExpectedPassword) == 0)
@@ -507,7 +507,7 @@ bool CFTPWorker::Port(const char* pArgs)
#ifdef FTPDAEMON_DEBUG
CString IPAddressString;
m_DataSocketIPAddress.Format(&IPAddressString);
CLogger::Get()->Write(m_LogName, LogDebug, "PORT set to: %s:%d", static_cast<const char*>(IPAddressString), m_nDataSocketPort);
LOGDBG("PORT set to: %s:%d", static_cast<const char*>(IPAddressString), m_nDataSocketPort);
#endif
SendStatus(TFTPStatus::Success, "Command OK.");
@@ -635,7 +635,7 @@ bool CFTPWorker::Retrieve(const char* pArgs)
{
UINT nBytesRead;
#ifdef FTPDAEMON_DEBUG
CLogger::Get()->Write(m_LogName, LogDebug, "Sending data");
LOGDBG("Sending data");
#endif
if (f_read(&File, m_DataBuffer, sizeof(m_DataBuffer), &nBytesRead) != FR_OK || pDataSocket->Send(m_DataBuffer, nBytesRead, 0) < 0)
{
@@ -687,7 +687,7 @@ bool CFTPWorker::Store(const char* pArgs)
while (true)
{
#ifdef FTPDAEMON_DEBUG
CLogger::Get()->Write(m_LogName, LogDebug, "Waiting to receive");
LOGDBG("Waiting to receive");
#endif
int nReceiveResult = pDataSocket->Receive(m_DataBuffer, sizeof(m_DataBuffer), MSG_DONTWAIT);
FRESULT nWriteResult;
@@ -697,7 +697,7 @@ bool CFTPWorker::Store(const char* pArgs)
{
if (pTimer->GetTicks() - nTimeout >= SocketTimeout * HZ)
{
CLogger::Get()->Write(m_LogName, LogError, "Socket timed out");
LOGERR("Socket timed out");
bSuccess = false;
break;
}
@@ -708,17 +708,17 @@ bool CFTPWorker::Store(const char* pArgs)
// All done
if (nReceiveResult < 0)
{
CLogger::Get()->Write(m_LogName, LogNotice, "Receive done, no more data");
LOGNOTE("Receive done, no more data");
break;
}
#ifdef FTPDAEMON_DEBUG
//CLogger::Get()->Write(m_LogName, LogDebug, "Received %d bytes", nReceiveResult);
//LOGDBG("Received %d bytes", nReceiveResult);
#endif
if ((nWriteResult = f_write(&File, m_DataBuffer, nReceiveResult, &nWritten)) != FR_OK)
{
CLogger::Get()->Write(m_LogName, LogError, "Write FAILED, return code %d", nWriteResult);
LOGERR("Write FAILED, return code %d", nWriteResult);
bSuccess = false;
break;
}
@@ -735,7 +735,7 @@ bool CFTPWorker::Store(const char* pArgs)
SendStatus(TFTPStatus::ActionAborted, "File action aborted, local error.");
#ifdef FTPDAEMON_DEBUG
CLogger::Get()->Write(m_LogName, LogDebug, "Closing socket/file");
LOGDBG("Closing socket/file");
#endif
delete pDataSocket;
f_close(&File);

View File

@@ -27,9 +27,9 @@
#include "net/udpmidi.h"
constexpr u16 MIDIPort = 1999;
LOGMODULE("udpmidi");
const char UDPMIDIName[] = "udpmidi";
constexpr u16 MIDIPort = 1999;
CUDPMIDIReceiver::CUDPMIDIReceiver(CUDPMIDIHandler* pHandler)
: CTask(TASK_STACK_SIZE, true),
@@ -49,7 +49,6 @@ bool CUDPMIDIReceiver::Initialize()
{
assert(m_pMIDISocket == nullptr);
CLogger* const pLogger = CLogger::Get();
CNetSubSystem* const pNet = CNetSubSystem::Get();
if ((m_pMIDISocket = new CSocket(pNet, IPPROTO_UDP)) == nullptr)
@@ -57,7 +56,7 @@ bool CUDPMIDIReceiver::Initialize()
if (m_pMIDISocket->Bind(MIDIPort) != 0)
{
pLogger->Write(UDPMIDIName, LogError, "Couldn't bind to port %d", MIDIPort);
LOGERR("Couldn't bind to port %d", MIDIPort);
return false;
}
@@ -72,7 +71,6 @@ void CUDPMIDIReceiver::Run()
assert(m_pHandler != nullptr);
assert(m_pMIDISocket != nullptr);
CLogger* const pLogger = CLogger::Get();
CScheduler* const pScheduler = CScheduler::Get();
while (true)
@@ -81,7 +79,7 @@ void CUDPMIDIReceiver::Run()
const int nMIDIResult = m_pMIDISocket->Receive(m_MIDIBuffer, sizeof(m_MIDIBuffer), 0);
if (nMIDIResult < 0)
pLogger->Write(UDPMIDIName, LogError, "MIDI socket receive error: %d", nMIDIResult);
LOGERR("MIDI socket receive error: %d", nMIDIResult);
else if (nMIDIResult > 0)
m_pHandler->OnUDPMIDIDataReceived(m_MIDIBuffer, nMIDIResult);

View File

@@ -28,6 +28,8 @@
#include "pisound.h"
LOGMODULE("pisound");
constexpr u8 SPIChipSelect = 0;
constexpr u8 SPIDelayMicroseconds = 10;
constexpr u32 SPIClockSpeed = 150000;
@@ -43,8 +45,6 @@ constexpr u8 GPIOOversamplingRatio2 = 16;
constexpr u8 GPIOSPIReset = 24;
constexpr u8 GPIOSPIDataAvailable = 25;
const char PisoundName[] = "pisound";
// Based on: https://github.com/raspberrypi/linux/blob/rpi-5.4.y/sound/soc/bcm/pisound.c
// https://github.com/raspberrypi/linux/blob/rpi-5.4.y/arch/arm/boot/dts/overlays/pisound-overlay.dts
@@ -86,8 +86,6 @@ bool CPisound::Initialize()
{
assert(m_pSPIMaster != nullptr);
CLogger* const pLogger = CLogger::Get();
// Set the oversampling ratio pins
switch (m_nSamplerate)
{
@@ -128,10 +126,10 @@ bool CPisound::Initialize()
// Flash the LEDs
Transfer16(0xF008);
pLogger->Write(PisoundName, LogNotice, "Serial number: %s", m_SerialNumber);
pLogger->Write(PisoundName, LogNotice, "ID: %s", m_ID);
pLogger->Write(PisoundName, LogNotice, "Firmware version: %s", m_FirmwareVersion);
pLogger->Write(PisoundName, LogNotice, "Hardware version: %s", m_HardwareVersion);
LOGNOTE("Serial number: %s", m_SerialNumber);
LOGNOTE("ID: %s", m_ID);
LOGNOTE("Firmware version: %s", m_FirmwareVersion);
LOGNOTE("Hardware version: %s", m_HardwareVersion);
return true;
}

View File

@@ -27,7 +27,7 @@
#include "power.h"
const char PowerName[] = "power";
LOGMODULE("power");
// Bits in the throttled status response
constexpr u32 UnderVoltageOccurredBit = 1 << 16;
@@ -72,22 +72,22 @@ void CPower::Awaken()
void CPower::OnEnterPowerSavingMode()
{
CLogger::Get()->Write(PowerName, LogNotice, "Entering power saving mode");
LOGNOTE("Entering power saving mode");
}
void CPower::OnExitPowerSavingMode()
{
CLogger::Get()->Write(PowerName, LogNotice, "Leaving power saving mode");
LOGNOTE("Leaving power saving mode");
}
void CPower::OnThrottleDetected()
{
CLogger::Get()->Write(PowerName, LogWarning, "CPU throttling by firmware detected; check power supply/cooling");
LOGWARN("CPU throttling by firmware detected; check power supply/cooling");
}
void CPower::OnUnderVoltageDetected()
{
CLogger::Get()->Write(PowerName, LogWarning, "Undervoltage detected; check power supply");
LOGWARN("Undervoltage detected; check power supply");
}
void CPower::UpdateThrottledStatus()

View File

@@ -25,7 +25,7 @@
#include "rommanager.h"
const char ROMManagerName[] = "rommanager";
LOGMODULE("rommanager");
const char* const Disks[] = { "SD", "USB" };
const char ROMDirectory[] = "roms";
@@ -229,7 +229,7 @@ bool CROMManager::CheckROM(const char* pPath)
CROMFile* pFile = new CROMFile();
if (!pFile->open(pPath))
{
CLogger::Get()->Write(ROMManagerName, LogError, "Couldn't open '%s' for reading", pPath);
LOGERR("Couldn't open '%s' for reading", pPath);
delete pFile;
return false;
}

View File

@@ -30,7 +30,7 @@
#include "soundfontmanager.h"
#include "utility.h"
const char SoundFontManagerName[] = "soundfontmanager";
LOGMODULE("soundfontmanager");
const char* const Disks[] = { "SD", "USB" };
const char SoundFontDirectory[] = "soundfonts";
@@ -99,10 +99,9 @@ bool CSoundFontManager::ScanSoundFonts()
// Sort into lexicographical order
Utility::QSort(m_SoundFontList, SoundFontListComparator, 0, m_nSoundFonts - 1);
CLogger* const pLogger = CLogger::Get();
pLogger->Write(SoundFontManagerName, LogNotice, "%d SoundFonts found:", m_nSoundFonts);
LOGNOTE("%d SoundFonts found:", m_nSoundFonts);
for (size_t i = 0; i < m_nSoundFonts; ++i)
pLogger->Write(SoundFontManagerName, LogNotice, "%d: %s (%s)", i, static_cast<const char*>(m_SoundFontList[i].Path), static_cast<const char*>(m_SoundFontList[i].Name));
LOGNOTE("%d: %s (%s)", i, static_cast<const char*>(m_SoundFontList[i].Path), static_cast<const char*>(m_SoundFontList[i].Name));
return true;
}
@@ -160,7 +159,7 @@ TFXProfile CSoundFontManager::GetSoundFontFXProfile(size_t nIndex) const
if (f_read(&File, Buffer, nSize, &nRead) != FR_OK)
{
CLogger::Get()->Write(SoundFontManagerName, LogError, "Error reading effects profile");
LOGERR("Error reading effects profile");
f_close(&File);
return FXProfile;
}
@@ -170,7 +169,7 @@ TFXProfile CSoundFontManager::GetSoundFontFXProfile(size_t nIndex) const
const int nResult = ini_parse_string(Buffer, INIHandler, &FXProfile);
if (nResult > 0)
CLogger::Get()->Write(SoundFontManagerName, LogWarning, "Effects profile parse error on line %d", nResult);
LOGWARN("Effects profile parse error on line %d", nResult);
f_close(&File);
return FXProfile;

View File

@@ -28,7 +28,7 @@
#include "synth/mt32synth.h"
#include "utility.h"
const char MT32SynthName[] = "mt32synth";
LOGMODULE("mt32synth");
constexpr size_t ROMOffsetVersionStringOld = 0x4015;
constexpr size_t ROMOffsetVersionString1_07 = 0x4011;
@@ -331,23 +331,23 @@ void CMT32Synth::GetPartLevels(unsigned int nTicks, float PartLevels[9], float P
bool CMT32Synth::onMIDIQueueOverflow()
{
CLogger::Get()->Write(MT32SynthName, LogError, "MIDI queue overflow");
LOGERR("MIDI queue overflow");
return false;
}
void CMT32Synth::printDebug(const char* pFmt, va_list pList)
{
//CLogger::Get()->WriteV(MT32SynthName, LogDebug, pFmt, pList);
//LOGDBG(pFmt, pList);
}
void CMT32Synth::showLCDMessage(const char* pMessage)
{
CLogger::Get()->Write(MT32SynthName, LogNotice, "LCD: %s", pMessage);
LOGNOTE("LCD: %s", pMessage);
}
void CMT32Synth::onDeviceReset()
{
CLogger::Get()->Write(MT32SynthName, LogDebug, "MT-32 reset");
LOGDBG("MT-32 reset");
m_MIDIMonitor.AllNotesOff();
m_MIDIMonitor.ResetControllers(false);
}

View File

@@ -33,7 +33,7 @@
#include "utility.h"
#include "zoneallocator.h"
const char SoundFontSynthName[] = "soundfontsynth";
LOGMODULE("soundfontsynth");
const char SoundFontPath[] = "soundfonts";
extern "C"
@@ -154,7 +154,7 @@ CSoundFontSynth::~CSoundFontSynth()
void CSoundFontSynth::FluidSynthLogCallback(int nLevel, const char* pMessage, void* pUser)
{
CLogger::Get()->Write(SoundFontSynthName, static_cast<TLogSeverity>(nLevel), pMessage);
CLogger::Get()->Write(From, static_cast<TLogSeverity>(nLevel), pMessage);
}
bool CSoundFontSynth::Initialize()
@@ -191,7 +191,7 @@ bool CSoundFontSynth::Initialize()
m_pSettings = new_fluid_settings();
if (!m_pSettings)
{
CLogger::Get()->Write(SoundFontSynthName, LogError, "Failed to create settings");
LOGERR("Failed to create settings");
return false;
}
@@ -370,7 +370,7 @@ bool CSoundFontSynth::SwitchSoundFont(size_t nIndex)
m_nCurrentSoundFontIndex = nIndex;
CLogger::Get()->Write(SoundFontSynthName, LogNotice, "Loaded \"%s\"", m_SoundFontManager.GetSoundFontName(nIndex));
LOGNOTE("Loaded \"%s\"", m_SoundFontManager.GetSoundFontName(nIndex));
if (m_pUI)
m_pUI->ClearSpinnerMessage();
@@ -380,7 +380,6 @@ bool CSoundFontSynth::SwitchSoundFont(size_t nIndex)
bool CSoundFontSynth::Reinitialize(const char* pSoundFontPath, const TFXProfile* pFXProfile)
{
const CConfig* const pConfig = CConfig::Get();
CLogger* const pLogger = CLogger::Get();
m_Lock.Acquire();
@@ -392,7 +391,7 @@ bool CSoundFontSynth::Reinitialize(const char* pSoundFontPath, const TFXProfile*
if (!m_pSynth)
{
m_Lock.Release();
pLogger->Write(SoundFontSynthName, LogError, "Failed to create synth");
LOGERR("Failed to create synth");
return false;
}
@@ -426,12 +425,12 @@ bool CSoundFontSynth::Reinitialize(const char* pSoundFontPath, const TFXProfile*
if (fluid_synth_sfload(m_pSynth, pSoundFontPath, true) == FLUID_FAILED)
{
pLogger->Write(SoundFontSynthName, LogError, "Failed to load SoundFont");
LOGERR("Failed to load SoundFont");
return false;
}
const float nLoadTime = (CTimer::GetClockTicks() - nLoadStart) / 1000000.0f;
pLogger->Write(SoundFontSynthName, TLogSeverity::LogNotice, "\"%s\" loaded in %0.2f seconds", pSoundFontPath, nLoadTime);
LOGNOTE("\"%s\" loaded in %0.2f seconds", pSoundFontPath, nLoadTime);
return true;
}
@@ -446,7 +445,6 @@ void CSoundFontSynth::ResetMIDIMonitor()
#ifndef NDEBUG
void CSoundFontSynth::DumpFXSettings() const
{
CLogger* const pLogger = CLogger::Get();
double nGain, nReverbDamping, nReverbLevel, nReverbRoomSize, nReverbWidth, nChorusDepth, nChorusLevel, nChorusSpeed;
int nChorusVoices;
@@ -462,18 +460,16 @@ void CSoundFontSynth::DumpFXSettings() const
assert(fluid_synth_get_chorus_group_nr(m_pSynth, -1, &nChorusVoices) == FLUID_OK);
assert(fluid_synth_get_chorus_group_speed(m_pSynth, -1, &nChorusSpeed) == FLUID_OK);
pLogger->Write(SoundFontSynthName, LogNotice, "Gain: %.2f", nGain);
LOGNOTE("Gain: %.2f", nGain);
pLogger->Write(SoundFontSynthName, LogNotice,
"Reverb: %.2f, %.2f, %.2f, %.2f",
LOGNOTE("Reverb: %.2f, %.2f, %.2f, %.2f",
nReverbDamping,
nReverbLevel,
nReverbRoomSize,
nReverbWidth
);
pLogger->Write(SoundFontSynthName, LogNotice,
"Chorus: %.2f, %.2f, %d, %.2f",
LOGNOTE("Chorus: %.2f, %.2f, %d, %.2f",
nChorusDepth,
nChorusLevel,
nChorusVoices,

View File

@@ -27,13 +27,13 @@
#include "utility.h"
#include "zoneallocator.h"
constexpr size_t MallocHeapSize = 32 * MEGABYTE;
const char ZoneAllocatorName[] = "zoneallocator";
// #define ZONE_ALLOCATOR_DEBUG
// #define ZONE_ALLOCATOR_TRACE
LOGMODULE("zoneallocator");
constexpr size_t MallocHeapSize = 32 * MEGABYTE;
CZoneAllocator* CZoneAllocator::s_pThis = nullptr;
CZoneAllocator::CZoneAllocator()
@@ -55,7 +55,6 @@ CZoneAllocator::~CZoneAllocator()
bool CZoneAllocator::Initialize()
{
CMemorySystem* pMemorySystem = CMemorySystem::Get();
CLogger* pLogger = CLogger::Get();
#if RASPI >= 4
const size_t nHighHeapSize = pMemorySystem->GetHeapFreeSpace(HEAP_HIGH);
@@ -78,24 +77,24 @@ bool CZoneAllocator::Initialize()
if (!m_pHeap)
{
if (m_nHeapSize >= MEGABYTE)
pLogger->Write(ZoneAllocatorName, LogError, "Couldn't allocate a %d megabyte heap", m_nHeapSize / MEGABYTE);
LOGERR("Couldn't allocate a %d megabyte heap", m_nHeapSize / MEGABYTE);
else
pLogger->Write(ZoneAllocatorName, LogError, "Couldn't allocate a %d byte heap", m_nHeapSize);
LOGERR("Couldn't allocate a %d byte heap", m_nHeapSize);
return false;
}
if (m_nHeapSize >= MEGABYTE)
pLogger->Write(ZoneAllocatorName, LogNotice, "Allocated a %d megabyte heap at %p", m_nHeapSize / MEGABYTE, m_pHeap);
LOGNOTE("Allocated a %d megabyte heap at %p", m_nHeapSize / MEGABYTE, m_pHeap);
else
pLogger->Write(ZoneAllocatorName, LogNotice, "Allocated a %d byte heap at %p", m_nHeapSize, m_pHeap);
LOGNOTE("Allocated a %d byte heap at %p", m_nHeapSize, m_pHeap);
#ifdef ZONE_ALLOCATOR_DEBUG
if ((reinterpret_cast<uintptr>(m_pHeap) & 15) == 0)
pLogger->Write(ZoneAllocatorName, LogDebug, "Heap is 16-byte aligned");
LOGDEBUG("Heap is 16-byte aligned");
else
pLogger->Write(ZoneAllocatorName, LogDebug, "Heap is NOT 16-byte aligned");
LOGDEBUG("Heap is NOT 16-byte aligned");
pLogger->Write(ZoneAllocatorName, LogDebug, "Size of block header: %d", sizeof(TBlock));
LOGDEBUG("Size of block header: %d", sizeof(TBlock));
#endif
// Initialize the heap with an empty block
@@ -111,7 +110,7 @@ void* CZoneAllocator::Alloc(size_t nSize, TZoneTag Tag)
if (Tag == TZoneTag::Free)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Zone allocation failed: tag value of 0 was used");
LOGERR("Zone allocation failed: tag value of 0 was used");
return nullptr;
}
@@ -127,7 +126,7 @@ void* CZoneAllocator::Alloc(size_t nSize, TZoneTag Tag)
// We've been through the whole linked list and couldn't find a free block
if (pNextBlock == pStartBlock)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Zone allocation failed: couldn't allocate %d bytes", nSize);
LOGERR("Zone allocation failed: couldn't allocate %d bytes", nSize);
return nullptr;
}
@@ -169,7 +168,7 @@ void* CZoneAllocator::Alloc(size_t nSize, TZoneTag Tag)
m_pCurrentBlock = pCandidateBlock->pNext;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Allocated %d bytes for tag %x", nSize, Tag);
LOGDBG("Allocated %d bytes for tag %x", nSize, Tag);
#endif
// Increment alloc counter
@@ -193,13 +192,13 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
if (Tag == TZoneTag::Free)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Zone reallocation failed: tag value of 0 was used");
LOGERR("Zone reallocation failed: tag value of 0 was used");
return nullptr;
}
if (pBlock->Tag == TZoneTag::Free)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Attempted to reallocate a freed block");
LOGERR("Attempted to reallocate a freed block");
return nullptr;
}
@@ -234,7 +233,7 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
GetEndMagic(pBlock) = BlockMagic;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Expanded block at %p in-place", pPtr);
LOGDBG("Expanded block at %p in-place", pPtr);
#endif
return pBlock + 1;
@@ -248,7 +247,7 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
if (!pDest)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Zone reallocation failed");
LOGERR("Zone reallocation failed");
return nullptr;
}
@@ -256,7 +255,7 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
Free(pPtr);
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Expanded block at %p by allocating new block", pPtr);
LOGDBG("Expanded block at %p by allocating new block", pPtr);
#endif
return pDest;
@@ -277,7 +276,7 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
*pNewBlock = *pBlock->pNext;
pNewBlock->nSize += nRemain;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Shrunk block at %p in-place; adjacent free space expanded", pPtr);
LOGDBG("Shrunk block at %p in-place; adjacent free space expanded", pPtr);
#endif
}
else
@@ -293,7 +292,7 @@ void* CZoneAllocator::Realloc(void* pPtr, size_t nSize, TZoneTag Tag)
#endif
GetEndMagic(pNewBlock) = BlockMagic;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Shrunk block at %p in-place; new free block inserted after", pPtr);
LOGDBG("Shrunk block at %p in-place; new free block inserted after", pPtr);
#endif
}
@@ -330,13 +329,13 @@ void CZoneAllocator::Free(void* pPtr)
if (pBlock->Tag == TZoneTag::Free)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Attempted to free an already-freed block");
LOGERR("Attempted to free an already-freed block");
return;
}
if (pBlock->nMagic != BlockMagic)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Attempted to free a block with a bad magic number (heap corruption?)");
LOGERR("Attempted to free a block with a bad magic number (heap corruption?)");
return;
}
@@ -354,7 +353,7 @@ void CZoneAllocator::Free(void* pPtr)
if (pBlock == m_pCurrentBlock)
m_pCurrentBlock = pAdjacentBlock;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Merged freed block at %p with previous block at %p", pPtr, pAdjacentBlock);
LOGDBG("Merged freed block at %p with previous block at %p", pPtr, pAdjacentBlock);
#endif
pBlock = pAdjacentBlock;
}
@@ -369,7 +368,7 @@ void CZoneAllocator::Free(void* pPtr)
if (pAdjacentBlock == m_pCurrentBlock)
m_pCurrentBlock = pBlock;
#ifdef ZONE_ALLOCATOR_TRACE
CLogger::Get()->Write(ZoneAllocatorName, LogDebug, "Merged freed block at %p with next block at %p", pPtr, pAdjacentBlock);
LOGDBG("Merged freed block at %p with next block at %p", pPtr, pAdjacentBlock);
#endif
}
@@ -408,7 +407,7 @@ void CZoneAllocator::FreeTag(u32 Tag)
{
if (Tag == TZoneTag::Free)
{
CLogger::Get()->Write(ZoneAllocatorName, LogError, "Attempted to free an invalid tag");
LOGERR("Attempted to free an invalid tag");
return;
}
@@ -427,23 +426,22 @@ void CZoneAllocator::FreeTag(u32 Tag)
void CZoneAllocator::Dump() const
{
CLogger* pLogger = CLogger::Get();
pLogger->Write(ZoneAllocatorName, LogNotice, "Allocation diagnostics:");
LOGNOTE("Allocation diagnostics:");
TBlock* pBlock = m_MainBlock.pNext;
do
{
pLogger->Write(ZoneAllocatorName, LogNotice, "Block address %p (%s):", pBlock, pBlock->Tag ? "IN-USE" : "FREE");
LOGNOTE("Block address %p (%s):", pBlock, pBlock->Tag ? "IN-USE" : "FREE");
// If the block is free, it doesn't need a valid tail magic
const bool bMagicOK = (pBlock->nMagic == BlockMagic) && (!pBlock->Tag || GetEndMagic(pBlock) == BlockMagic);
if (!bMagicOK)
pLogger->Write(ZoneAllocatorName, LogWarning, "WARNING: This memory block is probably corrupt!");
LOGWARN("WARNING: This memory block is probably corrupt!");
pLogger->Write(ZoneAllocatorName, LogNotice, "\tSize: %d bytes", pBlock->nSize);
pLogger->Write(ZoneAllocatorName, LogNotice, "\tTag: 0x%x", pBlock->Tag);
pLogger->Write(ZoneAllocatorName, LogNotice, "\tMagic: %s", bMagicOK ? "OK" : "BAD");
LOGNOTE("\tSize: %d bytes", pBlock->nSize);
LOGNOTE("\tTag: 0x%x", pBlock->Tag);
LOGNOTE("\tMagic: %s", bMagicOK ? "OK" : "BAD");
pBlock = pBlock->pNext;
} while (pBlock != &m_MainBlock);
}