Bayeux  3.4.1
Core Foundation library for SuperNEMO
module_manager.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2011-06-22
4  * Last modified : 2013-11-13
5  *
6  * Copyright (C) 2011-2013 Francois Mauger <mauger@lpccaen.in2p3.fr>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or (at
11  * your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  * Description:
24  *
25  * A manager/factory class for data (event record?) processing modules.
26  *
27  */
28 
29 #ifndef DPP_MODULE_MANAGER_H
30 #define DPP_MODULE_MANAGER_H 1
31 
32 // Standard library:
33 #include <string>
34 #include <vector>
35 
36 // Third party:
37 // - Boost:
38 #include <boost/cstdint.hpp>
39 // - Bayeux/datatools:
40 #include <datatools/logger.h>
41 
42 // This project:
43 #include <dpp/base_module.h>
44 #include <dpp/module_tools.h>
45 
46 namespace dpp {
47 
51  {
52  public:
53 
55  BLANK = 0,
58  };
59 
60  bool is_no_preload() const;
61 
62  bool is_initialization_at_load() const;
63 
64  bool has(const std::string & module_name_) const;
65 
66  void remove(const std::string & module_name_);
67 
68  base_module & grab(const std::string & module_name_);
69 
70  const base_module & get(const std::string & module_name_) const;
71 
73 
74  // DEPRECATED
76 
77  const module_handle_dict_type & get_modules() const ;
78 
81  void build_modules_infos(std::vector<std::pair<std::string,std::string> > & infos_) const;
82 
83  bool is_initialized() const;
84 
85  void initialize(const datatools::properties & setup_);
86 
87  void initialize_simple();
88 
89  void reset();
90 
91  module_manager(uint32_t flags_ = BLANK);
92 
93  virtual ~module_manager();
94 
95  bool has_service_manager() const;
96 
98 
100 
101  void set_service_manager(datatools::service_manager & service_manager_);
102 
103  void install_service_manager(const datatools::properties & service_manager_configuration_);
104 
105  virtual void tree_dump(std::ostream & out_ = std::clog,
106  const std::string & title_ = "",
107  const std::string & indent_ = "",
108  bool inherit_ = false) const;
109 
110  void load_module(const std::string & module_name_,
111  const std::string & module_id_,
112  const datatools::properties & module_config_);
113 
114  void create_module(module_entry_type & module_entry_);
115 
116  void initialize_module(module_entry_type & module_entry_);
117 
118  void load_modules(const datatools::multi_properties & modules_config_);
119 
120  void load_modules(const std::string & modules_defs_);
121 
123 
125 
126  protected:
127 
128  void _load_module(const std::string & module_name_,
129  const std::string & module_id_,
130  const datatools::properties & module_config_);
131 
132  void _load_modules(const datatools::multi_properties & modules_config_);
133 
134  void _create_module(module_entry_type & module_entry_);
135 
136  void _initialize_module(module_entry_type & module_entry_);
137 
138  void _reset_module(module_entry_type & module_entry_);
139 
140  public:
141 
143  bool has_module_type(const std::string & module_id_) const;
144 
146  template <class ModuleClass>
147  void register_module_type(const std::string & module_id_)
148  {
149  _factory_register_.registration(module_id_, boost::factory<ModuleClass*>());
150  return;
151  }
152 
154  void unregister_module_type(const std::string & module_id_);
155 
157  void build_registered_module_types(std::vector<std::string> & ids_) const;
158 
159  protected:
160 
161  void _preload_global_dict();
162 
163  private:
164 
165  datatools::logger::priority _logging_priority_;
166  bool _initialized_;
167  uint32_t _flags_;
168  base_module::factory_register_type _factory_register_;
169  module_handle_dict_type _modules_;
170  bool _service_manager_owner_;
171  datatools::service_manager * _service_manager_;
172 
173  };
174 
175 } // end of namespace dpp
176 
177 /***************
178  * OCD support *
179  ***************/
180 #include <datatools/ocd_macros.h>
182 
183 #endif // DPP_MODULE_MANAGER_H
184 
185 // Local Variables: --
186 // mode: c++ --
187 // c-file-style: "gnu" --
188 // tab-width: 2 --
189 // End: --
void _load_module(const std::string &module_name_, const std::string &module_id_, const datatools::properties &module_config_)
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
A container of mapped properties objects.
Definition: multi_properties.h:99
void _initialize_module(module_entry_type &module_entry_)
void remove(const std::string &module_name_)
Definition: module_manager.h:55
bool has_service_manager() const
Top-level namespace of the Bayeux/dpp module library.
Definition: base_module.h:56
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
static const uint32_t bit01
Definition: bit_mask.h:28
void _create_module(module_entry_type &module_entry_)
module_handle_dict_type & get_modules()
Module record entry class.
Definition: module_tools.h:60
void set_service_manager(datatools::service_manager &service_manager_)
virtual ~module_manager()
void install_service_manager(const datatools::properties &service_manager_configuration_)
void create_module(module_entry_type &module_entry_)
bool is_initialized() const
bool has(const std::string &module_name_) const
void register_module_type(const std::string &module_id_)
Register a factory for a given module class given a (unique) ID.
Definition: module_manager.h:147
DOCD_CLASS_DECLARATION(my::algo)
Declaration of the OCD support for the my::algo class.
std::map< std::string, module_entry_type > module_handle_dict_type
Definition: module_tools.h:141
Base processing module (abstract interface)
Definition: base_module.h:59
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Main old interface method for printing.
void load_module(const std::string &module_name_, const std::string &module_id_, const datatools::properties &module_config_)
bool is_no_preload() const
void build_modules_infos(std::vector< std::pair< std::string, std::string > > &infos_) const
void _reset_module(module_entry_type &module_entry_)
const base_module & get(const std::string &module_name_) const
datatools::service_manager & grab_service_manager()
bool is_initialization_at_load() const
void build_registered_module_types(std::vector< std::string > &ids_) const
Copy registered module factories IDs in the supplied vector.
base_module & grab(const std::string &module_name_)
void set_logging_priority(datatools::logger::priority)
module_manager(uint32_t flags_=BLANK)
datatools::logger::priority get_logging_priority() const
Utilities for logging information.
Definition: module_manager.h:56
void load_modules(const datatools::multi_properties &modules_config_)
static const uint32_t bit00
Definition: bit_mask.h:27
ctor_flag_type
Definition: module_manager.h:54
A manager for data processing modules.
Definition: module_manager.h:49
void initialize(const datatools::properties &setup_)
void _load_modules(const datatools::multi_properties &modules_config_)
const datatools::service_manager & get_service_manager() const
Service management class.
Definition: service_manager.h:57
bool has_module_type(const std::string &module_id_) const
Check if a module factory given by ID is registered.
module_handle_dict_type & grab_modules()
void initialize_module(module_entry_type &module_entry_)
void unregister_module_type(const std::string &module_id_)
Unregister a module factory.
A dictionary of arbitrary properties.
Definition: properties.h:125