#pragma once #include #include #include #include "LicenseManager.h" namespace license { namespace stats { struct GeneralStatistics { std::chrono::system_clock::time_point age; uint64_t instances = 0; uint64_t servers = 0; uint64_t clients = 0; uint64_t bots = 0; }; struct HistoryStatistics { enum HistoryType { LAST_DAY, DAY_YESTERDAY, DAY_7DAYS_AGO, LAST_WEEK, LAST_MONTH, LAST_HALF_YEAR }; static std::chrono::system_clock::time_point align_type(HistoryType type, const std::chrono::system_clock::time_point&); static std::chrono::milliseconds time_period(HistoryType type); static std::chrono::milliseconds cache_timeout(HistoryType type); static std::chrono::milliseconds type_duration(HistoryType type); std::chrono::system_clock::time_point evaluated; std::chrono::system_clock::time_point begin; std::chrono::system_clock::time_point end; std::chrono::milliseconds period; HistoryType type; std::deque> statistics; }; class StatisticManager { public: explicit StatisticManager(const std::shared_ptr& /* manager */); virtual ~StatisticManager(); void reset_cache_general(); std::shared_ptr general_statistics(); std::shared_ptr history(HistoryStatistics::HistoryType); private: std::shared_ptr license_manager; std::recursive_mutex _general_statistics_lock; std::recursive_mutex _general_statistics_generate_lock; std::shared_ptr _general_statistics; std::map _history_locks; std::map> _history; }; } }