From ef6abe654817967bf0308563490159e4c11e44dc Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 4 Jul 2006 16:51:11 +0000 Subject: [PATCH] more skeletons --- zypp/cache/SourceCacheInitializer.cpp | 9 +++- zypp/source/Makefile.am | 6 ++- zypp/source/SourceMediaAccess.cc | 76 +++++++++++++++++++++++++++++++++ zypp/source/SourceMediaAccess.h | 79 +++++++++++++++++++++++++++++++++++ zypp/source/yum/Makefile.am | 6 ++- zypp/source/yum/YUMSourceCacher.cc | 41 ++++++++++++++++++ zypp/source/yum/YUMSourceCacher.h | 63 ++++++++++++++++++++++++++++ 7 files changed, 274 insertions(+), 6 deletions(-) create mode 100644 zypp/source/SourceMediaAccess.cc create mode 100644 zypp/source/SourceMediaAccess.h create mode 100644 zypp/source/yum/YUMSourceCacher.cc create mode 100644 zypp/source/yum/YUMSourceCacher.h diff --git a/zypp/cache/SourceCacheInitializer.cpp b/zypp/cache/SourceCacheInitializer.cpp index f3ac170..9c9260f 100644 --- a/zypp/cache/SourceCacheInitializer.cpp +++ b/zypp/cache/SourceCacheInitializer.cpp @@ -27,7 +27,7 @@ namespace zypp namespace cache { ///////////////////////////////////////////////////////////////// -#define SOURCES_TABLE_SCHEMA "create table sources ( alias varchar primary key, type varchar, description varchar, url varchar, path varchar, enabled integer, autorefresh integer, timestamp varchar, checksum varchar);" +#define SOURCES_TABLE_SCHEMA "create table sources ( alias varchar primary key, type varchar, description varchar, url varchar, path varchar, enabled integer, autorefresh integer, timestamp varchar, checksum varchar);" // alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8 SourceCacheInitializer::SourceCacheInitializer( const Pathname &root_r, const Pathname &db_file ) @@ -48,13 +48,18 @@ SourceCacheInitializer::SourceCacheInitializer( const Pathname &root_r, const Pa createTables(); _just_initialized = true; _con->close(); + MIL << "Source cache initialized" << std::endl; + } + else + { + MIL << "Source cache already initialized" << std::endl; } } catch(exception &ex) { ERR << "Exception Occured: " << ex.what() << endl; } - + } bool SourceCacheInitializer::justInitialized() const diff --git a/zypp/source/Makefile.am b/zypp/source/Makefile.am index 39a04e7..adfc528 100644 --- a/zypp/source/Makefile.am +++ b/zypp/source/Makefile.am @@ -15,7 +15,8 @@ sourceinclude_HEADERS = \ Builtin.h \ PackageDelta.h \ MediaSet.h \ - SourceInfo.h + SourceInfo.h \ + SourceMediaAccess.h noinst_LTLIBRARIES = lib@PACKAGE@_source.la @@ -25,7 +26,8 @@ lib@PACKAGE@_source_la_SOURCES = \ SourceImpl.cc \ PackageDelta.cc \ MediaSet.cc \ - SourceInfo.cc + SourceInfo.cc \ + SourceMediaAccess.cc lib@PACKAGE@_source_la_LIBADD = \ diff --git a/zypp/source/SourceMediaAccess.cc b/zypp/source/SourceMediaAccess.cc new file mode 100644 index 0000000..46cbe84 --- /dev/null +++ b/zypp/source/SourceMediaAccess.cc @@ -0,0 +1,76 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/source/SourceMediaAccess.cc + * +*/ +#include +#include + +#include "zypp/base/LogTools.h" +#include "zypp/source/SourceMediaAccess.h" +//#include "zypp/source/SourceMediaAccessReportReceivers.h" + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +namespace source +{ ///////////////////////////////////////////////////////////////// + + + SourceMediaAccess::SourceMediaAccess( const Url &url, const Pathname &path, std::vector verifiers ) + : _url(url), + _path(path) + { + + } + + SourceMediaAccess::~SourceMediaAccess() + { + } + + + +// media::MediaVerifierRef SourceMediaAccess::verifier(unsigned media_nr) +// { return media::MediaVerifierRef(new media::NoVerifier()); } + + SourceMediaVerifier::SourceMediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr) + : _media_vendor(vendor_r) + , _media_id(id_r) + , _media_nr(media_nr) + {} + + bool SourceMediaVerifier::isDesiredMedia(const media::MediaAccessRef &ref) + { + if (_media_vendor.empty() || _media_id.empty()) + return true; + + Pathname media_file = "/media." + str::numstring(_media_nr) + "/media"; + ref->provideFile (media_file); + media_file = ref->localPath(media_file); + std::ifstream str(media_file.asString().c_str()); + std::string vendor; + std::string id; + +#warning check the stream status + getline(str, vendor); + getline(str, id); + + return (vendor == _media_vendor && id == _media_id ); + } + + +///////////////////////////////////////////////////////////////// +} // namespace source +/////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/source/SourceMediaAccess.h b/zypp/source/SourceMediaAccess.h new file mode 100644 index 0000000..baeb150 --- /dev/null +++ b/zypp/source/SourceMediaAccess.h @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_SourceMediaAccess_H +#define ZYPP_SourceMediaAccess_H + +#include +#include +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" +#include "zypp/media/MediaManager.h" +#include "zypp/Pathname.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + + DEFINE_PTR_TYPE(SourceMediaAccess); + + + class SourceMediaVerifier : public zypp::media::MediaVerifierBase + { + public: + /** ctor */ + SourceMediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1); + /** + * Check if the specified attached media contains + * the desired media number (e.g. SLES10 CD1). + */ + virtual bool isDesiredMedia(const media::MediaAccessRef &ref); + private: + std::string _media_vendor; + std::string _media_id; + media::MediaNr _media_nr; + }; + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : SourceCache + // + class SourceMediaAccess : public base::ReferenceCounted, private base::NonCopyable + { + friend std::ostream & operator<<( std::ostream & str, const SourceMediaAccess & obj ); + + public: + SourceMediaAccess( const Url &url, const Pathname &path, std::vector verifiers ); + ~SourceMediaAccess(); + protected: + virtual std::ostream & dumpOn( std::ostream & str ) const; + private: + Url _url; + Pathname _path; + }; + /////////////////////////////////////////////////////////////////// + + /** \relates SourceMediaAccess Stream output */ + inline std::ostream & operator<<( std::ostream & str, const SourceMediaAccess & obj ) + { return obj.dumpOn( str ); } + + + ///////////////////////////////////////////////////////////////// + } // namespace source + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_SourceMediaAccess_H diff --git a/zypp/source/yum/Makefile.am b/zypp/source/yum/Makefile.am index ed16e25..db6862d 100644 --- a/zypp/source/yum/Makefile.am +++ b/zypp/source/yum/Makefile.am @@ -19,7 +19,8 @@ sourceyuminclude_HEADERS = \ YUMPatchImpl.h \ YUMGroupImpl.h \ YUMPatternImpl.h \ - YUMProductImpl.h + YUMProductImpl.h \ + YUMSourceCacher.h noinst_LTLIBRARIES = lib@PACKAGE@_source_yum.la @@ -35,6 +36,7 @@ lib@PACKAGE@_source_yum_la_SOURCES = \ YUMPatchImpl.cc \ YUMGroupImpl.cc \ YUMPatternImpl.cc \ - YUMProductImpl.cc + YUMProductImpl.cc \ + YUMSourceCacher.cc ## ################################################## diff --git a/zypp/source/yum/YUMSourceCacher.cc b/zypp/source/yum/YUMSourceCacher.cc new file mode 100644 index 0000000..d9ced6d --- /dev/null +++ b/zypp/source/yum/YUMSourceCacher.cc @@ -0,0 +1,41 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#include "zypp/base/Logger.h" +#include "zypp/cache/SourceCacher.h" +#include "zypp/source/yum/YUMSourceCacher.h" + +using namespace std; + +////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +namespace source +{ ///////////////////////////////////////////////////////////////// +namespace yum +{ ///////////////////////////////////////////////////////////////// + + +YUMSourceCacher::YUMSourceCacher( const Pathname &root_r ) : cache::SourceCacher(root_r) +{ + +} + +YUMSourceCacher::~YUMSourceCacher() +{ +} + +std::ostream & YUMSourceCacher::dumpOn( std::ostream & str ) const +{ + return str; +} + +} +} +} diff --git a/zypp/source/yum/YUMSourceCacher.h b/zypp/source/yum/YUMSourceCacher.h new file mode 100644 index 0000000..1283bf8 --- /dev/null +++ b/zypp/source/yum/YUMSourceCacher.h @@ -0,0 +1,63 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_YUMSourceCacher_H +#define ZYPP_YUMSourceCacher_H + +#include +#include + +#include "zypp/cache/SourceCacher.h" +#include "zypp/Pathname.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace source + { ///////////////////////////////////////////////////////////////// + + namespace yum + { ///////////////////////////////////////////////////////////////// + + DEFINE_PTR_TYPE(YUMSourceCacher); + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : SourceCacher + // + class YUMSourceCacher : public cache::SourceCacher + { + friend std::ostream & operator<<( std::ostream & str, const YUMSourceCacher & obj ); + + public: + /** root path */ + YUMSourceCacher( const Pathname &root_r ); + ~YUMSourceCacher(); + protected: + + /** Overload to realize stream output. */ + virtual std::ostream & dumpOn( std::ostream & str ) const; + //typedef std::map MediaMap + }; + /////////////////////////////////////////////////////////////////// + + /** \relates SourceCacher Stream output */ + inline std::ostream & operator<<( std::ostream & str, const YUMSourceCacher & obj ) + { return obj.dumpOn( str ); } + + + ///////////////////////////////////////////////////////////////// + } // namespace cache + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +} +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_SOURCE_SourceCacher_H -- 2.7.4