JANA2
JServiceLocator Class Reference

JServiceLocator is a nexus for collecting, initializing, and retrieving JServices. More...

#include <JServiceLocator.h>

Public Member Functions

template<typename T >
void provide (std::shared_ptr< T > t)
 
template<typename T >
std::shared_ptr< T > get ()
 
void wire_everything ()
 

Detailed Description

JServiceLocator is a nexus for collecting, initializing, and retrieving JServices.

This may be exposed via the JApplication facade, or used on its own. JServiceLocator uses shared-pointer semantics to ensure that JServices always get freed, but also don't get freed prematurely if a JApplication or JServiceLocator go out of scope.

Member Function Documentation

template<typename T >
std::shared_ptr<T> JServiceLocator::get ( )
inline

Retrieve a JService. If acquire_services() has not yet been called, it will be. Usually called from Service::finalize(). It may be called from anywhere, but it is generally safer to retrieve the services we need during acquire_dependencies() and keep pointers to those, instead of keeping a pointer to the ServiceLocator itself. (This also makes it easier to migrate to dependency injection if we so desire)

Referenced by JPluginLoader::attach_plugin(), JApplication::GetService(), and JApplication::Initialize().

Here is the caller graph for this function:

template<typename T >
void JServiceLocator::provide ( std::shared_ptr< T >  t)
inline

Publish a Service to the ServiceLocator. This Service should have already been constructed, but not finalized. Users are intended to call this from InitPlugin() most of the time

Referenced by JApplication::Initialize(), and JApplication::ProvideService().

Here is the caller graph for this function:

void JServiceLocator::wire_everything ( )
inline

Make sure that all Services have been finalized. This is not strictly necessary, but it makes user errors easier to understand, and it prevents Services from being unpredictably finalized later on, particularly during computation.


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