12#ifndef ARCANE_SERVICEFACTORY_H
13#define ARCANE_SERVICEFACTORY_H
17#include "arcane/utils/NotSupportedException.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/ExternalRef.h"
21#include "arcane/IApplication.h"
22#include "arcane/ISession.h"
23#include "arcane/ISubDomain.h"
24#include "arcane/ServiceBuildInfo.h"
26#include "arcane/IServiceFactory.h"
27#include "arcane/ServiceRegisterer.h"
28#include "arcane/ServiceInfo.h"
29#include "arcane/IService.h"
30#include "arcane/ServiceProperty.h"
31#include "arcane/ServiceInstance.h"
49 : m_service_info(si), m_handle(
nullptr){}
54 Int32 v = std::atomic_fetch_add(&m_nb_ref,-1);
61 return m_service_info;
63 void setDotNetHandle(ExternalRef handle) { m_handle = handle; }
64 ExternalRef _internalDotNetHandle()
const override {
return m_handle; }
66 std::atomic<Int32> m_nb_ref = 0;
67 IServiceInfo* m_service_info;
77template<
typename InterfaceType>
83 : m_instance(i), m_service_info(si){}
88 Int32 v = std::atomic_fetch_add(&m_nb_ref,-1);
93 Ref<InterfaceType> instance()
override
99 return m_service_info;
102 std::atomic<Int32> m_nb_ref = 0;
103 Ref<InterfaceType> m_instance;
104 IServiceInfo* m_service_info;
119 : m_service_info(si), m_is_autoload(
false), m_is_singleton(
false) {}
129 virtual bool isModule()
const {
return false; }
130 virtual void initializeModuleFactory(
ISubDomain*) {}
131 virtual IModule* createModule(ISubDomain*,IMesh*) {
return nullptr; }
135 void setAutoload(
bool v) { m_is_autoload = v; }
136 void setSingleton(
bool v) { m_is_singleton = v; }
137 void initProperties(
int v)
139 if (v & SFP_Singleton)
141 if (v & SFP_Autoload)
144 void initProperties(){}
148 IServiceInfo* m_service_info;
160template<
typename InterfaceType>
180template<
typename InterfaceType>
187 : m_service_info(si), m_sub_factory(sub_factory), m_type_flags(si->
usageType())
193 delete m_sub_factory;
198 return _create(this->createServiceReference(sbi));
205 return _createReference(sbi);
210 return m_service_info;
223 InterfaceType* it = m_sub_factory->createInstance(
ServiceBuildInfo(m_service_info,sbib));
232 ServiceInstanceRef _create(Ref<InterfaceType> it)
234 IServiceInstance* x = (!it) ?
nullptr : new ServiceInstanceT<InterfaceType>(it,m_service_info);
235 return ServiceInstanceRef::createRef(x);
245template<
typename ServiceType,
typename InterfaceType>
253 ServiceType* st =
new ServiceType(sbi);
255 return makeRef<InterfaceType>(st);
289 Ref<ISingletonServiceInstance> createSingletonServiceInstance(
const ServiceBuildInfoBase& sbib)
override;
306template<
typename ServiceType,
typename ... Interfaces>
318 : m_service(service), m_service_info(si), m_adder(adder) {}
321 template<
typename InterfaceType>
void _create()
323 InterfaceType* x = m_service;
327 auto x_ref = Ref<InterfaceType>::_createNoDestroy(x);
330 auto instance_ref = ServiceInstanceRef::createRef(instance);
331 m_adder->addInstance(instance_ref);
334 template<
typename I1,
typename I2,
typename ... OtherInterfaces>
339 _create<I2,OtherInterfaces...>();
342 void createInterfaceInstances()
344 _create<Interfaces...>();
347 ServiceType* m_service;
357 ServiceType* st =
new ServiceType(sbi);
359 auto st_ref = makeRef(st);
361 ssf.createInterfaceInstances();
363 return ServiceInstanceRef::createRef(si);
374template<
typename InterfaceType>
379 typedef InterfaceType Interface;
382 : m_name(name), m_namespace_name(
nullptr)
387 : m_name(name), m_namespace_name(namespace_name)
394 template<
typename ServiceType>
void
398 if (m_namespace_name)
408 const char* m_namespace_name;
417template<
typename ServiceType>
423 template<
typename InterfaceType>
static void
426 i1.template registerToServiceInfo<ServiceType>(si);
429 template<
typename I1,
typename I2,
typename ... OtherInterfaces>
430 static void _create(
ServiceInfo* si,
const I1& i1,
const I2& i2,
const OtherInterfaces& ... args)
434 _create<I2,OtherInterfaces...>(si,i2,args...);
440 template<
typename ... Interfaces>
static void
475#define ARCANE_SERVICE_INTERFACE(ainterface)\
476 Arcane::Internal::ServiceInterfaceRegisterer< ainterface >(#ainterface)
479#define ARCANE_SERVICE_INTERFACE_NS(ainterface_ns,ainterface) \
480 Arcane::Internal::ServiceInterfaceRegisterer<ainterface_ns :: ainterface>(#ainterface_ns,#ainterface)
516#define ARCANE_REGISTER_SERVICE(aclass,a_service_property,...) \
519 Arcane::IServiceInfo*\
520 ARCANE_JOIN_WITH_LINE(arcaneCreateServiceInfo##aclass) (const Arcane::ServiceProperty& property) \
522 auto* si = Arcane::Internal::ServiceInfo::create(property,__FILE__,__LINE__); \
523 Arcane::Internal::ServiceAllInterfaceRegisterer<aclass> :: registerToServiceInfo(si,__VA_ARGS__); \
527Arcane::ServiceRegisterer ARCANE_EXPORT ARCANE_JOIN_WITH_LINE(globalServiceRegisterer##aclass) \
528 (& ARCANE_JOIN_WITH_LINE(arcaneCreateServiceInfo##aclass),a_service_property)
538#define ARCANE_REGISTER_AXL_SERVICE(aclass,a_service_properties) \
541 Arcane::IServiceInfo*\
542 ARCANE_JOIN_WITH_LINE(arcaneCreateServiceInfo##aclass) (const Arcane::ServiceProperty& properties) \
544 Arcane::ServiceInfo* si = Arcane::ServiceInfo::create(properties,__FILE__,__LINE__); \
545 aclass :: fillServiceInfo< aclass >(si); \
549Arcane::ServiceRegisterer ARCANE_EXPORT ARCANE_JOIN_WITH_LINE(globalServiceRegisterer##aclass) \
550 (& ARCANE_JOIN_WITH_LINE(arcaneCreateServiceInfo##aclass),a_service_properties)
572#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass,ainterface,aname) \
573ARCANE_REGISTER_SERVICE ( aclass, Arcane::ServiceProperty(#aname,Arcane::ST_Application) ,\
574 ARCANE_SERVICE_INTERFACE(ainterface) )
586#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass,ainterface,aname) \
587ARCANE_REGISTER_SERVICE ( aclass, Arcane::ServiceProperty(#aname,Arcane::ST_SubDomain) ,\
588 ARCANE_SERVICE_INTERFACE(ainterface) )
600#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY4(aclass,ainterface_ns,ainterface,aname) \
601ARCANE_REGISTER_SERVICE ( aclass, Arcane::ServiceProperty(#aname,Arcane::ST_SubDomain) ,\
602 ARCANE_SERVICE_INTERFACE_NS(ainterface_ns,ainterface) )
614#define ARCANE_REGISTER_CASE_OPTIONS_NOAXL_FACTORY(aclass,ainterface,aname) \
615ARCANE_REGISTER_SERVICE ( aclass, Arcane::ServiceProperty(#aname,Arcane::ST_CaseOption) , \
616 ARCANE_SERVICE_INTERFACE(ainterface) )
628#define ARCANE_REGISTER_CASE_OPTIONS_NOAXL_FACTORY4(aclass,ainterface_ns,ainterface,aname) \
629ARCANE_REGISTER_SERVICE ( aclass, Arcane::ServiceProperty(#aname,Arcane::ST_CaseOption) ,\
630 ARCANE_SERVICE_INTERFACE_NS(ainterface_ns,ainterface) )
Informations sur la fabrique d'un service.
Interface des informations d'un service ou d'un module.
virtual int usageType() const =0
Indique où peut être utilisé le service.
Interface d'une instance d'un service.
Interface du gestionnaire d'un sous-domaine.
Classe de base d'une instance de service en C#.
void removeReference() override
Supprime une référence.
void addReference() override
Ajoute une référence.
virtual Ref< InterfaceType > createReference(const ServiceBuildInfo &sbi)=0
Créé une instance du service .
static void registerToServiceInfo(ServiceInfo *si, const Interfaces &... args)
Enregistre dans le service les fabriques pour les interfacs Interfaces.
IServiceInfo * serviceInfo() const override
Retourne le IServiceInfo associé à cette fabrique.
ServiceInstanceRef createServiceInstance(const ServiceBuildInfoBase &sbi) override
Créé une instance du service à partir des infos de sbi.
IServiceInfo * serviceInfo() const override
Informations sur le service pouvant être créé par cette fabrique.
bool isSingleton() const override
vrai si le service est un service singleton (une seule instance)
bool isAutoload() const override
vrai si le service est un module et doit être chargé automatiquement
void addImplementedInterface(const String &name) override
Ajoute l'interface de nom name aux interfaces implémentées par ce service.
void removeReference() override
Supprime une référence.
void addReference() override
Ajoute une référence.
Ref< InterfaceType > createReference(const ServiceBuildInfo &sbi) override
Créé une instance du service .
void registerToServiceInfo(ServiceInfo *si) const
Enregistre dans si une fabrique pour créer une instance du service ServiceType.
Instances des services singletons.
IServiceInfo * serviceInfo() const override
Retourne le IServiceInfo associé à cette fabrique.
Informations pour créer un service.
eServiceType creationType() const
Type du service pouvant être créé par cette instance.
Structure contenant les informations pour créer un service.
Référence sur une instance de service.
Chaîne de caractères unicode.