From: Duncan Mac-Vicar P Date: Wed, 28 Jun 2006 09:37:26 +0000 (+0000) Subject: - allow to set SourceInfo bools as undeterminate too. X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~589 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ba7b249d9817101c20f8fc1a9b68a776b6a326aa;p=platform%2Fupstream%2Flibzypp.git - allow to set SourceInfo bools as undeterminate too. - implement knownSources() - test it in a test program --- diff --git a/zypp/cache/KnownSourcesCache.cpp b/zypp/cache/KnownSourcesCache.cpp index bf0c88a..9f51603 100644 --- a/zypp/cache/KnownSourcesCache.cpp +++ b/zypp/cache/KnownSourcesCache.cpp @@ -67,7 +67,34 @@ KnownSourcesCache::~KnownSourcesCache() source::SourceInfoList KnownSourcesCache::knownSources() const { - return source::SourceInfoList(); + source::SourceInfoList sources; + + try { + sqlite3_connection con(ZYPP_DB_FILE); + + { + sqlite3_command cmd(con, "select * from sources;"); + sqlite3_reader reader = cmd.executereader(); + + while(reader.read()) + { + 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)); + sources.push_back(info); + } + } + con.close(); + } + catch(exception &ex) { + ERR << "Exception Occured: " << ex.what() << endl; + } + return sources; } void KnownSourcesCache::storeSource( const source::SourceInfo &info ) @@ -81,12 +108,12 @@ void KnownSourcesCache::storeSource( const source::SourceInfo &info ) 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 + // FIXME no description cmd.bind(4, info.enabled() ? 1 : 0 ); cmd.bind(5, info.autorefresh() ? 1 : 0 ); cmd.bind(6, info.type()); - cmd.bind(6, info.cacheDir().asString()); - cmd.bind(7, info.path().asString()); + cmd.bind(7, info.cacheDir().asString()); + cmd.bind(8, info.path().asString()); cmd.executenonquery(); } diff --git a/zypp/parser/xmlstore/XMLSourceCacheParser.cc b/zypp/parser/xmlstore/XMLSourceCacheParser.cc index fb20230..326bf42 100644 --- a/zypp/parser/xmlstore/XMLSourceCacheParser.cc +++ b/zypp/parser/xmlstore/XMLSourceCacheParser.cc @@ -67,7 +67,7 @@ namespace xmlstore { else if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") ) dataPtr->setEnabled(false); else - dataPtr->setEnabled(indeterminate); + dataPtr->setEnabled(boost::indeterminate); } else if (name == "auto-refresh") { @@ -76,7 +76,7 @@ namespace xmlstore { if ( (_helper.content(child) == "false") || (_helper.content(child) == "0") ) dataPtr->setAutorefresh(false); else - dataPtr->setAutorefresh(indeterminate); + dataPtr->setAutorefresh(boost::indeterminate); } else if (name == "type") { diff --git a/zypp/source/SourceInfo.cc b/zypp/source/SourceInfo.cc index 5074fc4..d3f2b8e 100644 --- a/zypp/source/SourceInfo.cc +++ b/zypp/source/SourceInfo.cc @@ -11,15 +11,110 @@ */ #include +#include #include "zypp/source/SourceInfo.h" +using namespace boost; + /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// namespace source { + SourceInfo::SourceInfo() : + _enabled (indeterminate), + _autorefresh(indeterminate) + { + + } + + SourceInfo::SourceInfo( const Url & url, const Pathname & path, const std::string & alias, const Pathname & cache_dir, tribool autorefresh) + : _enabled (true), + _autorefresh(autorefresh), + _url(url), + _cache_dir(cache_dir), + _path(path), + _alias(alias) + { + + } + + SourceInfo & SourceInfo::setEnabled( boost::tribool enabled ) + { + _enabled = enabled; + return *this; + } + + SourceInfo & SourceInfo::setAutorefresh( boost::tribool autorefresh ) + { + _autorefresh = autorefresh; + return *this; + } + + SourceInfo & SourceInfo::setUrl( const Url &url ) + { + _url = url; + return *this; + } + + SourceInfo & SourceInfo::setPath( const Pathname &p ) + { + _path = p; + return *this; + } + + SourceInfo & SourceInfo::setAlias( const std::string &alias ) + { + _alias = alias; + return *this; + } + + SourceInfo & SourceInfo::setType( const std::string &t ) + { + _type = t; + return *this; + } + + SourceInfo & SourceInfo::setCacheDir( const Pathname &p ) + { + _cache_dir = p; + return *this; + } + + tribool SourceInfo::enabled() const + { return _enabled; } + + tribool SourceInfo::autorefresh() const + { return _enabled; } + + Pathname SourceInfo::cacheDir() const + { return _cache_dir; } + + Pathname SourceInfo::path() const + { return _path; } + + std::string SourceInfo::alias() const + { return _alias; } + + std::string SourceInfo::type() const + { return _type; } + + Url SourceInfo::url() const + { return _url; } + std::ostream & SourceInfo::dumpOn( std::ostream & str ) const + { + str << "--------------------------------------" << std::endl; + str << "- alias : " << alias() << std::endl; + str << "- url : " << url() << std::endl; + str << "- type : " << type() << std::endl; + str << "- enabled : " << enabled() << std::endl; + str << "- autorefresh : " << autorefresh() << std::endl; + str << "- path : " << path() << std::endl; + str << "- cache_dir : " << cacheDir() << std::endl; + return str; + } } ///////////////////////////////////////////////////////////////// diff --git a/zypp/source/SourceInfo.h b/zypp/source/SourceInfo.h index 942ab61..94fa5bc 100644 --- a/zypp/source/SourceInfo.h +++ b/zypp/source/SourceInfo.h @@ -18,8 +18,6 @@ #include "zypp/Pathname.h" #include "zypp/Url.h" -using namespace boost; - /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// @@ -30,91 +28,32 @@ namespace source { public: - SourceInfo() : - _enabled (indeterminate), - _autorefresh(indeterminate) - { - - } - - SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", tribool autorefresh = indeterminate) - : _enabled (true), - _autorefresh(autorefresh), - _url(url), - _cache_dir(cache_dir), - _path(path), - _alias(alias) - { - - } - - SourceInfo & setEnabled( bool enabled ) - { - _enabled = enabled; - return *this; - } - - SourceInfo & setAutorefresh( bool autorefresh ) - { - _autorefresh = autorefresh; - return *this; - } - - SourceInfo & setUrl( const Url &url ) - { - _url = url; - return *this; - } + SourceInfo(); - SourceInfo & setPath( const Pathname &p ) - { - _path = p; - return *this; - } + SourceInfo( const Url & url, const Pathname & path, const std::string & alias = "", const Pathname & cache_dir = "", boost::tribool autorefresh = boost::indeterminate); - SourceInfo & setAlias( const std::string &alias ) - { - _alias = alias; - return *this; - } + SourceInfo & setEnabled( boost::tribool enabled ); + SourceInfo & setAutorefresh( boost::tribool autorefresh ); + SourceInfo & setUrl( const Url &url ); + SourceInfo & setPath( const Pathname &p ); + SourceInfo & setAlias( const std::string &alias ); + SourceInfo & setType( const std::string &t ); + SourceInfo & setCacheDir( const Pathname &p ); + boost::tribool enabled() const; + boost::tribool autorefresh() const; + Pathname cacheDir() const; + Pathname path() const; + std::string alias() const; + std::string type() const; + Url url() const; - SourceInfo & setType( const std::string &t ) - { - _type = t; - return *this; - } - - SourceInfo & setCacheDir( const Pathname &p ) - { - _cache_dir = p; - return *this; - } - - tribool enabled() const - { return _enabled; } - - tribool autorefresh() const - { return _enabled; } - - Pathname cacheDir() const - { return _cache_dir; } - - Pathname path() const - { return _path; } - - std::string alias() const - { return _alias; } - - std::string type() const - { return _type; } - - Url url() const - { return _url; } + /** Overload to realize stream output. */ + std::ostream & dumpOn( std::ostream & str ) const; private: - tribool _enabled; - tribool _autorefresh; + boost::tribool _enabled; + boost::tribool _autorefresh; std::string _type; Url _url; Pathname _cache_dir; @@ -122,6 +61,10 @@ namespace source std::string _alias; }; + /** \relates SourceInfo Stream output */ + inline std::ostream & operator<<( std::ostream & str, const SourceInfo & obj ) + { return obj.dumpOn( str ); } + typedef std::list SourceInfoList; } ///////////////////////////////////////////////////////////////// diff --git a/zypp/target/store/serialize.cc b/zypp/target/store/serialize.cc index 3ebf376..d31ead5 100644 --- a/zypp/target/store/serialize.cc +++ b/zypp/target/store/serialize.cc @@ -55,7 +55,7 @@ static std::string xml_tag_enclose( const std::string &text, const std::string & return result; } -static std::ostream & operator<<( std::ostream & str, const tribool obj ) +static std::ostream & operator<<( std::ostream & str, const boost::tribool obj ) { if (obj) return str << "true";