ltmm::loader< ThreadPolicy > Class Template Reference

#include <ltmm/loader.hh>

Inheritance diagram for ltmm::loader< ThreadPolicy >:

Inheritance graph
[legend]
Collaboration diagram for ltmm::loader< ThreadPolicy >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename ThreadPolicy = single_thread>
class ltmm::loader< ThreadPolicy >

Class to load dynamic libraries.

Loading libraries - ltmm::loader::load
If filename is the empty string and the program was linked with -export-dynamic or -dlopen self, this member function will return a handle for the program itself, which can be used to access its symbols.

If the member function cannot find the library and the file name filename does not have a directory component it will additionally search in the following search paths for the module (in the order as follows):

user-defined search path
This search path can be set by the program using the member functions ltmm::loader<ThreadPolicy>::search_path and ltmm::loader<ThreadPolicy>::addto_search_path.
library's search path
This search path is the value of the environment variable LTDL_LIBRARY_PATH.
system library search path
The system dependent library search path (e.g. on GNU/Linux it is LD_LIBRARY_PATH)

Each search path must be a colon-separated list of absolute directories, for example, "/usr/lib/mypkg:/lib/foo".

If the file with the file name filename cannot be found the member function tries to append the following extensions:

  1. the libtool archive extension .la
  2. the extension used for native dynamic libraries on the host platform, e.g., .so, .sl, etc.

Parameters:
ThreadPolicy A policy object that says how to lock structures in a multi-threaded environment. Per default it is ltmm::single_thread, but see alse that class for more documentation.
Examples:

tests/simple.cc.

Definition at line 138 of file loader.hh.

Preloading

void preload (symbol &s)
static symbol_mappreloaded ()

Public Types

typedef ThreadPolicy thread_policy_type
typedef handle< thread_policy_typehandle_type
typedef backend< thread_policy_typebackend_type
typedef std::map< std::string,
symbol_list
symbol_map

Public Member Functions

handle_typenext_handle (handle_type *h)
backend_typenext_backend (backend_type *h)
Loading and unloading libraries
handle_typeload (const std::string &filename)
void unload (handle_type &h)
The user-defined search path
void addto_search_path (const std::string &dir)
std::string search_path (const std::string &path)
std::string search_path () const
Iteration on handles
handle_iterator begin_handle ()
handle_iterator end_handle ()
Backend handling and iteration
void insert_backend (backend_type &b)
void insert_backend (const backend_iterator &i, backend_type &b)
void remove_backend (backend_iterator &b)
void remove_backend (const std::string &name)
backend_iterator find_backend (const std::string &name)
backend_iterator begin_backend ()
backend_iterator end_backend ()

Static Public Member Functions

static loaderinstance ()

Protected Member Functions

 loader ()
virtual ~loader ()

Protected Attributes

lt_dlcaller_id _id

Static Protected Attributes

static loader_instance = 0
static thread_policy_type _lock
static symbol_map _preloaded

Classes

class  backend_iterator
 Forward iterator over backends in list. More...
class  guard
 Guard class. More...
class  handle_iterator
 Forward iterator over handles in list. More...


Member Typedef Documentation

template<typename ThreadPolicy = single_thread>
typedef backend<thread_policy_type> ltmm::loader< ThreadPolicy >::backend_type
 

Type of backends.

Definition at line 146 of file loader.hh.

template<typename ThreadPolicy = single_thread>
typedef handle<thread_policy_type> ltmm::loader< ThreadPolicy >::handle_type
 

Type of handles.

Definition at line 144 of file loader.hh.

template<typename ThreadPolicy = single_thread>
typedef std::map<std::string, symbol_list> ltmm::loader< ThreadPolicy >::symbol_map
 

The type of the map of symbol lists.

Definition at line 148 of file loader.hh.

template<typename ThreadPolicy = single_thread>
typedef ThreadPolicy ltmm::loader< ThreadPolicy >::thread_policy_type
 

The type of thread locks.

Definition at line 142 of file loader.hh.


Constructor & Destructor Documentation

template<typename ThreadPolicy>
ltmm::loader< ThreadPolicy >::loader  )  [inline, protected]
 

Constructor.

The constructor is protected, so that the client code can only access the loader via the singleton interface.

Exceptions:
ltmm::exception is thrown if the library could not be initialised.

Definition at line 454 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_id, lt_dlcaller_register(), lt_dlinit(), and lt_dlmutex_register().

Here is the call graph for this function:

template<typename ThreadPolicy>
ltmm::loader< ThreadPolicy >::~loader  )  [inline, protected, virtual]
 

Destructor.

The destructor is protected, so that the client code can only access the loader via the singleton interface.

Definition at line 473 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_instance, and lt_dlexit().

Here is the call graph for this function:


Member Function Documentation

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::addto_search_path const std::string &  dir  )  [inline]
 

Add a directory to user-defined library search path.

Parameters:
dir Directory to add.
Exceptions:
ltmm::exception on errors.

Definition at line 540 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_lock, and lt_dladdsearchdir().

Here is the call graph for this function:

template<typename ThreadPolicy>
loader< ThreadPolicy >::backend_iterator ltmm::loader< ThreadPolicy >::begin_backend  )  [inline]
 

