own implementation of singleton and logger
This commit is contained in:
1 parent
f6c5bcca39
commit
6aed7b0027
19 files changed
+745
-206
No files matched your search
@@ -8,6 +8,8 @@
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavformat/avformat.h>
|
||||
@@ -37,10 +39,6 @@ public:
|
||||
bool IsFinished() const { return m_finished.load(); }
|
||||
|
||||
private:
|
||||
void Log(const std::string &msg) {
|
||||
std::lock_guard<std::mutex> lock(m_logMtx);
|
||||
std::cout << "[AudioDecoder] " << msg << std::endl;
|
||||
}
|
||||
void Cleanup();
|
||||
void InternalDecode(std::string url, int targetSampleRate);
|
||||
std::atomic<DecodeStatus> m_status{DecodeStatus::Idle};
|
||||
|
||||
@@ -1,15 +1,24 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <singleton_atomic.hpp>
|
||||
#include <string>
|
||||
#include <ts6bot/Proxy.hpp>
|
||||
|
||||
#include <glaze/glaze.hpp>
|
||||
|
||||
#include "Singleton.hpp"
|
||||
|
||||
namespace ts6bot {
|
||||
|
||||
enum class LogLevel { Critical, Error, Warning, Info, Trace };
|
||||
enum class LogLevel {
|
||||
Trace,
|
||||
Debug,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Critical,
|
||||
None
|
||||
};
|
||||
|
||||
struct ServerQueryConfig {
|
||||
std::string host{"127.0.0.1"};
|
||||
@@ -48,7 +57,8 @@ struct Config {
|
||||
ProxyConfiguration proxy{};
|
||||
};
|
||||
|
||||
class Configuration : public SingletonAtomic<Configuration> {
|
||||
class Configuration : public Singleton<Configuration> {
|
||||
friend class Singleton<Configuration>;
|
||||
public:
|
||||
const Config getConfig() const noexcept { return m_config; }
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
#include <string_view>
|
||||
|
||||
#include "quill/Backend.h"
|
||||
#include "quill/Frontend.h"
|
||||
#include "quill/LogMacros.h"
|
||||
#include "quill/Logger.h"
|
||||
#include "quill/sinks/FileSink.h"
|
||||
#include "quill/sinks/ConsoleSink.h"
|
||||
|
||||
namespace ts6bot {
|
||||
|
||||
class Log {
|
||||
public:
|
||||
static void init(std::string_view file_path);
|
||||
static quill::Logger* logger();
|
||||
|
||||
private:
|
||||
static quill::Logger* g_logger;
|
||||
};
|
||||
|
||||
} // namespace ts6bot
|
||||
@@ -10,22 +10,21 @@
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <set>
|
||||
#include <singleton_atomic.hpp>
|
||||
#include <string>
|
||||
#include <teamspeak/public_definitions.h>
|
||||
#include <thread>
|
||||
#include <ts3_functions.h>
|
||||
#include <ts6bot/AudioDecoder.hpp>
|
||||
#include <quill/Logger.h>
|
||||
#include <quill/LogMacros.h>
|
||||
#include <vector>
|
||||
class MusicManager {
|
||||
public:
|
||||
explicit MusicManager(std::shared_ptr<TS3Functions> functions, quill::Logger* logger, std::uint64_t serverConnectionHandlerID = 0);
|
||||
explicit MusicManager(std::shared_ptr<TS3Functions> functions, std::uint64_t serverConnectionHandlerID = 0);
|
||||
~MusicManager();
|
||||
|
||||
struct Music {
|
||||
std::string name;
|
||||
std::string shortUrl;
|
||||
std::string length;
|
||||
std::string videoId;
|
||||
std::string requestedBy;
|
||||
YouTube::Result<definitions::Streams> streams;
|
||||
@@ -54,13 +53,15 @@ public:
|
||||
std::optional<Music> getCurrent() const { return m_current; }
|
||||
void removeFromQueue(std::size_t index);
|
||||
void removeFromQueue(const std::string &name);
|
||||
void addToQueueDirect(const std::string& vid, const std::string& title, const std::string& req, std::optional<definitions::Streams> streams);
|
||||
void addToQueueDirect(const std::string& vid, const std::string& title, const std::string& shortUrl, const std::string& length, const std::string& req, std::optional<definitions::Streams> streams);
|
||||
void checkQueueAndPlay();
|
||||
|
||||
// Youtube / Search
|
||||
std::vector<definitions::SearchResultItem> search(std::string name, int maxResults = 5) const;
|
||||
void playUrl(std::string url, const std::string &requester = "");
|
||||
|
||||
void playPlaylist(const std::string& playlistId, const std::string& requester);
|
||||
// Helper to extract playlist ID from URL
|
||||
std::optional<std::string> extractPlaylistId(std::string_view url);
|
||||
// Selection Logic
|
||||
// Stores the results for a specific user to select later
|
||||
void storePendingSearch(anyID clientId,
|
||||
@@ -72,7 +73,6 @@ private:
|
||||
static std::string formatDuration(const std::string &isoDuration);
|
||||
void updateWhisperList();
|
||||
|
||||
quill::Logger* m_logger;
|
||||
std::shared_ptr<TS3Functions> m_functions{nullptr};
|
||||
std::unique_ptr<AudioDecoder> m_microphone{nullptr};
|
||||
std::unique_ptr<YouTube::Client> m_client{nullptr};
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
|
||||
class SignalShutdown {
|
||||
public:
|
||||
explicit SignalShutdown(std::function<void()> onShutdown);
|
||||
~SignalShutdown();
|
||||
|
||||
SignalShutdown(const SignalShutdown&) = delete;
|
||||
SignalShutdown& operator=(const SignalShutdown&) = delete;
|
||||
|
||||
private:
|
||||
std::function<void()> m_OnShutdown;
|
||||
std::thread m_Thread;
|
||||
bool m_Running = true;
|
||||
};
|
||||
Reference in new issue
Block a user