pluginManager.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  *  this is part of Spm
00004  *
00005  *  Copyright (c) 2005-2007 Guillaume Chevallereau
00006  *
00007  *  This program is free software. You can redistribute it and/or modify it 
00008  *  under the terms of the GNU General Public License as published by the 
00009  *  Free Software Foundation. Either version 2 of the license or (at your 
00010  *  option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be usefull but WITHOUT
00013  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
00014  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for 
00015  *  more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License along 
00018  *  with this program; if not, write to the Free Software Foundation, Inc., 
00019  *  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
00020  */
00021 #ifndef __PLUGIN_SYSTEM_H__
00022 #define __PLUGIN_SYSTEM_H__
00023 
00024 #include "plugin.h"
00025 #include "pluginException.h"
00026 #include <map>
00027 #include <list>
00028 #include <ctime>
00029 #include <boost/shared_ptr.hpp>
00030 
00031 namespace Spm
00032 {
00033   namespace Core
00034   {
00035     class PackageManager;
00036   }
00037 
00038   namespace Plugin
00039   {
00044     class PluginManager 
00045     {
00046     private :
00047       friend class InstallerInterface;
00048       friend class Core::PackageManager;
00049       miniXml::ustring user_;
00050       std::list<boost::filesystem::path> pluginDirs_;
00051       std::list<Plugin *> plugins_;
00052       boost::signal<void (Plugin *)> newPlugin_;
00053       boost::signal<void (boost::filesystem::path)> newPluginDirectory_;
00054       PluginManager (const miniXml::ustring & userName);
00055       void readRegistryFile ();
00056       void writeRegistryFile ();
00057       void checkPluginDirs ();
00058       static std::map<miniXml::ustring,
00059                       boost::shared_ptr<PluginManager> > instances_;
00060       boost::shared_ptr<PluginManager> systemPluginManager_;
00061       void addPluginDir (const boost::filesystem::path & dir);
00062       void addPlugin (const boost::filesystem::path & file);
00063       void addPlugin (const Plugin * plugin);
00064       InstallerPlugin * getInstaller (const miniXml::ustring & url);
00065       void reset();
00066 
00067     public :
00068       typedef std::list<Plugin *>::iterator iterator;
00069       typedef std::list<Plugin *>::const_iterator const_iterator;
00070       typedef std::list<Plugin *>::reverse_iterator reverse_iterator;
00071       typedef std::list<Plugin *>::const_reverse_iterator const_reverse_iterator;
00072       
00073       ~PluginManager ();
00079       static boost::shared_ptr<PluginManager> & create (const miniXml::ustring & user);
00080       
00085       void add (const boost::filesystem::path & path);
00086 
00090       const std::list<Plugin *> & getPlugins ();
00091 
00096       const Plugin * getPlugin (const miniXml::ustring & pluginName)
00097         throw (NoPluginException);
00098 
00103       Plugin * getRefPlugin (const miniXml::ustring & pluginName)
00104         throw (NoPluginException);      
00105 
00111       StepPlugin * getStep (const miniXml::ustring & pluginName,
00112                             const Util::PropertyList & pOptions)
00113         throw (NoPluginException);
00114 
00119       DownloadPlugin * getDownloader (const miniXml::ustring & uri)
00120         throw (NoPluginHandlerException);
00121 
00126       InstallerPlugin * getInstaller (Util::Compressed * compressed,
00127                                       const Util::PropertyList & pList = Util::PropertyList());
00128 
00133       InfoInterface * getInfo (const miniXml::ustring pluginName,
00134                                const miniXml::ustring & uri);
00135 
00136       boost::signal<void (Plugin *)> & signalNewPlugin ();
00137       boost::signal<void (boost::filesystem::path)> & signalNewPluginDirectory ();
00138 
00139       inline iterator begin ()
00140       {
00141         return plugins_.begin ();
00142       }
00143 
00144       inline const_iterator begin () const
00145       {
00146         return plugins_.begin ();
00147       }
00148 
00149       inline reverse_iterator rbegin ()
00150       {
00151         return plugins_.rbegin ();
00152       }
00153 
00154       inline const_reverse_iterator rbegin () const
00155       {
00156         return plugins_.rbegin ();
00157       }
00158 
00159       inline iterator end ()
00160       {
00161         return plugins_.end ();
00162       }
00163 
00164       inline const_iterator end () const
00165       {
00166         return plugins_.end ();
00167       }
00168 
00169       inline reverse_iterator rend ()
00170       {
00171         return plugins_.rend ();
00172       }
00173 
00174       inline const_reverse_iterator rend () const
00175       {
00176         return plugins_.rend ();
00177       }
00178     };
00179 
00183     struct equalPluginByName : public std::binary_function<Plugin *, miniXml::ustring, bool>
00184     {
00185       bool operator() (Plugin * p,
00186                        const miniXml::ustring & pluginName) const;
00187     };
00191   }
00192 }
00193 #endif

Generated on Sat Mar 21 17:00:14 2009 for libSpm by  doxygen 1.5.2