[SCM] Development fot GoFind! branch, master, updated. 956fe808eafc1679f84d4c9d1f12db7423941798
Miriam Ruiz
miriam at debian.org
Sun Nov 23 22:23:39 UTC 2008
The following commit has been merged in the master branch:
commit 956fe808eafc1679f84d4c9d1f12db7423941798
Author: Miriam Ruiz <miriam at debian.org>
Date: Sun Nov 23 23:26:19 2008 +0100
Make a proper API/ABI for calling the plugins
diff --git a/dll.cpp b/dll.cpp
index 07ca683..4a8c134 100644
--- a/dll.cpp
+++ b/dll.cpp
@@ -50,6 +50,8 @@ bool DLLManager::GetSymbol(
// try extract a symbol from the library
// get any error message is there is any
+ dlerror(); // Clear previous error, just in case
+
if( h!=0 )
{
*v = dlsym( h, sym_name );
@@ -73,7 +75,7 @@ DLLFactoryBase::DLLFactoryBase(
// try get the factory function if there is no error yet
factory_func=0;
-
+
if( LastError()==0 )
{
GetSymbol( (void **)&factory_func, factory ? factory : "factory0" );
diff --git a/gofind.cpp b/gofind.cpp
index ecad3a1..4a1731f 100644
--- a/gofind.cpp
+++ b/gofind.cpp
@@ -90,18 +90,16 @@ int main(int argc, const char* argv[])
bindtextdomain ("gofind", NULL);
#endif
- DLLFactory<GUIPlugInFactory> gui_factory( "./gui_cli.so" );
-// DLLFactory<GUIPlugInFactory> gui_factory( "./gui_fltk.so" );
+ GUIPlugIn gui_plugin( "./gui_fltk.so" );
- if( ! gui_factory.factory )
+ if( gui_plugin.LastError())
{
- std::cout << _("Could not load GUI plugin") << std::endl;
+ std::cout << _("Could not load GUI plugin.") << std::endl;
return -1;
}
- GUIPlugIn *gui=gui_factory.factory->CreatePlugIn();
-
- gui->Comment(_("Starting system"));
+ gui_plugin.Init(argc, argv);
+ gui_plugin.Comment(_("Starting system"));
wibble::commandline::GamesOptions opts;
@@ -207,9 +205,8 @@ int main(int argc, const char* argv[])
printResults(pkgdata);
*/
- gui->Go(pkgdata);
+ gui_plugin.Go(pkgdata);
- delete gui;
return 0;
} catch (wibble::exception::BadOption& e) {
cerr << e.desc() << endl;
diff --git a/gui_cli.cpp b/gui_cli.cpp
index 5615eb5..ef2116e 100644
--- a/gui_cli.cpp
+++ b/gui_cli.cpp
@@ -1,9 +1,6 @@
/*
- * 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
@@ -20,16 +17,17 @@
*/
#include "common.h"
-#include "guiplugin.h"
#include "filter.h"
#include "slre.h"
+#include "pkgdata.h"
#include <typeinfo>
#include <iostream>
#include <string>
#include <ept/apt/packagerecord.h>
+#include <ept/textsearch/textsearch.h>
#include <wibble/regexp.h>
#include <wibble/string.h>
#include <xapian.h>
@@ -45,46 +43,12 @@
#define gettext(a) (a)
#endif
-#include <string.h>
-#include <stdarg.h>
-
using namespace std;
using namespace ept;
using namespace ept::debtags;
using namespace ept::apt;
using namespace ept::textsearch;
-class GUIPlugInCLI : public GUIPlugIn
-{
- public:
- GUIPlugInCLI(GUIPlugInFactory *f) : GUIPlugIn(f)
- {
- std::cout << "GUIPlugInCLI() Created" << std::endl;
- }
-
- virtual ~GUIPlugInCLI()
- {
- std::cout << "GUIPlugInCLI() destroyed" << std::endl;
- }
-
- virtual void Comment(const char *szFormat, ...);
- virtual bool Go(PackageData &pkgdata);
-};
-
-void GUIPlugInCLI::Comment(const char *szFormat, ...)
-{
- char str[4096];
- va_list arglist;
-
- *str = '\0';
-
- va_start(arglist, szFormat);
- vsprintf(str + strlen(str), szFormat, arglist);
- va_end(arglist);
-
- std::cout << "# " << str << std::endl;
-}
-
/*
static bool slre_test_capture(const struct slre_capture &c, const char *txt)
{
@@ -112,7 +76,7 @@ static bool slre_test_capture(const struct slre_capture &c, int num, ... )
return false;
}
-bool GUIPlugInCLI::Go(PackageData &pkgdata)
+static bool Go(PackageData &pkgdata)
{
std::ostream &out = std::cout;
@@ -350,46 +314,21 @@ bool GUIPlugInCLI::Go(PackageData &pkgdata)
return true;
}
-class GUIPlugInCLIFactory : public GUIPlugInFactory
-{
- public:
- GUIPlugInCLIFactory()
- {
-#ifdef GUIPLUGIN_VERSION
- if (version != GUIPlugInFactory::version)
- fprintf(stderr, "Wrong GUI Plugin Version: Program = 0x%04X, Plugin = 0x%04X\n", GUIPlugInFactory::version, version );
-#endif
- }
-
- ~GUIPlugInCLIFactory()
- {
- }
-
- virtual GUIPlugIn * CreatePlugIn()
- {
-#ifdef GUIPLUGIN_VERSION
- if (version != GUIPlugInFactory::version)
- return NULL;
-#endif
- return new GUIPlugInCLI(this);
- }
- protected:
-#ifdef GUIPLUGIN_VERSION
- const static unsigned int version;
-#endif
-};
+// Exported Stuff
-#ifdef GUIPLUGIN_VERSION
- const unsigned int GUIPlugInCLIFactory::version = GUIPLUGIN_VERSION;
-#endif
+extern "C" int init(int argc, const char *argv[])
+{
+ std::cout << _("CLI Plugin successfully loaded") << std::endl;
+ return 1; // true
+}
-//
-// The "C" linkage factory0() function creates the PlugIn Factory
-// class for this library
-//
+extern "C" void comment(const char *text)
+{
+ std::cout << "# " << text << std::endl;
+}
-extern "C" void * factory0( void )
+extern "C" int go(PackageData &pkgdata)
{
- return new GUIPlugInCLIFactory;
+ return Go(pkgdata);
}
diff --git a/gui_fltk.cpp b/gui_fltk.cpp
index fa57b56..19fd78b 100644
--- a/gui_fltk.cpp
+++ b/gui_fltk.cpp
@@ -20,7 +20,7 @@
*/
#include "common.h"
-#include "guiplugin.h"
+#include "pkgdata.h"
#include "fltk/ui.h"
#include <FL/Fl.H>
@@ -35,43 +35,10 @@
#define gettext(a) (a)
#endif
-#include <stdarg.h>
-#include <string.h>
#include <math.h>
#include <ept/apt/packagerecord.h>
-
-class GUIPlugInFLTK : public GUIPlugIn
-{
- public:
- GUIPlugInFLTK(GUIPlugInFactory *f) : GUIPlugIn(f)
- {
- std::cout << "GUIPlugInFLTK() Created" << std::endl;
- }
-
- virtual ~GUIPlugInFLTK()
- {
- std::cout << "GUIPlugInFLTK() destroyed" << std::endl;
- }
-
- virtual void Comment(const char *szFormat, ...);
- virtual bool Go(PackageData &pkgdata);
-};
-
-void GUIPlugInFLTK::Comment(const char *szFormat, ...)
-{
- char str[4096];
- va_list arglist;
-
- *str = '\0';
-
- va_start(arglist, szFormat);
- vsprintf(str + strlen(str), szFormat, arglist);
- va_end(arglist);
-
- std::cout << "# " << str << std::endl;
-}
-
+#include <ept/textsearch/textsearch.h>
static const char* ReadFlChoice(Fl_Choice& c)
{
@@ -258,7 +225,7 @@ static void CallBackInstalledOrNot(Fl_Round_Button*, void *data)
UpdateUILists(ui);
}
-bool GUIPlugInFLTK::Go(PackageData &pkgdata)
+static bool Go(PackageData &pkgdata)
{
#ifdef USE_GETTEXT
setlocale (LC_MESSAGES, "");
@@ -302,46 +269,21 @@ bool GUIPlugInFLTK::Go(PackageData &pkgdata)
return 0;
}
-class GUIPlugInFLTKFactory : public GUIPlugInFactory
-{
- public:
- GUIPlugInFLTKFactory()
- {
-#ifdef GUIPLUGIN_VERSION
- if (version != GUIPlugInFactory::version)
- fprintf(stderr, "Wrong GUI Plugin Version: Program = 0x%04X, Plugin = 0x%04X\n", GUIPlugInFactory::version, version );
-#endif
- }
-
- ~GUIPlugInFLTKFactory()
- {
- }
-
- virtual GUIPlugIn * CreatePlugIn()
- {
-#ifdef GUIPLUGIN_VERSION
- if (version != GUIPlugInFactory::version)
- return NULL;
-#endif
- return new GUIPlugInFLTK(this);
- }
- protected:
-#ifdef GUIPLUGIN_VERSION
- const static unsigned int version;
-#endif
-};
+// Exported Stuff
-#ifdef GUIPLUGIN_VERSION
- const unsigned int GUIPlugInFLTKFactory::version = GUIPLUGIN_VERSION;
-#endif
+extern "C" int init(int argc, const char *argv[])
+{
+ std::cout << _("FLTK Plugin successfully loaded") << std::endl;
+ return 1; // true
+}
-//
-// The "C" linkage factory0() function creates the PlugIn Factory
-// class for this library
-//
+extern "C" void comment(const char *text)
+{
+ std::cout << text << std::endl;
+}
-extern "C" void * factory0( void )
+extern "C" int go(PackageData &pkgdata)
{
- return new GUIPlugInFLTKFactory;
+ return Go(pkgdata);
}
diff --git a/guiplugin.cpp b/guiplugin.cpp
index 1786050..f9424f8 100644
--- a/guiplugin.cpp
+++ b/guiplugin.cpp
@@ -25,22 +25,49 @@
#include <typeinfo>
#include <iostream>
-#ifdef GUIPLUGIN_VERSION
- const unsigned int GUIPlugInFactory::version = GUIPLUGIN_VERSION;
-#endif
+#include <stdarg.h>
+#include <string.h>
-//
-// Announce to the world that the PlugIn base
-// class has been created or destroyed
-//
-
-GUIPlugIn::GUIPlugIn(GUIPlugInFactory *f) : factory(f)
+GUIPlugIn::GUIPlugIn(const char *filename) :
+ DLLManager(filename),
+ init(NULL),
+ comment(NULL),
+ go(NULL)
{
- std::cout << "GUIPlugIn Created" << std::endl;
+ if( LastError() )
+ std::cout << _("Error loading GUI plugin: ") << LastError() << std::endl;
+
+ GetSymbol((void **)&init, "init" );
+ if( LastError() )
+ std::cout << _("Error loading GUI plugin: ") << LastError() << std::endl;
+
+ GetSymbol((void **)&comment, "comment" );
+ if( LastError() )
+ std::cout << _("Error loading GUI plugin: ") << LastError() << std::endl;
+
+ GetSymbol((void **)&go, "go" );
+ if( LastError() )
+ std::cout << _("Error loading GUI plugin: ") << LastError() << std::endl;
}
GUIPlugIn::~GUIPlugIn()
{
- std::cout << "GUIPlugIn Destroyed" << std::endl;
}
+void GUIPlugIn::Comment(const char *szFormat, ...)
+{
+ if (comment)
+ {
+ char str[4096];
+ va_list arglist;
+
+ *str = '\0';
+
+ va_start(arglist, szFormat);
+ vsprintf(str + strlen(str), szFormat, arglist);
+ va_end(arglist);
+
+ comment(str);
+ }
+ else std::cout << _("No comment function found in plugin.") << std::endl;
+}
diff --git a/guiplugin.h b/guiplugin.h
index 1052350..93d8c47 100644
--- a/guiplugin.h
+++ b/guiplugin.h
@@ -27,45 +27,34 @@
#include <iostream>
-#define GUIPLUGIN_VERSION 0x0001
-
using namespace ept;
-class GUIPlugInFactory;
-
-class GUIPlugIn
+class GUIPlugIn : public DLLManager
{
public:
- GUIPlugIn(GUIPlugInFactory *f);
-
+ GUIPlugIn(const char *filename);
virtual ~GUIPlugIn();
- virtual void Comment(const char *szFormat, ...) = 0;
- virtual bool Go(PackageData &data) = 0;
-
- protected:
- GUIPlugInFactory *factory;
-};
+ void Comment(const char *szFormat, ...);
-class GUIPlugInFactory
-{
- public:
- GUIPlugInFactory()
+ inline int Init(int argc, const char *argv[])
{
- std::cout << "GUIPlugInFactory Created" << std::endl;
+ if (init) return init(argc, argv);
+ std::cout << _("No init function found in plugin.") << std::endl;
+ return -1; // error
}
-
- virtual ~GUIPlugInFactory()
+
+ inline int Go(PackageData &pkgdata)
{
- std::cout << "GUIPlugInFactory Destroy" << std::endl;
+ if (go) go(pkgdata);
+ std::cout << _("No go function found in plugin.") << std::endl;
+ return -1; // error
}
-
- virtual GUIPlugIn * CreatePlugIn() = 0;
protected:
-#ifdef GUIPLUGIN_VERSION
- const static unsigned int version;
-#endif
+ int (*init) (int argc, const char *argv[]);
+ void (*comment) (const char *text);
+ int (*go) (PackageData &pkgdata);
};
#endif // _GOFIND_GUIPLUGIN_H
--
Development fot GoFind!
More information about the Pkg-games-commits
mailing list