Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IServiceFactory.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/* IServiceFactory.h (C) 2000-2025 */
9/* */
10/* Service manufacturing interface. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ISERVICEFACTORY_H
13#define ARCANE_CORE_ISERVICEFACTORY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Ref.h"
19
20#include <atomic>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30/*!
31 * \brief Information about a service factory.
32 *
33 * This interface contains the necessary information about a service factory.
34 *
35 * Generally, instances of this class are either created by Arcane
36 * from an axl file, or using one of the service factory macros
37 * (defined in ServiceFactory.h).
38 *
39 * The list of interfaces supported by the service and the
40 * associated factories are described in serviceInfo().
41 */
42class ARCANE_CORE_EXPORT IServiceFactoryInfo
43{
44 public:
45
46 //! Release resources
48
49 public:
50
51 //! true if the service is a module and must be loaded automatically
52 //TODO: check if autoload is still useful for these services.
53 virtual bool isAutoload() const = 0;
54 //! true if the service is a singleton service (a single instance)
55 virtual bool isSingleton() const = 0;
56
57 public:
58
59 /*! \brief Information about the service that can be created by this factory.
60 *
61 * The returned instance remains the property of the application that created it
62 * and must neither be modified nor destroyed.
63 */
64 virtual IServiceInfo* serviceInfo() const = 0;
65};
66
67/*---------------------------------------------------------------------------*/
68/*---------------------------------------------------------------------------*/
69
70} // namespace Arcane
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75namespace Arcane::Internal
76{
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81/*!
82 * \brief internal.
83 * \brief Interface for a service factory (new version).
84 *
85 * This class uses a ReferenceCounter to manage its destruction.
86 */
87class ARCANE_CORE_EXPORT IServiceFactory2
88{
89 protected:
90
91 virtual ~IServiceFactory2() = default;
92
93 public:
94
95 //! Add a reference.
96 virtual void addReference() = 0;
97 //! Remove a reference.
98 virtual void removeReference() = 0;
99
100 public:
101
102 //! Create a service instance from the info in \a sbi.
104
105 //! Returns the IServiceInfo associated with this factory.
106 virtual IServiceInfo* serviceInfo() const = 0;
107};
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112/*!
113 * \brief internal.
114 * \brief Base class for a service factory.
115 *
116 * This class uses a ReferenceCounter to manage its destruction.
117 */
118class ARCANE_CORE_EXPORT AbstractServiceFactory
119: public IServiceFactory2
120{
121 protected:
122
123 AbstractServiceFactory()
124 : m_nb_ref(0)
125 {}
126
127 public:
128
129 void addReference() override;
130 void removeReference() override;
131
132 private:
133
134 std::atomic<Int32> m_nb_ref;
135};
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140/*!
141 * \internal
142 * \brief Factory for a service implementing the \a InterfaceType interface.
143 */
144template <typename InterfaceType>
146: public AbstractServiceFactory
147{
148 public:
149
150 virtual Ref<InterfaceType> createServiceReference(const ServiceBuildInfoBase& sbi) = 0;
151};
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
156/*!
157 * \brief internal.
158 * \brief Factory for a singleton service.
159 * A singleton service is created only once but can have multiple
160 * interfaces, and therefore there are as many IServiceInstance objects as interfaces
161 * implemented by the service.
162 *
163 * The \a createSingletonServiceInstance() method allows creating the singleton service instance
164 * as well as the IServiceInstance for each implemented interface.
165 */
166class ARCANE_CORE_EXPORT ISingletonServiceFactory
167{
168 public:
169
170 virtual ~ISingletonServiceFactory() = default;
171
172 //! Create an instance of a singleton service.
175
176 //! Returns the IServiceInfo associated with this factory.
177 virtual IServiceInfo* serviceInfo() const = 0;
178};
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
183} // namespace Arcane::Internal
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188#endif
Declarations of Arcane's general types.
Information about a service factory.
virtual bool isAutoload() const =0
true if the service is a module and must be loaded automatically
virtual ~IServiceFactoryInfo()
Release resources.
virtual bool isSingleton() const =0
true if the service is a singleton service (a single instance)
virtual IServiceInfo * serviceInfo() const =0
Information about the service that can be created by this factory.
Interface for service or module information.
void removeReference() override
Remove a reference.
void addReference() override
Add a reference.
virtual void addReference()=0
Add a reference.
virtual IServiceInfo * serviceInfo() const =0
Returns the IServiceInfo associated with this factory.
virtual void removeReference()=0
Remove a reference.
virtual ServiceInstanceRef createServiceInstance(const ServiceBuildInfoBase &sbi)=0
Create a service instance from the info in sbi.
virtual Ref< ISingletonServiceInstance > createSingletonServiceInstance(const ServiceBuildInfoBase &sbi)=0
Create an instance of a singleton service.
virtual IServiceInfo * serviceInfo() const =0
Returns the IServiceInfo associated with this factory.
Reference to an instance.
Information for creating a service.
Reference to a service instance.
Internal types of Arcane.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --