SourceCacher will be the class responsible for:
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 28 Jun 2006 16:07:23 +0000 (16:07 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 28 Jun 2006 16:07:23 +0000 (16:07 +0000)
- download metadata (and checking)
- insert data to cache (not directly, trough SourceCache)
- mean to be subclassed by YUM and SuSEtags

SourceCache:
- recives structs with data and inserts into the database

Later, we introduce a source which uses SourceCache to create
resolvables

zypp/CheckSum.h
zypp/cache/Makefile.am
zypp/cache/SourceCache.cpp [moved from zypp/cache/KnownSourcesCache.cpp with 51% similarity]
zypp/cache/SourceCache.h [moved from zypp/cache/KnownSourcesCache.h with 81% similarity]
zypp/cache/SourceCacher.cpp [new file with mode: 0644]
zypp/cache/SourceCacher.h [new file with mode: 0644]
zypp/source/SourceInfo.cc
zypp/source/SourceInfo.h

index 22bf5f2..a22eb77 100644 (file)
@@ -45,11 +45,13 @@ namespace zypp
 
     std::string type() const
     { return _type; }
+    
     std::string checksum() const
     { return _checksum; }
 
     bool empty() const
     { return (checksum().empty() || type().empty()); }
+    
   private:
     std::string _type;
     std::string _checksum;
index 6627338..48abe15 100644 (file)
@@ -6,7 +6,7 @@ INCLUDES = -DZYPP_BASE_LOGGER_LOGGROUP=\"cache\"
 
 cacheincludedir = $(pkgincludedir)/cache
 
-cacheinclude_HEADERS = KnownSourcesCache.h
+cacheinclude_HEADERS = SourceCache.h SourceCacher.h
 
 ## ##################################################
 
@@ -14,7 +14,7 @@ noinst_LTLIBRARIES =  lib@PACKAGE@_cache.la
 
 ## ##################################################
 
-lib@PACKAGE@_cache_la_SOURCES =        KnownSourcesCache.cpp
+lib@PACKAGE@_cache_la_SOURCES =        SourceCache.cpp SourceCacher.cpp
 
 lib@PACKAGE@_cache_la_LDFLAGS = @LIBZYPP_VERSION_INFO@
 
similarity index 51%
rename from zypp/cache/KnownSourcesCache.cpp
rename to zypp/cache/SourceCache.cpp
index 9f51603..9a164c9 100644 (file)
@@ -7,8 +7,11 @@
 |                                                                      |
 \---------------------------------------------------------------------*/
 
+#include <vector>
+
 #include "zypp/base/Logger.h"
-#include "zypp/cache/KnownSourcesCache.h"
+#include "zypp/base/String.h"
+#include "zypp/cache/SourceCache.h"
 #include "zypp/target/store/PersistentStorage.h"
 #include "zypp/cache/sqlite3x/sqlite3x.hpp"
 
@@ -24,7 +27,45 @@ namespace zypp
 namespace cache
 { /////////////////////////////////////////////////////////////////
 
-KnownSourcesCache::KnownSourcesCache( const Pathname &root_r )
+static int int_to_tribool( boost::tribool b )
+{
+  if (b)
+    return 1;
+  else if (!b)
+    return 0;
+  else
+    return 2;
+}  
+  
+static boost::tribool b tribool_to_int( int i )
+{
+  if (i==1)
+    return true;
+  else if (i==0)
+    return false;
+  else
+    return boost;indeterminate;
+}
+  
+static std::string checksum_to_string( const CheckSum &checksum )
+{
+  return checksum.type() + ":" checksum.checksum();
+}  
+  
+static CheckSum string_to_checksum( const std::string &checksum )
+{
+  std::vector<std::string> words;
+  if ( str::split( checksum, std::back_inserter(words), ":" ) != 2 )
+    return CheckSum();
+  
+  return CheckSum( words[0], words[19);
+}
+  
+#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
+  
+SourceCache::SourceCache( const Pathname &root_r )
 {
   try
   {
@@ -34,7 +75,7 @@ KnownSourcesCache::KnownSourcesCache( const Pathname &root_r )
       int count = con.executeint("select count(*) from sqlite_master where type='table' and name='sources';");
       if( count==0 )
       {
-        con.executenonquery("create table sources (  id integer primary key autoincrement,  alias varchar,  url varchar,  description varchar,  enabled integer, autorefresh integer, type varchar, cachedir varchar, path varchar);");
+        con.executenonquery(SOURCES_TABLE_SCHEMA);
         
         try
         {
@@ -61,11 +102,11 @@ KnownSourcesCache::KnownSourcesCache( const Pathname &root_r )
   } 
 }
 
-KnownSourcesCache::~KnownSourcesCache()
+SourceCache::~SourceCache()
 {
 }
 
-source::SourceInfoList KnownSourcesCache::knownSources() const
+source::SourceInfoList SourceCache::knownSources() const
 {
   source::SourceInfoList sources;
   
@@ -78,14 +119,17 @@ source::SourceInfoList KnownSourcesCache::knownSources() const
 
       while(reader.read())
       {
+        // alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8
         source::SourceInfo info;
-        info.setAlias(reader.getstring(1));
-        info.setUrl(reader.getstring(2));
-        info.setEnabled( (reader.getint(4) == 1 ) ? true : false );
-        info.setAutorefresh( (reader.getint(5) == 1 ) ? true : false );
-        info.setType(reader.getstring(6));
-        info.setCacheDir(reader.getstring(7));
-        info.setPath(reader.getstring(8));
+        info.setAlias(reader.getstring(0));
+        info.setType(reader.getstring(1));
+        info.setDescription(reader.getstring(2));
+        info.setUrl(reader.getstring(3));
+        info.setPath(reader.getstring(4));
+        info.setEnabled( int_to_tribool(reader.getint(5)) );
+        info.setAutorefresh( int_to_tribool( reader.getint(6) ));
+        info.setTimestamp(reader.getstring(7));
+        info.setChecksum(string_to_checksum(reader.getstring(8)));
         sources.push_back(info);
       }
     }
@@ -97,7 +141,7 @@ source::SourceInfoList KnownSourcesCache::knownSources() const
   return sources;
 }
 
-void KnownSourcesCache::storeSource( const source::SourceInfo &info )
+void SourceCache::storeSource( const source::SourceInfo &info )
 {
   try
   {
@@ -105,15 +149,18 @@ void KnownSourcesCache::storeSource( const source::SourceInfo &info )
     sqlite3_transaction trans(con);
 
     {
-      sqlite3_command cmd(con, "insert into sources ( alias, url, description, enabled, autorefresh, type, cachedir, path) values ( ?, ?, ?, ? , ?, ?, ?, ?);");
-      cmd.bind(1, info.alias());
-      cmd.bind(2, info.url().asCompleteString());
-      // FIXME no description
-      cmd.bind(4, info.enabled() ? 1 : 0 );
-      cmd.bind(5, info.autorefresh() ? 1 : 0 );
-      cmd.bind(6, info.type());
-      cmd.bind(7, info.cacheDir().asString());
-      cmd.bind(8, info.path().asString());
+      // alias 0 , type 1, desc 2, url 3, path 4, enabled 5, autorefresh 6, timestamp 7, checksum 8
+        
+      sqlite3_command cmd(con, "insert into sources ( alias, type, description, url, path, enabled, autorefresh, timestamp, checksum ) values ( ?, ?, ?, ? , ?, ?, ?, ?, ?);");
+      cmd.bind(0, info.alias());
+      cmd.bind(1, info.type());
+      cmd.bind(2, info.description());
+      cmd.bind(3, info.url().asCompleteString());
+      cmd.bind(4, info.path().asString());
+      cmd.bind(5, tribool_to_int(info.enabled()) );
+      cmd.bind(6, tribool_to_int(info.autorefresh()) );
+      cmd.bind(7, info.timestamp().asString());
+      cmd.bind(8, checksum_to_string(info.checksum()) );
       
       cmd.executenonquery();
     }
@@ -127,7 +174,7 @@ void KnownSourcesCache::storeSource( const source::SourceInfo &info )
   }
 } 
 
-std::ostream & KnownSourcesCache::dumpOn( std::ostream & str ) const
+std::ostream & SourceCache::dumpOn( std::ostream & str ) const
 {
   return str;
 }
similarity index 81%
rename from zypp/cache/KnownSourcesCache.h
rename to zypp/cache/SourceCache.h
index 567d6d8..6bc620d 100644 (file)
@@ -6,11 +6,11 @@
 |                         /_____||_| |_| |_|                           |
 |                                                                      |
 \---------------------------------------------------------------------*/
-/** \file      zypp/KnownSourcesCache.h
+/** \file      zypp/SourceCache.h
  *
 */
-#ifndef ZYPP_KnownSourcesCache_H
-#define ZYPP_KnownSourcesCache_H
+#ifndef ZYPP_SourceCache_H
+#define ZYPP_SourceCache_H
 
 #include <iosfwd>
 #include <string>
@@ -28,20 +28,20 @@ namespace zypp
   namespace cache
   { /////////////////////////////////////////////////////////////////
 
-    DEFINE_PTR_TYPE(KnownSourcesCache);
+    DEFINE_PTR_TYPE(SourceCache);
 
     ///////////////////////////////////////////////////////////////////
     //
-    // CLASS NAME : KnownSourcesCache
+    // CLASS NAME : SourceCache
     //
-    class KnownSourcesCache : public base::ReferenceCounted, private base::NonCopyable
+    class SourceCache : public base::ReferenceCounted, private base::NonCopyable
     {
-      friend std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj );
+      friend std::ostream & operator<<( std::ostream & str, const SourceCache & obj );
 
     public:
       /** root path */
-      KnownSourcesCache( const Pathname &root_r );
-      ~KnownSourcesCache();
+      SourceCache( const Pathname &root_r );
+      ~SourceCache();
       source::SourceInfoList knownSources() const;
       void storeSource( const source::SourceInfo &info );    
     protected:
@@ -52,8 +52,8 @@ namespace zypp
     };
     ///////////////////////////////////////////////////////////////////
 
-    /** \relates KnownSourcesCache Stream output */
-    inline std::ostream & operator<<( std::ostream & str, const KnownSourcesCache & obj )
+    /** \relates SourceCache Stream output */
+    inline std::ostream & operator<<( std::ostream & str, const SourceCache & obj )
     { return obj.dumpOn( str ); }
 
 
@@ -63,4 +63,4 @@ namespace zypp
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
-#endif // ZYPP_SOURCE_KnownSourcesCache_H
+#endif // ZYPP_SOURCE_SourceCache_H
diff --git a/zypp/cache/SourceCacher.cpp b/zypp/cache/SourceCacher.cpp
new file mode 100644 (file)
index 0000000..d03c45e
--- /dev/null
@@ -0,0 +1,33 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+
+#include "zypp/base/Logger.h"
+#include "zypp/cache/SourceCacher.h"
+
+using namespace std;
+
+//////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////
+namespace cache
+{ /////////////////////////////////////////////////////////////////
+
+SourceCacher::SourceCacher( const Pathname &root_r )
+{
+}
+
+SourceCacher::~SourceCacher()
+{
+}
+
+
+}
+}
+
diff --git a/zypp/cache/SourceCacher.h b/zypp/cache/SourceCacher.h
new file mode 100644 (file)
index 0000000..c0b0162
--- /dev/null
@@ -0,0 +1,64 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/SourceCacher.h
+ *
+*/
+#ifndef ZYPP_SourceCacher_H
+#define ZYPP_SourceCacher_H
+
+#include <iosfwd>
+#include <string>
+
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/source/SourceInfo.h"
+#include "zypp/Pathname.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace cache
+  { /////////////////////////////////////////////////////////////////
+
+    DEFINE_PTR_TYPE(SourceCacher);
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : SourceCacher
+    //
+    class SourceCacher : public base::ReferenceCounted, private base::NonCopyable
+    {
+      friend std::ostream & operator<<( std::ostream & str, const SourceCacher & obj );
+
+    public:
+      /** root path */
+      SourceCacher( const Pathname &root_r );
+      ~SourceCacher();
+    protected:
+
+      /** Overload to realize stream output. */
+      virtual std::ostream & dumpOn( std::ostream & str ) const;
+      //typedef std::map<media::MediaNr, media::MediaAccessId> MediaMap
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /** \relates SourceCacher Stream output */
+    inline std::ostream & operator<<( std::ostream & str, const SourceCacher & obj )
+    { return obj.dumpOn( str ); }
+
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace cache
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_SourceCacher_H
index d3f2b8e..adc1862 100644 (file)
@@ -82,6 +82,24 @@ namespace source
     return *this;
   }
      
+  SourceInfo & SourceInfo::setDescription( const std::string &description )
+  {
+    _description = description;
+    return *this;
+  }
+  
+  SourceInfo & SourceInfo::setChecksum( const CheckSum &checksum )
+  {
+    _checksum = checksum;
+    return *this;
+  }
+  
+  SourceInfo & SourceInfo::setTimesamp( const Date &timestamp )
+  {
+    _timestamp = timestamp;
+    return *this;
+  }
+  
   tribool SourceInfo::enabled() const
   { return _enabled; }
         
@@ -96,7 +114,16 @@ namespace source
     
   std::string SourceInfo::alias() const
   { return _alias; }
+  
+  std::string SourceInfo::description() const
+  { return _description; }
     
+  CheckSum SourceInfo::checksum() const
+  { return _checksum; }
+  
+  Date SourceInfo::timestamp() const
+  { return _timestamp; }
+  
   std::string SourceInfo::type() const
   { return _type; }
     
index 94fa5bc..99544ce 100644 (file)
@@ -17,6 +17,8 @@
 #include <boost/logic/tribool.hpp>
 #include "zypp/Pathname.h"
 #include "zypp/Url.h"
+#include "zypp/CheckSum.h"
+#include "zypp/Date.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -39,14 +41,21 @@ namespace source
     SourceInfo & setAlias( const std::string &alias );
     SourceInfo & setType( const std::string &t );
     SourceInfo & setCacheDir( const Pathname &p );
+    SourceInfo & setDescription( const std::string &description );
+    SourceInfo & setChecksum( const CheckSum &checksum );
+    SourceInfo & setTimesamp( const Date &timestamp );
     boost::tribool enabled() const;
     boost::tribool autorefresh() const;
     Pathname cacheDir() const;
     Pathname path() const;
     std::string alias() const;
     std::string type() const;
+    std::string description() const;
+    CheckSum checksum() const;
+    Date timestamp() const;
     Url url() const;
     
+    
     /** Overload to realize stream output. */
     std::ostream & dumpOn( std::ostream & str ) const;
     
@@ -59,6 +68,9 @@ namespace source
     Pathname _cache_dir;
     Pathname _path;
     std::string _alias;
+    std::string _description;
+    CheckSum _checksum;
+    Date _timestamp;
   };  
   
   /** \relates SourceInfo Stream output */