Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ServiceFinder2.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* ServiceFinder2.h (C) 2000-2019 */
9/* */
10/* Classe pour trouver un service donné. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_SERVICEFINDER2_H
13#define ARCANE_SERVICEFINDER2_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/Collection.h"
20#include "arcane/utils/Enumerator.h"
21
22#include "arcane/IServiceInfo.h"
23#include "arcane/IFactoryService.h"
24#include "arcane/IApplication.h"
25#include "arcane/IServiceFactory.h"
26#include "arcane/IServiceMng.h"
27#include "arcane/ServiceBuildInfo.h"
28#include "arcane/ServiceInstance.h"
29
30#include <set>
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35namespace Arcane
36{
37namespace Internal
38{
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
47template<typename InterfaceType>
49{
50 public:
52 public:
54 : m_application(app), m_service_build_info_base(sbi)
55 {
56 }
57
58 virtual ~ServiceFinderBase2T(){}
59
60 public:
68 ARCCORE_DEPRECATED_2019("Use createReference() instead")
69 virtual InterfaceType* create(const String& name)
70 {
71 return _create(name,m_service_build_info_base);
72 }
73
80 {
81 return _createReference(name,m_service_build_info_base);
82 }
83
94 ARCCORE_DEPRECATED_2019("Use createReference() instead")
95 virtual InterfaceType* create(const String& name,IMesh* mesh)
96 {
97 ISubDomain* sd = m_service_build_info_base.subDomain();
98 if (!sd)
99 return {};
100 if (mesh)
101 return _create(name,ServiceBuildInfoBase(sd,mesh));
102 return _create(name,ServiceBuildInfoBase(sd));
103 }
104
114 {
115 ISubDomain* sd = m_service_build_info_base.subDomain();
116 if (!sd)
117 return {};
118 if (mesh)
119 return _createReference(name,ServiceBuildInfoBase(sd,mesh));
120 return _createReference(name,ServiceBuildInfoBase(sd));
121 }
122
128 virtual InterfaceType* getSingleton()
129 {
130 IServiceMng* sm = m_service_build_info_base.serviceParent()->serviceMng();
132 for( typename SingletonServiceInstanceCollection::Enumerator i(singleton_services); ++i; ){
133 ISingletonServiceInstance* ssi = (*i).get();
134 if (ssi){
135 for( typename ServiceInstanceCollection::Enumerator k(ssi->interfaceInstances()); ++k; ){
136 IServiceInstance* sub_isi = (*k).get();
137 auto m = dynamic_cast< IServiceInstanceT<InterfaceType>* >(sub_isi);
138 if (m)
139 return m->instance().get();
140 }
141 }
142 }
143 return nullptr;
144 }
145
153 ARCCORE_DEPRECATED_2019("Use createAll(Array<ServiceRef<InterfaceType>>&) instead")
154 virtual void createAll(Array<InterfaceType*>& instances)
155 {
156 _createAll(instances,m_service_build_info_base);
157 }
158
163 {
164 return _createAll(m_service_build_info_base);
165 }
166
167 public:
168
169 SharedArray<FactoryType*> factories()
170 {
171 SharedArray<FactoryType*> m_factories;
172 for( typename ServiceFactory2Collection::Enumerator j(this->m_application->serviceFactories2()); ++j; ){
175 //m_application->traceMng()->info() << " FOUND sf2=" << sf2 << " M=" << m;
176 if (m){
177 m_factories.add(m);
178 }
179 }
180 return m_factories.constView();
181 }
182
183 void getServicesNames(Array<String>& names) const
184 {
185 for( typename ServiceFactory2Collection::Enumerator j(this->m_application->serviceFactories2()); ++j; ){
186 IServiceFactory2* sf2 = *j;
187 IServiceFactory2T<InterfaceType>* true_factory = dynamic_cast< IServiceFactory2T<InterfaceType>* >(sf2);
188 if (true_factory){
189 IServiceInfo* si = sf2->serviceInfo();
190 names.add(si->localName());
191 }
192 }
193 }
194
195 protected:
196
197 InterfaceType* _create(const String& name,const ServiceBuildInfoBase& sbib)
198 {
199 return _createReference(name,sbib)._release();
200 }
201
202 Ref<InterfaceType> _createReference(const String& name,const ServiceBuildInfoBase& sbib)
203 {
204 for( typename ServiceFactory2Collection::Enumerator j(this->m_application->serviceFactories2()); ++j; ){
205 Internal::IServiceFactory2* sf2 = *j;
206 IServiceInfo* s = sf2->serviceInfo();
207 if (s->localName()!=name)
208 continue;
209 IServiceFactory2T<InterfaceType>* m = dynamic_cast< IServiceFactory2T<InterfaceType>* >(sf2);
210 //m_application->traceMng()->info() << " FOUND sf2=" << sf2 << " M=" << m;
211 if (m){
212 Ref<InterfaceType> tt = m->createServiceReference(sbib);
213 if (!tt.isNull())
214 return tt;
215 }
216 }
217 return {};
218 }
219
220 void _createAll(Array<InterfaceType*>& instances,const ServiceBuildInfoBase& sbib)
221 {
222 UniqueArray<Ref<InterfaceType>> ref_instances = _createAll(sbib);
223 for( auto& x : ref_instances )
224 instances.add(x._release());
225 }
226
227 UniqueArray<Ref<InterfaceType>> _createAll(const ServiceBuildInfoBase& sbib)
228 {
229 UniqueArray<Ref<InterfaceType>> instances;
230 for( typename ServiceFactory2Collection::Enumerator j(this->m_application->serviceFactories2()); ++j; ){
231 Internal::IServiceFactory2* sf2 = *j;
232 IServiceFactory2T<InterfaceType>* m = dynamic_cast< IServiceFactory2T<InterfaceType>* >(sf2);
233 if (m){
234 Ref<InterfaceType> tt = m->createServiceReference(sbib);
235 if (tt.get()){
236 instances.add(tt);
237 }
238 }
239 }
240 return instances;
241 }
242
243 protected:
244
245 IApplication* m_application;
246 ServiceBuildInfoBase m_service_build_info_base;
247};
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252} // End namespace Internal
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
262template<typename InterfaceType,typename ParentType>
264: public Internal::ServiceFinderBase2T<InterfaceType>
265{
266 public:
269 {
270 }
271
273
274 public:
275};
276
277/*---------------------------------------------------------------------------*/
278/*---------------------------------------------------------------------------*/
279
280} // End namespace Arcane
281
282/*---------------------------------------------------------------------------*/
283/*---------------------------------------------------------------------------*/
284
285#endif
Tableau d'items de types quelconques.
Interface de l'application.
virtual ServiceFactory2Collection serviceFactories2()=0
Liste des fabriques de service.
virtual IServiceMng * serviceMng() const =0
Gestionnaire de services.
Interface d'une instance d'un service.
Definition IService.h:73
Interface du gestionnaire de services.
Definition IServiceMng.h:31
Interface d'une instance de service singleton.
Definition IService.h:95
Interface du gestionnaire d'un sous-domaine.
Definition ISubDomain.h:74
virtual IServiceInfo * serviceInfo() const =0
Retourne le IServiceInfo associé à cette fabrique.
Classe utilitaire pour retrouver un ou plusieurs services implémentant l'interface InterfaceType.
virtual InterfaceType * create(const String &name)
Créé une instance du service name.
virtual UniqueArray< Ref< InterfaceType > > createAll()
Créé une instance de chaque service qui implémente InterfaceType.
virtual InterfaceType * getSingleton()
Instance singleton du service ayant pour interface InterfaceType.
virtual Ref< InterfaceType > createReference(const String &name, IMesh *mesh)
Créé une instance du service name pour le maillage mesh.
virtual Ref< InterfaceType > createReference(const String &name)
Créé une instance du service name.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Informations pour créer un service.
IBase * serviceParent() const
Accès à l'instance parente qui a créée cette instance.
ISubDomain * subDomain() const
Accès au ISubDomain associé.
Classe utilitaire pour retrouver un ou plusieurs services implémentant l'interface InterfaceType.
InstanceType * _release()
Libère le pointeur du compteur de référence sans le détruire. Cela n'est autorisé que si l'implémenta...
Chaîne de caractères unicode.
void add(ArrayView< T > lhs, ConstArrayView< T > copy_array)
Ajoute le tableau copy_array dans l'instance.
Definition MathUtils.h:885
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-