Lunchbox  1.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lunchbox::Plugin Class Reference

Holder for all functions and information of one compression plugin DSO. More...

#include <plugin.h>

+ Inheritance diagram for lunchbox::Plugin:
+ Collaboration diagram for lunchbox::Plugin:

Public Types

Plugin function prototypes.
typedef size_t(* GetNumCompressors_t )()
 
typedef void *(* NewCompressor_t )(const unsigned)
 
typedef void(* DeleteCompressor_t )(void *const )
 
typedef void *(* NewDecompressor_t )(const unsigned)
 
typedef void(* DeleteDecompressor_t )(void *const )
 
typedef void(* Compress_t )(void *const, const unsigned, void *const, const uint64_t *, const uint64_t)
 
typedef unsigned(* GetNumResults_t )(void *const, const unsigned)
 
typedef void(* GetResult_t )(void *const, const unsigned, const unsigned, void **const, uint64_t *const )
 
typedef void(* Decompress_t )(void *const, const unsigned, const void *const *, const uint64_t *const, const unsigned, void *const, uint64_t *const, const uint64_t)
 
typedef bool(* IsCompatible_t )(const unsigned, const GLEWContext *)
 
typedef void(* Download_t )(void *const, const unsigned, const GLEWContext *, const uint64_t *, const unsigned, const uint64_t, uint64_t *, void **)
 
typedef void(* StartDownload_t )(void *const, const unsigned, const GLEWContext *, const uint64_t *, const unsigned, const uint64_t)
 
typedef void(* FinishDownload_t )(void *const, const unsigned, const GLEWContext *, const uint64_t *, const uint64_t, uint64_t *, void **)
 
typedef void(* Upload_t )(void *const, const unsigned, const GLEWContext *, const void *, const uint64_t *, const uint64_t, const uint64_t *, const unsigned)
 

Public Member Functions

LUNCHBOX_API Plugin (const std::string &libraryName)
 Construct and initialize a new plugin DSO. More...
 
virtual LUNCHBOX_API ~Plugin ()
 Destruct this plugin handle. More...
 
Data Access.
LUNCHBOX_API bool isGood () const
 
LUNCHBOX_API VisitorResult accept (PluginVisitor &visitor)
 Visit all compressors. More...
 
LUNCHBOX_API VisitorResult accept (ConstPluginVisitor &visitor) const
 Visit all compressors. More...
 
bool implementsType (const uint32_t name) const
 
LUNCHBOX_API EqCompressorInfo findInfo (const uint32_t name) const
 
LUNCHBOX_API const
CompressorInfos & 
getInfos () const
 
- Public Member Functions inherited from lunchbox::DSO
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
 

Public Attributes

Plugin function pointers.
GetNumCompressors_t const getNumCompressors
 Get the number of engines found in the plugin. More...
 
NewCompressor_t const newCompressor
 Get a new compressor instance. More...
 
NewDecompressor_t const newDecompressor
 Get a new decompressor instance. More...
 
DeleteCompressor_t const deleteCompressor
 Delete the compressor instance. More...
 
DeleteDecompressor_t const deleteDecompressor
 Delete the decompressor instance. More...
 
Compress_t const compress
 Compress data. More...
 
Decompress_t const decompress
 Decompress data. More...
 
GetNumResults_t const getNumResults
 Get the number of results from the last compression. More...
 
GetResult_t const getResult
 Get the nth result from the last compression. More...
 
IsCompatible_t const isCompatible
 Check if the transfer plugin can be used. More...
 
Download_t const download
 Download pixel data. More...
 
Upload_t const upload
 Upload pixel data. More...
 
StartDownload_t const startDownload
 Start downloading pixel data. More...
 
FinishDownload_t const finishDownload
 Start downloading pixel data. More...
 

Detailed Description

Holder for all functions and information of one compression plugin DSO.

Example:

