Bayeux  3.4.1
Core Foundation library for SuperNEMO
kernel.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2013-09-26
4  * Last modified: 2016-06-25
5  *
6  * License:
7  *
8  * Copyright (C) 2013-2016 Francois Mauger <mauger@lpccaen.in2p3.fr>
9  *
10  * This program 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 (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  * Boston, MA 02110-1301, USA.
24  *
25  * Description:
26  *
27  * The datatools kernel singleton with embedded resources and components.
28  *
29  */
30 
31 #ifndef DATATOOLS_KERNEL_H
32 #define DATATOOLS_KERNEL_H
33 
34 // Standard Library:
35 #include <iostream>
36 #include <memory>
37 
38 // Third Party:
39 #include <boost/noncopyable.hpp>
40 #include <boost/cstdint.hpp>
41 
42 #ifdef __clang__
43 #pragma clang diagnostic push
44 #pragma clang diagnostic ignored "-Wunused-local-typedef"
45 #endif
46 #include <boost/program_options.hpp>
47 #ifdef __clang__
48 #pragma clang diagnostic pop
49 #endif
50 
51 // This project:
52 #include <datatools/logger.h>
53 #include <datatools/i_tree_dump.h>
55 #include <datatools/bit_mask.h>
57 
58 namespace datatools {
59 
60  // Forward declaration:
61  class service_manager;
62  class urn_query_service;
63  class library_query_service;
64  class library_info;
65 
66  namespace configuration {
67 
68  // Forward declaration:
69  class variant_repository;
70  class variant_service;
71 
72  }
73 
75  class kernel
76  : private boost::noncopyable
78  {
79 
80  public:
81 
83  struct param_type {
84 
85  public:
86 
88  param_type();
89 
91  void reset();
92 
94  void print(std::ostream & out_,
95  const std::string & title_ = "",
96  const std::string & indent_ = "");
97 
98  public:
99 
100  bool help = false;
101  std::string logging_label = "fatal";
102  std::string locale_category;
103  std::string library_query_logging_label = "fatal";
104  bool inhibit_library_query = false;
105  bool inhibit_urn_query = false;
107  std::vector<std::string> unrecognized_args;
108  std::vector<std::string> resource_paths;
109  std::string variant_config;
110  std::vector<std::string> variant_registry_configs;
111  std::string variant_load;
112  std::string variant_store;
113  std::vector<std::string> variant_sets;
114 
115  bool splash = false;
116 #if DATATOOLS_WITH_QT_GUI == 1
117  bool inhibit_qt_gui = false;
118  bool variant_qt_gui = false;
119  std::string variant_qt_gui_style = "plastique";
120 #endif // DATATOOLS_WITH_QT_GUI == 1
121 
122  };
123 
125  static const uint32_t init_mask = datatools::bit_mask::nbits15;
126 
128  enum init_flags {
129  // Import value from datatools_init_flags:
147  };
148 
150  kernel();
151 
153  kernel(int argc_, char * argv_[], uint32_t flags = 0);
154 
156  virtual ~kernel();
157 
159  void initialize(int argc_, char * argv_[], uint32_t flags_ = 0);
160 
162  void shutdown();
163 
165  bool is_initialized() const;
166 
169 
172 
174  bool has_services() const;
175 
177  bool has_urn_query() const;
178 
181 
183  const urn_query_service & get_urn_query() const;
184 
186  bool has_library_query() const;
187 
190 
193 
195  bool has_library_info_register() const;
196 
199 
201  const library_info & get_library_info_register() const;
202 
204  bool has_variant_repository() const;
205 
208 
211 
213  bool has_variant_service() const;
214 
217 
220 
223 
225  void reset_variant_service();
226 
229 
232 
235 
237  bool has_locale_category() const;
238 
240  void set_locale_category(const std::string & lc_);
241 
243  const std::string & get_locale_category() const;
244 
246  const std::string & get_application_name() const;
247 
249  bool has_application_name() const;
250 
252  static bool is_instantiated();
253 
255  static kernel & instance();
256 
258  static kernel & instantiate();
259 
261  static const kernel & const_instance();
262 
264  static void build_opt_desc(boost::program_options::options_description &, param_type &, uint32_t flags_ = 0);
265 
267  static void print_splash(std::ostream & = std::clog);
268 
270  static void print_opt_desc(const boost::program_options::options_description &,
271  std::ostream & = std::clog,
272  const std::string & indent_ = "");
273 
274 #if DATATOOLS_WITH_QT_GUI == 1
275  bool is_qt_gui_activated() const;
277 #endif // DATATOOLS_WITH_QT_GUI == 1
278 
280  unsigned int get_nargs() const;
281 
283  const std::vector<std::string> & get_args() const;
284 
286  int get_argc() const;
287 
289  char ** get_argv() const;
290 
292  char * get_argv(int i_) const;
293 
297 
300 
302  bool is_urn_query_service_activated() const;
303 
305  bool is_variant_repository_activated() const;
306 
308  bool is_variant_service_allowed() const;
309 
311  void tree_dump(std::ostream & out_ = std::clog,
312  const std::string & title_ = "",
313  const std::string & indent_ = "",
314  bool inherit_ = false) const;
315 
318 
321 
324  const std::string & registry_name_ = "");
325 
327  bool has_configuration_registries() const;
328 
330  bool has_external_configuration_registry(const std::string & registry_name_) const;
331 
333  void clear_configuration_registry(const std::string & registry_name_);
334 
337 
340 
343 
344  private:
345 
347  void _initialize_();
348 
350  void _shutdown_();
351 
353  void _set_defaults_();
354 
356  void _construct_();
357 
359  void _initialize_services_();
360 
362  void _shutdown_services_();
363 
365  void _initialize_library_query_service_();
366 
368  void _shutdown_library_query_service_();
369 
371  void _initialize_urn_query_service_();
372 
374  void _shutdown_urn_query_service_();
375 
377  void _initialize_configuration_variant_repository_();
378 
379  private:
380 
381  // Management:
382  bool _initialized_ = false;
383  param_type _params_;
384  logger::priority _logging_;
385 
386  // Configuration parameters:
387  std::string _locale_category_;
388  std::string _application_name_;
389  unsigned int _nargs_ = 0;
390  std::vector<std::string> _args_;
391  int _argc_ = 0;
392  char ** _argv_ = nullptr;
393  std::vector<std::string> _unrecognized_args_;
394  bool _activate_library_query_service_ = true;
395  bool _activate_urn_query_service_ = true;
396  bool _activate_variant_repository_ = true;
397  bool _allowed_variant_service_ = true;
398 #if DATATOOLS_WITH_QT_GUI == 1
399  bool _activate_qt_gui_ = true;
400 #endif // DATATOOLS_WITH_QT_GUI == 1
401 
402  // Working internals:
403  std::unique_ptr<datatools::service_manager> _services_;
404  std::unique_ptr<configuration::variant_repository> _variant_repository_;
405  configuration::variant_service * _variant_service_ = nullptr;
406 #if DATATOOLS_WITH_QT_GUI == 1
407  // QApplication * _qapp_; //!< Handle to the Qt application
408 #endif // DATATOOLS_WITH_QT_GUI == 1
409 
410  // Singleton:
411  static kernel * _instance_;
412 
413  };
414 
415 } // end of namespace datatools
416 
417 #endif // DATATOOLS_KERNEL_H
418 
419 // Local Variables: --
420 // mode: c++ --
421 // c-file-style: "gnu" --
422 // tab-width: 2 --
423 // End: --
std::string variant_store
Path to the file where one stores the values of the variant parameters.
Definition: kernel.h:112
static const uint32_t nbits15
Definition: bit_mask.h:75
Definition: datatools_init.h:25
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
Definition: datatools_init.h:26
datatools::logger::priority get_logging() const
Return the logging priority threshold.
A service which allows queries about URNs thanks to embedded specialized dictionaries of URN informat...
Definition: urn_query_service.h:54
bool has_variant_repository() const
Check if the configuration variant repository is available.
bool has_library_info_register() const
Check if the library/component info register is available.
library_info & grab_library_info_register()
Return a mutable reference to the library/component info register.
static const uint32_t init_mask
Bit mask for the kernel initialization flags.
Definition: kernel.h:125
void clear_configuration_registry(const std::string &registry_name_)
Remove a imported registry given its name.
Definition: kernel.h:140
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
Host a register of static and/or dynamic informations about libraries or software components.
Definition: library_info.h:51
std::string variant_load
Path to the file from which one loads the values of the variant parameters.
Definition: kernel.h:111
Describe the datatools API configuration.
Definition: kernel.h:144
Inhibit help screen about kernel switches from the CLI terminal.
Definition: datatools_init.h:16
Deprecated.
Definition: kernel.h:137
bool is_urn_query_service_activated() const
Check if the URN query service is activated.
std::string variant_config
The configuration file for the system variant repository.
Definition: kernel.h:109
Reserved for future kernel initialization.
Definition: datatools_init.h:30
Reserved for future kernel initialization.
Definition: datatools_init.h:32
bool is_library_info_register_activated() const
Inhibit splash screen from the CLI terminal.
Definition: datatools_init.h:17
Definition: kernel.h:143
void clear_configuration_repository()
Clear the configuration variant repository.
void import_configuration_repository(configuration::variant_repository &rep_)
Import a configuration variant repository.
bool has_effective_variant_repository() const
Check if the effective configuration variant repository is available.
bool has_urn_query() const
Check if the system URN query service is available.
Definition: datatools_init.h:24
const library_query_service & get_library_query() const
Return a non mutable reference to the system library query service.
bool has_variant_service() const
Check if a configuration variant service is available.
void reset_variant_service()
Reset variant service.
void register_configuration_variant_registries()
Registration of configuration variant registries.
const library_info & get_library_info_register() const
Return a non mutable reference to the library/component info register.
void set_variant_service(configuration::variant_service &var_serv_)
Set a variant service.
void shutdown()
Shutdown.
void register_resource_paths()
Registration of resource paths.
configuration::variant_repository & grab_effective_variant_repository()
Return a mutable reference to the effective configuration variant repository.
static kernel & instance()
Return a mutable reference to the kernel singleton.
void initialize(int argc_, char *argv_[], uint32_t flags_=0)
Initialization from command line arguments.
std::vector< std::string > variant_registry_configs
List of configuration files for the variant registries to be embedded in the system variant repositor...
Definition: kernel.h:110
bool help
Flag to print the help about datatools' command line options.
Definition: kernel.h:100
static kernel & instantiate()
Instantiate and return a mutable reference to the kernel singleton.
const urn_query_service & get_urn_query() const
Return a non mutable reference to the system URN query service.
bool has_external_configuration_registry(const std::string &registry_name_) const
Check for an external registry given its name.
urn_query_service & grab_urn_query()
Return a mutable reference to the system URN query service.
init_flags
Kernel initialization flags (15 bits)
Definition: kernel.h:128
void set_logging(datatools::logger::priority)
Set the logging priority threshold.
static const kernel & const_instance()
Return a non mutable reference to the kernel singleton.
char ** get_argv() const
Return the command line arguments.
std::vector< std::string > unrecognized_args
List of unrecognized arguments.
Definition: kernel.h:107
Reserved for future kernel initialization.
Definition: datatools_init.h:31
The set of configuration parameters for the datatools kernel.
Definition: kernel.h:83
std::vector< std::string > variant_sets
List of directives to set the values of the variant parameters.
Definition: kernel.h:113
bool splash
Flag to display the datatools splash screen.
Definition: kernel.h:115
bool is_variant_repository_activated() const
Check if the variant repository is activated.
bool is_initialized() const
Check initialization status.
static void print_splash(std::ostream &=std::clog)
Print splash screen.
Definition: kernel.h:130
bool inhibit_library_query
Flag to inhibit the use of the embedded library information registry.
Definition: kernel.h:104
Deprecated.
Definition: kernel.h:136
void set_locale_category(const std::string &lc_)
Set the locale category.
virtual ~kernel()
Destruction with on-the-fly shutdown if needed.
Definition: kernel.h:131
deprecated
Definition: datatools_init.h:22
kernel()
Default constructor.
unsigned int get_nargs() const
Return the command line argument count.
std::string library_query_logging_label
Logging priority label for the embedded library information registry.
Definition: kernel.h:103
Definition: kernel.h:146
const configuration::variant_service & get_variant_service() const
Return a non mutable reference to the configuration variant service.
Reserved for future kernel initialization.
Definition: datatools_init.h:29
void print(std::ostream &out_, const std::string &title_="", const std::string &indent_="")
Print.
const std::vector< std::string > & get_args() const
Return the list of command line arguments.
Definition: kernel.h:145
bool has_services() const
Check if the system services are available.
static void print_opt_desc(const boost::program_options::options_description &, std::ostream &=std::clog, const std::string &indent_="")
Print description of options.
const configuration::variant_repository & get_effective_variant_repository() const
Return a non mutable reference to the effective configuration variant repository.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
deprecated
Definition: datatools_init.h:23
bool is_variant_service_allowed() const
Check if the variant service is allowed.
Utilities for logging information.
configuration::variant_repository & grab_variant_repository()
Return a mutable reference to the configuration variant repository.
Definition: datatools_init.h:27
bool inhibit_variant_repository
Flag to inhibit the use of the variant repository.
Definition: kernel.h:106
configuration::variant_service & grab_variant_service()
Return a mutable reference to the configuration variant service.
void clear_imported_configuration_repository()
Clear all imported registries from the configuration variant repository.
const configuration::variant_repository & get_variant_repository() const
Return a non mutable reference to the configuration variant repository.
Inhibit local category setting from CLI.
Definition: datatools_init.h:18
std::vector< std::string > resource_paths
List of resource paths directives.
Definition: kernel.h:108
const std::string & get_locale_category() const
Return the locale category.
static bool is_instantiated()
Check if the kernel singleton is available.
Describe the datatools API configuration.
Inhibit logging level setting from CLI.
Definition: datatools_init.h:19
bool has_configuration_registries() const
Check if the kernel has configuration variant registries.
Variant user interface service.
Definition: variant_service.h:47
bool has_locale_category() const
Check if a specific locale_category is defined.
Inhibit system library query service.
Definition: datatools_init.h:20
void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
bool is_library_query_service_activated() const
Check if the library query service is activated.
Definition: kernel.h:133
void import_configuration_registry(configuration::variant_repository &rep_, const std::string &registry_name_="")
Import some (or all) configuration variant registry from a repository.
bool has_library_query() const
Check if the system library query service is available.
static void build_opt_desc(boost::program_options::options_description &, param_type &, uint32_t flags_=0)
Build description of options.
std::string locale_category
The locale category.
Definition: kernel.h:102
library_query_service & grab_library_query()
Return a mutable reference to the system library query service.
bool has_application_name() const
Check if the name of the current application is defined.
Library information query service.
Definition: library_query_service.h:34
The datatools kernel singleton with embedded resources and components.
Definition: kernel.h:75
Variant repository.
Definition: variant_repository.h:57
const std::string & get_application_name() const
Return the name of the current application.
Inhibit system URN query service.
Definition: datatools_init.h:28
std::string logging_label
Logging priority label.
Definition: kernel.h:101
Definition: datatools_init.h:21
bool inhibit_urn_query
Flag to inhibit the use of the URN query service.
Definition: kernel.h:105
int get_argc() const
Return the command line argument count.