summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xTODOS5
-rwxr-xr-xtests/modules/Common.hpp23
-rwxr-xr-xtests/modules/GNUmakefile6
-rwxr-xr-xtests/modules/Makefile.W327
-rwxr-xr-xtests/modules/test2.MUST6
-rwxr-xr-xtests/modules/test2.cpp36
-rwxr-xr-xtests/modules/testmod2/GNUmakefile39
-rwxr-xr-xtests/modules/testmod2/Makefile.W3246
-rwxr-xr-xtests/modules/testmod2/TestMod2.cpp13
-rwxr-xr-xtests/modules/testmod2/TestMod2.hpp20
10 files changed, 197 insertions, 4 deletions
diff --git a/TODOS b/TODOS
index 0645fd3..f672b09 100755
--- a/TODOS
+++ b/TODOS
@@ -6,3 +6,8 @@
- spooling in RIS:
- thread-safe tempnames
- Windows, respect environment variables like TEMP
+- module loader
+ - use weak pointers to create objects (pointers which don't transfer
+ ownership but act more as a handle). Avoid funny trouble with
+ objects originating for modules (especially DLLs on Windows)
+
diff --git a/tests/modules/Common.hpp b/tests/modules/Common.hpp
new file mode 100755
index 0000000..dc1f22a
--- /dev/null
+++ b/tests/modules/Common.hpp
@@ -0,0 +1,23 @@
+#ifndef __COMMON_H
+#define __COMMON_H
+
+#include "Singleton.hpp"
+
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+class Common : public Singleton< Common >
+{
+ private:
+ string m_name;
+
+ public:
+ Common( ) : m_name( "noname" ) { cout << "Created common object" << endl; }
+ virtual ~Common( ) { cout << "Destroyed common object" << endl; }
+ void setName( string name ) { m_name = name; }
+ void print( string s ) { cout << m_name << ": " << s << endl; }
+};
+
+#endif
diff --git a/tests/modules/GNUmakefile b/tests/modules/GNUmakefile
index 76e131f..70a2a37 100755
--- a/tests/modules/GNUmakefile
+++ b/tests/modules/GNUmakefile
@@ -1,6 +1,6 @@
TOPDIR = ../..
-SUBDIRS = testmod
+SUBDIRS = testmod testmod2
INCLUDE_DIRS = \
-I. -I$(TOPDIR)/src
@@ -10,7 +10,8 @@ INCLUDE_LDFLAGS =
INCLUDE_LIBS =
TEST_CPP_BINS = \
- test1$(EXE)
+ test1$(EXE) \
+ test2$(EXE)
OBJS =
@@ -25,3 +26,4 @@ local_distclean:
local_test:
@./exec_test test1 "Module loader"
+ @./exec_test test2 "Module loader with singleton"
diff --git a/tests/modules/Makefile.W32 b/tests/modules/Makefile.W32
index 3830e31..8a745a0 100755
--- a/tests/modules/Makefile.W32
+++ b/tests/modules/Makefile.W32
@@ -1,6 +1,6 @@
TOPDIR = ..\..
-SUBDIRS = testmod
+SUBDIRS = testmod testmod2
!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk
@@ -17,13 +17,15 @@ INCLUDE_LIBS = \
$(TOPDIR)\src\crawler.lib
TEST_CPP_BINS = \
- test1.exe
+ test1.exe \
+ test2.exe
OBJS =
!INCLUDE $(TOPDIR)\makefiles\nmake\sub.mk
test1.exe: test1.obj
+test2.exe: test2.obj
local_all:
@@ -34,3 +36,4 @@ local_distclean:
local_test:
@-exec_test test1 "Module loader"
+ @-exec_test test2 "Module loader with singleton"
diff --git a/tests/modules/test2.MUST b/tests/modules/test2.MUST
new file mode 100755
index 0000000..08fb28b
--- /dev/null
+++ b/tests/modules/test2.MUST
@@ -0,0 +1,6 @@
+Created common object
+test2: hello from main
+Created common object
+test2: hello from module
+Destroyed common object
+Destroyed common object
diff --git a/tests/modules/test2.cpp b/tests/modules/test2.cpp
new file mode 100755
index 0000000..b07f0e3
--- /dev/null
+++ b/tests/modules/test2.cpp
@@ -0,0 +1,36 @@
+#include "ModuleLoader.hpp"
+#include "Base.hpp"
+#include "Common.hpp"
+
+#include <vector>
+#include <string>
+#include <iostream>
+
+using namespace std;
+
+int main( void )
+{
+ try {
+ Common &c = Common::instance( );
+ c.setName( "test2" );
+
+ vector<string> modules;
+#ifndef _WIN32
+ modules.push_back( "./testmod2/mod_test2.so" );
+#else
+ modules.push_back( ".\\testmod2\\mod_test2.dll" );
+#endif
+ ModuleLoader<Base> loader( modules );
+
+ Base *obj = loader.create( "testmod2" );
+ 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/testmod2/GNUmakefile b/tests/modules/testmod2/GNUmakefile
new file mode 100755
index 0000000..3011479
--- /dev/null
+++ b/tests/modules/testmod2/GNUmakefile
@@ -0,0 +1,39 @@
+TOPDIR = ../../..
+
+SUBDIRS =
+
+-include $(TOPDIR)/makefiles/gmake/platform.mk
+
+INCLUDE_DIRS = \
+ -I. -I$(TOPDIR)/src -I..
+
+INCLUDE_CXXFLAGS = \
+
+INCLUDE_LDFLAGS = \
+
+INCLUDE_LIBS = \
+ $(TOPDIR)/src/libcrawler.a
+
+DYNAMIC_MODULE = \
+ mod_test2.so
+
+STATIC_LIB = \
+ libtest2.a
+
+CPP_OBJS = \
+ TestMod2.o
+
+-include $(TOPDIR)/makefiles/gmake/sub.mk
+
+local_all:
+
+local_clean:
+
+local_distclean:
+
+local_install:
+
+local_uninstall:
+
+local_test:
+
diff --git a/tests/modules/testmod2/Makefile.W32 b/tests/modules/testmod2/Makefile.W32
new file mode 100755
index 0000000..9640019
--- /dev/null
+++ b/tests/modules/testmod2/Makefile.W32
@@ -0,0 +1,46 @@
+TOPDIR = ..\..\..
+
+SUBDIRS =
+
+!INCLUDE $(TOPDIR)\makefiles\nmake\platform.mk
+
+INCLUDE_CXXFLAGS = \
+ /D_WIN32_WINNT=0x504
+
+INCLUDE_DIRS = \
+ /I. \
+ /I$(TOPDIR)\src \
+ /I..
+
+INCLUDE_LDFLAGS = \
+
+INCLUDE_LIBS = \
+ $(TOPDIR)\src\crawler.lib
+
+DYNAMIC_MODULE = \
+ mod_test2.dll
+
+STATIC_LIB = \
+ test2.lib
+
+CPP_OBJS = \
+ TestMod2.obj
+
+SHARED_CPP_OBJS = \
+ TestMod2.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/testmod2/TestMod2.cpp b/tests/modules/testmod2/TestMod2.cpp
new file mode 100755
index 0000000..972ccb0
--- /dev/null
+++ b/tests/modules/testmod2/TestMod2.cpp
@@ -0,0 +1,13 @@
+#include "TestMod2.hpp"
+#include "Common.hpp"
+
+#include <iostream>
+
+using namespace std;
+
+void Derived::hello( )
+{
+ Common::instance( ).print( "hello from module" );
+}
+
+REGISTER_MODULE( "testmod2", Base, Derived )
diff --git a/tests/modules/testmod2/TestMod2.hpp b/tests/modules/testmod2/TestMod2.hpp
new file mode 100755
index 0000000..f4886cd
--- /dev/null
+++ b/tests/modules/testmod2/TestMod2.hpp
@@ -0,0 +1,20 @@
+#ifndef __TESTMOD_H
+#define __TESTMOD_H
+
+#include "Base.hpp"
+
+#include "ModuleRegistry.hpp"
+
+class Derived : public Base
+{
+ public:
+ Derived( ) { }
+
+ virtual ~Derived( ) { }
+
+ virtual void hello( );
+};
+
+DECLARE_MODULE( Base )
+
+#endif