/* Copyright (c) 2010, Cedric Stalder <cedric.stalder@gmail.com>
* 2010-2014, Stefan Eilemann <eile@eyescale.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.
*/
#define TEST_RUNTIME 600 // seconds
#include <test.h>
#include <lunchbox/buffer.h>
#include <lunchbox/clock.h>
#include <lunchbox/compressor.h>
#include <lunchbox/compressorInfo.h>
#include <lunchbox/compressorResult.h>
#include <lunchbox/decompressor.h>
#include <lunchbox/file.h>
#include <lunchbox/memoryMap.h>
#include <lunchbox/plugin.h>
#include <lunchbox/pluginRegistry.h>
#include <lunchbox/rng.h>
#include <algorithm>
using namespace lunchbox;
void _testFile();
void _testRandom();
void _testData( const uint32_t nameCompressor, const std::string& name,
const uint8_t* data, const uint64_t size );
std::vector< uint32_t > getCompressorNames( const uint32_t tokenType );
Strings getFiles( const std::string& path, Strings& files,
const std::string& ext );
PluginRegistry registry;
uint64_t _result = 0;
uint64_t _size = 0;
float _compressionTime = 0;
float _decompressionTime = 0;
float _baseTime = 0.f;
int main( int, char** )
{
registry.addDirectory( std::string( LUNCHBOX_BUILD_DIR ) + "/lib" );
TEST( registry.addLunchboxPlugins( ));
registry.init();
_testFile();
_testRandom();
registry.exit();
Compressor compressor;
TEST( !compressor.isGood( ));
TEST( !compressor );
Decompressor decompressor;
TEST( !decompressor.isGood( ));
TEST( !decompressor );
return EXIT_SUCCESS;
}
std::vector< uint32_t > getCompressorNames( const uint32_t tokenType )
{
const Plugins& plugins = registry.getPlugins();
std::vector< uint32_t > names;
for( PluginsCIter i = plugins.begin(); i != plugins.end(); ++i )
{
const CompressorInfos& infos = (*i)->getInfos();
for( CompressorInfosCIter j = infos.begin(); j != infos.end(); ++j )
{
if ( (*j).tokenType == tokenType )
names.push_back( (*j).name );
}
}
std::sort( names.begin(), names.end( ));
return names;
}
void _testData( const uint32_t compressorName, const std::string& name,
const uint8_t* data, const uint64_t size )
{
Compressor compressor( registry, compressorName );
Decompressor decompressor( registry, compressorName );
TEST( compressor.isGood( ));
TEST( compressor );
TESTINFO( decompressor.isGood(), compressorName );
TESTINFO( decompressor, compressorName );
const uint64_t flags = EQ_COMPRESSOR_DATA_1D;
uint64_t inDims[2] = { 0, size };
compressor.compress( const_cast<uint8_t*>(data), inDims, flags );
Clock clock;
compressor.compress( const_cast<uint8_t*>(data), inDims, flags );
const float compressTime = clock.getTimef();
const CompressorResult& compressed = compressor.getResult();
const uint64_t compressedSize = compressed.getSize();
std::vector< void * > chunks;
std::vector< uint64_t > chunkSizes;
chunks.resize( compressed.chunks.size( ));
chunkSizes.resize( chunks.size( ));
for( unsigned i = 0; i < chunks.size(); ++i )
{
chunks[ i ] = compressed.chunks[i].data;
chunkSizes[ i ] = compressed.chunks[i].getNumBytes();
}
Bufferb result;
result.resize( size );
uint8_t* outData = result.getData();
decompressor.decompress( &chunks.front(), &chunkSizes.front(),
chunks.size(), outData, inDims );
clock.reset();
decompressor.decompress( &chunks.front(), &chunkSizes.front(),
chunks.size(), outData, inDims );
const float decompressTime = clock.getTimef();
TEST( memcmp( outData, data, size ) == 0 );
std::cout << std::setw(20) << name << ", 0x" << std::setw(8)
<< std::setfill( '0' ) << std::hex << compressorName << std::dec
<< std::setfill(' ') << ", " << std::setw(10) << size << ", "
<< std::setw(10) << compressedSize << ", " << std::setw(10)
<< compressTime << ", " << std::setw(10) << decompressTime
<< std::endl;
_size += size;
_result += compressedSize;
_compressionTime += compressTime;
_decompressionTime += decompressTime;
}
void _testFile()
{
std::vector< uint32_t >compressorNames =
getCompressorNames( EQ_COMPRESSOR_DATATYPE_BYTE );
std::vector< std::string > files;
getFiles( "", files, ".*\\.dll" );
getFiles( "", files, ".*\\.exe" );
getFiles( "", files, ".*\\.so" );
getFiles( "../bin", files, ".*\\.dll" );
getFiles( "../lib", files, ".*\\.so" );
getFiles( "../../install/bin", files, ".*\\.dll" );
getFiles( "../../install/lib", files, ".*\\.so" );
getFiles( "images", files, ".*\\.rgb" );
getFiles( "", files, ".*\\.a" );
getFiles( "", files, ".*\\.dylib" );
getFiles( "/Users/eile/Library/Models/mediumPly/", files, ".*\\.bin" );
getFiles( "/Users/eile/Library/Models/mediumPly/", files, ".*\\.ply" );
getFiles( "/home/eilemann/Software/Models/mediumPly/", files, ".*\\.bin" );
getFiles( "/home/eilemann/Software/Models/mediumPly/", files, ".*\\.ply" );
// Limit to 30 files using a pseudo-random selection for reproducability
const size_t maxFiles = 30;
if( files.size() > maxFiles )
{
const size_t cut = files.size() - maxFiles;
for( size_t i = 0; i < cut; ++i )
files.erase( files.begin() + (i * 997 /*prime*/) % files.size( ));
}
std::cout.setf( std::ios::right, std::ios::adjustfield );
std::cout.precision( 5 );
std::cout << " File, Compressor, Uncompress, "
<< "Compressed, t_comp, t_decomp" << std::endl;
for( std::vector< uint32_t >::const_iterator i = compressorNames.begin();
i != compressorNames.end(); ++i )
{
_result = 0;
_size = 0;
_compressionTime = 0;
_decompressionTime = 0;
for( StringsCIter j = files.begin(); j != files.end(); ++j )
{
MemoryMap file;
const uint8_t* data = static_cast<const uint8_t*>( file.map( *j ));
if( !data )
{
LBERROR << "Can't mmap " << *j << std::endl;
continue;
}
const size_t size = file.getSize();
const std::string name = getFilename( *j );
_testData( *i, name, data, size );
}
if( _baseTime == 0.f )
_baseTime = _compressionTime + _decompressionTime;
std::cout << std::setw(24) << "Total, 0x" << std::setw(8)
<< std::setfill( '0' ) << std::hex << *i << std::dec
<< std::setfill(' ') << ", " << std::setw(10) << _size << ", "
<< std::setw(10) << _result << ", " << std::setw(10)
<< _compressionTime << ", " << std::setw(10)
<< _decompressionTime << std::endl
<< " info->ratio = " << float(_result) / float(_size)
<< "f;" << std::endl
<< " info->speed = " << float(_baseTime) /
float(_compressionTime + _decompressionTime)
<< "f;" << std::endl << std::endl;
}
}
void _testRandom()
{
ssize_t size = LB_10MB;
uint8_t* data = new uint8_t[size];
RNG rng;
#pragma omp parallel for
for( ssize_t i = 0; i < size; ++i )
data[i] = rng.get< uint8_t >();
std::vector< uint32_t >compressorNames =
getCompressorNames( EQ_COMPRESSOR_DATATYPE_BYTE );
_result = 0;
_size = 0;
_compressionTime = 0;
_decompressionTime = 0;
for( std::vector<uint32_t>::const_iterator i = compressorNames.begin();
i != compressorNames.end(); ++i )
{
size = LB_10MB;
for( size_t j = 0; j<8; ++j ) // test all granularities between mod 8..1
{
_testData( *i, "Random data", data, size );
--size;
}
std::cout << std::setw(24) << "Total, 0x" << std::setw(8)
<< std::setfill( '0' ) << std::hex << *i << std::dec
<< std::setfill(' ') << ", " << std::setw(10) << _size << ", "
<< std::setw(10) << _result << ", " << std::setw(10)
<< _compressionTime << ", " << std::setw(10)
<< _decompressionTime << std::endl << std::endl;
}
delete [] data;
}
Strings getFiles( const std::string& path, Strings& files,
const std::string& ext )
{
Strings paths = registry.getDirectories();
if( !path.empty( ))
paths.push_back( path );
for( uint64_t j = 0; j < paths.size(); ++j )
{
const Strings& candidates = searchDirectory( paths[j], ext );
for( StringsCIter i = candidates.begin(); i != candidates.end(); ++i )
{
const std::string& filename = *i;
files.push_back( paths[j] + '/' + filename );
}
}
return files;
}

