diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2010-01-24 00:16:33 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2010-01-24 00:16:33 +0000 |
| commit | 416f5b0dcd3e2cf4993acf4dff02a7477be835e2 (patch) | |
| tree | ab80d37da1737717d65637f739aa818e7346e19f /FL | |
| parent | 51acfa41eb2e0a823fc22ca76514a56ea0e152ae (diff) | |
Still not having added Fl_Tree and Fl_Table to Fluid, I remembered the plugin concept we had early on. It occured to me that writing plugins must not be difficult, and that FLTK already has everything needed. So here it is, a plugin implementation for FLTK. The MSWindows/Cygwin implementation is untested due to lack of a machine. The dynamic loading still needs a test implementation. Comments welcome.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7023 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
| -rw-r--r-- | FL/Fl_Plugin.H | 105 | ||||
| -rw-r--r-- | FL/Fl_Preferences.H | 16 |
2 files changed, 116 insertions, 5 deletions
diff --git a/FL/Fl_Plugin.H b/FL/Fl_Plugin.H new file mode 100644 index 000000000..dcfc3bcdb --- /dev/null +++ b/FL/Fl_Plugin.H @@ -0,0 +1,105 @@ +// +// "$Id: Fl_Plugin.H 6995 2010-01-12 08:48:55Z matt $" +// +// A Plugin system for FLTK, implemented in Fl_Preferences.cxx. +// +// Copyright 2002-2010 by Matthias Melcher. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems on the following page: +// +// http://www.fltk.org/str.php +// + +/* \file + Fl_Plugin class . */ + +#ifndef Fl_Plugin_H +# define Fl_Plugin_H + +# include "Fl_Preferences.H" + + +/** + \brief Fl_Plugin allows link-time and run-time integration of binary modules. + + Fl_Plugin and Fl_Plugin_Manager provide a small and simple solution for + linking C++ classes at run-time, or optionally linking modules at compile + time without the need to change the main application. + + Fl_Plugin_Manager uses static initialisation to create the plugin interface + early during startup. Plugins are stored in a temporary database, organized + in classes. + + Plugins should derive a new class from Fl_Plugin as a base: + \code + class My_Plugin : public Fl_Plugin { + public: + My_Plugin() : Fl_Plugin("effects", "blur") { } + void do_something(...); + }; + My_Plugin blur_plugin(); + \endcode + + Plugins can be put into modules and either linked befor distribution, or loaded + from dynamically linkable files. An Fl_Plugin_Manager is used to list and + access all currently loaded plugins. + \code + Fl_Plugin_Manager mgr("effects"); + int i, n = mgr.plugins(); + for (i=0; i<n; i++) { + My_Plugin *pin = (My_Plugin*)mgr.plugin(i); + pin->do_something(); + } + \endcode + */ +class FL_EXPORT Fl_Plugin +{ + Fl_Preferences::ID id; +public: + Fl_Plugin(const char *klass, const char *name); + virtual ~Fl_Plugin(); +}; + + +/** + \brief Fl_Plugin_Manager manages link-time and run-time plugin binaries. + \see Fl_Plugin + */ +class FL_EXPORT Fl_Plugin_Manager : public Fl_Preferences +{ +public: + Fl_Plugin_Manager(const char *klass); + ~Fl_Plugin_Manager(); + + /** \brief Return the number of plugins in the klass. + */ + int plugins() { return groups(); } + Fl_Plugin *plugin(int index); + Fl_Preferences::ID addPlugin(const char *name, Fl_Plugin *plugin); + + static void removePlugin(Fl_Preferences::ID id); + static int load(const char *filename); + static int loadAll(const char *filepath, const char *pattern=0); +}; + + +#endif // !Fl_Preferences_H + +// +// End of "$Id: Fl_Preferences.H 6995 2010-01-12 08:48:55Z matt $". +// diff --git a/FL/Fl_Preferences.H b/FL/Fl_Preferences.H index 44d007f90..798e421d6 100644 --- a/FL/Fl_Preferences.H +++ b/FL/Fl_Preferences.H @@ -61,7 +61,7 @@ reasons. One application can have multiple preferences files. Extensive binary data however should be stored in separate files: see getUserdataPath(). - + \note Starting with FLTK 1.3, preference databases are expected to be in utf8 encoding. Previous databases were stored in the current chracter set or code page which renders them incompatible @@ -97,12 +97,17 @@ public: Fl_Preferences( Fl_Preferences *parent, const char *group ); Fl_Preferences( Fl_Preferences &parent, int groupIndex ); Fl_Preferences( Fl_Preferences *parent, int groupIndex ); + Fl_Preferences(const Fl_Preferences&); Fl_Preferences( ID id ); ~Fl_Preferences(); /** Return an ID that can later be reused to open more references to this dataset. */ ID id() { return (ID)node; } + + /** Remove the group with this ID from a databse. + */ + static char remove(ID id) { return ((Node*)id)->remove(); } /** Return the name of this entry. */ @@ -189,13 +194,12 @@ public: private: - // make the following functions unavailable - Fl_Preferences(); - Fl_Preferences(const Fl_Preferences&); + Fl_Preferences() : node(0), rootNode(0) { } Fl_Preferences &operator=(const Fl_Preferences&); static char nameBuffer[128]; static char uuidBuffer[40]; + static Fl_Preferences *runtimePrefs; class RootNode; @@ -253,6 +257,7 @@ private: public: RootNode( Fl_Preferences *, Root root, const char *vendor, const char *application ); RootNode( Fl_Preferences *, const char *path, const char *vendor, const char *application ); + RootNode( Fl_Preferences * ); ~RootNode(); int read(); int write(); @@ -260,9 +265,10 @@ private: }; friend class RootNode; +protected: + Node *node; RootNode *rootNode; - }; |
