pluginSystem.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 "pluginDef.h"
00026 #include "pluginException.h"
00027 #include <map>
00028 #include <list>
00029 #include <string>
00030 #include <ctime>
00031 #include <boost/shared_ptr.hpp>
00032 
00033 namespace Spm
00034 {
00035   namespace Core
00036   {
00037     class PackageSystem;
00038   }
00039 
00040   namespace Plugin
00041   {
00046     class PluginSystem 
00047     {
00048     private :
00049       friend class InstallerInterface;
00050       friend class Core::PackageSystem;
00051       std::string __user;
00052       std::list<boost::filesystem::path> __pluginDirs;
00053       std::list<Plugin *> __plugins;
00054       boost::signal<void (Plugin *)> __newPlugin;
00055       boost::signal<void (boost::filesystem::path)> __newPluginDirectory;
00056       PluginSystem (const std::string & userName);
00057       void readRegistryFile ();
00058       void writeRegistryFile ();
00059       void checkPluginDirs ();
00060       static std::map<std::string,
00061                       boost::shared_ptr<PluginSystem> > __instances;
00062       boost::shared_ptr<PluginSystem> __systemPluginSystem;
00063       miniXml::Document * xmlRegistry;
00068       void addPluginDir (const boost::filesystem::path & dir);
00069 
00074       void addPlugin (const boost::filesystem::path & file);
00075 
00080       InstallerPlugin * getInstaller (const std::string & url)
00081         throw (NoPluginHandlerException);
00082 
00083     public :
00084       typedef std::list<Plugin *>::iterator iterator;
00085       typedef std::list<Plugin *>::const_iterator const_iterator;
00086       typedef std::list<Plugin *>::reverse_iterator reverse_iterator;
00087       typedef std::list<Plugin *>::const_reverse_iterator const_reverse_iterator;
00088       
00089       ~PluginSystem ();
00095       static boost::shared_ptr<PluginSystem> create (const std::string & user);
00096       
00101       void add (const boost::filesystem::path & path);
00102 
00106       const std::list<Plugin *> & getPlugins ();
00107 
00112       const Plugin * getPlugin (const std::string & pluginName)
00113         throw (NoPluginException);
00114 
00119       Plugin * getRefPlugin (const std::string & pluginName)
00120         throw (NoPluginException);      
00121 
00127       StepPlugin * getStep (const std::string & pluginName,
00128                             const std::map<std::string,std::string> & pOptions)
00129         throw (NoPluginException);
00130 
00135       DownloadPlugin * getDownloader (const std::string & uri)
00136         throw (NoPluginHandlerException);
00137 
00142       InstallerPlugin * getInstaller (Util::Compressed * compressed)    
00143         throw (NoPluginHandlerException);
00144 
00145       boost::signal<void (Plugin *)> & signalNewPlugin ();
00146       boost::signal<void (boost::filesystem::path)> & signalNewPluginDirectory ();
00147 
00148       inline iterator begin ()
00149       {
00150         return __plugins.begin ();
00151       }
00152 
00153       inline const_iterator begin () const
00154       {
00155         return __plugins.begin ();
00156       }
00157 
00158       inline reverse_iterator rbegin ()
00159       {
00160         return __plugins.rbegin ();
00161       }
00162 
00163       inline const_reverse_iterator rbegin () const
00164       {
00165         return __plugins.rbegin ();
00166       }
00167 
00168       inline iterator end ()
00169       {
00170         return __plugins.end ();
00171       }
00172 
00173       inline const_iterator end () const
00174       {
00175         return __plugins.end ();
00176       }
00177 
00178       inline reverse_iterator rend ()
00179       {
00180         return __plugins.rend ();
00181       }
00182 
00183       inline const_reverse_iterator rend () const
00184       {
00185         return __plugins.rend ();
00186       }
00187     };
00188 
00192     struct equalPluginByName : public std::binary_function<Plugin *, std::string, bool>
00193     {
00194       bool operator() (Plugin * p,
00195                        const std::string & pluginName) const;
00196     };
00200   }
00201 }
00202 #endif

Generated on Wed Jul 4 15:27:21 2007 for libSpm by  doxygen 1.4.6