apt @VERSION@
algorithms.h
00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: algorithms.h,v 1.10 2001/05/22 04:17:41 jgg Exp $
00004 /* ######################################################################
00005 
00006    Algorithms - A set of misc algorithms
00007    
00008    This simulate class displays what the ordering code has done and
00009    analyses it with a fresh new dependency cache. In this way we can
00010    see all of the effects of an upgrade run.
00011 
00012    pkgDistUpgrade computes an upgrade that causes as many packages as
00013    possible to move to the newest verison.
00014    
00015    pkgApplyStatus sets the target state based on the content of the status
00016    field in the status file. It is important to get proper crash recovery.
00017 
00018    pkgFixBroken corrects a broken system so that it is in a sane state.
00019  
00020    pkgAllUpgrade attempts to upgade as many packages as possible but 
00021    without installing new packages.
00022    
00023    The problem resolver class contains a number of complex algorithms
00024    to try to best-guess an upgrade state. It solves the problem of 
00025    maximizing the number of install state packages while having no broken
00026    packages. 
00027 
00028    ##################################################################### */
00029                                                                         /*}}}*/
00030 #ifndef PKGLIB_ALGORITHMS_H
00031 #define PKGLIB_ALGORITHMS_H
00032 
00033 
00034 #include <apt-pkg/packagemanager.h>
00035 #include <apt-pkg/depcache.h>
00036 
00037 #include <iostream>
00038 
00039 class pkgAcquireStatus;
00040 
00041 class pkgSimulate : public pkgPackageManager                            /*{{{*/
00042 {
00043    protected:
00044 
00045    class Policy : public pkgDepCache::Policy
00046    {
00047       pkgDepCache *Cache;
00048       public:
00049       
00050       virtual VerIterator GetCandidateVer(PkgIterator const &Pkg)
00051       {
00052          return (*Cache)[Pkg].CandidateVerIter(*Cache);
00053       }
00054       
00055       Policy(pkgDepCache *Cache) : Cache(Cache) {};
00056    };
00057    
00058    unsigned char *Flags;
00059    
00060    Policy iPolicy;
00061    pkgDepCache Sim;
00062    pkgDepCache::ActionGroup group;
00063    
00064    // The Actuall installation implementation
00065    virtual bool Install(PkgIterator Pkg,std::string File);
00066    virtual bool Configure(PkgIterator Pkg);
00067    virtual bool Remove(PkgIterator Pkg,bool Purge);
00068 
00069 private:
00070    void ShortBreaks();
00071    void Describe(PkgIterator iPkg,std::ostream &out,bool Current,bool Candidate);
00072    
00073    public:
00074 
00075    pkgSimulate(pkgDepCache *Cache);
00076 };
00077                                                                         /*}}}*/
00078 class pkgProblemResolver                                                /*{{{*/
00079 {
00081    void *d;
00082 
00083    pkgDepCache &Cache;
00084    typedef pkgCache::PkgIterator PkgIterator;
00085    typedef pkgCache::VerIterator VerIterator;
00086    typedef pkgCache::DepIterator DepIterator;
00087    typedef pkgCache::PrvIterator PrvIterator;
00088    typedef pkgCache::Version Version;
00089    typedef pkgCache::Package Package;
00090    
00091    enum Flags {Protected = (1 << 0), PreInstalled = (1 << 1),
00092                Upgradable = (1 << 2), ReInstateTried = (1 << 3),
00093                ToRemove = (1 << 4)};
00094    signed short *Scores;
00095    unsigned char *Flags;
00096    bool Debug;
00097    
00098    // Sort stuff
00099    static pkgProblemResolver *This;
00100    static int ScoreSort(const void *a,const void *b);
00101 
00102    struct PackageKill
00103    {
00104       PkgIterator Pkg;
00105       DepIterator Dep;
00106    };
00107 
00108    void MakeScores();
00109    bool DoUpgrade(pkgCache::PkgIterator Pkg);
00110 
00111    bool ResolveInternal(bool const BrokenFix = false);
00112    bool ResolveByKeepInternal();
00113    
00114    protected:
00115    bool InstOrNewPolicyBroken(pkgCache::PkgIterator Pkg);
00116 
00117    public:
00118    
00119    inline void Protect(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= Protected; Cache.MarkProtected(Pkg);};
00120    inline void Remove(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] |= ToRemove;};
00121    inline void Clear(pkgCache::PkgIterator Pkg) {Flags[Pkg->ID] &= ~(Protected | ToRemove);};
00122    
00123    // Try to intelligently resolve problems by installing and removing packages   
00124    bool Resolve(bool BrokenFix = false);
00125    
00126    // Try to resolve problems only by using keep
00127    bool ResolveByKeep();
00128 
00129    // Install all protected packages   
00130    void InstallProtect();   
00131    
00132    pkgProblemResolver(pkgDepCache *Cache);
00133    ~pkgProblemResolver();
00134 };
00135                                                                         /*}}}*/
00136 bool pkgDistUpgrade(pkgDepCache &Cache);
00137 bool pkgApplyStatus(pkgDepCache &Cache);
00138 bool pkgFixBroken(pkgDepCache &Cache);
00139 bool pkgAllUpgrade(pkgDepCache &Cache);
00140 bool pkgMinimizeUpgrade(pkgDepCache &Cache);
00141 
00142 void pkgPrioSortList(pkgCache &Cache,pkgCache::Version **List);
00143 
00144 bool ListUpdate(pkgAcquireStatus &progress, pkgSourceList &List, int PulseInterval=0);
00145                      
00146 #endif