SourceManager.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #ifndef ZYPP_SOURCEMANAGER_H
00013 #define ZYPP_SOURCEMANAGER_H
00014 
00015 #include <iosfwd>
00016 #include <list>
00017 #include <map>
00018 
00019 #include "zypp/base/ReferenceCounted.h"
00020 #include "zypp/base/NonCopyable.h"
00021 //#include "zypp/base/Iterator.h"
00022 
00023 #include "zypp/base/Gettext.h" // move with FailedSourcesRestoreException & SourcesAlreadyRestoredException
00024 
00025 #include "zypp/Source.h"
00026 #include "zypp/Url.h"
00027 #include "zypp/Pathname.h"
00028 
00030 namespace zypp
00031 { 
00032 
00033   DEFINE_PTR_TYPE(SourceManager)
00034 
00035   
00036   class FailedSourcesRestoreException : public Exception
00037   {
00038     public:
00039       FailedSourcesRestoreException()
00040       : Exception(N_("Unable to restore all sources."))
00041       , _summary()
00042       , _translatedSummary()
00043       , _aliases()
00044       {}
00045       virtual ~FailedSourcesRestoreException() throw() {};
00046 
00047       void append( std::string source, std::string alias, const Exception& problem );
00048       bool empty() const;
00049       
00050       std::set<std::string> aliases() const;
00051       
00052     protected:
00053       virtual std::ostream & dumpOn( std::ostream & str ) const;
00054       virtual std::ostream & dumpOnTranslated( std::ostream & str ) const;
00055     private:
00056       std::string _summary;
00057       std::string _translatedSummary;
00058       std::set<std::string> _aliases;
00059   };
00060 
00062   class SourcesAlreadyRestoredException : public Exception
00063   {
00064     public:
00065       SourcesAlreadyRestoredException()
00066       : Exception(N_("At least one source already registered, cannot restore sources from persistent store."))
00067       {}
00068       virtual ~SourcesAlreadyRestoredException() throw() {};
00069   };
00070 
00072   //
00073   //    CLASS NAME : SourceManager
00074   //
00082   class SourceManager : public base::ReferenceCounted, private base::NonCopyable
00083   {
00084     friend std::ostream & operator<<( std::ostream & str, const SourceManager & obj );
00085 
00086   public:
00088     static SourceManager_Ptr sourceManager();
00089 
00090   public:
00092     ~SourceManager();
00093 
00094   public:
00096     typedef Source_Ref::NumericId SourceId;
00097 
00098   private:
00100     typedef std::map<SourceId, Source_Ref> SourceMap;
00101 
00104     typedef SourceMap::const_iterator const_iterator;
00105 
00106     const_iterator begin() const;
00107 
00108     const_iterator end() const;
00110 
00111   public:
00114     typedef MapKVIteratorTraits<SourceMap>::Key_const_iterator SourceId_const_iterator;
00115 
00116     SourceId_const_iterator SourceId_begin() const;
00117 
00118     SourceId_const_iterator SourceId_end() const;
00120 
00121   public:
00124     typedef MapKVIteratorTraits<SourceMap>::Value_const_iterator Source_const_iterator;
00125 
00126     Source_const_iterator Source_begin() const;
00127 
00128     Source_const_iterator Source_end() const;
00130 
00131   public:
00132 
00139     void reset() ;
00140 
00146     typedef struct { std::string alias; Url url; std::string type; bool autorefresh; } SourceInfo;
00147     typedef std::list<SourceInfo> SourceInfoList;
00148     SourceInfoList knownSourceInfos(const Pathname &root_r);
00149     
00159     void store(Pathname root_r, bool metadata_cache );
00160 
00179     bool restore(Pathname root_r, bool use_caches = true, const std::string &alias_filter = "", const std::string &url_filter = "" );
00180 
00186     Source_Ref findSource(SourceId id);
00187 
00193     Source_Ref findSource(const std::string & alias_r);
00194 
00203     Source_Ref findSourceByUrl(const Url & url_r);
00204 
00209     std::list<SourceId> enabledSources() const;
00210 
00214     std::list<SourceId> allSources() const;
00215 
00221     SourceId addSource(Source_Ref source_r);
00222 
00224     void removeSource(SourceId id);
00225 
00227     void removeSource(const std::string & alias_r);
00228 
00230     void removeSourceByUrl(const Url & url_r);
00231 
00237     void releaseAllSources();
00238 
00245     void reattachSources(const Pathname & attach_point);
00246 
00250     void disableAllSources();
00251 
00259     static void disableSourcesAt( const Pathname & root );
00260 
00261   private:
00263     SourceManager();
00264   };
00266 
00268   std::ostream & operator<<( std::ostream & str, const SourceManager & obj );
00269 
00271 } // namespace zypp
00273 #endif // ZYPP_SOURCEMANAGER_H

Generated on Thu Jul 6 00:07:26 2006 for zypp by  doxygen 1.4.6