From 0a08914a01906d3f823c6c0273b5e96f22160b91 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Fri, 20 Dec 2024 15:10:38 -0600 Subject: [PATCH] refactor app config --- repertory/librepertory/include/app_config.hpp | 230 +++++------------- repertory/librepertory/src/app_config.cpp | 226 +++++++++++++++++ 2 files changed, 285 insertions(+), 171 deletions(-) diff --git a/repertory/librepertory/include/app_config.hpp b/repertory/librepertory/include/app_config.hpp index d239f9d8..f309e593 100644 --- a/repertory/librepertory/include/app_config.hpp +++ b/repertory/librepertory/include/app_config.hpp @@ -143,141 +143,77 @@ private: } public: - [[nodiscard]] auto get_api_auth() const -> std::string { return api_auth_; } + [[nodiscard]] auto get_api_auth() const -> std::string; - [[nodiscard]] auto get_api_port() const -> std::uint16_t { return api_port_; } + [[nodiscard]] auto get_api_port() const -> std::uint16_t; - [[nodiscard]] auto get_api_user() const -> std::string { return api_user_; } + [[nodiscard]] auto get_api_user() const -> std::string; - [[nodiscard]] auto get_cache_directory() const -> std::string { - return cache_directory_; - } + [[nodiscard]] auto get_cache_directory() const -> std::string; - [[nodiscard]] auto get_chunk_downloader_timeout_secs() const -> std::uint8_t { - return std::max(static_cast(5U), - min_download_timeout_secs_.load()); - } + [[nodiscard]] auto get_chunk_downloader_timeout_secs() const -> std::uint8_t; [[nodiscard]] auto get_config_file_path() const -> std::string; - [[nodiscard]] auto get_database_type() const -> database_type { - return db_type_; - } + [[nodiscard]] auto get_database_type() const -> database_type; - [[nodiscard]] auto get_data_directory() const -> std::string { - return data_directory_; - } + [[nodiscard]] auto get_data_directory() const -> std::string; - [[nodiscard]] auto get_enable_chunk_download_timeout() const -> bool { - return enable_chunk_downloader_timeout_; - } + [[nodiscard]] auto get_enable_chunk_download_timeout() const -> bool; - [[nodiscard]] auto get_enable_comm_duration_events() const -> bool { - return enable_comm_duration_events_; - } + [[nodiscard]] auto get_enable_comm_duration_events() const -> bool; - [[nodiscard]] auto get_enable_drive_events() const -> bool { - return enable_drive_events_; - } + [[nodiscard]] auto get_enable_drive_events() const -> bool; - [[nodiscard]] auto get_encrypt_config() const -> encrypt_config { - return encrypt_config_; - } + [[nodiscard]] auto get_encrypt_config() const -> encrypt_config; #if defined(_WIN32) - [[nodiscard]] auto get_enable_mount_manager() const -> bool { - return enable_mount_manager_; - } + [[nodiscard]] auto get_enable_mount_manager() const -> bool; #endif // defined(_WIN32) - [[nodiscard]] auto get_event_level() const -> event_level { - return event_level_; - } + [[nodiscard]] auto get_event_level() const -> event_level; - [[nodiscard]] auto get_eviction_delay_mins() const -> std::uint32_t { - return eviction_delay_mins_; - } + [[nodiscard]] auto get_eviction_delay_mins() const -> std::uint32_t; - [[nodiscard]] auto get_eviction_uses_accessed_time() const -> bool { - return eviction_uses_accessed_time_; - } + [[nodiscard]] auto get_eviction_uses_accessed_time() const -> bool; - [[nodiscard]] auto get_high_frequency_interval_secs() const -> std::uint16_t { - return std::max(static_cast(1U), - high_freq_interval_secs_.load()); - } + [[nodiscard]] auto get_high_frequency_interval_secs() const -> std::uint16_t; - [[nodiscard]] auto get_host_config() const -> host_config { - return host_config_; - } + [[nodiscard]] auto get_host_config() const -> host_config; [[nodiscard]] auto get_json() const -> json; - [[nodiscard]] auto get_log_directory() const -> std::string { - return log_directory_; - } + [[nodiscard]] auto get_log_directory() const -> std::string; - [[nodiscard]] auto get_low_frequency_interval_secs() const -> std::uint16_t { - return std::max(static_cast(1U), - low_freq_interval_secs_.load()); - } + [[nodiscard]] auto get_low_frequency_interval_secs() const -> std::uint16_t; [[nodiscard]] auto get_max_cache_size_bytes() const -> std::uint64_t; - [[nodiscard]] auto get_max_upload_count() const -> std::uint8_t { - return std::max(std::uint8_t(1U), max_upload_count_.load()); - } + [[nodiscard]] auto get_max_upload_count() const -> std::uint8_t; - [[nodiscard]] auto get_med_frequency_interval_secs() const -> std::uint16_t { - return std::max(static_cast(1U), - med_freq_interval_secs_.load()); - } + [[nodiscard]] auto get_med_frequency_interval_secs() const -> std::uint16_t; - [[nodiscard]] auto get_online_check_retry_secs() const -> std::uint16_t { - return std::max(std::uint16_t(15U), online_check_retry_secs_.load()); - } + [[nodiscard]] auto get_online_check_retry_secs() const -> std::uint16_t; - [[nodiscard]] auto get_orphaned_file_retention_days() const -> std::uint16_t { - return std::min(static_cast(31U), - std::max(static_cast(1U), - orphaned_file_retention_days_.load())); - } + [[nodiscard]] auto get_orphaned_file_retention_days() const -> std::uint16_t; - [[nodiscard]] auto get_preferred_download_type() const -> download_type { - return preferred_download_type_; - } + [[nodiscard]] auto get_preferred_download_type() const -> download_type; - [[nodiscard]] auto get_provider_type() const -> provider_type { - return prov_; - } + [[nodiscard]] auto get_provider_type() const -> provider_type; - [[nodiscard]] auto get_remote_config() const -> remote::remote_config { - return remote_config_; - } + [[nodiscard]] auto get_remote_config() const -> remote::remote_config; - [[nodiscard]] auto get_remote_mount() const -> remote::remote_mount { - return remote_mount_; - } + [[nodiscard]] auto get_remote_mount() const -> remote::remote_mount; - [[nodiscard]] auto get_retry_read_count() const -> std::uint16_t { - return std::max(std::uint16_t(2), retry_read_count_.load()); - } + [[nodiscard]] auto get_retry_read_count() const -> std::uint16_t; - [[nodiscard]] auto get_ring_buffer_file_size() const -> std::uint16_t { - return std::max(static_cast(64U), - std::min(static_cast(1024U), - ring_buffer_file_size_.load())); - } + [[nodiscard]] auto get_ring_buffer_file_size() const -> std::uint16_t; - [[nodiscard]] auto get_s3_config() const -> s3_config { return s3_config_; } + [[nodiscard]] auto get_s3_config() const -> s3_config; - [[nodiscard]] auto get_sia_config() const -> sia_config { - return sia_config_; - } + [[nodiscard]] auto get_sia_config() const -> sia_config; - [[nodiscard]] auto get_task_wait_ms() const -> std::uint16_t { - return std::max(static_cast(50U), task_wait_ms_.load()); - } + [[nodiscard]] auto get_task_wait_ms() const -> std::uint16_t; [[nodiscard]] auto get_value_by_name(const std::string &name) const -> std::string; @@ -286,119 +222,71 @@ public: void save(); - void set_api_auth(const std::string &api_auth) { - set_value(api_auth_, api_auth); - } + void set_api_auth(const std::string &api_auth); - void set_api_port(std::uint16_t api_port) { set_value(api_port_, api_port); } + void set_api_port(std::uint16_t api_port); - void set_api_user(const std::string &api_user) { - set_value(api_user_, api_user); - } - - void set_chunk_downloader_timeout_secs( - std::uint8_t chunk_downloader_timeout_secs) { - set_value(download_timeout_secs_, chunk_downloader_timeout_secs); - } - - void set_database_type(const database_type &type) { - set_value(db_type_, type); - } + void set_api_user(const std::string &api_user); void - set_enable_chunk_downloader_timeout(bool enable_chunk_downloader_timeout) { - set_value(enable_chunk_downloader_timeout_, - enable_chunk_downloader_timeout); - } + set_chunk_downloader_timeout_secs(std::uint8_t chunk_downloader_timeout_secs); - void set_enable_comm_duration_events(bool enable_comm_duration_events) { - set_value(enable_comm_duration_events_, enable_comm_duration_events); - } + void set_database_type(const database_type &type); - void set_enable_drive_events(bool enable_drive_events) { - set_value(enable_drive_events_, enable_drive_events); - } + void + set_enable_chunk_downloader_timeout(bool enable_chunk_downloader_timeout); + + void set_enable_comm_duration_events(bool enable_comm_duration_events); + + void set_enable_drive_events(bool enable_drive_events); #if defined(_WIN32) - void set_enable_mount_manager(bool enable_mount_manager) { - set_value(enable_mount_manager_, enable_mount_manager); - } + void set_enable_mount_manager(bool enable_mount_manager); #endif // defined(_WIN32) - void set_event_level(const event_level &level) { - if (set_value(event_level_, level)) { - event_system::instance().raise( - event_level_to_string(level)); - } - } + void set_event_level(const event_level &level); void set_encrypt_config(encrypt_config cfg); - void set_eviction_delay_mins(std::uint32_t eviction_delay_mins) { - set_value(eviction_delay_mins_, eviction_delay_mins); - } + void set_eviction_delay_mins(std::uint32_t eviction_delay_mins); - void set_eviction_uses_accessed_time(bool eviction_uses_accessed_time) { - set_value(eviction_uses_accessed_time_, eviction_uses_accessed_time); - } + void set_eviction_uses_accessed_time(bool eviction_uses_accessed_time); void - set_high_frequency_interval_secs(std::uint16_t high_frequency_interval_secs) { - set_value(high_freq_interval_secs_, high_frequency_interval_secs); - } + set_high_frequency_interval_secs(std::uint16_t high_frequency_interval_secs); void set_host_config(host_config cfg); void - set_low_frequency_interval_secs(std::uint16_t low_frequency_interval_secs) { - set_value(low_freq_interval_secs_, low_frequency_interval_secs); - } + set_low_frequency_interval_secs(std::uint16_t low_frequency_interval_secs); - void set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes) { - set_value(max_cache_size_bytes_, max_cache_size_bytes); - } + void set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes); - void set_max_upload_count(std::uint8_t max_upload_count) { - set_value(max_upload_count_, max_upload_count); - } + void set_max_upload_count(std::uint8_t max_upload_count); void - set_med_frequency_interval_secs(std::uint16_t med_frequency_interval_secs) { - set_value(med_freq_interval_secs_, med_frequency_interval_secs); - } + set_med_frequency_interval_secs(std::uint16_t med_frequency_interval_secs); - void set_online_check_retry_secs(std::uint16_t online_check_retry_secs) { - set_value(online_check_retry_secs_, online_check_retry_secs); - } + void set_online_check_retry_secs(std::uint16_t online_check_retry_secs); void - set_orphaned_file_retention_days(std::uint16_t orphaned_file_retention_days) { - set_value(orphaned_file_retention_days_, orphaned_file_retention_days); - } + set_orphaned_file_retention_days(std::uint16_t orphaned_file_retention_days); - void set_preferred_download_type(const download_type &type) { - set_value(preferred_download_type_, type); - } - - void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size) { - set_value(ring_buffer_file_size_, ring_buffer_file_size); - } + void set_preferred_download_type(const download_type &type); void set_remote_config(remote::remote_config cfg); void set_remote_mount(remote::remote_mount cfg); - void set_retry_read_count(std::uint16_t retry_read_count) { - set_value(retry_read_count_, retry_read_count); - } + void set_retry_read_count(std::uint16_t retry_read_count); + + void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size); void set_s3_config(s3_config cfg); void set_sia_config(sia_config cfg); - void set_task_wait_ms(std::uint16_t task_wait_ms) { - set_value(task_wait_ms_, task_wait_ms); - } + void set_task_wait_ms(std::uint16_t task_wait_ms); [[nodiscard]] auto set_value_by_name(const std::string &name, const std::string &value) -> std::string; diff --git a/repertory/librepertory/src/app_config.cpp b/repertory/librepertory/src/app_config.cpp index 8013dc6f..35a9f942 100644 --- a/repertory/librepertory/src/app_config.cpp +++ b/repertory/librepertory/src/app_config.cpp @@ -735,10 +735,70 @@ auto app_config::default_rpc_port(const provider_type &prov) -> std::uint16_t { return PROVIDER_RPC_PORTS.at(static_cast(prov)); } +auto api_config::get_api_auth() const -> std::string { return api_auth_; } + +auto api_config::get_api_port() const -> std::uint16_t { return api_port_; } + +auto api_config::get_api_user() const -> std::string { return api_user_; } + +auto api_config::get_cache_directory() const -> std::string { + return cache_directory_; +} + +auto api_config::get_chunk_downloader_timeout_secs() const -> std::uint8_t { + return std::max(static_cast(5U), + min_download_timeout_secs_.load()); +} + auto app_config::get_config_file_path() const -> std::string { return utils::path::combine(data_directory_, {"config.json"}); } +auto app_config::get_database_type() const -> database_type { return db_type_; } + +auto app_config::get_data_directory() const -> std::string { + return data_directory_; +} + +auto app_config::get_enable_chunk_download_timeout() const -> bool { + return enable_chunk_downloader_timeout_; +} + +auto app_config::get_enable_comm_duration_events() const -> bool { + return enable_comm_duration_events_; +} + +auto app_config::get_enable_drive_events() const -> bool { + return enable_drive_events_; +} + +auto app_config::get_encrypt_config() const -> encrypt_config { + return encrypt_config_; +} + +#if defined(_WIN32) +auto app_config::get_enable_mount_manager() const -> bool { + return enable_mount_manager_; +} +#endif // defined(_WIN32) + +auto app_config::get_event_level() const -> event_level { return event_level_; } + +auto app_config::get_eviction_delay_mins() const -> std::uint32_t { + return eviction_delay_mins_; +} + +auto app_config::get_eviction_uses_accessed_time() const -> bool { + return eviction_uses_accessed_time_; +} + +auto app_config::get_high_frequency_interval_secs() const -> std::uint16_t { + return std::max(static_cast(1U), + high_freq_interval_secs_.load()); +} + +auto app_config::get_host_config() const -> host_config { return host_config_; } + auto app_config::get_json() const -> json { json ret = { {JSON_API_AUTH, api_auth_}, @@ -834,6 +894,15 @@ auto app_config::get_json() const -> json { return ret; } +auto app_config::get_log_directory() const -> std::string { + return log_directory_; +} + +auto app_config::get_low_frequency_interval_secs() const -> std::uint16_t { + return std::max(static_cast(1U), + low_freq_interval_secs_.load()); +} + auto app_config::get_max_cache_size_bytes() const -> std::uint64_t { auto max_space = std::max(min_cache_size_bytes, max_cache_size_bytes_.load()); auto free_space = utils::file::get_free_drive_space(get_cache_directory()); @@ -841,6 +910,29 @@ auto app_config::get_max_cache_size_bytes() const -> std::uint64_t { : max_space; } +auto app_config::get_max_upload_count() const -> std::uint8_t { + return std::max(std::uint8_t(1U), max_upload_count_.load()); +} + +auto app_config::get_med_frequency_interval_secs() const -> std::uint16_t { + return std::max(static_cast(1U), + med_freq_interval_secs_.load()); +} + +auto app_config::get_online_check_retry_secs() const -> std::uint16_t { + return std::max(std::uint16_t(15U), online_check_retry_secs_.load()); +} + +auto app_config::get_orphaned_file_retention_days() const -> std::uint16_t { + return std::min(static_cast(31U), + std::max(static_cast(1U), + orphaned_file_retention_days_.load())); +} + +auto app_config::get_preferred_download_type() const -> download_type { + return preferred_download_type_; +} + auto app_config::get_provider_display_name(const provider_type &prov) -> std::string { static const std::array std::string { return PROVIDER_NAMES.at(static_cast(prov)); } +auto app_config::get_provider_type() const -> provider_type { return prov_; } + +auto app_config::get_remote_config() const -> remote::remote_config { + return remote_config_; +} + +auto app_config::get_remote_mount() const -> remote::remote_mount { + return remote_mount_; +} + +auto app_config::get_retry_read_count() const -> std::uint16_t { + return std::max(std::uint16_t(2), retry_read_count_.load()); +} + +auto app_config::get_ring_buffer_file_size() const -> std::uint16_t { + return std::max(static_cast(64U), + std::min(static_cast(1024U), + ring_buffer_file_size_.load())); +} + +auto app_config::get_s3_config() const -> s3_config { return s3_config_; } + +auto app_config::get_sia_config() const -> sia_config { return sia_config_; } + +auto app_config::get_task_wait_ms() const -> std::uint16_t { + return std::max(static_cast(50U), task_wait_ms_.load()); +} + auto app_config::get_value_by_name(const std::string &name) const -> std::string { REPERTORY_USES_FUNCTION_NAME(); @@ -1004,14 +1124,108 @@ void app_config::save() { }); } +void app_config::set_api_auth(const std::string &api_auth) { + set_value(api_auth_, api_auth); +} + +void app_config::set_api_port(std::uint16_t api_port) { + set_value(api_port_, api_port); +} + +void app_config::set_api_user(const std::string &api_user) { + set_value(api_user_, api_user); +} + +void app_config::set_chunk_downloader_timeout_secs( + std::uint8_t chunk_downloader_timeout_secs) { + set_value(download_timeout_secs_, chunk_downloader_timeout_secs); +} + +void app_config::set_database_type(const database_type &type) { + set_value(db_type_, type); +} + +void app_config::set_enable_chunk_downloader_timeout( + bool enable_chunk_downloader_timeout) { + set_value(enable_chunk_downloader_timeout_, enable_chunk_downloader_timeout); +} + +void app_config::set_enable_comm_duration_events( + bool enable_comm_duration_events) { + set_value(enable_comm_duration_events_, enable_comm_duration_events); +} + +void app_config::set_enable_drive_events(bool enable_drive_events) { + set_value(enable_drive_events_, enable_drive_events); +} + +#if defined(_WIN32) +void app_config::set_enable_mount_manager(bool enable_mount_manager) { + set_value(enable_mount_manager_, enable_mount_manager); +} +#endif // defined(_WIN32) + +void app_config::set_event_level(const event_level &level) { + if (set_value(event_level_, level)) { + event_system::instance().raise( + event_level_to_string(level)); + } +} + void app_config::set_encrypt_config(encrypt_config cfg) { set_value(encrypt_config_, cfg); } +void app_config::set_eviction_delay_mins(std::uint32_t eviction_delay_mins) { + set_value(eviction_delay_mins_, eviction_delay_mins); +} + +void app_config::set_eviction_uses_accessed_time( + bool eviction_uses_accessed_time) { + set_value(eviction_uses_accessed_time_, eviction_uses_accessed_time); +} + +void app_config::set_high_frequency_interval_secs( + std::uint16_t high_frequency_interval_secs) { + set_value(high_freq_interval_secs_, high_frequency_interval_secs); +} + void app_config::set_host_config(host_config cfg) { set_value(host_config_, cfg); } +void app_config::set_low_frequency_interval_secs( + std::uint16_t low_frequency_interval_secs) { + set_value(low_freq_interval_secs_, low_frequency_interval_secs); +} + +void app_config::set_max_cache_size_bytes(std::uint64_t max_cache_size_bytes) { + set_value(max_cache_size_bytes_, max_cache_size_bytes); +} + +void app_config::set_max_upload_count(std::uint8_t max_upload_count) { + set_value(max_upload_count_, max_upload_count); +} + +void app_config::set_med_frequency_interval_secs( + std::uint16_t med_frequency_interval_secs) { + set_value(med_freq_interval_secs_, med_frequency_interval_secs); +} + +void app_config::set_online_check_retry_secs( + std::uint16_t online_check_retry_secs) { + set_value(online_check_retry_secs_, online_check_retry_secs); +} + +void app_config::set_orphaned_file_retention_days( + std::uint16_t orphaned_file_retention_days) { + set_value(orphaned_file_retention_days_, orphaned_file_retention_days); +} + +void app_config::set_preferred_download_type(const download_type &type) { + set_value(preferred_download_type_, type); +} + void app_config::set_remote_config(remote::remote_config cfg) { set_value(remote_config_, cfg); } @@ -1020,10 +1234,22 @@ void app_config::set_remote_mount(remote::remote_mount cfg) { set_value(remote_mount_, cfg); } +void app_config::set_retry_read_count(std::uint16_t retry_read_count) { + set_value(retry_read_count_, retry_read_count); +} + +void set_ring_buffer_file_size(std::uint16_t ring_buffer_file_size) { + set_value(ring_buffer_file_size_, ring_buffer_file_size); +} + void app_config::set_s3_config(s3_config cfg) { set_value(s3_config_, cfg); } void app_config::set_sia_config(sia_config cfg) { set_value(sia_config_, cfg); } +void app_config::set_task_wait_ms(std::uint16_t task_wait_ms) { + set_value(task_wait_ms_, task_wait_ms); +} + auto app_config::set_value_by_name(const std::string &name, const std::string &value) -> std::string { REPERTORY_USES_FUNCTION_NAME();