Teaspeak-Server/server/src/lincense/LicenseHelper.h

40 lines
1.3 KiB
C++

#pragma once
#include <ThreadPool/Mutex.h>
#include "../../../license/shared/License.h"
#include "../../../license/shared/LicenseRequest.h"
namespace license {
class LicenseHelper {
public:
LicenseHelper();
~LicenseHelper();
void tick();
std::shared_ptr<license::LicenseInfo> getLicenseInfo() {
std::lock_guard lock(this->request.info_lock);
return this->request.info;
}
private:
std::mutex license_tick_lock;
std::chrono::system_clock::time_point scheduled_request;
std::chrono::system_clock::time_point last_request;
std::chrono::system_clock::time_point last_successful_request;
size_t request_fail_count = 0;
struct {
std::shared_ptr<license::LicenceRequest> current = nullptr;
std::mutex current_lock;
std::shared_ptr<license::LicenseInfo> info;
std::mutex info_lock;
std::thread prepare_thread;
} request;
void do_request(bool /* verbose */);
void handle_request_failed(bool /* verbose */, const std::string& /* error */);
void callback_certificate_update(const license::WebCertificate&);
};
}