DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // "$Id: Fl_Plugin.H 6995 2010-01-12 08:48:55Z matt $" |
| 3 | // |
| 4 | // A Plugin system for FLTK, implemented in Fl_Preferences.cxx. |
| 5 | // |
| 6 | // Copyright 2002-2010 by Matthias Melcher. |
| 7 | // |
| 8 | // This library is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU Library General Public |
| 10 | // License as published by the Free Software Foundation; either |
| 11 | // version 2 of the License, or (at your option) any later version. |
| 12 | // |
| 13 | // This library is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // Library General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU Library General Public |
| 19 | // License along with this library; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 21 | // USA. |
| 22 | // |
| 23 | // Please report all bugs and problems on the following page: |
| 24 | // |
| 25 | // http://www.fltk.org/str.php |
| 26 | // |
| 27 | |
| 28 | /* \file |
| 29 | Fl_Plugin class . */ |
| 30 | |
| 31 | #ifndef Fl_Plugin_H |
| 32 | # define Fl_Plugin_H |
| 33 | |
| 34 | # include "Fl_Preferences.H" |
| 35 | |
| 36 | |
| 37 | /** |
| 38 | \brief Fl_Plugin allows link-time and run-time integration of binary modules. |
| 39 | |
| 40 | Fl_Plugin and Fl_Plugin_Manager provide a small and simple solution for |
| 41 | linking C++ classes at run-time, or optionally linking modules at compile |
| 42 | time without the need to change the main application. |
| 43 | |
| 44 | Fl_Plugin_Manager uses static initialisation to create the plugin interface |
| 45 | early during startup. Plugins are stored in a temporary database, organized |
| 46 | in classes. |
| 47 | |
| 48 | Plugins should derive a new class from Fl_Plugin as a base: |
| 49 | \code |
| 50 | class My_Plugin : public Fl_Plugin { |
| 51 | public: |
| 52 | My_Plugin() : Fl_Plugin("effects", "blur") { } |
| 53 | void do_something(...); |
| 54 | }; |
| 55 | My_Plugin blur_plugin(); |
| 56 | \endcode |
| 57 | |
| 58 | Plugins can be put into modules and either linked before distribution, or loaded |
| 59 | from dynamically linkable files. An Fl_Plugin_Manager is used to list and |
| 60 | access all currently loaded plugins. |
| 61 | \code |
| 62 | Fl_Plugin_Manager mgr("effects"); |
| 63 | int i, n = mgr.plugins(); |
| 64 | for (i=0; i<n; i++) { |
| 65 | My_Plugin *pin = (My_Plugin*)mgr.plugin(i); |
| 66 | pin->do_something(); |
| 67 | } |
| 68 | \endcode |
| 69 | */ |
| 70 | class FL_EXPORT Fl_Plugin { |
| 71 | Fl_Preferences::ID id; |
| 72 | public: |
| 73 | Fl_Plugin(const char *klass, const char *name); |
| 74 | virtual ~Fl_Plugin(); |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | /** |
| 79 | \brief Fl_Plugin_Manager manages link-time and run-time plugin binaries. |
| 80 | \see Fl_Plugin |
| 81 | */ |
| 82 | class FL_EXPORT Fl_Plugin_Manager : public Fl_Preferences { |
| 83 | public: |
| 84 | Fl_Plugin_Manager(const char *klass); |
| 85 | ~Fl_Plugin_Manager(); |
| 86 | |
| 87 | /** \brief Return the number of plugins in the klass. |
| 88 | */ |
| 89 | int plugins() { return groups(); } |
| 90 | Fl_Plugin *plugin(int index); |
| 91 | Fl_Plugin *plugin(const char *name); |
| 92 | Fl_Preferences::ID addPlugin(const char *name, Fl_Plugin *plugin); |
| 93 | |
| 94 | static void removePlugin(Fl_Preferences::ID id); |
| 95 | static int load(const char *filename); |
| 96 | static int loadAll(const char *filepath, const char *pattern=0); |
| 97 | }; |
| 98 | |
| 99 | |
| 100 | #endif // !Fl_Preferences_H |
| 101 | |
| 102 | // |
| 103 | // End of "$Id: Fl_Preferences.H 6995 2010-01-12 08:48:55Z matt $". |
| 104 | // |