#ifndef CONFIG_H_ #define CONFIG_H_ #include "config.h" #include "../os/os.h" #include "ConfigurationState.h" #include #include #include #include //#include namespace proto = google::protobuf; namespace bts { namespace config { internal::ConfigurationState config_state; ////////////////////////////////////////// // Public API ////////////////////////////////////////// extern "C" BTS_EXPORT void initialize() { config_state.initialize_settings(); } extern "C" BTS_EXPORT bool initialize_nothrow(char* error_message, size_t len) { try { initialize(); } catch(std::exception& e) { std::string msg = e.what(); if (msg.size() < len) { os::strncpy(error_message, msg.c_str(), len); } return false; } return true; } //extern "C" const proto::Message& get_message(const google::protobuf::Descriptor* descriptor) { return config_state.get_message(descriptor); } namespace interop { ////////////////////////////////////////////////// // Functions used for interop to other languages ///////////////////////////////////////////////// std::string getbuffer_serialized_buffer; extern "C" BTS_EXPORT const char* get_buffer(const char* key_name, int& out_length) { google::protobuf::DescriptorPool const* pool = google::protobuf::DescriptorPool::generated_pool(); const proto::Descriptor* message_desc = pool->FindMessageTypeByName(key_name); const proto::Message& message = get_message(message_desc); getbuffer_serialized_buffer.clear(); message.SerializePartialToString(&getbuffer_serialized_buffer); out_length = getbuffer_serialized_buffer.size(); return getbuffer_serialized_buffer.c_str(); } extern "C" BTS_EXPORT const proto::Message* get_named(const char* key_name) { return config_state.try_get_message_or_default(key_name); } BTS_EXPORT std::string get_macro_string(const char* name) { return config_state.get_macro_string(name); } } namespace internal { ////////////////////////////////////////// // Functions used in testing ////////////////////////////////////////// extern "C" BTS_EXPORT void initialize_for_test(const std::string& values, bool print_errors) { config_state.reset(); config_state.load_string(values, print_errors); } extern "C" BTS_EXPORT void reset() { config_state.reset(); } extern "C" BTS_EXPORT bool check_rules(char* error_msg, size_t len) { try { config_state.check_rules(); } catch(std::exception& e) { std::string msg = e.what(); if (msg.size() < len) { os::strncpy(error_msg, msg.c_str(), len); } return false; } return true; } }}} // end namespaces #endif