Fixed the Logging system to actually be able to handle errors. Database is also fixed to use directories.

This commit is contained in:
2024-04-23 22:29:49 -07:00
parent 2734cc00fb
commit f030ac62ae
61 changed files with 884 additions and 602 deletions

View File

@@ -77,7 +77,7 @@ namespace ehs
if (snd_pcm_hw_params_set_access(hdl, params, SND_PCM_ACCESS_MMAP_INTERLEAVED) < 0)
{
EHS_LOG_INT("Error", 0, "Failed to set access.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to set access.");
return;
}
@@ -113,7 +113,7 @@ namespace ehs
}
default:
{
EHS_LOG_INT("Error", 0, "Invalid data type.");
EHS_LOG_INT(LogType::ERR, 0, "Invalid data type.");
return;
}
}
@@ -125,7 +125,7 @@ namespace ehs
{
if (snd_pcm_hw_params_set_channels_near(hdl, params, &channels) < 0)
{
EHS_LOG_INT("Error", 1, "Failed to set channels.");
EHS_LOG_INT(LogType::ERR, 1, "Failed to set channels.");
return;
}
}
@@ -134,26 +134,26 @@ namespace ehs
{
if (snd_pcm_hw_params_set_rate_near(hdl, params, &sampleRate, nullptr) < 0)
{
EHS_LOG_INT("Error", 2, "Failed to set sample rate.");
EHS_LOG_INT(LogType::ERR, 2, "Failed to set sample rate.");
return;
}
}
if (snd_pcm_hw_params_set_period_time_near(hdl, params, &period, nullptr) < 0)
{
EHS_LOG_INT("Error", 3, "Failed to set period.");
EHS_LOG_INT(LogType::ERR, 3, "Failed to set period.");
return;
}
if (snd_pcm_hw_params_set_buffer_time_near(hdl, params, &latency, nullptr) < 0)
{
EHS_LOG_INT("Error", 4, "Failed to set latency.");
EHS_LOG_INT(LogType::ERR, 4, "Failed to set latency.");
return;
}
if (snd_pcm_hw_params(hdl, params) < 0)
{
EHS_LOG_INT("Error", 5, "Failed to apply hardware parameters.");
EHS_LOG_INT(LogType::ERR, 5, "Failed to apply hardware parameters.");
return;
}
@@ -162,7 +162,7 @@ namespace ehs
snd_pcm_format_t format;
if (snd_pcm_hw_params_get_format(params, &format) < 0)
{
EHS_LOG_INT("Error", 6, "Failed to retrieve audio device properties.");
EHS_LOG_INT(LogType::ERR, 6, "Failed to retrieve audio device properties.");
return;
}
@@ -200,7 +200,7 @@ namespace ehs
}
default:
{
EHS_LOG_INT("Error", 7, "Format unsupported.");
EHS_LOG_INT(LogType::ERR, 7, "Format unsupported.");
break;
}
}
@@ -210,7 +210,7 @@ namespace ehs
{
if (snd_pcm_hw_params_get_channels(params, &channels) < 0)
{
EHS_LOG_INT("Error", 8, "Failed to retrieve channel count.");
EHS_LOG_INT(LogType::ERR, 8, "Failed to retrieve channel count.");
return;
}
}
@@ -220,14 +220,14 @@ namespace ehs
int dir;
if (snd_pcm_hw_params_get_rate(params, &sampleRate, &dir) < 0)
{
EHS_LOG_INT("Error", 9, "Failed to retrieve sample rate.");
EHS_LOG_INT(LogType::ERR, 9, "Failed to retrieve sample rate.");
return;
}
}
if (snd_pcm_hw_params_get_buffer_size(params, &maxFrames) < 0)
{
EHS_LOG_INT("Error", 10, "Failed to retrieve buffer size.");
EHS_LOG_INT(LogType::ERR, 10, "Failed to retrieve buffer size.");
}
snd_pcm_sw_params_t* swParams = nullptr;
@@ -235,31 +235,31 @@ namespace ehs
if (snd_pcm_sw_params_current(hdl, swParams) < 0)
{
EHS_LOG_INT("Error", 11, "Failed to retrieve software parameters.");
EHS_LOG_INT(LogType::ERR, 11, "Failed to retrieve software parameters.");
return;
}
if (snd_pcm_sw_params_set_silence_threshold(hdl, swParams, maxFrames) < 0)
{
EHS_LOG_INT("Error", 12, "Failed to set silence threshold.");
EHS_LOG_INT(LogType::ERR, 12, "Failed to set silence threshold.");
return;
}
if (snd_pcm_sw_params_set_silence_size(hdl, swParams, maxFrames) < 0)
{
EHS_LOG_INT("Error", 12, "Failed to set silence size.");
EHS_LOG_INT(LogType::ERR, 12, "Failed to set silence size.");
return;
}
if (snd_pcm_sw_params(hdl, swParams) < 0)
{
EHS_LOG_INT("Error", 13, "Failed to set software parameters.");
EHS_LOG_INT(LogType::ERR, 13, "Failed to set software parameters.");
return;
}
if (snd_pcm_prepare(hdl) < 0)
{
EHS_LOG_INT("Error", 14, "Failed to prepare audio stream.");
EHS_LOG_INT(LogType::ERR, 14, "Failed to prepare audio stream.");
return;
}
@@ -281,10 +281,10 @@ namespace ehs
snd_pcm_state_t state = snd_pcm_state(hdl);
if (state == SND_PCM_STATE_XRUN)
{
EHS_LOG_INT("Warning", 0, "Buffer overrun/underrun occurred.");
EHS_LOG_INT(LogType::WARN, 0, "Buffer overrun/underrun occurred.");
if (snd_pcm_recover(hdl, -EPIPE, 0) < 0)
{
EHS_LOG_INT("Error", 1, "Failed to recover from buffer overrun/underrun.");
EHS_LOG_INT(LogType::ERR, 1, "Failed to recover from buffer overrun/underrun.");
return 0;
}
return GetAvailFrames();
@@ -293,7 +293,7 @@ namespace ehs
{
if (snd_pcm_start(hdl) < 0)
{
EHS_LOG_INT("Error", 2, "Failed to start audio stream.");
EHS_LOG_INT(LogType::ERR, 2, "Failed to start audio stream.");
return 0;
}
@@ -305,10 +305,10 @@ namespace ehs
{
if (frames == -EPIPE)
{
EHS_LOG_INT("Warning", 3, "Buffer overrun/underrun occurred.");
EHS_LOG_INT(LogType::WARN, 3, "Buffer overrun/underrun occurred.");
if (snd_pcm_recover(hdl, -EPIPE, 1) < 0)
{
EHS_LOG_INT("Error", 4, "Failed to recover from buffer overrun/underrun.");
EHS_LOG_INT(LogType::ERR, 4, "Failed to recover from buffer overrun/underrun.");
return 0;
}
@@ -316,7 +316,7 @@ namespace ehs
}
else
{
EHS_LOG_INT("Error", 5, "Failed to retrieve available frames with error #" + Str_8::FromNum(frames) + ".");
EHS_LOG_INT(LogType::ERR, 5, "Failed to retrieve available frames with error #" + Str_8::FromNum(frames) + ".");
return 0;
}
}
@@ -329,7 +329,7 @@ namespace ehs
const snd_pcm_channel_area_t* areas;
if (snd_pcm_mmap_begin(hdl, &areas, offset, frames) < 0)
{
EHS_LOG_INT("Error", 0, "Failed to map audio buffer.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to map audio buffer.");
return nullptr;
}
@@ -341,7 +341,7 @@ namespace ehs
snd_pcm_sframes_t committed = snd_pcm_mmap_commit(hdl, offset, frames);
if (committed < 0)
{
EHS_LOG_INT("Error", 0, "Failed to commit mapped audio buffer.");
EHS_LOG_INT(LogType::ERR, 0, "Failed to commit mapped audio buffer.");
return;
}
}
@@ -366,7 +366,7 @@ namespace ehs
}
else
{
EHS_LOG_INT("Error", 0, "Wrong value for the audio device type.");
EHS_LOG_INT(LogType::ERR, 0, "Wrong value for the audio device type.");
return {};
}