r8426 - software/gofind

Miriam Ruiz miriam at alioth.debian.org
Mon Nov 17 22:03:17 UTC 2008


Author: miriam
Date: 2008-11-17 22:03:17 +0000 (Mon, 17 Nov 2008)
New Revision: 8426

Added:
   software/gofind/dll.cpp
   software/gofind/dll.h
   software/gofind/guiplugin.cpp
   software/gofind/guiplugin.h
Modified:
   software/gofind/Engine.h
   software/gofind/Environment.h
   software/gofind/GamesOptions.h
   software/gofind/Makefile
   software/gofind/boolparser.cpp
   software/gofind/boolparser.h
   software/gofind/cfgmanager.h
   software/gofind/common.h
   software/gofind/filter.h
   software/gofind/utf8.h
Log:
Add initial support for gui plugins



Modified: software/gofind/Engine.h
===================================================================
--- software/gofind/Engine.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/Engine.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -1,5 +1,5 @@
-#ifndef GAMEUI_ENGINE_H
-#define GAMEUI_ENGINE_H
+#ifndef _GOFIND_ENGINE_H
+#define _GOFIND_ENGINE_H
 
 /*
  * Backend engine for game installer UI
@@ -166,4 +166,5 @@
 };
 
 // vim:set ts=4 sw=4:
-#endif
+
+#endif // _GOFIND_ENGINE_H

Modified: software/gofind/Environment.h
===================================================================
--- software/gofind/Environment.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/Environment.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -1,5 +1,5 @@
-#ifndef DEBTAGS_ENVIRONMENT_H
-#define DEBTAGS_ENVIRONMENT_H
+#ifndef _GOFIND_ENVIRONMENT_H
+#define _GOFIND_ENVIRONMENT_H
 
 /*
  * Common environment for many program parts
@@ -72,4 +72,5 @@
 static inline Environment& env() { return Environment::get(); }
 
 // vim:set ts=4 sw=4:
-#endif
+
+#endif // _GOFIND_ENVIRONMENT_H

Modified: software/gofind/GamesOptions.h
===================================================================
--- software/gofind/GamesOptions.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/GamesOptions.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -1,5 +1,5 @@
-#ifndef GAMES_OPTIONS_H
-#define GAMES_OPTIONS_H
+#ifndef _GOFIND_GAMESOPTIONS_H
+#define _GOFIND_GAMESOPTIONS_H
 
 /*
  * Commandline parser for the game viewer
@@ -66,4 +66,5 @@
 }
 
 // vim:set ts=4 sw=4:
-#endif
+
+#endif // _GOFIND_GAMESOPTIONS_H

Modified: software/gofind/Makefile
===================================================================
--- software/gofind/Makefile	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/Makefile	2008-11-17 22:03:17 UTC (rev 8426)
@@ -1,13 +1,38 @@
-all: gofind
+#!/usr/bin/make -f
 
-CFLAGS= -O2 -g `pkg-config libtagcoll2 boolstuff-0.1 --cflags` -Wall -Werror
+# Copyright (C) 2007-2008  Miriam Ruiz <little_miry at yahoo.es>
+#
+# http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+CFLAGS= -O2 -g `pkg-config libtagcoll2 boolstuff-0.1 --cflags` -Wall -Werror -fPIC
 LDFLAGS= 
-LIBS= -lept -lept-core -lapt-pkg -lxapian `pkg-config libtagcoll2 boolstuff-0.1 --libs`
+LIBS= -lept -lept-core -lapt-pkg -lxapian -ldl `pkg-config libtagcoll2 boolstuff-0.1 --libs`
 
-OBJS= Engine.o Environment.o filter.o gofind.o taghandler.o cfgmanager.o boolparser.o slre.o utf8.o
+OBJS= Engine.o Environment.o filter.o gofind.o taghandler.o cfgmanager.o boolparser.o slre.o utf8.o dll.o guiplugin.o
+PLUGINS=gui_cli.so
 
+all: gofind $(PLUGINS)
+
+# the main executable has to be linked with the -rdynamic flag
+# so the plug in libraries can call inherited methods and
+# access vtables in the main executable.
+
 gofind: $(OBJS)
-	g++ -o $@ $+ $(LDFLAGS) $(LIBS)
+	g++ -o $@ $+ -rdynamic $(LDFLAGS) $(LIBS)
 
 %.o: %.cpp
 	g++ -o $@ -c $+ $(CFLAGS)
@@ -15,10 +40,13 @@
 %.o: %.c
 	gcc -o $@ -c $+ $(CFLAGS)
 
+%.so : %.o
+	g++ $(CFLAGS) -shared $^ -o $@
+
 TEST_OBJS=  filter.test.o taghandler.test.o cfgmanager.test.o boolparser.test.o slre.test.o utf8.test.o CuTest.o test.o
 
 test: $(TEST_OBJS)
-	g++ -o $@ $+ $(LDFLAGS) $(LIBS)
+	g++ -o $@ $+ -rdynamic $(LDFLAGS) $(LIBS)
 
 test.c:
 	sh CuTest.sh > $@
@@ -33,4 +61,4 @@
 	gcc -o $@ -DUNIT_TEST -c $+ $(CFLAGS)
 
 clean:
-	rm -f gofind test test.c *.o
+	rm -f gofind test test.c *.o *.so

Modified: software/gofind/boolparser.cpp
===================================================================
--- software/gofind/boolparser.cpp	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/boolparser.cpp	2008-11-17 22:03:17 UTC (rev 8426)
@@ -29,6 +29,7 @@
 
 #include <cassert>
 #include <memory>
+#include <cstring>
 
 #include <string.h>
 

Modified: software/gofind/boolparser.h
===================================================================
--- software/gofind/boolparser.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/boolparser.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -20,8 +20,8 @@
     02111-1307, USA.
 */
 
