From 4f7600cfd2da9a71f6c45cd0142719ed07633cd5 Mon Sep 17 00:00:00 2001 From: Jiri Srain Date: Fri, 27 Jan 2006 15:10:04 +0000 Subject: [PATCH] added implementation of target classes, which are container for target storages (currently RPM is only added, XML not yet) --- zypp/Makefile.am | 2 + zypp/Target.cc | 79 +++++++++++++++++++++++++++++++++++++ zypp/Target.h | 87 +++++++++++++++++++++++++++++++++++++++++ zypp/ZYpp.cc | 12 ++++++ zypp/ZYpp.h | 16 ++++++++ zypp/target/Makefile.am | 6 ++- zypp/target/TargetImpl.cc | 85 ++++++++++++++++++++++++++++++++++++++++ zypp/target/TargetImpl.h | 93 ++++++++++++++++++++++++++++++++++++++++++++ zypp/zypp_detail/ZYppImpl.cc | 22 +++++++++++ zypp/zypp_detail/ZYppImpl.h | 19 ++++++++- 10 files changed, 418 insertions(+), 3 deletions(-) create mode 100644 zypp/Target.cc create mode 100644 zypp/Target.h create mode 100644 zypp/target/TargetImpl.cc create mode 100644 zypp/target/TargetImpl.h diff --git a/zypp/Makefile.am b/zypp/Makefile.am index bc72a58..06c2f58 100644 --- a/zypp/Makefile.am +++ b/zypp/Makefile.am @@ -43,6 +43,7 @@ pkginclude_HEADERS = NeedAType.h \ Source.h \ SourceFactory.h \ SourceManager.h \ + Target.h \ Selection.h \ Pattern.h \ Message.h \ @@ -104,6 +105,7 @@ lib@PACKAGE@_la_SOURCES = \ Source.cc \ SourceFactory.cc\ SourceManager.cc\ + Target.cc \ Selection.cc \ Pattern.cc \ Message.cc \ diff --git a/zypp/Target.cc b/zypp/Target.cc new file mode 100644 index 0000000..abdc614 --- /dev/null +++ b/zypp/Target.cc @@ -0,0 +1,79 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/Target.cc + * +*/ +#include + +#include + +#include "zypp/Target.h" +#include "zypp/target/TargetImpl.h" + +using namespace std; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + + IMPL_PTR_TYPE(Target); + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : Target::Target + // METHOD TYPE : Ctor + // + Target::Target( const Pathname & root ) + { + _pimpl = RW_pointer >(new Impl(root)); + } + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : Target::Target + // METHOD TYPE : Ctor + // + Target::Target( const Impl_Ptr & impl_r ) + : _pimpl( impl_r ) + { + assert( impl_r ); + } + + Target_Ptr Target::_nullimpl; + + /** Null implementation */ + Target_Ptr Target::nullimpl() + { + if (! _nullimpl) + { + _nullimpl = new Target(target::TargetImpl::nullimpl()); + } + return _nullimpl; + } + + + /////////////////////////////////////////////////////////////////// + // + // Forward to TargetImpl: + // + /////////////////////////////////////////////////////////////////// + + const ResStore & Target::resolvables() + { return _pimpl->resolvables(); } + + target::rpm::RpmDb & Target::rpmDb() + { return _pimpl->rpm(); } + + std::ostream & Target::dumpOn( std::ostream & str ) const + { return _pimpl->dumpOn( str ); } + + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/Target.h b/zypp/Target.h new file mode 100644 index 0000000..38aff03 --- /dev/null +++ b/zypp/Target.h @@ -0,0 +1,87 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/Target.h + * +*/ +#ifndef ZYPP_TARGET_H +#define ZYPP_TARGET_H + +#include + +#include "zypp/base/PtrTypes.h" + +#include "zypp/ResStore.h" +#include "zypp/Pathname.h" +#include "zypp/target/TargetImpl.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + namespace target + { + class TargetImpl; + namespace rpm { + class RpmDb; + } + } + + DEFINE_PTR_TYPE(Target); + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : Target + // + /** + */ + class Target : public base::ReferenceCounted, public base::NonCopyable + { + public: + typedef target::TargetImpl Impl; + typedef intrusive_ptr Impl_Ptr; + + public: + + /** All resolvables provided by the target. */ + const ResStore & resolvables(); + /** Null implementation */ + static Target_Ptr nullimpl(); + /** Refference to the RPM database */ + target::rpm::RpmDb & rpmDb(); + + public: + /** Factory ctor */ + Target( const Pathname & root = "/" ); + /** Factory ctor */ + explicit + Target( const Impl_Ptr & impl_r ); + + private: + friend std::ostream & operator<<( std::ostream & str, const Target & obj ); + /** Stream output. */ + std::ostream & dumpOn( std::ostream & str ) const; + + private: + /** Pointer to implementation */ + RW_pointer > _pimpl; + + static Target_Ptr _nullimpl; + + public: + }; + /////////////////////////////////////////////////////////////////// + + /** \relates Target Stream output. */ + inline std::ostream & operator<<( std::ostream & str, const Target & obj ) + { return obj.dumpOn( str ); } + + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_TARGET_H diff --git a/zypp/ZYpp.cc b/zypp/ZYpp.cc index e23ccbf..e4abc80 100644 --- a/zypp/ZYpp.cc +++ b/zypp/ZYpp.cc @@ -73,6 +73,18 @@ namespace zypp _pimpl->addResolvables (store); } + Target_Ptr ZYpp::target() const + { return _pimpl->target(); } + + void ZYpp::initTarget(const Pathname & root) + { _pimpl->initTarget(root); } + + void ZYpp::finishTarget() + { _pimpl->finishTarget(); } + + + + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/ZYpp.h b/zypp/ZYpp.h index 33e8f7e..6b799d2 100644 --- a/zypp/ZYpp.h +++ b/zypp/ZYpp.h @@ -17,6 +17,7 @@ #include "zypp/base/ReferenceCounted.h" #include "zypp/base/NonCopyable.h" #include "zypp/base/PtrTypes.h" +#include "zypp/Target.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -51,6 +52,21 @@ namespace zypp void removeResolvables (const ResStore& store); + /** + * \throws Exception + */ + Target_Ptr target() const; + + /** + * \throws Exception + */ + void initTarget(const Pathname & root); + + /** + * \throws Exception + */ + void finishTarget(); + protected: /** Dtor */ virtual ~ZYpp(); diff --git a/zypp/target/Makefile.am b/zypp/target/Makefile.am index 4c2e504..c25bc7d 100644 --- a/zypp/target/Makefile.am +++ b/zypp/target/Makefile.am @@ -7,7 +7,8 @@ SUBDIRS = hal rpm store targetincludedir = $(pkgincludedir)/target -targetinclude_HEADERS = +targetinclude_HEADERS = \ + TargetImpl.h ## ################################################## @@ -15,7 +16,8 @@ noinst_LTLIBRARIES = lib@PACKAGE@_target.la ## ################################################## -lib@PACKAGE@_target_la_SOURCES = +lib@PACKAGE@_target_la_SOURCES = \ + TargetImpl.cc lib@PACKAGE@_target_la_LDFLAGS = @LIBZYPP_VERSION_INFO@ diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc new file mode 100644 index 0000000..279dadd --- /dev/null +++ b/zypp/target/TargetImpl.cc @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/target/TargetImpl.cc + * +*/ +#include +#include "zypp/base/Logger.h" + +#include "zypp/target/TargetImpl.h" + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace target + { ///////////////////////////////////////////////////////////////// + + IMPL_PTR_TYPE(TargetImpl); + + TargetImpl_Ptr TargetImpl::_nullimpl; + + /** Null implementation */ + TargetImpl_Ptr TargetImpl::nullimpl() + { + if (_nullimpl == 0) + _nullimpl = new TargetImpl; + return _nullimpl; + } + + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : TargetImpl::TargetImpl + // METHOD TYPE : Ctor + // + TargetImpl::TargetImpl(const Pathname & root_r) + : _root(root_r) + { + _rpm.initDatabase(); + MIL << "Initialized target on " << _root << endl; + } + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : TargetImpl::~TargetImpl + // METHOD TYPE : Dtor + // + TargetImpl::~TargetImpl() + { + _rpm.closeDatabase(); + MIL << "Targets closed" << endl; + } + + const ResStore & TargetImpl::resolvables() + { + _store.clear(); + // RPM objects + std::list packages = _rpm.getPackages(); + for (std::list::const_iterator it = packages.begin(); + it != packages.end(); + it++) + { + _store.insert(*it); + } + // TODO objects from the XML store + return _store; + } + + rpm::RpmDb & TargetImpl::rpm() + { return _rpm; } + + ///////////////////////////////////////////////////////////////// + } // namespace target + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/target/TargetImpl.h b/zypp/target/TargetImpl.h new file mode 100644 index 0000000..ee63bbb --- /dev/null +++ b/zypp/target/TargetImpl.h @@ -0,0 +1,93 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/target/TargetImpl.h + * +*/ +#ifndef ZYPP_TARGET_TARGETIMPL_H +#define ZYPP_TARGET_TARGETIMPL_H + +#include + +#include "zypp/base/ReferenceCounted.h" +#include "zypp/base/NonCopyable.h" +#include "zypp/base/PtrTypes.h" +#include "zypp/ResStore.h" + +#include "zypp/Pathname.h" +#include "zypp/media/MediaAccess.h" +#include "zypp/Target.h" +#include "zypp/target/rpm/RpmDb.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace target + { ///////////////////////////////////////////////////////////////// + + DEFINE_PTR_TYPE(TargetImpl); + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : TargetImpl + // + /** Base class for concrete Target implementations. + * + * Constructed by \ref TargetFactory. Public access via \ref Target + * interface. + */ + class TargetImpl : public base::ReferenceCounted, private base::NonCopyable + { + friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj ); + + public: + /** Ctor. */ + TargetImpl(const Pathname & root_r = "/"); + /** Dtor. */ + virtual ~TargetImpl(); + + /** Null implementation */ + static TargetImpl_Ptr nullimpl(); + + public: + + /** All resolvables in the target. */ + const ResStore & resolvables(); + + /** Overload to realize stream output. */ + virtual std::ostream & dumpOn( std::ostream & str ) const + { return str << "TargetImpl"; } + + /** The RPM database */ + rpm::RpmDb & rpm(); + + protected: + /** All resolvables provided by the target. */ + ResStore _store; + /** Path to the target */ + Pathname _root; + /** RPM database */ + rpm::RpmDb _rpm; + private: + /** Null implementation */ + static TargetImpl_Ptr _nullimpl; + }; + /////////////////////////////////////////////////////////////////// + + /** \relates TargetImpl Stream output */ + inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj ) + { return obj.dumpOn( str ); } + + ///////////////////////////////////////////////////////////////// + } // namespace target + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_TARGET_TARGETIMPL_H diff --git a/zypp/zypp_detail/ZYppImpl.cc b/zypp/zypp_detail/ZYppImpl.cc index a157bf4..fea8c05 100644 --- a/zypp/zypp_detail/ZYppImpl.cc +++ b/zypp/zypp_detail/ZYppImpl.cc @@ -53,6 +53,28 @@ namespace zypp _pool.erase(*it); } } + + Target_Ptr ZYppImpl::target() const + { + if (! _target) + ZYPP_THROW(Exception("Target not initialized.")); + return _target; + } + + void ZYppImpl::initTarget(const Pathname & root) + { + if (_target) + _target = Target_Ptr(); +#warning FIXME does this release the memory? _target is intrusive_ptr. Once more below... + _target = new Target(root); + } + + void ZYppImpl::finishTarget() + { +// if (_target) +// _target = 0; + _target = 0; + } /****************************************************************** ** diff --git a/zypp/zypp_detail/ZYppImpl.h b/zypp/zypp_detail/ZYppImpl.h index e50db2d..6aa885f 100644 --- a/zypp/zypp_detail/ZYppImpl.h +++ b/zypp/zypp_detail/ZYppImpl.h @@ -15,7 +15,7 @@ #include #include "zypp/ResPoolManager.h" -#include "zypp/SourceManager.h" +#include "zypp/Target.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -47,10 +47,27 @@ namespace zypp void addResolvables (const ResStore& store); void removeResolvables (const ResStore& store); + + /** + * \throws Exception + */ + Target_Ptr target() const; + + /** + * \throws Exception + */ + void initTarget(const Pathname & root); + + /** + * \throws Exception + */ + void finishTarget(); private: /** */ ResPoolManager _pool; + /** */ + Target_Ptr _target; }; /////////////////////////////////////////////////////////////////// -- 2.7.4