Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE > Class Template Reference

Service implementation returning a provider. More...

#include <ServiceProviderWrappers.h>

Inheritance diagram for gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >:

Public Types

using concrete_provider_type = PROVIDER
 type of service provider implementation More...
 
using service_interface_type = INTERFACE
 art service interface class More...
 
using provider_type = typename service_interface_type::provider_type
 type of service provider interface More...
 
using Parameters = ::art::ServiceTable< typename concrete_provider_type::Config >
 Type of configuration parameter (for art description) More...
 

Public Member Functions

 ServiceProviderImplementationWrapper (Parameters const &config,::art::ActivityRegistry &)
 Constructor (using a configuration table) More...
 

Private Member Functions

virtual provider_type const * do_provider () const override
 Returns a constant pointer to the service provider. More...
 

Private Attributes

std::unique_ptr< concrete_provider_typeprov
 service provider More...
 

Detailed Description

template<typename PROVIDER, typename INTERFACE>
class gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >

Service implementation returning a provider.


Template Parameters
INTERFACEtype of art service being implemented
PROVIDERtype of service provider to be returned
See also
ServiceProviderInterfaceWrapper

This class is suitable for a simple art service implementing an interface. This is the case of a service that can have multiple implementations, for example an experiment-specific access to a database. In this case, the art service is described by an interface, and many services can inherit and implement it.

In the factorization model recommended in GArSoft, this hierarchy of art service implementations derived by a common interface is mirrored in a matching hierarchy of service provider implementation derived by a common service provider interface. In this model, services are basically trivial classes that return a pointer to the provider through a prescribed interface. The only relevant exception is that services may also register framework callbacks.

Given the nature of the service returning a provider, its structure is repetitive. This class implements most of that repetitive frame. The resulting service is not reacting to any framework events.

The configuration of the service is passed directly to the provider.

Given that we want to have a service that implements the service MyServiceInterface and returns a provider implementation "A" called MyProviderA, the simplest way to create it with this template is:

#include "CoreUtils/ServiceProviderWrappers.h"
#include "path/to/MyProviderA.h"
#include "path/to/MyServiceInterface.h"

#include "art/Framework/Services/Registry/ServiceDeclarationMacros.h"
#include "art/Framework/Services/Registry/ServiceDefinitionMacros.h"

namespace myprov {

  using MyServiceA = gar::ServiceProviderImplementationWrapper
    <MyProviderA, MyServiceInterface>;

}

DECLARE_ART_SERVICE_INTERFACE_IMPL
  (myprov::MyServiceA, myprov::MyService, LEGACY)

The class MyServiceInterface is expected to have been defined via ServiceProviderInterfaceWrapper. An implementation file is necessary too, that will look like:

#include "path/to/MyServiceA.h"

DEFINE_ART_SERVICE_INTERFACE_IMPL
  (myprov::MyServiceA, myprov::MyService)

If callback registration is needed, a class can derive from this template and still gain a bit of boilerplate facility. That is:

Requirements on the service provider (PROVIDER):

Requirements on the service interface (INTERFACE):

Definition at line 241 of file ServiceProviderWrappers.h.

Member Typedef Documentation

template<typename PROVIDER , typename INTERFACE >
using gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::concrete_provider_type = PROVIDER

type of service provider implementation

Definition at line 245 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::Parameters = ::art::ServiceTable<typename concrete_provider_type::Config>

Type of configuration parameter (for art description)

Definition at line 255 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::provider_type = typename service_interface_type::provider_type

type of service provider interface

Definition at line 251 of file ServiceProviderWrappers.h.

template<typename PROVIDER , typename INTERFACE >
using gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::service_interface_type = INTERFACE

art service interface class

Definition at line 248 of file ServiceProviderWrappers.h.

Constructor & Destructor Documentation

template<typename PROVIDER , typename INTERFACE >
gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::ServiceProviderImplementationWrapper ( Parameters const &  config,
::art::ActivityRegistry  
)
inline

Constructor (using a configuration table)

Definition at line 260 of file ServiceProviderWrappers.h.

261  : prov(std::make_unique<concrete_provider_type>(config()))
262  {}
std::unique_ptr< concrete_provider_type > prov
service provider
static Config * config
Definition: config.cpp:1054

Member Function Documentation

template<typename PROVIDER , typename INTERFACE >
virtual provider_type const* gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::do_provider ( ) const
inlineoverrideprivatevirtual

Returns a constant pointer to the service provider.

Definition at line 269 of file ServiceProviderWrappers.h.

270  { return prov.get(); }
std::unique_ptr< concrete_provider_type > prov
service provider

Member Data Documentation

template<typename PROVIDER , typename INTERFACE >
std::unique_ptr<concrete_provider_type> gar::ServiceProviderImplementationWrapper< PROVIDER, INTERFACE >::prov
private

service provider

Definition at line 266 of file ServiceProviderWrappers.h.


The documentation for this class was generated from the following file: