First working jukebox using Subsonic API

This commit is contained in:
emeric
2026-02-17 23:16:52 +01:00
parent c338521843
commit 3963969cec
39 changed files with 1464 additions and 277 deletions
+13 -9
View File
@@ -27,10 +27,11 @@
namespace lms::core
{
IOContextRunner::IOContextRunner(boost::asio::io_context& ioContext, std::size_t threadCount, std::string_view name)
: _ioContext{ ioContext }
: _name{ name }
, _ioContext{ ioContext }
, _work{ boost::asio::make_work_guard(ioContext) }
{
LMS_LOG(UTILS, INFO, "Starting IO context with " << threadCount << " threads...");
LMS_LOG(UTILS, INFO, "Starting IO context '" << _name << "' with " << threadCount << " threads...");
for (std::size_t i{}; i < threadCount; ++i)
{
@@ -61,12 +62,9 @@ namespace lms::core
}
}
void IOContextRunner::stop()
IOContextRunner::~IOContextRunner()
{
LMS_LOG(UTILS, DEBUG, "Stopping IO context...");
_work.reset();
_ioContext.stop();
LMS_LOG(UTILS, DEBUG, "IO context stopped!");
wait();
}
std::size_t IOContextRunner::getThreadCount() const
@@ -74,11 +72,17 @@ namespace lms::core
return _threads.size();
}
IOContextRunner::~IOContextRunner()
void IOContextRunner::wait()
{
stop();
if (_threads.empty())
return;
LMS_LOG(UTILS, DEBUG, "Waiting IO context '" << _name << "'...");
_work.reset();
for (std::thread& t : _threads)
t.join();
LMS_LOG(UTILS, DEBUG, "IO context '" << _name << "' waited!...");
_threads.clear();
}
} // namespace lms::core
+4
View File
@@ -39,6 +39,8 @@ namespace lms::core::logging
return "API_SUBSONIC";
case Module::AUDIO:
return "AUDIO";
case Module::AUDIO_OUTPUT_STREAM:
return "AUDIO_OS";
case Module::AUTH:
return "AUTH";
case Module::CHILDPROCESS:
@@ -55,6 +57,8 @@ namespace lms::core::logging
return "FEEDBACK";
case Module::HTTP:
return "HTTP";
case Module::JUKEBOX:
return "JUKEBOX";
case Module::MAIN:
return "MAIN";
case Module::METADATA:
+3
View File
@@ -37,10 +37,12 @@ namespace lms::core::logging
DEBUG,
};
// TODO remove this and make each module define its name
enum class Module
{
API_SUBSONIC,
AUDIO,
AUDIO_OUTPUT_STREAM,
AUTH,
CHILDPROCESS,
COVER,
@@ -48,6 +50,7 @@ namespace lms::core::logging
DBUPDATER,
FEATURE,
FEEDBACK,
JUKEBOX,
HTTP,
MAIN,
METADATA,
@@ -20,6 +20,7 @@
#pragma once
#include <thread>
#include <vector>
#include <boost/asio/executor_work_guard.hpp>
#include <boost/asio/io_context.hpp>
@@ -34,10 +35,11 @@ namespace lms::core
IOContextRunner(const IOContextRunner&) = delete;
IOContextRunner& operator=(const IOContextRunner&) = delete;
void stop();
void wait();
std::size_t getThreadCount() const;
private:
const std::string _name;
boost::asio::io_context& _ioContext;
boost::asio::executor_work_guard<boost::asio::io_context::executor_type> _work;
std::vector<std::thread> _threads;