122 lines
4.0 KiB
C++
Executable File
122 lines
4.0 KiB
C++
Executable File
#ifndef CONFIGURATIONSTATE_H_
|
|
#define CONFIGURATIONSTATE_H_
|
|
|
|
#include "ConfigurationException.h"
|
|
#include "ConfigLog.h"
|
|
#include "lib/expression/ExpressionEvaluator.h"
|
|
#include "lib/expression/Value.h"
|
|
#include "ConfigDownloader.h"
|
|
|
|
#include <google/protobuf/descriptor.h>
|
|
#include "text_format/text_format.h"
|
|
#include <google/protobuf/dynamic_message.h>
|
|
#include <google/protobuf/descriptor.pb.h>
|
|
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
|
|
|
#include <boost/utility.hpp>
|
|
#include <boost/scoped_ptr.hpp>
|
|
#include <mutex>
|
|
#include <vector>
|
|
|
|
|
|
namespace google {
|
|
namespace protobuf {
|
|
class Message;
|
|
class DescriptorPool;
|
|
class DynamicMessageFactory;
|
|
class Descriptor;
|
|
class FileDescriptorProto;
|
|
class DescriptorProto;
|
|
}
|
|
}
|
|
|
|
namespace bts {
|
|
namespace config {
|
|
class System;
|
|
}}
|
|
|
|
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_settings();
|
|
|
|
int load(const std::string& url, const std::string& fallback, 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 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<proto::DescriptorPool> _dynamic_pool;
|
|
boost::scoped_ptr<proto::DynamicMessageFactory> _prototype_factory;
|
|
const proto::Message* _prototype; // owned by prototype_factory
|
|
std::vector<std::shared_ptr<proto::Message> > _config_chain;
|
|
std::shared_ptr<proto::Message> _defaults;
|
|
|
|
std::shared_ptr<ConfigPropertyEvaluator> _properties;
|
|
expression::ExpressionEvaluator _rule_engine;
|
|
std::map<std::string, std::string> _macros;
|
|
std::shared_ptr<ConfigValueQueue> _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);
|
|
|
|
}}}
|
|
#endif
|