Bayeux  3.4.1
Core Foundation library for SuperNEMO
variant_service.h
Go to the documentation of this file.
1 //
5 // Copyright (c) 2016 by Francois Mauger <mauger@lpccaen.in2p3.fr>
6 // Copyright (c) 2016 by Université de Caen
7 //
8 // This file is part of Bayeux.
9 //
10 // Bayeux is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Bayeux is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Bayeux. If not, see <http://www.gnu.org/licenses/>.
22 
23 #ifndef DATATOOLS_CONFIGURATION_VARIANT_SERVICE_H
24 #define DATATOOLS_CONFIGURATION_VARIANT_SERVICE_H
25 
26 // Standard Library:
27 #include <string>
28 #include <vector>
29 #include <map>
30 #include <stdexcept>
31 
32 // Third party:
33 // - Boost
34 #include <boost/cstdint.hpp>
35 #include <boost/program_options.hpp>
36 // - Bayeux:
37 #include <bayeux/bayeux.h>
38 // - Bayeux/datatools:
41 
42 namespace datatools {
43 
44  namespace configuration {
45 
48  {
49  public:
50 
52  class variant_exception : public std::runtime_error {
53  public:
54  variant_exception(const std::string& msg) : std::runtime_error(msg) {}
55  };
56 
58  enum config_flags {
71  };
72 
76  struct config
77  {
79  config();
80 
82  bool is_active() const;
83 
85  void print(std::ostream & out_,
86  const std::string & title_ = "",
87  const std::string & indent_ = "") const;
88 
89  // Configuration parameters:
90  std::string label;
91  std::string logging;
92  std::string config_filename;
93  std::vector<std::string> registry_rules;
94  std::vector<std::string> registry_dependencies;
95  std::string profile_load;
97  std::vector<std::string> settings;
98  std::string profile_store;
99 #if DATATOOLS_WITH_QT_GUI == 1
100  bool gui = false;
101 #endif // DATATOOLS_WITH_QT_GUI == 1
102  bool tui = false;
103  std::string reporting_filename;
104  };
105 
107  static void init_options(boost::program_options::options_description & opts_,
108  config & cfg_,
109  uint32_t flags_ = 0);
110 
113  {
115  registry_record();
116 
118  int init_registry(int & max_rank_, const std::string & registry_rule_);
119 
121  int add_dependency(const std::string & registry_dependency_rule_);
122 
124  bool is_valid() const;
125 
127  const std::string & get_name() const;
128 
130  const std::string & get_display_name() const;
131 
133  const std::string & get_description() const;
134 
136  int get_rank() const;
137 
139  const std::string & get_config_file() const;
140 
142  const std::vector<std::string> & get_dependencies() const;
143 
144  // Attributes:
145  std::string _name_;
146  std::string _display_name_;
147  std::string _description_;
148  int _rank_;
149  std::string _config_file_;
150  std::vector<std::string> _dependencies_;
151 
152  };
153 
155  typedef std::map<std::string, registry_record> registry_record_dict_type;
156 
157  // Default Constructor
158  variant_service(uint32_t flags_ = 0);
159 
160  // Destructor
162 
164  void set_label(const std::string &);
165 
167  const std::string & get_label() const;
168 
171 
173  void set_repository_config(const std::string & config_);
174 
176  void add_registry_rule(const std::string & registry_rule_);
177 
179  void add_registry_dependency(const std::string & registry_dependency_rule_);
180 
182  bool has_registry_record(const std::string & registry_name_) const;
183 
185  void set_input_profile(const std::string & ip_);
186 
189 
191  void set_settings(const std::vector<std::string> & setting_);
192 
194  void set_output_profile(const std::string & op_);
195 
197  bool is_reporting() const;
198 
200  bool has_reporting_file() const;
201 
203  void set_reporting_file(const std::string & urf_);
204 
206  void configure(const config & cfg_, bool lock_ = true);
207 
209  int32_t get_max_rank() const;
210 
212  int32_t get_next_rank() const;
213 
214  // //! Return the first free rank for registries
215  // int32_t get_free_rank() const;
216 
217 #if DATATOOLS_WITH_QT_GUI == 1
218  void set_gui(bool);
220 #endif // DATATOOLS_WITH_QT_GUI == 1
221 
223  void set_tui(bool);
224 
226  bool is_started() const;
227 
229  void start();
230 
232  void stop();
233 
237  void apply_setting(const std::string & setting_);
238 
241 
243  const variant_repository & get_repository() const;
244 
245  private:
246 
247  // Private methods wrapped in start/stop actions:
248 
249  //----------------------------------------------------------------------
251  void _do_build_();
252 
253  //----------------------------------------------------------------------
255  void _do_variant_config_();
256 
257  //----------------------------------------------------------------------
259  registry_record & _add_registry_record(const registry_record & registry_record_);
260 
261  //----------------------------------------------------------------------
263  void _do_variant_additional_registries_setup_();
264 
265  //----------------------------------------------------------------------
267  void _do_variant_load_profile_();
268 
269  //----------------------------------------------------------------------
271  void _do_variant_store_profile_();
272 
273  //----------------------------------------------------------------------
275  void _do_variant_apply_settings_();
276 
277 #if DATATOOLS_WITH_QT_GUI == 1
278  //----------------------------------------------------------------------
280  void _do_variant_launch_gui_();
281 #endif // DATATOOLS_WITH_QT_GUI == 1
282 
283  //----------------------------------------------------------------------
285  void _do_variant_launch_tui_();
286 
287  //----------------------------------------------------------------------
294  void _do_variant_system_export_();
295 
296  //----------------------------------------------------------------------
299  void _do_variant_system_discard_();
300 
301  //----------------------------------------------------------------------
303  void _do_variant_reporting_init_();
304 
305  //----------------------------------------------------------------------
307  void _do_variant_reporting_fini_();
308 
309  private:
310 
311  // Configuration:
312  datatools::logger::priority _logging_;
313  std::string _label_;
314  std::string _repository_config_;
315  std::vector<std::string> _registry_rules_;
316  std::vector<std::string> _registry_deps_;
317  std::string _input_profile_;
318  std::vector<std::string> _settings_;
319  std::string _output_profile_;
320  bool _dont_ignore_unknown_at_load_ = false;
321  #if DATATOOLS_WITH_QT_GUI == 1
322  bool _gui_ = false;
323 #endif // DATATOOLS_WITH_QT_GUI == 1
324  bool _tui_ = false;
325  std::string _reporting_file_;
326 
327  // Embedded working data:
328  bool _started_;
329  registry_record_dict_type _registries_;
330  variant_repository _repository_;
331  variant_reporting _reporting_;
332 
333  };
334 
335  } // namespace configuration
336 
337 } // namespace datatools
338 
339 #endif // DATATOOLS_CONFIGURATION_VARIANT_SERVICE_H
340 
341 // Local Variables: --
342 // mode: c++ --
343 // c-file-style: "gnu" --
344 // tab-width: 2 --
345 // End: --
Provide system init for Bayeux internals.
void start()
Run startup operations at application startup.
static const uint32_t bit08
Definition: bit_mask.h:35
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
void add_registry_dependency(const std::string &registry_dependency_rule_)
Add a dependency to a variant registry in the variant repository.
config_flags
Special flags to publish variant related program options.
Definition: variant_service.h:58
const variant_repository & get_repository() const
std::string config_filename
Variant configuration file.
Definition: variant_service.h:92
static const uint32_t bit07
Definition: bit_mask.h:34
Variant service configuration parameters.
Definition: variant_service.h:76
int32_t get_max_rank() const
Return the max rank for registries.
static void init_options(boost::program_options::options_description &opts_, config &cfg_, uint32_t flags_=0)
Initialize options description associated to a config structure.
bool profile_load_dont_ignore_unknown
Flag to ignore unknown registry at profile load.
Definition: variant_service.h:96
static const uint32_t bit01
Definition: bit_mask.h:28
static const uint32_t bit09
Definition: bit_mask.h:36
static const uint32_t bit03
Definition: bit_mask.h:30
bool is_active() const
Check if the variant is activated.
bool is_started() const
Check started flag.
void set_repository_config(const std::string &config_)
Set the main configuration file for the variant repository.
std::vector< std::string > _dependencies_
Dependencies.
Definition: variant_service.h:150
std::vector< std::string > settings
List of variant settings.
Definition: variant_service.h:97
static const uint32_t bit04
Definition: bit_mask.h:31
bool is_reporting() const
Check is reporting is used.
Record for an additional registry.
Definition: variant_service.h:112
static const uint32_t bit06
Definition: bit_mask.h:33
const std::vector< std::string > & get_dependencies() const
Return the list of dependencies of the registry.
const std::string & get_name() const
Return the name of the registry.
int init_registry(int &max_rank_, const std::string &registry_rule_)
Apply a registry rule.
int _rank_
Rank of the variant registry.
Definition: variant_service.h:148
bool tui
Launch the variant TUI editor.
Definition: variant_service.h:102
bool has_reporting_file() const
Check for a usage reporting filename.
void apply_setting(const std::string &setting_)
Return a handle to the variant repository.
std::string profile_load
Variant profile load.
Definition: variant_service.h:95
void set_logging(datatools::logger::priority)
Set the logging priority thresold.
static const uint32_t bit11
Definition: bit_mask.h:38
void configure(const config &cfg_, bool lock_=true)
Configure the service with a set of parameters.
std::map< std::string, registry_record > registry_record_dict_type
Type alias for a dictionary of registry records.
Definition: variant_service.h:155
void set_tui(bool)
Activate the variant TUI editor.
int get_rank() const
Return the rank of the registry.
const std::string & get_display_name() const
Return the display name of the registry.
int32_t get_next_rank() const
Return the next available rank for registries.
std::string reporting_filename
Variant usage reporting file.
Definition: variant_service.h:103
static const uint32_t bit10
Definition: bit_mask.h:37
static const uint32_t bit02
Definition: bit_mask.h:29
int add_dependency(const std::string &registry_dependency_rule_)
Apply a registry dependency rule.
variant processing reporting
Definition: io.h:124
static const uint32_t bit05
Definition: bit_mask.h:32
void set_label(const std::string &)
Set the label.
std::string logging
Variant logging.
Definition: variant_service.h:91
const std::string & get_description() const
Return the description of the registry.
void set_dont_ignore_unknown_at_load(bool)
Set the ignore unknown at load flag.
void set_reporting_file(const std::string &urf_)
Set the usage reporting filename.
std::string _display_name_
Display name of the variant registry.
Definition: variant_service.h:146
void stop()
Run termination at application stop.
const std::string & get_config_file() const
Return the config file of the registry.
void set_input_profile(const std::string &ip_)
Set the optional input variant profile filename.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
void print(std::ostream &out_, const std::string &title_="", const std::string &indent_="") const
Smart print.
variant_exception(const std::string &msg)
Definition: variant_service.h:54
std::string _name_
Name of the variant registry.
Definition: variant_service.h:145
Exception for variant related error.
Definition: variant_service.h:52
bool is_valid() const
Check the validity of the record.
static const uint32_t bit00
Definition: bit_mask.h:27
Variant user interface service.
Definition: variant_service.h:47
void add_registry_rule(const std::string &registry_rule_)
Add the configuration of a variant registry in the variant repository.
bool has_registry_record(const std::string &registry_name_) const
Check if an additional variant registry is defined.
std::vector< std::string > registry_dependencies
Variant registry dependencies.
Definition: variant_service.h:94
std::string label
Label.
Definition: variant_service.h:90
std::string _description_
Description of the variant registry.
Definition: variant_service.h:147
void set_output_profile(const std::string &op_)
Set the optional output variant profile filename.
variant_repository & grab_repository()
Return a handle to the variant repository.
std::string _config_file_
Configuration file.
Definition: variant_service.h:149
Variant repository.
Definition: variant_repository.h:57
std::string profile_store
Variant profile store.
Definition: variant_service.h:98
const std::string & get_label() const
Return the label.
std::vector< std::string > registry_rules
Variant registry definitions.
Definition: variant_service.h:93
void set_settings(const std::vector< std::string > &setting_)
Set the setting rules for variant parameters.