#pragma once #ifndef CONFIGURATIONSTATE_H_ #define CONFIGURATIONSTATE_H_ #include "ConfigDownloader.h" #include "ConfigLog.h" #include "ConfigurationException.h" #include "lib/expression/ExpressionEvaluator.h" #include "lib/expression/Value.h" #include "text_format/text_format.h" #include #include #include #include #include #include #include #include namespace google { namespace protobuf { class Message; class DescriptorPool; class DynamicMessageFactory; class Descriptor; class FileDescriptorProto; class DescriptorProto; } // namespace protobuf } // namespace google namespace bts { namespace config { class System; } } // namespace bts namespace proto = google::protobuf; namespace bts { namespace config { namespace internal { class ConfigPropertyEvaluator; class ConfigValueQueue; class ConfigurationState { public: ConfigurationState(void); ~ConfigurationState(void); void initialize_defaults(IConfigLog &log); void initialize_defaults(IConfigLog &log, const std::vector &proto_dirs); void initialize_settings(); int load(const std::string &url, IConfigLog &); int load_string(const std::string &values, bool print_errors = false); void reset(); const proto::Message &get_message(const proto::Descriptor *property_desc); const proto::Message *try_get_message(const std::string &property_name); const proto::Message * try_get_message_or_default(const std::string &property_name); bool is_initialized() { return _is_initialized; } expression::Value get_macro(const std::string &name); std::string get_macro_string(const std::string &name); void check_rules(); const google::protobuf::Descriptor * get_descriptor_by_name(const std::string &name); private: BTS_NO_COPY(ConfigurationState); void initialize_builtins(); void initialize_introspection(); void initialize_macros(); void add_macro(const proto::Message *); void add_metadata_field( proto::FileDescriptorProto *file_dp, proto::DescriptorProto *message_dp, const proto::Descriptor *base_field, int index); void generate_all_config_proto(IConfigLog &, const std::vector &proto_dirs); const proto::Message *try_get_value( const std::string &field_name, const proto::Message &message) const; std::string settings_path(); bool _is_initialized; std::recursive_mutex _initialization_mutex; boost::scoped_ptr _dynamic_pool; boost::scoped_ptr _prototype_factory; const proto::Message *_prototype; // owned by prototype_factory std::vector> _config_chain; std::shared_ptr _defaults; std::shared_ptr _properties; expression::ExpressionEvaluator _rule_engine; std::map _macros; std::shared_ptr _deferred_queue; // ConfigLog _log; std::string _host; uint32_t _port; }; std::string get_include(const proto::Message &messages); std::string get_fallback(const proto::Message &message); struct PathType { enum type { not_found, file, directory }; }; PathType::type get_path_type(std::string path); // Loads a file or directory and merges the values into one Message. // Caller is responsible for processing includes bool load_message( std::string url, proto::Message &out_message, IConfigLog &, ConfigValueQueue &); int load_directory( std::string url, ConfigDownloader &, proto::Message &out_message, IConfigLog &, ConfigValueQueue &); ConfigDownloader::Result load_file( std::string url, ConfigDownloader &, proto::Message &out_message, IConfigLog &, ConfigValueQueue &, bool required = true); void parse_stream( const std::string &file, proto::io::ZeroCopyInputStream &stream, proto::Message &out_message, IConfigLog &, ConfigValueQueue &lookup); } // namespace internal } // namespace config } // namespace bts #endif