summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-10-05 12:39:14 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2014-10-05 12:39:14 +0200
commit4174158dc75b5ed892b293b18b7dd5c85aa36f2f (patch)
tree15833550838d912174c54d05583d5374f03c35e9
parentd207e5a4f68cf56699b6f59487d3456f1c5e5f01 (diff)
downloadcrawler-4174158dc75b5ed892b293b18b7dd5c85aa36f2f.tar.gz
crawler-4174158dc75b5ed892b293b18b7dd5c85aa36f2f.tar.bz2
added void * userdata to initModule
-rwxr-xr-xinclude/module/ModuleLoader.hpp28
-rwxr-xr-xinclude/module/ModuleRegistry.hpp20
-rw-r--r--tests/modules/UserData.hpp9
-rw-r--r--tests/modules/test4.MUST2
-rwxr-xr-xtests/modules/test4.cpp6
-rwxr-xr-xtests/modules/testmod4/TestMod4.cpp12
6 files changed, 49 insertions, 28 deletions
diff --git a/include/module/ModuleLoader.hpp b/include/module/ModuleLoader.hpp
index 9626972..6eb9079 100755
--- a/include/module/ModuleLoader.hpp
+++ b/include/module/ModuleLoader.hpp
@@ -43,14 +43,14 @@ class BaseModuleLoader {
mapType m_modules;
public:
-
- BaseModuleLoader( const std::vector<std::string> files )
+
+ BaseModuleLoader( const std::vector<std::string> files, void *user_data = 0 )
{
Module< Interface, CtorParams> m;
for( std::vector<std::string>::const_iterator it = files.begin( ); it != files.end( ); it++ ) {
#ifndef _WIN32
- m.handle = dlopen( it->c_str( ), RTLD_NOW );
+ m.handle = dlopen( it->c_str( ), RTLD_NOW | RTLD_LOCAL );
#else
m.handle = LoadLibrary( it->c_str( ) );
#endif
@@ -81,7 +81,7 @@ class BaseModuleLoader {
}
if( m.registry->initModule != 0 ) {
- m.registry->initModule( );
+ m.registry->initModule( user_data );
}
m_modules.insert( std::make_pair( m.registry->name, m ) );
@@ -131,8 +131,8 @@ class ModuleLoader< Interface, NullType > : public BaseModuleLoader< Interface,
{
public:
- ModuleLoader< Interface >( const std::vector<std::string> files )
- : BaseModuleLoader< Interface >(files ) { }
+ ModuleLoader< Interface >( const std::vector<std::string> files, void *user_data = 0 )
+ : BaseModuleLoader< Interface >( files, user_data ) { }
Interface *create( std::string subclass )
{
@@ -160,8 +160,8 @@ class ModuleLoader< Interface, TYPELIST_1( T1 ) > : public BaseModuleLoader< Int
{
public:
- ModuleLoader< Interface, TYPELIST_1( T1 ) >( const std::vector<std::string> files )
- : BaseModuleLoader< Interface, TYPELIST_1( T1 ) >( files ) { }
+ ModuleLoader< Interface, TYPELIST_1( T1 ) >( const std::vector<std::string> files, void *user_data = 0 )
+ : BaseModuleLoader< Interface, TYPELIST_1( T1 ) >( files, user_data ) { }
Interface *create( std::string subclass, T1 t1 )
{
@@ -189,8 +189,8 @@ class ModuleLoader< Interface, TYPELIST_2( T1, T2 ) > : public BaseModuleLoader<
{
public:
- ModuleLoader< Interface, TYPELIST_2( T1, T2 ) >( const std::vector<std::string> files )
- : BaseModuleLoader< Interface, TYPELIST_2( T1, T2 ) >( files ) { }
+ ModuleLoader< Interface, TYPELIST_2( T1, T2 ) >( const std::vector<std::string> files, void *user_data = 0 )
+ : BaseModuleLoader< Interface, TYPELIST_2( T1, T2 ) >( files, user_data ) { }
Interface *create( std::string subclass, T1 t1, T2 t2 )
{
@@ -218,8 +218,8 @@ class ModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) > : public BaseModuleLoa
{
public:
- ModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) >( const std::vector<std::string> files )
- : BaseModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) >( files ) { }
+ ModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) >( const std::vector<std::string> files, void *user_data = 0 )
+ : BaseModuleLoader< Interface, TYPELIST_3( T1, T2, T3 ) >( files, user_data ) { }
Interface *create( std::string subclass, T1 t1, T2 t2, T3 t3 )
{
@@ -247,8 +247,8 @@ class ModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) > : public BaseModul
{
public:
- ModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) >( const std::vector<std::string> files )
- : BaseModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) >( files ) { }
+ ModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) >( const std::vector<std::string> files, void *user_data = 0 )
+ : BaseModuleLoader< Interface, TYPELIST_4( T1, T2, T3, T4 ) >( files, user_data ) { }
Interface *create( std::string subclass, T1 t1, T2 t2, T3 t3, T4 t4 )
{
diff --git a/include/module/ModuleRegistry.hpp b/include/module/ModuleRegistry.hpp
index d8ee90c..d98c9ba 100755
--- a/include/module/ModuleRegistry.hpp
+++ b/include/module/ModuleRegistry.hpp
@@ -11,13 +11,13 @@ struct ModuleRegistry;
template< typename Interface>
struct ModuleRegistry< Interface > {
std::string name;
- void (*initModule)( );
+ void (*initModule)( void *user_data );
void (*destroyModule)( );
Interface *(*create)( );
void (*destroy)( Interface *obj );
ModuleRegistry( std::string _name,
- void (*_initModule)( ),
+ void (*_initModule)( void *user_data ),
void (*_destroyModule)( ),
Interface *(*_create)( ),
void (*_destroy)( Interface *obj ) )
@@ -31,13 +31,13 @@ struct ModuleRegistry< Interface > {
template< typename Interface, typename P1 >
struct ModuleRegistry< Interface, TYPELIST_1( P1 ) > {
std::string name;
- void (*initModule)( );
+ void (*initModule)( void *user_data );
void (*destroyModule)( );
Interface *(*create)( P1 );
void (*destroy)( Interface *obj );
ModuleRegistry( std::string _name,
- void (*_initModule)( ),
+ void (*_initModule)( void *user_data ),
void (*_destroyModule)( ),
Interface *(*_create)( P1 ),
void (*_destroy)( Interface *obj ) )
@@ -51,13 +51,13 @@ struct ModuleRegistry< Interface, TYPELIST_1( P1 ) > {
template< typename Interface, typename P1, typename P2 >
struct ModuleRegistry< Interface, TYPELIST_2( P1, P2 ) > {
std::string name;
- void (*initModule)( );
+ void (*initModule)( void *user_data );
void (*destroyModule)( );
Interface *(*create)( P1, P2 );
void (*destroy)( Interface *obj );
ModuleRegistry( std::string _name,
- void (*_initModule)( ),
+ void (*_initModule)( void *user_data ),
void (*_destroyModule)( ),
Interface *(*_create)( P1, P2 ),
void (*_destroy)( Interface *obj ) )
@@ -71,13 +71,13 @@ struct ModuleRegistry< Interface, TYPELIST_2( P1, P2 ) > {
template< typename Interface, typename P1, typename P2, typename P3 >
struct ModuleRegistry< Interface, TYPELIST_3( P1, P2, P3 ) > {
std::string name;
- void (*initModule)( );
+ void (*initModule)( void *user_data );
void (*destroyModule)( );
Interface *(*create)( P1, P2, P3 );
void (*destroy)( Interface *obj );
ModuleRegistry( std::string _name,
- void (*_initModule)( ),
+ void (*_initModule)( void *user_data ),
void (*_destroyModule)( ),
Interface *(*_create)( P1, P2, P3 ),
void (*_destroy)( Interface *obj ) )
@@ -91,13 +91,13 @@ struct ModuleRegistry< Interface, TYPELIST_3( P1, P2, P3 ) > {
template< typename Interface, typename P1, typename P2, typename P3, typename P4 >
struct ModuleRegistry< Interface, TYPELIST_4( P1, P2, P3, P4 ) > {
std::string name;
- void (*initModule)( );
+ void (*initModule)( void *user_data );
void (*destroyModule)( );
Interface *(*create)( P1, P2, P3, P4 );
void (*destroy)( Interface *obj );
ModuleRegistry( std::string _name,
- void (*_initModule)( ),
+ void (*_initModule)( void *user_data ),
void (*_destroyModule)( ),
Interface *(*_create)( P1, P2, P3, P4 ),
void (*_destroy)( Interface *obj ) )
diff --git a/tests/modules/UserData.hpp b/tests/modules/UserData.hpp
new file mode 100644
index 0000000..83b301d
--- /dev/null
+++ b/tests/modules/UserData.hpp
@@ -0,0 +1,9 @@
+#ifndef _USER_DATA_INCLUDED
+#define _USER_DATA_INCLUDED
+
+struct UserData {
+ int version;
+ string text;
+};
+
+#endif
diff --git a/tests/modules/test4.MUST b/tests/modules/test4.MUST
index a675dba..1d14a0c 100644
--- a/tests/modules/test4.MUST
+++ b/tests/modules/test4.MUST
@@ -1,5 +1,5 @@
Created common object
-test4: Module 4 initModule called
+test4: Module 4 initModule called with user data: 47 hello there
test4: hello from main
test4: hello world from module
test4: Module 4 destroyModule called
diff --git a/tests/modules/test4.cpp b/tests/modules/test4.cpp
index 8e1bfbe..4e71295 100755
--- a/tests/modules/test4.cpp
+++ b/tests/modules/test4.cpp
@@ -1,6 +1,7 @@
#include "ModuleLoader.hpp"
#include "Base.hpp"
#include "Common.hpp"
+#include "UserData.hpp"
#include <vector>
#include <string>
@@ -20,7 +21,10 @@ int main( void )
#else
modules.push_back( ".\\testmod4\\mod_test4.dll" );
#endif
- ModuleLoader<Base> loader( modules );
+ UserData user_data;
+ user_data.version = 47;
+ user_data.text.assign( "hello there" );
+ ModuleLoader<Base> loader( modules, (void *)&user_data );
Base *obj = loader.create( "testmod4" );
c.print( "hello from main" );
diff --git a/tests/modules/testmod4/TestMod4.cpp b/tests/modules/testmod4/TestMod4.cpp
index cd0578e..de8b1b6 100755
--- a/tests/modules/testmod4/TestMod4.cpp
+++ b/tests/modules/testmod4/TestMod4.cpp
@@ -1,10 +1,12 @@
#include "TestMod4.hpp"
#include "Common.hpp"
+#include "UserData.hpp"
#include <iostream>
#include <vector>
#include <string>
+#include <sstream>
using namespace std;
@@ -21,9 +23,15 @@ void Derived::hello( )
Common::instance( ).print( "hello world from module" );
}
-static void initModule( )
+static void initModule( void *user_data )
{
- Common::instance( ).print( "Module 4 initModule called" );
+ UserData *data = (UserData *)user_data;
+ ostringstream ss;
+
+ ss << "Module 4 initModule called with user data: "
+ << data->version << " " << data->text;
+
+ Common::instance( ).print( ss.str( ) );
}
static void destroyModule( )