Definition at line 38 of file plugin.h.

Constructor & Destructor Documentation

LUNCHBOX_API lunchbox::Plugin::Plugin ( const std::string &  libraryName)
explicit

Construct and initialize a new plugin DSO.

Version
1.7.1
virtual LUNCHBOX_API lunchbox::Plugin::~Plugin ( )
virtual

Destruct this plugin handle.

Version
1.7.1

Member Function Documentation

LUNCHBOX_API VisitorResult lunchbox::Plugin::accept ( PluginVisitor visitor)

Visit all compressors.

Version
1.7.1
LUNCHBOX_API VisitorResult lunchbox::Plugin::accept ( ConstPluginVisitor visitor) const

Visit all compressors.

Version
1.7.1
LUNCHBOX_API bool lunchbox::Plugin::isGood ( ) const
Returns
true if the plugin is usable.
Version
1.7.1

Member Data Documentation

Compress_t const lunchbox::Plugin::compress

Compress data.

Version
1.7.1

Definition at line 124 of file plugin.h.

Decompress_t const lunchbox::Plugin::decompress

Decompress data.

Version
1.7.1

Definition at line 127 of file plugin.h.

DeleteCompressor_t const lunchbox::Plugin::deleteCompressor

Delete the compressor instance.

Version
1.7.1

