JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::DynamicLoader Class Reference

#include <jevois/Core/DynamicLoader.H>

Class to open shared object (.so) files and load functions contained in them.

This class allows one to open a shared library (.so file) and to invoke functions or classes that are in that library.

Engine uses DynamicLoader to load the appropriate vision processing Module each time the user selects a new VideoMapping (i.e., changes image resolution in a USB webcam program running on a host computer, or invokes the setmapping command over Serial port).

This class is modified from DynamicLoader in the Neuromorphic Robotics Toolkit (NRT).

Definition at line 69 of file DynamicLoader.H.

Public Member Functions

 DynamicLoader (std::string const &filename, bool closeOnDestroy)
 Open the shared object located at filename, throws if fail. More...
 
std::string const & sopath () const
 Retrieve the path to the .so file of this loader, useful to avoid closing and re-loading the same .so file. More...
 
 ~DynamicLoader ()
 Destructor, may close the object on destroy (see constructor arguments) More...
 
void close ()
 Close the shared object file. More...
 
template<class Signature >
std::function< Signature > load (std::string const &functionName)
 Load the symbol named functionName. More...
 

Constructor & Destructor Documentation

◆ DynamicLoader()

jevois::DynamicLoader::DynamicLoader ( std::string const &  filename,
bool  closeOnDestroy 
)
inline

Open the shared object located at filename, throws if fail.

If closeOnDestroy is true, the .so file will be closed when the DynamicLoader object is destroyed. If you want to maintain access to the functions and classes in a .so file after the loader has run out of scope, set closeOnDestroy to false (and you will then have no way of ever unloading that .so file until termination of your program).

Definition at line 20 of file DynamicLoaderImpl.H.

References LFATAL.

◆ ~DynamicLoader()

jevois::DynamicLoader::~DynamicLoader ( )
inline

Destructor, may close the object on destroy (see constructor arguments)

Definition at line 42 of file DynamicLoaderImpl.H.

References close().

Member Function Documentation

◆ close()

void jevois::DynamicLoader::close ( )
inline

Close the shared object file.

Beware that closing the object file will remove all links to any objects/functions/etc that have been created from the shared object. Use this function only if you want nothing more to do with anything created from this object file.

Definition at line 48 of file DynamicLoaderImpl.H.

Referenced by ~DynamicLoader().

◆ load()

template<class Signature >
std::function< Signature > jevois::DynamicLoader::load ( std::string const &  functionName)
inline

Load the symbol named functionName.

This method returns an std::function that points to the requested name in the shared object opened by this DynamicLoader. For example, to load the function int foo(double x, bool y) from the file "mySharedObject.so" you should write:

jevois::DynamicLoader loader("./mySharedObject.so");
try
{
std::function<int(double,bool)> foo = loader.load<int(double,bool)>("foo");
int result = foo(3.0, true);
}
catch (std::exception const & e)
{
LFATAL(e.what());
}

You should not try to use anything returned by load() after the DynamicLoader has been close()'d (or destroyed, see constructor arguments).

Throws if the requested symbol could not be found in the opened shared object.

Definition at line 55 of file DynamicLoaderImpl.H.

References LFATAL.

◆ sopath()

std::string const & jevois::DynamicLoader::sopath ( ) const

Retrieve the path to the .so file of this loader, useful to avoid closing and re-loading the same .so file.

Definition at line 38 of file DynamicLoaderImpl.H.


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