Bayeux  3.4.1
Core Foundation library for SuperNEMO
service_tools.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date : 2011-06-07
4  * Last modified : 2017-07-13
5  *
6  * Copyright (C) 2011-2017 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  * Service tools, typedefs.
26  *
27  */
28 
29 #ifndef DATATOOLS_SERVICE_TOOLS_H
30 #define DATATOOLS_SERVICE_TOOLS_H
31 
32 // Standard Library:
33 #include <string>
34 #include <map>
35 #include <vector>
36 #include <memory>
37 
38 // Third Party:
39 // - Boost:
40 #include <boost/cstdint.hpp>
41 
42 // This project:
43 #include <datatools/exception.h>
44 #include <datatools/handle.h>
45 #include <datatools/i_tree_dump.h>
46 #include <datatools/properties.h>
47 #include <datatools/bit_mask.h>
48 
49 namespace datatools {
50 
52  class base_service;
54 
62  };
63 
66 
67  std::string id;
68  std::string version;
69  std::string meta;
72  void reset();
73  };
74 
75  // Long typedef names
76  typedef std::map<std::string, int> dependency_level_dict_type;
77  typedef std::map<std::string, dependency_info_type> service_dependency_dict_type;
78 
79  class service_manager;
80 
87  {
88  public:
89 
91  enum status_type {
96  };
97 
98  public:
99 
101  service_entry();
102 
104  service_entry(const std::string & name_, service_manager & mgr_);
105 
107  ~service_entry();
108 
110  const std::string & get_service_name() const;
111 
113  void set_service_name(const std::string &);
114 
116  const std::string & get_service_id() const;
117 
119  void set_service_id(const std::string &);
120 
123 
126 
129 
131  bool can_be_dropped() const;
132 
134  uint32_t get_service_status() const;
135 
137  void update_service_status(uint32_t);
138 
140  void reset_service_status(uint32_t);
141 
143  bool is_created() const;
144 
146  bool is_initialized() const;
147 
149  bool has_master(const std::string& name_) const;
150 
152  virtual void tree_dump(std::ostream& out_ = std::clog,
153  const std::string & title_ = "",
154  const std::string & indent_ = "",
155  bool inherit_ = false) const;
156 
158  const service_handle_type & get_service_handle() const;
159 
162 
164  bool has_service_manager() const;
165 
167  void set_service_manager(service_manager & smgr_);
168 
170  const service_manager & get_service_manager() const;
171 
174 
175  private:
176 
177  std::string service_name;
178  service_manager * manager = nullptr;
179  std::string service_id;
180  datatools::properties service_config;
181  uint32_t service_status = STATUS_BLANK;
182  service_handle_type service_handle;
183 
184  public:
185 
186  // Not supported for now:
188  // dependency_level_dict_type service_slaves; ///< The list of depending services (by names)
189 
190  };
191 
193  typedef std::shared_ptr<service_entry> service_entry_ptr;
194 
196  typedef std::map<std::string, service_entry_ptr> service_dict_type;
197 
199  bool service_exists(const service_dict_type & services_,
200  const std::string & service_name_);
201 
203  bool service_of_type_exists(const service_dict_type & services_,
204  const std::string & service_type_id_,
205  const std::string & service_name_);
206 
208  void merge_services(service_dict_type & services_,
209  service_dict_type & merged_,
210  bool duplicate_throw_ = false);
211 
213  bool find_service_name_with_id(const service_dict_type & services_,
214  const std::string & service_type_id_,
215  std::string & service_name_);
216 
218  bool find_service_names_with_id(const service_dict_type & services_,
219  const std::string & service_type_id_,
220  std::vector<std::string> & service_names_);
221 
224  const std::string & service_name_);
225 
227  const base_service & get_service(const service_dict_type & services_,
228  const std::string & service_name_);
229 
230 } // end of namespace datatools
231 
232 #endif // DATATOOLS_SERVICE_TOOLS_H
233 
234 // Local Variables: --
235 // mode: c++ --
236 // c-file-style: "gnu" --
237 // tab-width: 2 --
238 // End: --
uint32_t get_service_status() const
Return the service status.
const base_service & get_service(const service_dict_type &services_, const std::string &service_name_)
Return the const reference to a service given its name.
The service does not depend on the external service.
Definition: service_tools.h:58
void set_service_config(const datatools::properties &)
Set the service configuration.
bool find_service_names_with_id(const service_dict_type &services_, const std::string &service_type_id_, std::vector< std::string > &service_names_)
Find all service names with given registered service type identifier from a dictionary of services.
Record that stores informations about the dependency between services :
Definition: service_tools.h:65
An interface with utilities for printable objects.
Definition: i_tree_dump.h:36
static const uint32_t bit01
Definition: bit_mask.h:28
std::map< std::string, service_entry_ptr > service_dict_type
Type alias for a flat dictionary of service entries.
Definition: service_tools.h:196
The base service class.
Definition: base_service.h:68
service_dependency_dict_type service_masters
The list of services the service depends on (by names)
Definition: service_tools.h:187
Empty flag.
Definition: service_tools.h:92
void merge_services(service_dict_type &services_, service_dict_type &merged_, bool duplicate_throw_=false)
Merge a service dictionary.
std::map< std::string, dependency_info_type > service_dependency_dict_type
Definition: service_tools.h:77
Initialization flag.
Definition: service_tools.h:94
bool is_initialized() const
Check if the service object is initialized.
std::string meta
Auxiliary information.
Definition: service_tools.h:69
service_manager & grab_service_manager()
Return a mutable reference to the service manager.
Strictly depends on the external service.
Definition: service_tools.h:61
base_service & grab_service(service_dict_type &services_, const std::string &service_name_)
Return the mutable reference to a service given its name.
datatools::properties & grab_service_config()
Return a reference to the mutable service configuration.
Utility macros for exception handling.
Broken dependency flag.
Definition: service_tools.h:95
const std::string & get_service_name() const
Return the service name.
std::map< std::string, int > dependency_level_dict_type
Definition: service_tools.h:76
void reset_service_status(uint32_t)
Reset the service status.
Internal entry for service objects stored in the service manager class.
Definition: service_tools.h:85
service_entry()
Default constructor.
std::shared_ptr< service_entry > service_entry_ptr
Type alias for a shared pointer on a service entry instance.
Definition: service_tools.h:193
bool has_master(const std::string &name_) const
Check if the service object has master service with given name.
service_handle_type & grab_service_handle()
Return a handle to the mutable service.
bool has_service_manager() const
Check if service manager is available.
datatools::handle< base_service > service_handle_type
Definition: service_tools.h:52
static const uint32_t bit02
Definition: bit_mask.h:29
The service can work without the external service.
Definition: service_tools.h:59
std::string version
Version of the external dependee service.
Definition: service_tools.h:68
void set_service_id(const std::string &)
Set the service identifier.
~service_entry()
Destructor.
Unknown/undefined dependency relationship.
Definition: service_tools.h:57
bool service_exists(const service_dict_type &services_, const std::string &service_name_)
Check if a service with given name exists.
virtual void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const
Smart print.
void set_service_manager(service_manager &smgr_)
Set the service manager.
dependency_level_type
Constants to measure the level of dependance between services.
Definition: service_tools.h:56
void update_service_status(uint32_t)
Update the service status.
const datatools::properties & get_service_config() const
Return a reference to the non mutable service configuration.
std::string id
ID of the external dependee service.
Definition: service_tools.h:67
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
bool is_created() const
Check if the service object is instantiated.
dependency_level_type level
Level of the dependency (see dependency_level_type enum)
Definition: service_tools.h:70
bool find_service_name_with_id(const service_dict_type &services_, const std::string &service_type_id_, std::string &service_name_)
Find the service name with given registered service type identifier from a dictionary of services.
const service_handle_type & get_service_handle() const
Return a handle to the non mutable service.
Creation/instantiation flag.
Definition: service_tools.h:93
Not so strong dependency on the external service (however part of the service may be invalidated)
Definition: service_tools.h:60
static const uint32_t bit00
Definition: bit_mask.h:27
const service_manager & get_service_manager() const
Return a reference to the service manager.
bool can_be_dropped() const
Check if service can be dropped.
void set_service_name(const std::string &)
Set the service name.
bool service_of_type_exists(const service_dict_type &services_, const std::string &service_type_id_, const std::string &service_name_)
Check if a service with given name and registered service type identifier exists.
const std::string & get_service_id() const
Return the service identifier.
Service management class.
Definition: service_manager.h:57
status_type
Service status flags.
Definition: service_tools.h:91
A dictionary of arbitrary properties.
Definition: properties.h:125