Leosac  0.8.0
Open Source Access Control
ConfigManager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
23 #include "tools/log.hpp"
24 #include <boost/property_tree/ptree.hpp>
25 #include <map>
26 #include <memory>
27 #include <string>
28 #include <vector>
29 #include <zmqpp/zmqpp.hpp>
30 
31 namespace Leosac
32 {
33 class Kernel;
34 
46 {
47  public:
51  ConfigManager(const boost::property_tree::ptree &cfg);
52  virtual ~ConfigManager() = default;
53 
54  ConfigManager(const ConfigManager &) = default;
55 
56  ConfigManager(ConfigManager &&) = delete;
57  ConfigManager &operator=(const ConfigManager &) = delete;
59 
68  boost::property_tree::ptree get_general_config() const;
69 
76  boost::property_tree::ptree get_exportable_general_config() const;
77 
87  boost::property_tree::ptree get_application_config();
88 
95  bool store_config(const std::string &module,
96  const boost::property_tree::ptree &cfg);
97 
101  bool has_config(const std::string &module) const;
102 
106  const boost::property_tree::ptree &load_config(const std::string &module) const;
107 
113  bool remove_config(const std::string &module);
114 
118  enum class ConfigFormat : uint8_t
119  {
120  BOOST_ARCHIVE = 0,
121  XML = 1,
122  };
123 
127  const boost::property_tree::ptree &kconfig() const;
128 
132  boost::property_tree::ptree &kconfig();
133 
140  void set_kconfig(const boost::property_tree::ptree &new_cfg);
141 
146  std::list<std::string> get_non_importable_modules() const;
147 
151  bool is_module_importable(const std::string &) const;
152 
159  uint64_t config_version() const;
160 
161  void config_version(uint64_t new_version);
162 
166  void incr_version();
167 
173  const std::string &instance_name() const;
174 
175  private:
179  std::map<std::string, boost::property_tree::ptree> modules_configs_;
180 
185  boost::property_tree::ptree kernel_config_;
186 
187  uint64_t version_;
188 
189  std::string instance_name_;
190 };
191 }
192 
193 zmqpp::message &operator>>(zmqpp::message &msg,
195 
196 zmqpp::message &operator<<(zmqpp::message &msg,
Leosac::ConfigManager::load_config
const boost::property_tree::ptree & load_config(const std::string &module) const
Return the stored configuration for a given module.
Definition: ConfigManager.cpp:133
Leosac::ConfigManager::instance_name
const std::string & instance_name() const
Return the name of the instanced assigned in the configuration file.
Definition: ConfigManager.cpp:271
operator>>
zmqpp::message & operator>>(zmqpp::message &msg, Leosac::ConfigManager::ConfigFormat &fmt)
Definition: ConfigManager.cpp:142
Leosac::ConfigManager
That class helps manage the configuration for the application and its module.
Definition: ConfigManager.hpp:45
Leosac::ConfigManager::operator=
ConfigManager & operator=(const ConfigManager &)=delete
Leosac::ConfigManager::ConfigFormat
ConfigFormat
This enum is used internally, when core request module configuration.
Definition: ConfigManager.hpp:118
Leosac::ConfigManager::kconfig
const boost::property_tree::ptree & kconfig() const
Return const & on the general config tree.
Definition: ConfigManager.cpp:166
Leosac::ConfigManager::store_config
bool store_config(const std::string &module, const boost::property_tree::ptree &cfg)
Store the configuration tree for a module.
Definition: ConfigManager.cpp:117
Leosac::ConfigManager::ConfigManager
ConfigManager(const boost::property_tree::ptree &cfg)
Construct the Configuration Manager from a property tree.
Definition: ConfigManager.cpp:31
Leosac::ConfigManager::set_kconfig
void set_kconfig(const boost::property_tree::ptree &new_cfg)
Update Leosac's core config ptree.
Definition: ConfigManager.cpp:186
Leosac::ConfigManager::instance_name_
std::string instance_name_
Definition: ConfigManager.hpp:189
Leosac::ConfigManager::ConfigFormat::BOOST_ARCHIVE
@ BOOST_ARCHIVE
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::ConfigManager::get_general_config
boost::property_tree::ptree get_general_config() const
Extract the current "general configuration".
Definition: ConfigManager.cpp:59
Leosac::ConfigManager::modules_configs_
std::map< std::string, boost::property_tree::ptree > modules_configs_
Maps a module's name to a property tree object.
Definition: ConfigManager.hpp:179
leosacexception.hpp
Exception class for LEOSAC Project related errors.
Leosac::ConfigManager::has_config
bool has_config(const std::string &module) const
Do we have config information for the module.
Definition: ConfigManager.cpp:261
Leosac::ConfigManager::incr_version
void incr_version()
Increment by 1 the current version number.
Definition: ConfigManager.cpp:256
Leosac::ConfigManager::get_exportable_general_config
boost::property_tree::ptree get_exportable_general_config() const
Return the property_tree of item inside the <kernel> tag (except <modules>`) that are marked exportab...
Definition: ConfigManager.cpp:76
Leosac::ConfigManager::config_version
uint64_t config_version() const
Return the current configuration version.
Definition: ConfigManager.cpp:251
Leosac::ConfigManager::get_non_importable_modules
std::list< std::string > get_non_importable_modules() const
Returns a list of module name that should not be imported.
Definition: ConfigManager.cpp:230
Leosac::ConfigManager::is_module_importable
bool is_module_importable(const std::string &) const
Helper around get_non_importable_modules()
Definition: ConfigManager.cpp:245
log.hpp
Leosac::ConfigManager::ConfigFormat::XML
@ XML
Leosac::ConfigManager::kernel_config_
boost::property_tree::ptree kernel_config_
Property tree for general configuration.
Definition: ConfigManager.hpp:185
Leosac::ConfigManager::~ConfigManager
virtual ~ConfigManager()=default
Leosac::ConfigManager::remove_config
bool remove_config(const std::string &module)
Remove the config entry for the module named module.
Definition: ConfigManager.cpp:176
Leosac::ConfigManager::get_application_config
boost::property_tree::ptree get_application_config()
Retrieve the (current, running) configuration from the application and its modules.
Definition: ConfigManager.cpp:41
operator<<
zmqpp::message & operator<<(zmqpp::message &msg, const Leosac::ConfigManager::ConfigFormat &fmt)
Definition: ConfigManager.cpp:155
Leosac::ConfigManager::version_
uint64_t version_
Definition: ConfigManager.hpp:187