From 578f8d8b0bec9ba3e5a1f8b4bf26b66f58dd6752 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 4 Oct 2014 20:43:17 +0200 Subject: added init and destroy functions to modules --- tests/modules/GNUmakefile | 6 +++-- tests/modules/Makefile.W32 | 7 +++-- tests/modules/test4.MUST | 5 ++++ tests/modules/test4.cpp | 36 ++++++++++++++++++++++++++ tests/modules/testmod/TestMod.cpp | 2 +- tests/modules/testmod2/TestMod2.cpp | 2 +- tests/modules/testmod3/TestMod3.cpp | 2 +- tests/modules/testmod4/GNUmakefile | 43 +++++++++++++++++++++++++++++++ tests/modules/testmod4/Makefile.W32 | 51 +++++++++++++++++++++++++++++++++++++ tests/modules/testmod4/TestMod4.cpp | 34 +++++++++++++++++++++++++ tests/modules/testmod4/TestMod4.hpp | 25 ++++++++++++++++++ 11 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 tests/modules/test4.MUST create mode 100755 tests/modules/test4.cpp create mode 100755 tests/modules/testmod4/GNUmakefile create mode 100755 tests/modules/testmod4/Makefile.W32 create mode 100755 tests/modules/testmod4/TestMod4.cpp create mode 100755 tests/modules/testmod4/TestMod4.hpp (limited to 'tests') diff --git a/tests/modules/GNUmakefile b/tests/modules/GNUmakefile index f61374d..2c4aac9 100755 --- a/tests/modules/GNUmakefile +++ b/tests/modules/GNUmakefile @@ -1,6 +1,6 @@ TOPDIR = ../.. -SUBDIRS = libcommon testmod testmod2 testmod3 +SUBDIRS = libcommon testmod testmod2 testmod3 testmod4 INCLUDE_DIRS = \ -I. -I$(TOPDIR)/src \ @@ -19,7 +19,8 @@ INCLUDE_LIBS = \ TEST_CPP_BINS = \ test1$(EXE) \ test2$(EXE) \ - test3$(EXE) + test3$(EXE) \ + test4$(EXE) OBJS = @@ -36,3 +37,4 @@ local_test: @./exec_test test1 "Module loader" @./exec_test test2 "Module loader with singleton" @./exec_test test3 "Load module in module" + @./exec_test test4 "Module initialization" diff --git a/tests/modules/Makefile.W32 b/tests/modules/Makefile.W32 index ea86b36..5705031 100755 --- a/tests/modules/Makefile.W32 +++ b/tests/modules/Makefile.W32 @@ -1,6 +1,6 @@ TOPDIR = ..\.. -SUBDIRS = testmod testmod2 testmod3 +SUBDIRS = testmod testmod2 testmod3 testmod4 !INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk @@ -25,7 +25,8 @@ INCLUDE_LIBS = \ TEST_CPP_BINS = \ test1.exe \ test2.exe \ - test3.exe + test3.exe \ + test4.exe OBJS = @@ -34,6 +35,7 @@ OBJS = test1.exe: test1.obj test2.exe: test2.obj test3.exe: test3.obj +test4.exe: test4.obj # must build test2.lib first becase it contains DDL exports for the # Common singleton @@ -48,3 +50,4 @@ local_test: @-exec_test test1 "Module loader" @-exec_test test2 "Module loader with singleton" @-exec_test test3 "Load module in module" + @-exec_test test4 "Module initialization" diff --git a/tests/modules/test4.MUST b/tests/modules/test4.MUST new file mode 100644 index 0000000..2a45d20 --- /dev/null +++ b/tests/modules/test4.MUST @@ -0,0 +1,5 @@ +Created common object +test4: Module 4 initModule called +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 new file mode 100755 index 0000000..8e1bfbe --- /dev/null +++ b/tests/modules/test4.cpp @@ -0,0 +1,36 @@ +#include "ModuleLoader.hpp" +#include "Base.hpp" +#include "Common.hpp" + +#include +#include +#include + +using namespace std; + +int main( void ) +{ + try { + Common &c = Common::instance( ); + c.setName( "test4" ); + + vector modules; +#ifndef _WIN32 + modules.push_back( "./testmod4/mod_test4.so" ); +#else + modules.push_back( ".\\testmod4\\mod_test4.dll" ); +#endif + ModuleLoader loader( modules ); + + Base *obj = loader.create( "testmod4" ); + c.print( "hello from main" ); + obj->hello( ); + loader.destroy( obj ); + + } catch( exception &e ) { + cerr << "Module loader error: " << e.what( ); + return 1; + } + + return 0; +} diff --git a/tests/modules/testmod/TestMod.cpp b/tests/modules/testmod/TestMod.cpp index 0728b87..e019e30 100755 --- a/tests/modules/testmod/TestMod.cpp +++ b/tests/modules/testmod/TestMod.cpp @@ -9,4 +9,4 @@ void Derived::hello( ) cout << "hello" << endl; } -REGISTER_MODULE( "testmod", Base, Derived ) +REGISTER_MODULE( "testmod", 0, 0, Base, Derived ) diff --git a/tests/modules/testmod2/TestMod2.cpp b/tests/modules/testmod2/TestMod2.cpp index 972ccb0..454bf8f 100755 --- a/tests/modules/testmod2/TestMod2.cpp +++ b/tests/modules/testmod2/TestMod2.cpp @@ -10,4 +10,4 @@ void Derived::hello( ) Common::instance( ).print( "hello from module" ); } -REGISTER_MODULE( "testmod2", Base, Derived ) +REGISTER_MODULE( "testmod2", 0, 0, Base, Derived ) diff --git a/tests/modules/testmod3/TestMod3.cpp b/tests/modules/testmod3/TestMod3.cpp index 4962442..c37fe72 100755 --- a/tests/modules/testmod3/TestMod3.cpp +++ b/tests/modules/testmod3/TestMod3.cpp @@ -32,4 +32,4 @@ void Derived::hello( ) Common::instance( ).print( "hello world from module" ); } -REGISTER_MODULE( "testmod3", Base, Derived ) +REGISTER_MODULE( "testmod3", 0, 0, Base, Derived ) diff --git a/tests/modules/testmod4/GNUmakefile b/tests/modules/testmod4/GNUmakefile new file mode 100755 index 0000000..b5bdf06 --- /dev/null +++ b/tests/modules/testmod4/GNUmakefile @@ -0,0 +1,43 @@ +TOPDIR = ../../.. + +SUBDIRS = + +-include $(TOPDIR)/makefiles/gmake/platform.mk + +INCLUDE_DIRS = \ + -I. -I$(TOPDIR)/src -I.. \ + -I$(TOPDIR)/include/module \ + -I$(TOPDIR)/include/util \ + -I$(TOPDIR)/tests/modules/libcommon + +INCLUDE_CXXFLAGS = \ + +INCLUDE_LDFLAGS = \ + -L$(TOPDIR)/src/libcrawler + +INCLUDE_LIBS = \ + -lcrawler + +DYNAMIC_MODULE = \ + mod_test4.so + +STATIC_LIB = \ + libtest4.a + +CPP_OBJS = \ + TestMod4.o + +-include $(TOPDIR)/makefiles/gmake/sub.mk + +local_all: + +local_clean: + +local_distclean: + +local_install: + +local_uninstall: + +local_test: + diff --git a/tests/modules/testmod4/Makefile.W32 b/tests/modules/testmod4/Makefile.W32 new file mode 100755 index 0000000..6bf7af1 --- /dev/null +++ b/tests/modules/testmod4/Makefile.W32 @@ -0,0 +1,51 @@ +TOPDIR = ..\..\.. + +SUBDIRS = + +!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk + +INCLUDE_CXXFLAGS = \ + /D_WIN32_WINNT=0x504 + +INCLUDE_DIRS = \ + /I. \ + /I$(TOPDIR)\src \ + /I$(TOPDIR)\include\module \ + /I$(TOPDIR)\include\util \ + /I$(TOPDIR)\include\crawler \ + /I.. \ + /I..\libcommon + +INCLUDE_LDFLAGS = \ + +INCLUDE_LIBS = \ + $(TOPDIR)\src\libutil\util.lib \ + ..\libcommon\common.lib + +DYNAMIC_MODULE = \ + mod_test4.dll + +STATIC_LIB = \ + test4.lib + +CPP_OBJS = \ + TestMod4.obj + +SHARED_CPP_OBJS = \ + TestMod4.dllobj + +!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk + +$(STATIC_LIB): $(CPP_OBJS) + $(LINK) /lib /nologo /out:$@ $(STATIC_LDFLAGS) $? + +$(DYNAMIC_MODULE): $(SHARED_CPP_OBJS) + $(LINK) /dll /nologo /out:$@ $(LDFLAGS) $(LIBS) $? + +local_all: $(STATIC_LIB) $(DYNAMIC_MODULE) + +local_clean: + +local_distclean: + +local_test: diff --git a/tests/modules/testmod4/TestMod4.cpp b/tests/modules/testmod4/TestMod4.cpp new file mode 100755 index 0000000..cd0578e --- /dev/null +++ b/tests/modules/testmod4/TestMod4.cpp @@ -0,0 +1,34 @@ +#include "TestMod4.hpp" +#include "Common.hpp" + +#include + +#include +#include + +using namespace std; + +Derived::Derived( ) +{ +} + +Derived::~Derived( ) +{ +} + +void Derived::hello( ) +{ + Common::instance( ).print( "hello world from module" ); +} + +static void initModule( ) +{ + Common::instance( ).print( "Module 4 initModule called" ); +} + +static void destroyModule( ) +{ + Common::instance( ).print( "Module 4 destroyModule called" ); +} + +REGISTER_MODULE( "testmod4", &initModule, &destroyModule, Base, Derived ) diff --git a/tests/modules/testmod4/TestMod4.hpp b/tests/modules/testmod4/TestMod4.hpp new file mode 100755 index 0000000..d4d4d99 --- /dev/null +++ b/tests/modules/testmod4/TestMod4.hpp @@ -0,0 +1,25 @@ +#ifndef __TESTMOD_H +#define __TESTMOD_H + +#include "Base.hpp" + +#include "ModuleRegistry.hpp" + +#include "ModuleLoader.hpp" + +class Derived : public Base +{ + public: + Derived( ); + + virtual ~Derived( ); + + virtual void hello( ); + + private: + ModuleLoader *m_loader; +}; + +DECLARE_MODULE( Base ) + +#endif -- cgit v1.2.3-54-g00ecf