Lunchbox  1.12.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
lunchbox::DSO Class Reference

Helper to access dynamic shared objects (DSO) More...

#include <dso.h>

+ Inheritance diagram for lunchbox::DSO:
+ Collaboration diagram for lunchbox::DSO:

Public Member Functions

LUNCHBOX_API DSO ()
 Construct a new dynamic shared object. More...
 
LUNCHBOX_API DSO (const std::string &name)
 Construct and initialize a dynamic shared object. More...
 
LUNCHBOX_API ~DSO ()
 Destruct this DSO handle. More...
 
LUNCHBOX_API bool open (const std::string &fileName)
 Open a dynamic shared object. More...
 
LUNCHBOX_API void close ()
 Close the DSO, invalidates retrieved function pointers. More...
 
LUNCHBOX_API void * getFunctionPointer (const std::string &functionName) const
 
template<class F >
getFunctionPointer (const std::string &func) const
 
LUNCHBOX_API bool isOpen () const
 
LUNCHBOX_API bool operator== (const DSO &rhs) const
 
bool operator!= (const DSO &rhs) const
 

Detailed Description

Helper to access dynamic shared objects (DSO)

Example:

/* Copyright (c) 2014, Stefan.Eilemann@epfl.ch
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "test.h"
#include <lunchbox/dso.h>
#include <boost/filesystem.hpp>
#ifdef __linux__
# include <gnu/lib-names.h>
#endif
#ifdef _WIN32
# include <lunchbox/os.h>
# define fork CreateThread
const std::string forkFun( "CreateThread" );
#else
const std::string forkFun( "fork" );
#endif
namespace fs = boost::filesystem;
int main( int, char** )
{
lunchbox::Strings libraries;
#ifdef _WIN32
libraries.push_back( "Kernel32.dll" );
libraries.push_back( "Ws2_32.dll" );
#elif defined (Darwin)
libraries.push_back( "/usr/lib/libc.dylib" );
libraries.push_back( "/usr/lib/libtermcap.dylib" );
#else
libraries.push_back( LIBPTHREAD_SO );
libraries.push_back( LIBM_SO );
#endif
lunchbox::DSO one( libraries[0] );
lunchbox::DSO two( libraries[1] );
TEST( one.isOpen( ));
TEST( two.isOpen( ));
TEST( !three.isOpen( ));
TEST( one != two );
TEST( one != three );
TEST( three.open( libraries[0] ));
TEST( one == three );
TEST( !three.open( libraries[0] ));
TEST( one == three );
TEST( one.getFunctionPointer( forkFun ));
TEST( one.getFunctionPointer( forkFun ) == &fork );
TEST( !one.getFunctionPointer( "fooBar" ));
one.close();
TEST( one != two );
TEST( one != three );
TEST( !one.getFunctionPointer( forkFun ));
two.close();
TEST( one == two );
TEST( one != three );
return EXIT_SUCCESS;
}

Definition at line 35 of file dso.h.

Constructor & Destructor Documentation

LUNCHBOX_API lunchbox::DSO::DSO ( )

Construct a new dynamic shared object.

Version
1.0
LUNCHBOX_API lunchbox::DSO::DSO ( const std::string &  name)
explicit

Construct and initialize a dynamic shared object.

Version
1.7.1
LUNCHBOX_API lunchbox::DSO::~DSO ( )

Destruct this DSO handle.

Version
1.0

Member Function Documentation

LUNCHBOX_API void lunchbox::DSO::close ( )

Close the DSO, invalidates retrieved function pointers.

Version
1.0
LUNCHBOX_API void* lunchbox::DSO::getFunctionPointer ( const std::string &  functionName) const
Returns
a function pointer in the DSO, or 0 if the function is not exported by the DSO.
Version
1.0

Referenced by getFunctionPointer().

+ Here is the caller graph for this function:

template<class F >
F lunchbox::DSO::getFunctionPointer ( const std::string &  func) const
inline
Returns
a typed function pointer in the DSO, or 0 if the function is not exported by the DSO.
Version
1.7.1

Definition at line 75 of file dso.h.

References getFunctionPointer().

+ Here is the call graph for this function:

LUNCHBOX_API bool lunchbox::DSO::isOpen ( ) const
Returns
true if the DSO is loaded.
Version
1.0
LUNCHBOX_API bool lunchbox::DSO::open ( const std::string &  fileName)

Open a dynamic shared object.

Parameters
fileNameThe file name of the DSO.
Returns
true if the DSO was opened, false upon error.
Version
1.0
bool lunchbox::DSO::operator!= ( const DSO rhs) const
inline
Returns
true if both instances manage different shared objects.
Version
1.9.1

Definition at line 91 of file dso.h.

LUNCHBOX_API bool lunchbox::DSO::operator== ( const DSO rhs) const
Returns
true if both instances manage the same shared object.
Version
1.9.1

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