Teaspeak-Server/server/src/weblist/WebListManager.h
2020-03-02 13:33:57 +01:00

50 lines
1.5 KiB
C++

#pragma once
#include <thread>
#include <memory>
#include <chrono>
#include <mutex>
#include <deque>
#include <condition_variable>
struct event_base;
namespace ts {
namespace server {
class VirtualServer;
}
namespace weblist {
class TSWebClient;
class WebListManager {
private:
struct Entry {
std::shared_ptr<server::VirtualServer> server;
std::shared_ptr<TSWebClient> current_request;
std::chrono::system_clock::time_point last_success;
std::chrono::system_clock::time_point scheduled_request;
int fail_count = 0;
uint16_t session_count = 1;
std::string last_name;
};
public:
WebListManager();
~WebListManager();
void enable_report(const std::shared_ptr<server::VirtualServer>& /* server */);
bool reports_enabled(const std::shared_ptr<server::VirtualServer>& /* server */);
void disable_report(const std::shared_ptr<server::VirtualServer>& /* server */);
void tick();
bool enabled = false;
private:
struct event_base* event_base{nullptr};
std::thread event_base_dispatch{};
std::mutex entry_lock{};
std::condition_variable entry_cv{};
std::deque<std::shared_ptr<Entry>> entries{};
};
}
}