added implementation of target classes, which are container for target
authorJiri Srain <jsrain@suse.cz>
Fri, 27 Jan 2006 15:10:04 +0000 (15:10 +0000)
committerJiri Srain <jsrain@suse.cz>
Fri, 27 Jan 2006 15:10:04 +0000 (15:10 +0000)
storages (currently RPM is only added, XML not yet)

zypp/Makefile.am
zypp/Target.cc [new file with mode: 0644]
zypp/Target.h [new file with mode: 0644]
zypp/ZYpp.cc
zypp/ZYpp.h
zypp/target/Makefile.am
zypp/target/TargetImpl.cc [new file with mode: 0644]
zypp/target/TargetImpl.h [new file with mode: 0644]
zypp/zypp_detail/ZYppImpl.cc
zypp/zypp_detail/ZYppImpl.h

index bc72a58..06c2f58 100644 (file)
@@ -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 (file)
index 0000000..abdc614
--- /dev/null
@@ -0,0 +1,79 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/Target.cc
+ *
+*/
+#include <cassert>
+
+#include <iostream>
+
+#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<Impl, rw_pointer::Intrusive<Impl> >(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 (file)
index 0000000..38aff03
--- /dev/null
@@ -0,0 +1,87 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/Target.h
+ *
+*/
+#ifndef ZYPP_TARGET_H
+#define ZYPP_TARGET_H
+
+#include <iosfwd>
+
+#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> 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<Impl,rw_pointer::Intrusive<Impl> > _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
index e23ccbf..e4abc80 100644 (file)
@@ -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
 ///////////////////////////////////////////////////////////////////
index 33e8f7e..6b799d2 100644 (file)
@@ -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();
index 4c2e504..c25bc7d 100644 (file)
@@ -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 (file)
index 0000000..279dadd
--- /dev/null
@@ -0,0 +1,85 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/target/TargetImpl.cc
+ *
+*/
+#include <iostream>
+#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<Package::Ptr> packages = _rpm.getPackages();
+      for (std::list<Package::Ptr>::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 (file)
index 0000000..ee63bbb
--- /dev/null
@@ -0,0 +1,93 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/target/TargetImpl.h
+ *
+*/
+#ifndef ZYPP_TARGET_TARGETIMPL_H
+#define ZYPP_TARGET_TARGETIMPL_H
+
+#include <iosfwd>
+
+#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
index a157bf4..fea8c05 100644 (file)
@@ -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<Target>. Once more below...
+       _target = new Target(root);
+     }
+  
+    void ZYppImpl::finishTarget()
+    {
+//      if (_target)
+//     _target = 0;
+      _target = 0;
+    }
     
     /******************************************************************
      **
index e50db2d..6aa885f 100644 (file)
@@ -15,7 +15,7 @@
 #include <iosfwd>
 
 #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;
     };
     ///////////////////////////////////////////////////////////////////