-#ifndef _games_boolparser_h
-#define _games_boolparser_h
+#ifndef _GOFIND_BOOLPARSER_H
+#define _GOFIND_BOOLPARSER_H
 
 #include <boolstuff/BoolExpr.h>
 
@@ -105,4 +105,4 @@
     BoolParser &operator = (const BoolParser &);
 };
 
-#endif  /* _games_boolparser_h */
+#endif  // _GOFIND_BOOLPARSER_H

Modified: software/gofind/cfgmanager.h
===================================================================
--- software/gofind/cfgmanager.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/cfgmanager.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -16,8 +16,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _games_configmanager_h
-#define _games_configmanager_h
+#ifndef _GOFIND_CONFIGMANAGER_H
+#define _GOFIND_CONFIGMANAGER_H
 
 class ConfigManager
 {
@@ -35,4 +35,4 @@
 private:
 };
 
-#endif
+#endif // _GOFIND_CONFIGMANAGER_H

Modified: software/gofind/common.h
===================================================================
--- software/gofind/common.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/common.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -17,8 +17,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _games_common_h
-#define _games_common_h
+#ifndef _GOFIND_COMMON_H
+#define _GOFIND_COMMON_H
 
 #ifdef __cplusplus
 extern "C" {
@@ -88,4 +88,4 @@
 }
 #endif
 
-#endif
+#endif // _GOFIND_COMMON_H