Get a forward iterator pointing to the first element in the backend list.

Definition at line 814 of file loader.hh.

References ltmm::loader< ThreadPolicy >::next_backend().

Here is the call graph for this function:

template<typename ThreadPolicy>
loader< ThreadPolicy >::handle_iterator ltmm::loader< ThreadPolicy >::begin_handle  )  [inline]
 

Return an iterator pointing at start of handle list.

Definition at line 687 of file loader.hh.

References ltmm::loader< ThreadPolicy >::next_handle().

Here is the call graph for this function:

template<typename ThreadPolicy>
loader< ThreadPolicy >::backend_iterator ltmm::loader< ThreadPolicy >::end_backend  )  [inline]
 

Get a forward iterator pointing to just afte the end of the backend list.

Definition at line 825 of file loader.hh.

Referenced by ltmm::loader< ThreadPolicy >::find_backend(), ltmm::loader< ThreadPolicy >::insert_backend(), and ltmm::loader< ThreadPolicy >::remove_backend().

template<typename ThreadPolicy>
loader< ThreadPolicy >::handle_iterator ltmm::loader< ThreadPolicy >::end_handle  )  [inline]
 

return an iterator pointing just after end of list.

Definition at line 698 of file loader.hh.

template<typename ThreadPolicy>
loader< ThreadPolicy >::backend_iterator ltmm::loader< ThreadPolicy >::find_backend const std::string &  name  )  [inline]
 

Find a backend loader.

Definition at line 889 of file loader.hh.

References ltmm::loader< ThreadPolicy >::end_backend(), lt_dlloader_data(), and lt_dlloader_find().

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::insert_backend const backend_iterator i,
backend_type b
[inline]
 

Insert after an iterator position.

Definition at line 844 of file loader.hh.

References ltmm::loader< ThreadPolicy >::backend_iterator::_current, ltmm::backend< ThreadPolicy >::_place, lt_user_dlloader::dlloader_data, lt_user_dlloader::dlloader_exit, ltmm::loader< ThreadPolicy >::end_backend(), lt_user_dlloader::find_sym, lt_dlloader_add(), lt_dlloader_find(), lt_user_dlloader::module_close, lt_user_dlloader::module_open, ltmm::backend< ThreadPolicy >::name(), ltmm::backend< ThreadPolicy >::prefix(), and lt_user_dlloader::sym_prefix.

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::insert_backend backend_type b  )  [inline]
 

Add a backend to the list of loaders.

Parameters:
b The loader to add.

Definition at line 835 of file loader.hh.

References ltmm::loader< ThreadPolicy >::end_backend().

Here is the call graph for this function:

template<typename ThreadPolicy>
loader< ThreadPolicy > & ltmm::loader< ThreadPolicy >::instance  )  [inline, static]
 

Get the static (singleton) object.

Examples:
tests/factory.cc, and tests/simple.cc.

Definition at line 482 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_instance, and ltmm::loader< ThreadPolicy >::_lock.

template<typename ThreadPolicy>
handle< ThreadPolicy > & ltmm::loader< ThreadPolicy >::load const std::string &  filename  )  [inline]
 

Load a dynamic library.

If the same module is loaded several times, the same handle is returned. See also class description.

Parameters:
filename Is the file name of the library to load.
Returns:
A handle to the library loaded.
Exceptions:
ltmm::exception If the method fails, an exception is thrown.

Definition at line 496 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_id, ltmm::loader< ThreadPolicy >::_lock, lt_dlcaller_get_data(), lt_dlcaller_set_data(), lt_dlgetinfo(), lt_dlopenext(), lt_ptr, and lt_dlinfo::ref_count.

Here is the call graph for this function:

template<typename ThreadPolicy>
backend< ThreadPolicy > * ltmm::loader< ThreadPolicy >::next_backend backend_type h  )  [inline]
 

Static member function used by backend_iterator.

Definition at line 708 of file loader.hh.

References ltmm::backend< ThreadPolicy >::_place, lt_dlloader_data(), and lt_dlloader_next().

Referenced by ltmm::loader< ThreadPolicy >::begin_backend(), and ltmm::loader< ThreadPolicy >::backend_iterator::operator++().

Here is the call graph for this function:

template<typename ThreadPolicy>
handle< ThreadPolicy > * ltmm::loader< ThreadPolicy >::next_handle handle_type h  )  [inline]
 

Static member function used by handle_iterator.

Definition at line 592 of file loader.hh.

References ltmm::handle< ThreadPolicy >::_handle, ltmm::loader< ThreadPolicy >::_id, lt_dlcaller_get_data(), and lt_dlhandle_next().

Referenced by ltmm::loader< ThreadPolicy >::begin_handle(), and ltmm::loader< ThreadPolicy >::handle_iterator::operator++().

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::preload symbol s  )  [inline]
 

Add a symbol to the preloaded symbols.

Exceptions:
ltmm::exception Thrown in case of errors.
Parameters:
s The symbol to add.

Definition at line 940 of file loader.hh.

