void PrintStatusUpdate()

in ctsTraffic/ctsConfig.cpp [3208:3288]


void PrintStatusUpdate() noexcept
{
    if (!g_shutdownCalled)
    {
        if (g_printStatusInformation)
        {
            auto writeToConsole = false;
            // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
            switch (g_consoleVerbosity) // NOLINT(hicpp-multiway-paths-covered)
            {
                // case 0: // nothing
                case 1: // status updates
                // case 2: // error info
                // case 3: // connection info
                // case 4: // connection info + error info
                case 5: // connection info + error info + status updates
                case 6: // above + debug info
                {
                    writeToConsole = true;
                }
            }

            if (const auto lock = g_statusUpdateLock.try_lock())
            {
                // capture the timeslices
                const auto lPrevioutimeslice = g_previousPrintTimeslice;
                // ReSharper disable once CppTooWideScopeInitStatement
                const auto lCurrentTimeslice = ctTimer::SnapQpcInMillis() - g_configSettings->StartTimeMilliseconds;

                if (lCurrentTimeslice > lPrevioutimeslice)
                {
                    // write out the header to the console every 40 updates 
                    if (writeToConsole)
                    {
                        if (g_printTimesliceCount != 0 && 0 == g_printTimesliceCount % 40)
                        {
                            if (const auto* header = g_printStatusInformation->PrintHeader(StatusFormatting::ConsoleOutput))
                            {
                                fwprintf(stdout, L"%ws", header);
                            }
                        }
                    }

                    // need to indicate either print_status() or LogStatus() to reset the status info,
                    // - the data *must* be reset once and *only once* in this function

                    auto statusCount = 0;
                    if (writeToConsole)
                    {
                        ++statusCount;
                    }
                    if (g_statusLogger)
                    {
                        ++statusCount;
                    }

                    if (writeToConsole)
                    {
                        --statusCount;
                        const bool clearStatus = 0 == statusCount;
                        if (const auto* printString = g_printStatusInformation->PrintStatus(StatusFormatting::ConsoleOutput, lCurrentTimeslice, clearStatus))
                        {
                            fwprintf(stdout, L"%ws", printString);
                        }
                    }

                    if (g_statusLogger)
                    {
                        --statusCount;
                        const bool clearStatus = 0 == statusCount;
                        g_statusLogger->LogStatus(g_printStatusInformation, lCurrentTimeslice, clearStatus);
                    }

                    // update tracking values
                    g_previousPrintTimeslice = lCurrentTimeslice;
                    ++g_printTimesliceCount;
                }
            }
        }
    }
}