Author: mlandres
Date: Thu Jul 19 17:13:51 2007
New Revision: 6108
URL: http://svn.opensuse.org/viewcvs/zypp?rev=6108&view=rev
Log:
changed ZConfig to become a singleton
Modified:
trunk/libzypp/zypp/RepoManager.cc
trunk/libzypp/zypp/TranslatedText.cc
trunk/libzypp/zypp/ZConfig.cc
trunk/libzypp/zypp/ZConfig.h
trunk/libzypp/zypp/cache/CacheStore.h
trunk/libzypp/zypp/cache/ResolvableQuery.h
trunk/libzypp/zypp/parser/susetags/ContentFileReader.cc
trunk/libzypp/zypp/parser/susetags/RepoParser.cc
Modified: trunk/libzypp/zypp/RepoManager.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/RepoManager.cc?rev=6108&r1=6107&r2=6108&view=diff
==============================================================================
--- trunk/libzypp/zypp/RepoManager.cc (original)
+++ trunk/libzypp/zypp/RepoManager.cc Thu Jul 19 17:13:51 2007
@@ -57,10 +57,9 @@
RepoManagerOptions::RepoManagerOptions()
{
- ZConfig globalConfig;
- repoCachePath = globalConfig.defaultRepoCachePath();
- repoRawCachePath = globalConfig.defaultRepoRawCachePath();
- knownReposPath = globalConfig.defaultKnownReposPath();
+ repoCachePath = ZConfig::instance().defaultRepoCachePath();
+ repoRawCachePath = ZConfig::instance().defaultRepoRawCachePath();
+ knownReposPath = ZConfig::instance().defaultKnownReposPath();
}
////////////////////////////////////////////////////////////////////////////
@@ -252,7 +251,7 @@
std::list<RepoInfo> RepoManager::knownRepositories() const
{
MIL << endl;
-
+
if ( PathInfo(_pimpl->options.knownReposPath).isExist() )
return repositories_in_dir(_pimpl->options.knownReposPath);
else
@@ -292,7 +291,7 @@
status = RepoStatus( rawpath + "/content");
}
break;
-
+
case RepoType::RPMPLAINDIR_e :
{
if ( PathInfo(Pathname(rawpath + "/cookie")).isExist() )
@@ -308,7 +307,7 @@
}
return status;
}
-
+
void RepoManager::refreshMetadata( const RepoInfo &info,
RawMetadataRefreshPolicy policy,
const ProgressData::ReceiverFnc & progress )
@@ -347,12 +346,12 @@
{
MediaSetAccess media(url);
shared_ptrrepo::Downloader downloader_ptr;
-
+
if ( repokind.toEnum() == RepoType::RPMMD_e )
downloader_ptr.reset(new yum::Downloader(info.path()));
else
downloader_ptr.reset( new susetags::Downloader(info.path()));
-
+
/**
* Given a downloader, sets the other repos raw metadata
* path as cache paths for the fetcher, so if another
@@ -366,7 +365,7 @@
{
downloader_ptr->addCachePath(rawcache_path_for_repoinfo( _pimpl->options, *it ));
}
-
+
RepoStatus newstatus = downloader_ptr->status(media);
bool refresh = false;
if ( oldstatus.checksum() == newstatus.checksum() )
@@ -425,7 +424,7 @@
{
ZYPP_THROW(RepoUnknownTypeException());
}
-
+
// ok we have the metadata, now exchange
// the contents
TmpDir oldmetadata;
@@ -463,7 +462,7 @@
progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
progress.name(str::form(_("Building repository '%s' cache"), info.alias().c_str()));
progress.toMin();
-
+
assert_alias(info);
Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
@@ -513,7 +512,7 @@
}
CombinedProgressData subprogrcv( progress, 100);
-
+
switch ( repokind.toEnum() )
{
case RepoType::RPMMD_e :
@@ -593,7 +592,7 @@
progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
progress.name(str::form(_("Cleaning repository '%s' cache"), info.alias().c_str()));
progress.toMin();
-
+
cache::CacheStore store(_pimpl->options.repoCachePath);
data::RecordId id = store.lookupRepository(info.alias());
@@ -618,7 +617,7 @@
progress.sendTo( progressrcv );
progress.name(str::form(_("Reading repository '%s' cache"), info.alias().c_str()));
progress.toMin();
-
+
cache::CacheStore store(_pimpl->options.repoCachePath);
if ( ! store.isCached( info.alias() ) )
@@ -627,12 +626,12 @@
MIL << "Repository " << info.alias() << " is cached" << endl;
data::RecordId id = store.lookupRepository(info.alias());
-
+
repo::cached::RepoOptions opts( info, _pimpl->options.repoCachePath, id );
opts.readingResolvablesProgress = progressrcv;
repo::cached::RepoImpl::Ptr repoimpl =
new repo::cached::RepoImpl( opts );
-
+
repoimpl->resolvables();
// read the resolvables from cache
return Repository(repoimpl);
@@ -707,7 +706,7 @@
progress.sendTo( ProgressReportAdaptor( progressrcv, report ) );
progress.name(str::form(_("Adding repository '%s'"), info.alias().c_str()));
progress.toMin();
-
+
std::list<RepoInfo> repos = knownRepositories();
for ( std::list<RepoInfo>::const_iterator it = repos.begin();
it != repos.end();
@@ -718,10 +717,10 @@
}
progress.set(50);
-
+
// assert the directory exists
filesystem::assert_dir(_pimpl->options.knownReposPath);
-
+
Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath,
generate_filename(info));
// now we have a filename that does not exists
@@ -766,7 +765,7 @@
// assert the directory exists
filesystem::assert_dir(_pimpl->options.knownReposPath);
-
+
Pathname repofile = generate_non_existing_name(_pimpl->options.knownReposPath, filename);
// now we have a filename that does not exists
MIL << "Saving " << repos.size() << " repo" << ( repos.size() ? "s" : "" ) << " in " << repofile << endl;
@@ -833,10 +832,10 @@
// write them back except the deleted one.
//TmpFile tmp;
//std::ofstream file(tmp.path().c_str());
-
+
// assert the directory exists
filesystem::assert_dir(todelete.filepath().dirname());
-
+
std::ofstream file(todelete.filepath().c_str());
if (!file) {
//ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
@@ -888,10 +887,10 @@
// write them back except the deleted one.
//TmpFile tmp;
//std::ofstream file(tmp.path().c_str());
-
+
// assert the directory exists
filesystem::assert_dir(toedit.filepath().dirname());
-
+
std::ofstream file(toedit.filepath().c_str());
if (!file) {
//ZYPP_THROW (Exception( "Can't open " + tmp.path().asString() ) );
Modified: trunk/libzypp/zypp/TranslatedText.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/TranslatedText.cc?rev=6108&r1=6107&r2=6108&view=diff
==============================================================================
--- trunk/libzypp/zypp/TranslatedText.cc (original)
+++ trunk/libzypp/zypp/TranslatedText.cc Thu Jul 19 17:13:51 2007
@@ -52,7 +52,7 @@
Locale toReturn( lang );
if ( lang == Locale::noCode )
{
- toReturn = ZConfig().defaultTextLocale();
+ toReturn = ZConfig::instance().defaultTextLocale();
}
do
Modified: trunk/libzypp/zypp/ZConfig.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.cc?rev=6108&r1=6107&r2=6108&view=diff
==============================================================================
--- trunk/libzypp/zypp/ZConfig.cc (original)
+++ trunk/libzypp/zypp/ZConfig.cc Thu Jul 19 17:13:51 2007
@@ -23,6 +23,59 @@
///////////////////////////////////////////////////////////////////
//
+ // CLASS NAME : ZConfig::Impl
+ //
+ /** ZConfig implementation.
+ */
+ class ZConfig::Impl
+ {
+ public:
+ Impl()
+ {}
+
+ ~Impl()
+ {}
+
+ public:
+
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ZConfig::instance
+ // METHOD TYPE : ZConfig &
+ //
+ ZConfig & ZConfig::instance()
+ {
+ static ZConfig _instance; // The singleton
+ return _instance;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ZConfig::ZConfig
+ // METHOD TYPE : Ctor
+ //
+ ZConfig::ZConfig()
+ : _pimpl( new Impl )
+ {
+ MIL << "ZConfig singleton created." << endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // METHOD NAME : ZConfig::~ZConfig
+ // METHOD TYPE : Dtor
+ //
+ ZConfig::~ZConfig( )
+ {}
+
+ ///////////////////////////////////////////////////////////////////
+#warning change methods to use the singleton
+
+ ///////////////////////////////////////////////////////////////////
+ //
// METHOD NAME : ZConfig::systemArchitecture
// METHOD TYPE : Arch
//
@@ -45,17 +98,17 @@
{
return Pathname("/var/lib/zypp/cache/raw");
}
-
+
Pathname ZConfig::defaultRepoCachePath() const
{
return Pathname("/var/lib/zypp/cache");
}
-
+
Pathname ZConfig::defaultKnownReposPath() const
{
return Pathname("/etc/zypp/repos.d");
}
-
+
const std::string & ZConfig::cacheDBSplitJoinSeparator() const
{
static std::string s("!@$");
Modified: trunk/libzypp/zypp/ZConfig.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/ZConfig.h?rev=6108&r1=6107&r2=6108&view=diff
==============================================================================
--- trunk/libzypp/zypp/ZConfig.h (original)
+++ trunk/libzypp/zypp/ZConfig.h Thu Jul 19 17:13:51 2007
@@ -14,6 +14,9 @@
#include <iosfwd>
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+
#include "zypp/Arch.h"
#include "zypp/Locale.h"
#include "zypp/Pathname.h"
@@ -29,10 +32,16 @@
/** Interim helper class to collect global options and settings.
* Use it to avoid hardcoded values and calls to getZypp() just
* to retrieve some value like architecture, languages or tmppath.
+ *
+ * \ingroup Singleton
*/
- class ZConfig
+ class ZConfig : private base::NonCopyable
{
public:
+ /** Singleton ctor */
+ static ZConfig & instance();
+
+ public:
/** The system architecture. */
Arch systemArchitecture() const;
@@ -40,29 +49,39 @@
* descriptions, etc. passed to the UI.
*/
Locale defaultTextLocale() const;
-
+
/**
* Path where the repo metadata is downloaded and kept.
*/
Pathname defaultRepoRawCachePath() const;
-
+
/**
* Path where the processed cache is kept
* (this is where zypp.db is located.
*/
Pathname defaultRepoCachePath() const;
-
+
/**
* Path where the known repositories
* .repo files are kept
*/
Pathname defaultKnownReposPath() const;
-
+
/**
* Separator string for storing/reading sets of strings to/from
* metadata cache DB.
*/
const std::string & cacheDBSplitJoinSeparator() const;
+
+ public:
+ class Impl;
+ /** Dtor */
+ ~ZConfig();
+ private:
+ /** Default ctor. */
+ ZConfig();
+ /** Pointer to implementation */
+ RW_pointer