1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQPkgSelMapper.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-pkg"
21 #include <ycp/y2log.h>
23 #include "YQPkgSelMapper.h"
27 int YQPkgSelMapper::_refCount = 0;
28 YQPkgSelMapper::Cache YQPkgSelMapper::_cache;
31 YQPkgSelMapper::YQPkgSelMapper()
33 if ( ++_refCount == 1 )
38 YQPkgSelMapper::~YQPkgSelMapper()
40 if ( --_refCount == 0 )
42 y2debug( "Destroying pkg -> selectable cache" );
48 void YQPkgSelMapper::rebuildCache()
51 y2debug( "Building pkg -> selectable cache" );
53 for ( ZyppPoolIterator sel_it = zyppPkgBegin();
54 sel_it != zyppPkgEnd();
57 ZyppSel sel = *sel_it;
59 if ( sel->installedObj() )
61 // The installed package (if there is any) may or may not be in the list
62 // of available packages. Better make sure to insert it.
64 ZyppPkg installedPkg = tryCastToZyppPkg( sel->installedObj() );
67 _cache.insert( CachePair( installedPkg, sel ) );
70 zypp::ui::Selectable::available_iterator it = sel->availableBegin();
72 while ( it != sel->availableEnd() )
74 ZyppPkg pkg = tryCastToZyppPkg( *it );
77 _cache.insert( CachePair( pkg, sel ) );
83 y2debug( "Building pkg -> selectable cache done" );
88 YQPkgSelMapper::findZyppSel( ZyppPkg pkg )
90 YQPkgSelMapper mapper; // This will build a cache, if there is none yet
93 YQPkgSelMapper::CacheIterator it = YQPkgSelMapper::_cache.find( pkg );
95 if ( it != YQPkgSelMapper::_cache.end() )
98 y2warning( "No selectable found for package %s", pkg->name().c_str() );