00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __INSTALLER_INTERFACE_H__
00022 #define __INSTALLER_INTERFACE_H__
00023
00024 #include "interface.h"
00025 #include "stepInterface.h"
00026 #include <list>
00027 #include <util/compressed.h>
00028 #include <boost/signals.hpp>
00029 #include <boost/thread/recursive_mutex.hpp>
00030
00031 #define SPM_INSTALLER_PLUGIN(plugin) \
00032 extern "C" \
00033 { \
00034 plugin * getSpmPluginInfo () \
00035 { \
00036 return new plugin (); \
00037 } \
00038 \
00039 Spm::Plugin::pluginDescription_t getSpmPluginDescription () \
00040 { \
00041 return plugin ().getDescription (); \
00042 } \
00043 \
00044 plugin * getSpmInstallerPlugin (Spm::Util::Compressed * compressed, \
00045 const Spm::Util::PropertyList & pList) \
00046 { \
00047 return new plugin (compressed, \
00048 pList); \
00049 } \
00050 \
00051 int spmHandleCompressed (Spm::Util::Compressed * compressed, \
00052 Spm::Util::PropertyList & pList) \
00053 { \
00054 return plugin::handle(compressed, \
00055 pList); \
00056 } \
00057 \
00058 int spmHandleUrl (miniXml::ustring & url, \
00059 Spm::Util::PropertyList & pList) \
00060 { \
00061 return plugin::handle(url, \
00062 pList); \
00063 } \
00064 }
00065
00066 namespace Spm
00067 {
00068 namespace Plugin
00069 {
00070 const int NOT_HANDLING = -1;
00075 class InstallerInterface : public Interface
00076 {
00077 protected:
00078 boost::filesystem::path prefix_;
00079 boost::filesystem::path runningDir_;
00080 Util::Compressed * compressed_;
00081 miniXml::ustring name_;
00082 miniXml::ustring version_;
00083 std::list<miniXml::ustring> dependency_;
00084 boost::signal<void (StepInterface *)> changedStep_;
00085 boost::signal<void (InstallerInterface *)> metaDataParsed_;
00086 boost::signal<void (InstallerInterface *)> haveOptions_;
00087 boost::recursive_mutex mutex_;
00088 std::list<StepInterface *> steps_;
00089 std::list<StepInterface *>::iterator itStep_;
00090
00091 InstallerInterface () : Interface()
00092 {
00093 description_.pluginType_ = INSTALLER_TYPE;
00094 compressed_ = NULL;
00095 }
00096
00097 InstallerInterface (Util::Compressed * archive,
00098 const Util::PropertyList & pList = Util::PropertyList()) : Interface()
00099 {
00100 description_.pluginType_ = INSTALLER_TYPE;
00101 compressed_ = archive;
00102 options_ = pList;
00103 }
00104
00105 void setState (state_e pluginState)
00106 {
00107 currentState_ = pluginState;
00108 }
00109
00110 public:
00111 ~InstallerInterface ()
00112 {
00113 for(itStep_ = steps_.begin ();
00114 itStep_ != steps_.end ();
00115 itStep_++)
00116 delete (*itStep_);
00117 steps_.clear ();
00118
00119 if(compressed_)
00120 delete (compressed_);
00121 compressed_ = NULL;
00122 }
00123
00127 virtual void init ()
00128 {
00129 }
00130
00134 virtual void postInstall ()
00135 {
00136 }
00137
00141 virtual void install ()
00142 {
00143 try
00144 {
00145 setState(INITIALIZATION);
00146 init ();
00147 setState(RUNNING);
00148 itStep_ = steps_.begin ();
00149 while (itStep_ != steps_.end ())
00150 {
00151 changedStep_ ((*itStep_));
00152 (*itStep_)->run (runningDir_.string ());
00153 {
00154 boost::recursive_mutex::scoped_lock lock (mutex_);
00155 itStep_++;
00156 }
00157 }
00158 postInstall ();
00159 setState(ENDED);
00160 }
00161 catch (Spm::Plugin::InstallException & ie)
00162 {
00163 setState(FAILED);
00164 throw;
00165 }
00166 }
00167
00171 virtual const StepInterface * getActualStep ()
00172 {
00173 boost::recursive_mutex::scoped_lock lock (mutex_);
00174 if (currentState_ != RUNNING)
00175 return NULL;
00176 if (!steps_.size())
00177 return NULL;
00178 if (itStep_ == steps_.end ())
00179 return NULL;
00180 return *itStep_;
00181 }
00182
00186 virtual const std::list<boost::filesystem::path> getInstalledElement () = 0;
00187
00191 virtual std::map<miniXml::ustring,
00192 miniXml::ustring> getUsedOptions () = 0;
00193
00194 virtual std::map<miniXml::ustring,
00195 boost::tuple<miniXml::ustring,
00196 int,
00197 Util::PropertyList::propertyType_e> > getOptions () = 0;
00198
00202 const boost::filesystem::path & getPrefix ()
00203 {
00204 boost::recursive_mutex::scoped_lock lock (mutex_);
00205 return prefix_;
00206 }
00207
00211 virtual const miniXml::ustring & getPackageName ()
00212 {
00213 boost::recursive_mutex::scoped_lock lock (mutex_);
00214 return name_;
00215 }
00216
00220 virtual const miniXml::ustring & getPackageVersion ()
00221 {
00222 boost::recursive_mutex::scoped_lock lock (mutex_);
00223 return version_;
00224 }
00225
00229 virtual const std::list<miniXml::ustring> & getDependency ()
00230 {
00231 boost::recursive_mutex::scoped_lock lock (mutex_);
00232 return dependency_;
00233 }
00234
00238 Util::PropertyList & installOptions ()
00239 {
00240 return options_;
00241 }
00242
00247 virtual void installOptions (const Util::PropertyList & pList)
00248 {
00249 boost::recursive_mutex::scoped_lock lock (mutex_);
00250 options_ = pList;
00251 haveOptions_(this);
00252 }
00253
00257 boost::signal<void (StepInterface *)> & signalChangedStep ()
00258 {
00259 boost::recursive_mutex::scoped_lock lock (mutex_);
00260 return changedStep_;
00261 }
00262
00266 boost::signal<void (InstallerInterface *)> & signalMetaDataParsed ()
00267 {
00268 boost::recursive_mutex::scoped_lock lock (mutex_);
00269 return metaDataParsed_;
00270 }
00271
00275 boost::signal<void (InstallerInterface *)> & signalHaveOptions ()
00276 {
00277 boost::recursive_mutex::scoped_lock lock (mutex_);
00278 return haveOptions_;
00279 }
00280 };
00281 }
00282 }
00283
00284 #endif