References lt_dlsymlist::address, lt_dlpreload(), ltmm::symbol::name(), lt_dlsymlist::name, and ltmm::symbol::ptr().

Here is the call graph for this function:

template<typename ThreadPolicy>
loader< ThreadPolicy >::symbol_map & ltmm::loader< ThreadPolicy >::preloaded  )  [inline, static]
 

Get (and set internally) list of preloaded symbols.

Note, that it is important that the program is linked with the -dlopen option passed to Libtool for this to work. The reason is, that it references an external symbol that is only defined if -dlopen is used. If the application isn't linked with -dlopen, then it will result in a compile time error of an undefined reference to lt_preloaded_symbols. *

Exceptions:
ltmm::exception Thrown in case of errors.
Returns:
map of preloaded symbols. The map consist of a key, which is the file where the symbols is founds, and a value of a ltmm::symbol_list, which is a list of ltmm::symbol objects. The key @PROGRAM@ denotes the application itself. Note, that the names are mangled, so they may look very odd indeed.
Examples:
tests/factory.cc, and tests/simple.cc.

Definition at line 909 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_lock, ltmm::loader< ThreadPolicy >::_preloaded, lt_dlsymlist::address, lt_dlpreload_default(), lt_preloaded_symbols, and lt_dlsymlist::name.

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::remove_backend const std::string &  name  )  [inline]
 

Remove a backend from the list.

Definition at line 878 of file loader.hh.

References lt_dlloader_remove().

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::remove_backend backend_iterator b  )  [inline]
 

Remove a backend from the list.

Definition at line 868 of file loader.hh.

References ltmm::loader< ThreadPolicy >::backend_iterator::_current, ltmm::loader< ThreadPolicy >::end_backend(), and ltmm::backend< ThreadPolicy >::name().

Here is the call graph for this function:

template<typename ThreadPolicy>
std::string ltmm::loader< ThreadPolicy >::search_path  )  const [inline]
 

Get the user-defined library search path.

Returns:
the search path.
Exceptions:
ltmm::exception on errors.

Definition at line 559 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_lock, and lt_dlgetsearchpath().

Here is the call graph for this function:

template<typename ThreadPolicy>
std::string ltmm::loader< ThreadPolicy >::search_path const std::string &  path  )  [inline]
 

Set the user-defined library search path.

Parameters:
path the new user-defined search path.
Returns:
the search path.
Exceptions:
ltmm::exception on errors.

Definition at line 549 of file loader.hh.

References ltmm::loader< ThreadPolicy >::_lock, lt_dlgetsearchpath(), and lt_dlsetsearchpath().

Here is the call graph for this function:

template<typename ThreadPolicy>
void ltmm::loader< ThreadPolicy >::unload handle_type h  )  [inline]
 

Unload a library.

Decrement the reference count on the module handle. If it drops to zero and no other module depends on this module, then the module is unloaded.

Exceptions:
ltmm::exception If the method fails.
Parameters:
h The library to unload.

Definition at line 526 of file loader.hh.

References ltmm::handle< ThreadPolicy >::_handle, ltmm::loader< ThreadPolicy >::_id, ltmm::loader< ThreadPolicy >::_lock, lt_dlcaller_set_data(), lt_dlclose(), lt_ptr, and ltmm::handle< ThreadPolicy >::reference_count().

Here is the call graph for this function:


Member Data Documentation

template<typename ThreadPolicy = single_thread>
lt_dlcaller_id ltmm::loader< ThreadPolicy >::_id [protected]
 

Caller ID to resolve user data in modules.

Definition at line 169 of file loader.hh.

Referenced by ltmm::loader< ThreadPolicy >::load(), ltmm::loader< ThreadPolicy >::loader(), ltmm::loader< ThreadPolicy >::next_handle(), and ltmm::loader< ThreadPolicy >::unload().

template<typename ThreadPolicy = single_thread>
loader< ThreadPolicy > * ltmm::loader< ThreadPolicy >::_instance = 0 [static, protected]
 

Static (singleton) instance.

Definition at line 951 of file loader.hh.

Referenced by ltmm::loader< ThreadPolicy >::instance(), and ltmm::loader< ThreadPolicy >::~loader().

template<typename ThreadPolicy = single_thread>
ThreadPolicy ltmm::loader< ThreadPolicy >::_lock [static, protected]
 

Static lock.

Definition at line 955 of file loader.hh.

Referenced by ltmm::loader< ThreadPolicy >::addto_search_path(), ltmm::loader< ThreadPolicy >::instance(), ltmm::loader< ThreadPolicy >::load(), ltmm::loader< ThreadPolicy >::preloaded(), ltmm::loader< ThreadPolicy >::search_path(), and ltmm::loader< ThreadPolicy >::unload().

template<typename ThreadPolicy = single_thread>
std::map< std::string, symbol_list > ltmm::loader< ThreadPolicy >::_preloaded [static, protected]
 

Map of preloaded symbols.

Definition at line 958 of file loader.hh.

Referenced by ltmm::loader< ThreadPolicy >::preloaded().


The documentation for this class was generated from the following file:
Top of page
Last update Mon Jun 27 13:25:41 2005
Christian Holm
Created by DoxyGen 1.4.3-20050530