Free Electron
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
fe::Library Class Reference

Interface into a dynamic library to access its factories. More...

#include <Library.h>

Inheritance diagram for fe::Library:
Inheritance graph
[legend]

Classes

class  BaseFactory
 Type-nonspecific base class for factories. More...
 
class  Factory
 Type-specific factory template. More...
 

Public Member Functions

template<typename T >
void add (const String &name)
 Create a named factory for the given type and add it to the library's collection. More...
 
template<typename T >
void addSingleton (const String &name)
 Create a named factory for the given type, but treat it as a singleton. More...
 
const Stringname (void) const
 Return the library name. More...
 
void populateManifest (Array< String > &names) const
 Append the names of the available factories to the given array. More...
 
U32 adjustedReferences (void) const
 Return number of references adjusted for singletons. More...
 
void releaseSingletons (void)
 Release all instantiated singletons. More...
 
I32 strayCount (void)
 
I32 adjustStrayCount (I32 inc)
 
sp< Componentcreate (U32 factoryIndex)
 Create component using the known index. More...
 
String factoryName (U32 factoryIndex)
 
hp< Registryregistry (void) const
 
void setRegistry (sp< Registry > spRegistry)
 
sp< LibrarygetChainLibrary (void) const
 
void setChainLibrary (sp< Library > &rspLibrary)
 Enforce FIFO by referencing prev lib on stack. More...
 
void setName (const char *a_name)
 for use in static lib scenario More...
 
DL_LoadergetLoader (void) const
 
void setLoader (DL_Loader *pLoader)
 
- Public Member Functions inherited from fe::Counted
virtual void acquire (void)
 Increment the reference count. More...
 
virtual void acquire (int &rCount)
 Increment the reference count (and get the count) More...
 
virtual void release (void)
 Decrement the reference count. More...
 
virtual void abandon (void)
 Decrement the reference count. More...
 
int count (void) const
 Return the count of references. More...
 
void setName (const String &)
 
void trackReference (void *pReference, String what)
 
void untrackReference (void *pReference)
 
void registerRegion (void *pT, U32 bytes)
 

Static Public Member Functions

template<typename T >
static sp< Componentcreate (String name, Library *pLibrary=NULL, I32 a_factoryIndex=-1)
 Instantiate and initialize a component without using a factory. More...
 
- Static Public Member Functions inherited from fe::Counted
static String reportTracker (void)
 
static U32 trackerCount (void)
 

Private Member Functions

void addFactory (BaseFactory *pFactory, BWORD singleton)
 

Static Private Member Functions

static void initComponent (sp< Component > &rspComponent, void *ptr, U32 size, String name, Library *pLibrary, I32 a_factoryIndex)
 

Private Attributes

Array< FactoryData > m_factories
 
sp< Librarym_spChainLibrary
 
DL_Loaderm_pLoader
 
I32 m_strayCount
 
Registrym_pRegistry
 
String m_name
 

Additional Inherited Members

- Protected Member Functions inherited from fe::Counted
int releaseInternal (void)
 Decrement the reference count. More...
 
void suppressReport (void)
 

Detailed Description

Interface into a dynamic library to access its factories.

Each dynamic library should contain a single code block exposing component implementations it can create. For example,

extern "C"
{
FE_DL_EXPORT fe::Library *CreateLibrary(fe::sp<fe::Master>)
{
fe::Library *pLibrary = new fe::Library();
pLibrary->add<MyComponent>("my.component");
pLibrary->addSingleton<MySingleton>("my.singleton");
return pLibrary;
}
}

This code block will create the neccessary factories. It is not optional since omitting it makes the library useless (you can set up automatic dynamic linking in your build).

Another code block can be optionally used to automatically load any number of other libraries prior to the given library. For example,

extern "C"
{
FE_DL_EXPORT void ListDependencies(fe::List<fe::String*>& list)
{
list.append(new fe::String("otherDL"));
list.append(new fe::String("anotherDL"));
}
}

If this block is omitted, no dependency preloading is performed.

By convention, these two blocks are provided together in a file named like moduleDL.cc, one for each module.

Member Function Documentation

◆ add()

template<typename T >
void fe::Library::add ( const String name)
inline

Create a named factory for the given type and add it to the library's collection.

◆ addSingleton()

template<typename T >
void fe::Library::addSingleton ( const String name)
inline

Create a named factory for the given type, but treat it as a singleton.

◆ adjustedReferences()

U32 fe::Library::adjustedReferences ( void  ) const

Return number of references adjusted for singletons.

Once this drops to 1 plus the number of factories, there are no outstanding references outside of the Library and the singletons it has instantiated.

◆ create() [1/2]

sp< Component > fe::Library::create ( U32  factoryIndex)

Create component using the known index.

◆ create() [2/2]

template<typename T >
static sp<Component> fe::Library::create ( String  name,
Library pLibrary = NULL,
I32  a_factoryIndex = -1 
)
inlinestatic

Instantiate and initialize a component without using a factory.

This is useful for unit tests that don't want to utilize a proper library. It is not intended for general use.

You have to explicitly provide the class type as the template argument.

◆ factoryName()

String fe::Library::factoryName ( U32  factoryIndex)

◆ getChainLibrary()

sp<Library> fe::Library::getChainLibrary ( void  ) const
inline

◆ getLoader()

DL_Loader* fe::Library::getLoader ( void  ) const
inline

◆ name()

const String& fe::Library::name ( void  ) const
inline

Return the library name.

◆ populateManifest()

void fe::Library::populateManifest ( Array< String > &  names) const

Append the names of the available factories to the given array.

◆ registry()

hp< Registry > fe::Library::registry ( void  ) const

◆ releaseSingletons()

void fe::Library::releaseSingletons ( void  )

Release all instantiated singletons.

This command is intended to be part of an internal shutdown procedure. If any of the singletons was still otherwise referenced and an attempt is made to create the singleton again, a new independent instance of the singleton will be created.

◆ setChainLibrary()

void fe::Library::setChainLibrary ( sp< Library > &  rspLibrary)
inline

Enforce FIFO by referencing prev lib on stack.

◆ setLoader()

void fe::Library::setLoader ( DL_Loader pLoader)
inline

◆ setName()

void fe::Library::setName ( const char *  a_name)
inline

for use in static lib scenario

◆ setRegistry()

void fe::Library::setRegistry ( sp< Registry spRegistry)

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