Bayeux  3.4.1
Core Foundation library for SuperNEMO
base_service.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-08-30
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  *
24  * Description:
25  *
26  * Base service.
27  *
28  */
29 
30 #ifndef DATATOOLS_BASE_SERVICE_H
31 #define DATATOOLS_BASE_SERVICE_H
32 
33 // Standard Library
34 #include <iostream>
35 #include <map>
36 #include <stdexcept>
37 #include <typeinfo>
38 #include <vector>
39 
40 // Third Party
41 #include <boost/function/function_base.hpp>
42 
43 // This project (Bayeux/datatools)
45 #include <datatools/i_tree_dump.h>
48 #include <datatools/exception.h>
49 #include "datatools/factory-inl.h"
50 
51 #include <datatools/logger.h>
52 #ifndef Q_MOC_RUN
54 #endif // Q_MOC_RUN
55 
57 namespace datatools {
58 
59  // Forward class declaration:
60  class properties;
61  class object_configuration_description;
62 
70  {
71  public:
72 
74  base_service();
75 
77  base_service(const std::string & name_,
78  const std::string & display_name_ = "",
79  const std::string & description_ = "",
81 
83  virtual ~base_service();
84 
86  virtual void fetch_dependencies(service_dependency_dict_type & /*dependencies_*/) const;
87 
89  virtual int initialize_simple();
90 
92  virtual int initialize_standalone(const datatools::properties & config_);
93 
95  virtual int initialize_with_services(service_dict_type & service_dict_);
96 
98  virtual int initialize(const datatools::properties & config_,
99  service_dict_type & service_dict_) = 0;
100 
102  virtual int reset() = 0;
103 
105  virtual bool is_initialized() const = 0;
106 
108  virtual std::string service_class_id() const = 0;
109 
111  void print_tree(std::ostream & out_ = std::clog,
112  const boost::property_tree::ptree & options_ = empty_options()) const override;
113 
116  void tree_dump(std::ostream & out_ = std::clog,
117  const std::string & title_ = "",
118  const std::string & indent_ = "",
119  bool inherit_ = false) const override;
120 
123 
124  protected:
125 
127  void _common_initialize(const datatools::properties & config_);
128 
131  void common_initialize(const datatools::properties & config_);
132 
133  // Factory stuff :
135 
136 #ifndef Q_MOC_RUN
137  DR_CLASS_RTTI()
139 #endif // Q_MOC_RUN
140 
141  };
142 
143 } // end of namespace datatools
144 
146 
147 #ifndef Q_MOC_RUN
148 // Activate reflection layer:
150 #endif // Q_MOC_RUN
151 
152 #define DATATOOLS_SERVICE_REGISTRATION_INTERFACE(SERVICE_CLASS_NAME) \
153  private: \
154  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_INTERFACE(::datatools::base_service, SERVICE_CLASS_NAME) \
155  public: \
156  virtual std::string service_class_id() const; \
157 
158 
159 #define DATATOOLS_SERVICE_REGISTRATION_IMPLEMENT(SERVICE_CLASS_NAME,SERVICE_ID) \
160  DATATOOLS_FACTORY_SYSTEM_AUTO_REGISTRATION_IMPLEMENTATION (::datatools::base_service,SERVICE_CLASS_NAME,SERVICE_ID) \
161  std::string SERVICE_CLASS_NAME::service_class_id() const {return SERVICE_ID;}
162 
163 
164 #endif // DATATOOLS_BASE_SERVICE_H
165 
166 // Local Variables: --
167 // mode: c++ --
168 // c-file-style: "gnu" --
169 // tab-width: 2 --
170 // End: --
static const boost::property_tree::ptree & empty_options()
#define DR_CLASS_INIT(Introspectable)
Inform Camp that class Introspectable exists and trigger the automatic registration of dedicated refl...
Definition: reflection_interface.h:149
virtual bool is_initialized() const =0
Check if service is initialized.
priority
Priority levels for logging from most to least critical.
Definition: logger.h:82
virtual int reset()=0
Reset the service.
void _common_initialize(const datatools::properties &config_)
Common initialization of services.
A fatal error. The application will most likely terminate. This is the highest priority.
Definition: logger.h:85
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
void common_initialize(const datatools::properties &config_)
virtual int initialize_with_services(service_dict_type &service_dict_)
Initialize the service using with access to a dictionary of other services.
std::map< std::string, dependency_info_type > service_dependency_dict_type
Definition: service_tools.h:77
An object that describes the way an object of a given class can be configured through properties.
Definition: object_configuration_description.h:234
virtual ~base_service()
Destructor.
Utility macros for exception handling.
virtual void fetch_dependencies(service_dependency_dict_type &) const
Undocumented unused/unimplemented method.
virtual std::string service_class_id() const =0
Return the service class.
base_service()
Default constructor.
void tree_dump(std::ostream &out_=std::clog, const std::string &title_="", const std::string &indent_="", bool inherit_=false) const override
static void common_ocd(datatools::object_configuration_description &ocd_)
Basic OCD support shared by all inherited modules.
The Bayeux/datatools library top-level namespace.
Definition: algo.h:13
Utilities for logging information.
virtual int initialize_standalone(const datatools::properties &config_)
Initialize the service using only a list of properties without the needs of other services.
virtual int initialize_simple()
Initialize the service without a list of properties nor other services.
A base class with useful attributes usable in many contexts.
Definition: enriched_base.h:52
#define DR_CLASS_RTTI()
Declare Camp RTTI within class declaration.
Definition: reflection_interface.h:46
#define DATATOOLS_FACTORY_SYSTEM_REGISTER_INTERFACE(BaseType)
Declaration of a system (allocator/functor) factory register as a static member of a base class and s...
Definition: factory_macros.h:52
virtual int initialize(const datatools::properties &config_, service_dict_type &service_dict_)=0
Initialize the service using a list of properties with access to a dictionary of other services.
void print_tree(std::ostream &out_=std::clog, const boost::property_tree::ptree &options_=empty_options()) const override
Smart print.
A dictionary of arbitrary properties.
Definition: properties.h:125