Added: software/gofind/dll.cpp
===================================================================
--- software/gofind/dll.cpp	                        (rev 0)
+++ software/gofind/dll.cpp	2008-11-17 22:03:17 UTC (rev 8426)
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 1995  Jeff Koftinoff <jeffk at jdkoftinoff.com>
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "dll.h"
+
+#include <typeinfo>
+#include <iostream>
+#include <string>
+#include <dlfcn.h>
+
+DLLManager::DLLManager( const char *fname )
+{
+    // Try to open the library now and get any error message.
+	
+	h=dlopen( fname, RTLD_NOW );
+	err=dlerror();
+}
+
+DLLManager::~DLLManager()
+{
+	// close the library if it isn't null
+	if( h!=0 )
+    	dlclose(h);
+}
+
+bool DLLManager::GetSymbol( 
+			   void **v,
+			   const char *sym_name
+			   )
+{
+	// try extract a symbol from the library
+	// get any error message is there is any
+	
+	if( h!=0 )
+	{
+		*v = dlsym( h, sym_name );
+    	err=dlerror();
+	    if( err==0 )
+       	  return true;
+    	else
+    	  return false;
+	}
+	else
+	{	
+        return false;
+	}
+	
+}
+
+DLLFactoryBase::DLLFactoryBase(
+			       const char *fname,
+			       const char *factory
+			       ) : DLLManager(fname)
+{
+	// try get the factory function if there is no error yet
+	
+	factory_func=0;
+	
+	if( LastError()==0 )
+	{		
+    	GetSymbol( (void **)&factory_func, factory ? factory : "factory0" );
+	}
+	
+}
+
+DLLFactoryBase::~DLLFactoryBase()
+{
+}
+
+
+

Added: software/gofind/dll.h
===================================================================
--- software/gofind/dll.h	                        (rev 0)
+++ software/gofind/dll.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 1995  Jeff Koftinoff <jeffk at jdkoftinoff.com>
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _GOFIND_DLLMANAGER_H
+#define _GOFIND_DLLMANAGER_H
+
+//
+// class DLLManager is the simple ELF C++ Library manager.
+//
+// It tries to dynamically load the specified shared library
+// when it is construted.
+//
+// You should call LastError() before doing anything.  If it 
+// returns NULL there is no error.
+//
+
+
+class DLLManager
+{
+ public:
+	DLLManager( const char *fname );
+	virtual ~DLLManager();
+
+
+	bool GetSymbol( void **, const char *sym_name );
+
+	const char *LastError() 
+	{
+		 return err;
+	}
+	
+ protected:
+	void *h;
+	const char *err;
+};
+
+
+//
+// class DLLFactoryBase is the base class used for the DLLFactory
+// template class.  
+// 
+// It inherits from the DLLManager class and must be constructed with
+// the file name of the shared library and the function name within that
+// library which will create the desired C++ factory class.
+// If you do not provide func_name to the constructor, it defaults to
+// the undecorated "C" symbol "factory0"
+//
+// factory_func will be set to a pointer to the requested factory creator 
+// function.  If there was an error linking to the shared library,
+// factory_func will be 0.
+//
+// You can call 'LastError()' to find the error message that occurred.
+//
+//
+
+class DLLFactoryBase : public DLLManager
+{
+ public:
+	DLLFactoryBase(
+		       const char *fname,
+		       const char *func_name=0
+		       );
+		
+	virtual ~DLLFactoryBase();
+	
+	void * (*factory_func)(void);	
+};
+
+
+//
+// The DLLFactory template class inherits from DLLFactoryBase.
+// The constructor takes the file name of the shared library
+// and the undecorated "C" symbol name of the factory creator
+// function.  The factory creator function in your shared library
+// MUST either return a pointer to an object that is a subclass
+// of 'T' or it must return 0.
+//
+// If everything is cool, then 'factory' will point to the
+// requested factory class.  If not, it will be 0.
+//
+// Since the DLLFactory template ultimately inherits DLLManager,
+// you can call LastError() to get any error code information
+//
+// The created factory is OWNED by the DLLFactory class.  
+// The created factory will get deleted when the DLLFactory class
+// is deleted, because the DLL will get unloaded as well.
+//
+
+template <class T>
+class DLLFactory : public DLLFactoryBase
+{
+ public:
+	DLLFactory(
+		   const char *fname,
+		   const char *func_name=0
+		   ) : DLLFactoryBase( fname, func_name )
+	{
+		if( factory_func )
+		  factory = (T *)factory_func();
+		else 
+		  factory = 0;
+	}
+	
+	~DLLFactory()
+	{
+		delete factory;
+	}
+
+	T *factory;
+};
+
+#endif // _GOFIND_DLLMANAGER_H

