Graphite  Version 3
An experimental 3D geometry processing program
OGF::ModuleManager Class Reference

Manages dynamically loadable modules. More...

#include <OGF/basic/modules/modmgr.h>

Inheritance diagram for OGF::ModuleManager:
GEO::Environment GEO::Counted

Public Types

typedef void(* function_ptr) ()
 A generic function pointer.
 

Public Member Functions

bool load_module (const std::string &module_name, bool quiet=false)
 Loads a dynamic module. More...
 
bool bind_module (const std::string &module_name, Module *module)
 Declares a Module object to the ModuleManager. More...
 
bool unbind_module (const std::string &module_name)
 Removes a Module object from the ModuleManager. More...
 
Moduleresolve_module (const std::string &module_name)
 Retreives a Module object by name. More...
 
virtual bool get_local_value (const std::string &name, std::string &value) const
 overloads Environment::get_local_value() More...
 
virtual bool set_local_value (const std::string &name, const std::string &value)
 overloads Environment::set_local_value() More...
 
- Public Member Functions inherited from GEO::Environment
virtual bool add_environment (Environment *env)
 Adds a child environment. More...
 
bool has_value (const std::string &name) const
 Tests if a variable exists. More...
 
virtual bool get_value (const std::string &name, std::string &value) const
 Retrieves the value of a variable. More...
 
std::string get_value (const std::string &name) const
 Retrieves the value of a variable. More...
 
virtual bool set_value (const std::string &name, const std::string &value)
 Sets a variable value. More...
 
virtual Environmentfind_environment (const std::string &name)
 Finds the environment that declares a variable as a local name. More...
 
virtual bool add_observer (const std::string &name, VariableObserver *observer)
 Attaches an observer to a variable. More...
 
virtual bool remove_observer (const std::string &name, VariableObserver *observer)
 Detaches an observer from a variable. More...
 
virtual bool notify_observers (const std::string &name, bool recursive=false)
 Notifies observers. More...
 
- Public Member Functions inherited from GEO::Counted
void ref () const
 Increments the reference count. More...
 
void unref () const
 Decrements the reference count. More...
 
bool is_shared () const
 Check if the object is shared. More...
 
int nb_refs () const
 Gets the number of references that point to this object. More...
 

Static Public Member Functions

static void initialize ()
 Initializes the ModuleManager system. More...
 
static void terminate ()
 Terminates the ModuleManager system. More...
 
static void terminate_dynamic_modules ()
 Terminates the dynamic modules. More...
 
static ModuleManagerinstance ()
 Gets a pointer to the ModuleManager instance. More...
 
static function_ptr resolve_function (const std::string &name)
 Finds a pointer to a function by its name. More...
 
static void * resolve_symbol (const std::string &name)
 Finds a pointer to a symbol by its name. More...
 
static void append_dynamic_libraries_path (const std::string &path)
 Adds a path where dynamic libraries can be loaded. More...
 
- Static Public Member Functions inherited from GEO::Environment
static Environmentinstance ()
 Gets the root environment. More...
 
static void terminate ()
 Cleans up the environment. More...
 
- Static Public Member Functions inherited from GEO::Counted
static void ref (const Counted *counted)
 Increments the reference count. More...
 
static void unref (const Counted *counted)
 Decrements the reference count. More...
 

Protected Member Functions

 ModuleManager ()
 Forbids construction by client code.
 
 ~ModuleManager ()
 Forbids destruction by client code.
 
void do_terminate_modules ()
 Terminates all the modules registered in the system.
 
- Protected Member Functions inherited from GEO::Environment
 ~Environment () override
 Environment destructor. More...
 
bool notify_observers (const std::string &name, const std::string &value, bool recursive)
 Notifies observers. More...
 
bool notify_local_observers (const std::string &name, const std::string &value)
 Notifies local observers. More...
 
- Protected Member Functions inherited from GEO::Counted
 Counted ()
 Creates a reference counted object. More...
 
virtual ~Counted ()
 Destroys a reference counted object. More...
 

Detailed Description

Manages dynamically loadable modules.

