00001
00002
00003
00004
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
00022
00023 #include "zypp/base/Gettext.h"
00024
00025 #include "zypp/source/SourceInfo.h"
00026
00027 #include "zypp/Source.h"
00028 #include "zypp/Url.h"
00029 #include "zypp/Pathname.h"
00030
00032 namespace zypp
00033 {
00034
00035 DEFINE_PTR_TYPE(SourceManager)
00036
00037
00038 class FailedSourcesRestoreException : public Exception
00039 {
00040 public:
00041 FailedSourcesRestoreException()
00042 : Exception(N_("Unable to restore all sources."))
00043 , _summary()
00044 , _translatedSummary()
00045 , _aliases()
00046 {}
00047 virtual ~FailedSourcesRestoreException() throw() {};
00048
00049 void append( std::string source, std::string alias, const Exception& problem );
00050 bool empty() const;
00051
00052 std::set<std::string> aliases() const;
00053
00054 protected:
00055 virtual std::ostream & dumpOn( std::ostream & str ) const;
00056 virtual std::ostream & dumpOnTranslated( std::ostream & str ) const;
00057 private:
00058 std::string _summary;
00059 std::string _translatedSummary;
00060 std::set<std::string> _aliases;
00061 };
00062
00064 class SourcesAlreadyRestoredException : public Exception
00065 {
00066 public:
00067 SourcesAlreadyRestoredException()
00068 : Exception(N_("At least one source already registered, cannot restore sources from persistent store."))
00069 {}
00070 virtual ~SourcesAlreadyRestoredException() throw() {};
00071 };
00072
00074
00075
00076
00084 class SourceManager : public base::ReferenceCounted, private base::NonCopyable
00085 {
00086 friend std::ostream & operator<<( std::ostream & str, const SourceManager & obj );
00087
00088 public:
00090 static SourceManager_Ptr sourceManager();
00091
00092 public:
00094 ~SourceManager();
00095
00096 public:
00098 typedef Source_Ref::NumericId SourceId;
00099
00100 private:
00102 typedef std::map<SourceId, Source_Ref> SourceMap;
00103
00106 typedef SourceMap::const_iterator const_iterator;
00107
00108 const_iterator begin() const;
00109
00110 const_iterator end() const;
00112
00113 public:
00116 typedef MapKVIteratorTraits<SourceMap>::Key_const_iterator SourceId_const_iterator;
00117
00118 SourceId_const_iterator SourceId_begin() const;
00119
00120 SourceId_const_iterator SourceId_end() const;
00122
00123 public:
00126 typedef MapKVIteratorTraits<SourceMap>::Value_const_iterator Source_const_iterator;
00127
00128 Source_const_iterator Source_begin() const;
00129
00130 Source_const_iterator Source_end() const;
00132
00133 public:
00134
00141 void reset() ;
00142
00148 source::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 renameSource( SourceId id, const std::string & new_alias_r );
00225
00227 void removeSource(SourceId id);
00228
00230 void removeSource(const std::string & alias_r);
00231
00233 void removeSourceByUrl(const Url & url_r);
00234
00240 void releaseAllSources();
00241
00248 void reattachSources(const Pathname & attach_point);
00249
00253 void disableAllSources();
00254
00262 static void disableSourcesAt( const Pathname & root );
00263
00264 private:
00266 SourceManager();
00267 };
00269
00271 std::ostream & operator<<( std::ostream & str, const SourceManager & obj );
00272
00274 }
00276 #endif // ZYPP_SOURCEMANAGER_H