/* * Copyright (c) Facebook, Inc. and its affiliates. * * This software may be used and distributed according to the terms of the * GNU General Public License version 2. */ #pragma once #include #include #include #include "eden/fs/config/gen-cpp2/eden_config_types.h" namespace facebook { namespace eden { class EdenConfig; /** * An interface that defines how to obtain a possibly reloaded EdenConfig * instance. */ class ReloadableConfig { public: explicit ReloadableConfig(std::shared_ptr config); ReloadableConfig( std::shared_ptr config, ConfigReloadBehavior reload); ~ReloadableConfig(); /** * Get the EdenConfig data. * * The config data may be reloaded from disk depending on the value of the * reload parameter. */ std::shared_ptr getEdenConfig( ConfigReloadBehavior reload = ConfigReloadBehavior::AutoReload); private: struct ConfigState { explicit ConfigState(const std::shared_ptr& config) : config{config} {} std::shared_ptr config; }; folly::Synchronized state_; std::atomic lastCheck_{}; // Reload behavior, when set this overrides reload behavior passed to methods // This is used in tests where we want to set the manually set the EdenConfig // and avoid reloading it from disk. std::optional reloadBehavior_{std::nullopt}; }; } // namespace eden } // namespace facebook