Definition at line 71 of file modmgr.h.

Member Function Documentation

◆ append_dynamic_libraries_path()

static void OGF::ModuleManager::append_dynamic_libraries_path ( const std::string &  path)
static

Adds a path where dynamic libraries can be loaded.

Under Windows, adds the path to the PATH environment variable. Under Unixes, adds the path to the LD_LIBRARY_PATH environment variable.

Parameters
[in]paththe path to be added.

◆ bind_module()

bool OGF::ModuleManager::bind_module ( const std::string &  module_name,
Module module 
)

Declares a Module object to the ModuleManager.

Ownership of the module object is transfered to the module manager.

Parameters
[in]module_namename of the module
[in]modulea pointer to the module object
Return values
trueif the module could be successfully bound
falseotherwise (e.g. if a module with the same name was already bound)

◆ get_local_value()

virtual bool OGF::ModuleManager::get_local_value ( const std::string &  name,
std::string &  value 
) const
virtual

overloads Environment::get_local_value()

Defines the "loaded_modules" and "loaded_dynamic_modules" variables.

Parameters
[in]namename of the variable to be queried
[out]valuevalue of the variable
Return values
trueif a variable with name was found
falseotherwise

Implements GEO::Environment.

◆ initialize()

static void OGF::ModuleManager::initialize ( )
static

Initializes the ModuleManager system.

Called once when Graphite starts.

◆ instance()

static ModuleManager* OGF::ModuleManager::instance ( )
static

Gets a pointer to the ModuleManager instance.

Returns
The pointer to the instance of the ModuleManager.

◆ load_module()

bool OGF::ModuleManager::load_module ( const std::string &  module_name,
bool  quiet = false 
)

Loads a dynamic module.

Searches a dll that matches the module name in the OGF path, managed by the FileManager.

Parameters
[in]module_namethe name of the module, as displayed to the user (without "lib" prefix, without ".dll" or ".so" extension)
[in]quietif true, status messages are displayed
Return values
trueif the module was successfully loaded
falseotherwise
See also
FileManager

◆ resolve_function()

static function_ptr OGF::ModuleManager::resolve_function ( const std::string &  name)
static

Finds a pointer to a function by its name.

Searches all the functions currently loaded in all the dynamic libraries used by the current process.

Parameters
[in]namethe name of the function.
Returns
a pointer to the function or nullptr if no function was found.

◆ resolve_module()

Module* OGF::ModuleManager::resolve_module ( const std::string &  module_name)

Retreives a Module object by name.

Parameters
[in]module_namename of the module
Returns
the module object associated with module_name if it exists, nil otherwise

◆ resolve_symbol()

static void* OGF::ModuleManager::resolve_symbol ( const std::string &  name)
static

Finds a pointer to a symbol by its name.

Searches all the functions currently loaded in all the dynamic libraries used by the current process.

Parameters
[in]namethe name of the symbol.
Returns
a pointer to the symbol or nullptr if no symbol was found.

◆ set_local_value()

virtual bool OGF::ModuleManager::set_local_value ( const std::string &  name,
const std::string &  value 
)
virtual

overloads Environment::set_local_value()

Defines no additional variable ("loaded_modules" and "loaded_dynamic_modules" are readonly).

Parameters
[in]namename of the variable to be set
[in]valuenew value for the variable
Return values
trueif a variable with name could be set to value
falseotherwise

Implements GEO::Environment.

◆ terminate()

static void OGF::ModuleManager::terminate ( )
static

Terminates the ModuleManager system.

Called once when Graphite exits.

◆ terminate_dynamic_modules()

static void OGF::ModuleManager::terminate_dynamic_modules ( )
static

Terminates the dynamic modules.

The dynamic modules are those that are loaded on-demand by Graphite. This function is called once when Graphite exits.

◆ unbind_module()

bool OGF::ModuleManager::unbind_module ( const std::string &  module_name)

Removes a Module object from the ModuleManager.

Parameters
[in]module_namename of the module.
Return values
trueif the module could be successfully unbound
falseotherwise (e.g. if no module of that name was found in the ModuleManager)

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