JeVois  1.22
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Loading...
Searching...
No Matches
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.
 
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.
 
 ~DynamicLoader ()
 Destructor, may close the object on destroy (see constructor arguments)
 
void close ()
 Close the shared object file.
 
template<class Signature >
std::function< Signature > load (std::string const &functionName)
 Load the symbol named functionName.
 

Constructor & Destructor Documentation

◆ DynamicLoader()

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

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).

◆ ~DynamicLoader()

jevois::DynamicLoader::~DynamicLoader ( )

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

Member Function Documentation

◆ close()

void jevois::DynamicLoader::close ( )

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.

◆ load()

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

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());
}
Class to open shared object (.so) files and load functions contained in them.
#define LFATAL(msg)
Convenience macro for users to print out console or syslog messages, FATAL level.
Definition Log.H:230

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.

◆ 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.


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