Definition at line 118 of file plugin.h.

DeleteDecompressor_t const lunchbox::Plugin::deleteDecompressor

Delete the decompressor instance.

Version
1.7.1

Definition at line 121 of file plugin.h.

Download_t const lunchbox::Plugin::download

Download pixel data.

Version
1.7.1

Definition at line 139 of file plugin.h.

FinishDownload_t const lunchbox::Plugin::finishDownload

Start downloading pixel data.

Version
1.7.1

Definition at line 148 of file plugin.h.

GetNumCompressors_t const lunchbox::Plugin::getNumCompressors

Get the number of engines found in the plugin.

Version
1.7.1

Definition at line 109 of file plugin.h.

GetNumResults_t const lunchbox::Plugin::getNumResults

Get the number of results from the last compression.

Version
1.7.1

Definition at line 130 of file plugin.h.

GetResult_t const lunchbox::Plugin::getResult

Get the nth result from the last compression.

Version
1.7.1

Definition at line 133 of file plugin.h.

IsCompatible_t const lunchbox::Plugin::isCompatible

Check if the transfer plugin can be used.

Version
1.7.1

Definition at line 136 of file plugin.h.

NewCompressor_t const lunchbox::Plugin::newCompressor

Get a new compressor instance.

Version
1.7.1

Definition at line 112 of file plugin.h.

NewDecompressor_t const lunchbox::Plugin::newDecompressor

Get a new decompressor instance.

Version
1.7.1

Definition at line 115 of file plugin.h.

StartDownload_t const lunchbox::Plugin::startDownload

Start downloading pixel data.

Version
1.7.1

Definition at line 145 of file plugin.h.

Upload_t const lunchbox::Plugin::upload

Upload pixel data.

Version
1.7.1

Definition at line 142 of file plugin.h.


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