Modified: software/gofind/filter.h
===================================================================
--- software/gofind/filter.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/filter.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -16,8 +16,8 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#ifndef _games_filter_h
-#define _games_filter_h
+#ifndef _GOFIND_FILTER_H
+#define _GOFIND_FILTER_H
 
 #include "taghandler.h"
 
@@ -120,4 +120,4 @@
 
 extern PackageFilter pkgfilter;
 
-#endif
+#endif // _GOFIND_FILTER_H

Added: software/gofind/guiplugin.cpp
===================================================================
--- software/gofind/guiplugin.cpp	                        (rev 0)
+++ software/gofind/guiplugin.cpp	2008-11-17 22:03:17 UTC (rev 8426)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 1995  Jeff Koftinoff <jeffk at jdkoftinoff.com>
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <typeinfo>
+#include <iostream>
+
+#include "guiplugin.h"
+
+//
+// Announce to the world that the PlugIn base
+// class has been created or destroyed
+//
+
+GUIPlugIn::GUIPlugIn() 
+{
+	std::cout << "GUIPlugIn Created" << std::endl;
+}
+
+GUIPlugIn::~GUIPlugIn()
+{
+	std::cout << "GUIPlugIn Destroyed" << std::endl;
+}
+

Added: software/gofind/guiplugin.h
===================================================================
--- software/gofind/guiplugin.h	                        (rev 0)
+++ software/gofind/guiplugin.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 1995  Jeff Koftinoff <jeffk at jdkoftinoff.com>
+ * Copyright (C) 2008  Miriam Ruiz <little_miry at yahoo.es>
+ *
+ * http://www.jdkoftinoff.com/main/Articles/Linux_Articles/ELF_Plugins/ 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __PLUGIN_H
+#define __PLUGIN_H
+
+#include "dll.h"
+
+#include <iostream>
+
+//
+// PlugIn is an abstract class.
+//
+// This is an example plug in.  This plug in only has one method, Show(),
+// which we will use to show its name.
+//
+//
+
+class GUIPlugIn
+{
+ public:
+	GUIPlugIn();
+
+	virtual ~GUIPlugIn();
+
+	virtual void Show() = 0;	
+};
+
+
+//
+// The is an example factory for plug ins. 
+//
+// This example factory only announces when it is created/destroyed and
+// has the single abstract method CreatePlugIn() which returns a type 
+// of plug in.
+//
+// In the real world, you may have multiple different classes in each
+// shared library that are made to work together.  All these classes
+// must be created by the Factory class.
+//
+// You may find it useful to have the objects that you create with
+// the factory class be given a pointer to the factory class so
+// they can create their own objects that they need, using the same
+// factory class.  Compiler support of covariant return types is 
+// real useful here.
+//
+
+
+class GUIPlugInFactory
+{
+ public:
+	GUIPlugInFactory() 
+	{
+		std::cout << "GUIPlugInFactory Created" << std::endl;
+	}
+	
+	virtual ~GUIPlugInFactory()
+	{
+		std::cout << "GUIPlugInFactory Destroy" << std::endl;
+	}
+	
+	virtual GUIPlugIn * CreatePlugIn() = 0;
+};
+
+#endif

Modified: software/gofind/utf8.h
===================================================================
--- software/gofind/utf8.h	2008-11-17 21:34:12 UTC (rev 8425)
+++ software/gofind/utf8.h	2008-11-17 22:03:17 UTC (rev 8426)
@@ -15,8 +15,8 @@
  * the above three licenses.
  */
 
-#ifndef GOPLAY_UTF8_H_
-#define GOPLAY_UTF8_H_
+#ifndef _GOPLAY_UTF8_H
+#define _GOPLAY_UTF8_H
 
 #ifdef __cplusplus
 extern "C" {
@@ -47,4 +47,4 @@
 }
 #endif
 
-#endif /* GOPLAY_UTF8_H_ */
+#endif // _GOPLAY_UTF8_H




More information about the Pkg-games-commits mailing list