임시저장

This commit is contained in:
2025-01-30 01:11:26 +09:00
parent 30569f4472
commit 3186561818
9 changed files with 140 additions and 34 deletions

View File

@@ -14,7 +14,7 @@
namespace bumbleBee {
class AsyncDownloadManager {
public:
static AsyncDownloadManager& getInstance(int worker_count, std::weak_ptr<dpp::cluster> bot, std::weak_ptr<bumbleBee::MusicQueue> musicQueue) {
static AsyncDownloadManager& getInstance(int worker_count, std::weak_ptr<dpp::cluster> bot, std::shared_ptr<bumbleBee::MusicQueue> musicQueue) {
static AsyncDownloadManager dl(worker_count);
dl.bot = bot;
dl.musicQueue = musicQueue;
@@ -24,15 +24,11 @@ public:
std::thread th(&bumbleBee::AsyncDownloadManager::enqueueAsyncDL, this, query);
th.detach();
}
private:
AsyncDownloadManager(int worker_count){
worker_thread.reserve(worker_count);
terminate = false;
for (int i=0; i<worker_count; i++) {
worker_thread.emplace_back([this](){this->downloadWorker();});
}
}
~AsyncDownloadManager(){
auto cluster = bot.lock();
assert(cluster);
cluster->log(dpp::ll_info, "AsyncDownloadManager Destructor called.");
terminate = true;
dlQueueCondition.notify_all();
@@ -41,6 +37,15 @@ private:
}
}
private:
AsyncDownloadManager(int worker_count){
worker_thread.reserve(worker_count);
terminate = false;
for (int i=0; i<worker_count; i++) {
worker_thread.emplace_back([this](){this->downloadWorker();});
}
}
void enqueueAsyncDL(std::string query);
void downloadWorker();
@@ -48,7 +53,7 @@ private:
std::condition_variable dlQueueCondition;
std::mutex dlQueueMutex;
std::weak_ptr<dpp::cluster> bot;
std::weak_ptr<bumbleBee::MusicQueue> musicQueue;
std::shared_ptr<bumbleBee::MusicQueue> musicQueue;
std::vector<std::thread> worker_thread;
bool terminate;
};

View File

@@ -3,7 +3,6 @@
#define _BUMBLEBEE_HPP_
#include <dpp/dpp.h>
#include <dpp/nlohmann/json.hpp>
#include <boost/asio.hpp>
#include <memory>
#include <BumbleBeeCommand.hpp>
#include <MusicQueue.hpp>

View File

@@ -1,10 +1,39 @@
#pragma once
#ifndef _MUSICQUEUE_HPP_
#define _MUSICQUEUE_HPP_
#include <memory>
#include <functional>
#include <condition_variable>
#include <list>
namespace bumbleBee {
class MusicQueueElement {
public:
MusicQueueElement(std::string id, std::string url) : id(id), url(url) {}
std::string id;
std::string url;
};
class MusicQueue {
public:
MusicQueue() {
currentPlayingPosition = queue.begin();
repeat = false;
}
void enqueue(std::shared_ptr<MusicQueueElement> Element);
std::shared_ptr<MusicQueueElement> dequeue();
std::weak_ptr<MusicQueueElement> nowplaying();
std::weak_ptr<MusicQueueElement> next_music();
std::weak_ptr<MusicQueueElement> jump_to_index(int idx);
bool repeat;
std::function<void()> on_queue_added;
private:
std::condition_variable queueItemAdded;
std::mutex queueMutex;
std::list<std::shared_ptr<MusicQueueElement>> queue;
std::list<std::shared_ptr<MusicQueueElement>>::iterator currentPlayingPosition;
};
}