2019-07-17 13:37:18 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <memory>
|
|
|
|
#include <chrono>
|
|
|
|
#include <mutex>
|
|
|
|
#include <deque>
|
|
|
|
|
|
|
|
struct event_base;
|
|
|
|
namespace ts {
|
2020-01-23 20:57:58 -05:00
|
|
|
namespace server {
|
|
|
|
class TSServer;
|
|
|
|
}
|
|
|
|
namespace weblist {
|
|
|
|
class TSWebClient;
|
|
|
|
class WebListManager {
|
|
|
|
private:
|
|
|
|
struct Entry {
|
|
|
|
std::shared_ptr<server::TSServer> 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::TSServer>& /* server */);
|
|
|
|
bool reports_enabled(const std::shared_ptr<server::TSServer>& /* server */);
|
|
|
|
void disable_report(const std::shared_ptr<server::TSServer>& /* server */);
|
|
|
|
|
|
|
|
void tick();
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
private:
|
|
|
|
struct event_base* event_base = nullptr;
|
|
|
|
std::thread event_base_dispatch;
|
|
|
|
|
|
|
|
std::mutex entry_lock;
|
|
|
|
std::deque<std::shared_ptr<Entry>> entries;
|
|
|
|
};
|
|
|
|
}
|
2019-07-17 13:37:18 -04:00
|
|
|
}
|