Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ServiceRegisterer.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* ServiceRegisterer.h (C) 2000-2025 */
9/* */
10/* Singleton allowing service registration. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_SERCVICEREGISTERER_H
13#define ARCANE_CORE_SERCVICEREGISTERER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
19#include "arcane/core/ModuleProperty.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \brief Service and module registrar
32 *
33 * This class implements the Singleton pattern for a given service.
34 *
35 * It allows declaring a global variable that automatically registers
36 * the IServiceFactory of the desired service. This class is not used
37 * directly but through the ARCANE_DEFINE_SERVICE(name) macro.
38 *
39 * Since this class is used with global instances, they are
40 * constructed before the code enters main(). Therefore, extreme care
41 * must be taken not to use any objects or perform allocations (in
42 * particular, the service name must be a standard const char*). For
43 * this purpose, the list of registered services is maintained in a
44 * linked list, and each instance contains pointers to the next and
45 * previous members of the list. The first element of the list is
46 * obtained by calling ServiceRegisterer::firstService().
47 */
48class ARCANE_CORE_EXPORT ServiceRegisterer
49{
50 public:
51
52 typedef IModuleFactoryInfo* (*ModuleFactoryWithPropertyFunc)(const ModuleProperty& properties);
53 typedef IServiceInfo* (*ServiceInfoWithPropertyCreateFunc)(const ServiceProperty& properties);
54
55 public:
56
57 /*!
58 * \brief Creates a registrar for the service \a name and the function \a func.
59 *
60 * This constructor is used to register a service.
61 */
62 ServiceRegisterer(ServiceInfoWithPropertyCreateFunc func, const ServiceProperty& properties) ARCANE_NOEXCEPT;
63
64 /*!
65 * \brief Creates a registrar for the module \a name with properties \a properties.
66 *
67 * This constructor is used to register a module.
68 */
69 ServiceRegisterer(ModuleFactoryWithPropertyFunc func, const ModuleProperty& properties) ARCANE_NOEXCEPT;
70
71 public:
72
73 /*!
74 * \brief Creation function for the 'ServiceInfo' instance if it is a service.
75 *
76 * This pointer may be null if it is not a service, in which case
77 * infoCreatorFunction() must be used.
78 */
79 ServiceInfoWithPropertyCreateFunc infoCreatorWithPropertyFunction() { return m_info_function_with_property; }
80
81 /*!
82 * \brief Creation function for the factory if it is a module.
83 *
84 * This pointer may be null if it is not a module, in which case
85 * infoCreatorFunction() must be used.
86 */
87 ModuleFactoryWithPropertyFunc moduleFactoryWithPropertyFunction() { return m_module_factory_with_property_functor; }
88
89 //! Service name
90 const char* name() { return m_name; }
91
92 /*!
93 * \brief Service properties.
94 *
95 * \deprecated Use \a serviceProperty() instead
96 */
97 ARCANE_DEPRECATED_260 const ServiceProperty& property() const { return m_service_property; }
98
99 //! Properties in the case of a service
100 const ServiceProperty& serviceProperty() const { return m_service_property; }
101
102 //! Properties in the case of a module
103 const ModuleProperty& moduleProperty() const { return m_module_property; }
104
105 //! Previous service (0 if the first)
106 ServiceRegisterer* previousService() const { return m_previous; }
107
108 //! Next service (0 if the last)
109 ServiceRegisterer* nextService() const { return m_next; }
110
111 private:
112
113 //! Positions the previous service
114 /*! Used internally to build the service chain */
115 void setPreviousService(ServiceRegisterer* s) { m_previous = s; }
116
117 //! Positions the next service
118 /*! Used internally to build the service chain */
119 void setNextService(ServiceRegisterer* s) { m_next = s; }
120
121 public:
122
123 //! Access to the first element of the service registrar chain
124 static ServiceRegisterer* firstService();
125
126 //! Number of service registrars in the chain
127 static Integer nbService();
128
129 private:
130
131 //! Function to create the IModuleFactory
132 ModuleFactoryWithPropertyFunc m_module_factory_with_property_functor = nullptr;
133 //! Function to create the IServiceInfo
134 ServiceInfoWithPropertyCreateFunc m_info_function_with_property = nullptr;
135 //! Service name
136 const char* m_name = nullptr;
137 //! Service properties
138 ServiceProperty m_service_property;
139 //! Module properties
140 ModuleProperty m_module_property;
141 //! Previous service
142 ServiceRegisterer* m_previous = nullptr;
143 //! Next service
144 ServiceRegisterer* m_next = nullptr;
145
146 private:
147
148 void _init();
149};
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154} // namespace Arcane
155
156/*---------------------------------------------------------------------------*/
157/*---------------------------------------------------------------------------*/
158
159#endif
Declarations of Arcane's general types.
This file contains the various types and classes for specifying service properties.
Information about a module factory.
Interface for service or module information.
Module creation properties.
Service creation properties.
Service and module registrar.
ServiceRegisterer * previousService() const
Previous service (0 if the first).
ServiceRegisterer * nextService() const
Next service (0 if the last).
const ServiceProperty & serviceProperty() const
Properties in the case of a service.
const char * name()
Service name.
ModuleFactoryWithPropertyFunc moduleFactoryWithPropertyFunction()
Creation function for the factory if it is a module.
ServiceInfoWithPropertyCreateFunc infoCreatorWithPropertyFunction()
Creation function for the 'ServiceInfo' instance if it is a service.
const ModuleProperty & moduleProperty() const
Properties in the case of a module.
ARCANE_DEPRECATED_260 const ServiceProperty & property() const
Service properties.
ServiceRegisterer(ServiceInfoWithPropertyCreateFunc func, const ServiceProperty &properties) ARCANE_NOEXCEPT
Creates a registrar for the service name and the function func.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.