apt @VERSION@

dpkgpm.h

00001 // -*- mode: cpp; mode: fold -*-
00002 // Description                                                          /*{{{*/
00003 // $Id: dpkgpm.h,v 1.8 2001/05/07 05:05:13 jgg Exp $
00004 /* ######################################################################
00005 
00006    DPKG Package Manager - Provide an interface to dpkg
00007    
00008    ##################################################################### */
00009                                                                         /*}}}*/
00010 #ifndef PKGLIB_DPKGPM_H
00011 #define PKGLIB_DPKGPM_H
00012 
00013 #include <apt-pkg/packagemanager.h>
00014 #include <vector>
00015 #include <map>
00016 #include <stdio.h>
00017 
00018 using std::vector;
00019 using std::map;
00020 
00021 
00022 class pkgDPkgPM : public pkgPackageManager
00023 {
00024    private:
00025 
00026    bool stdin_is_dev_null;
00027 
00028    // the buffer we use for the dpkg status-fd reading
00029    char dpkgbuf[1024];
00030    int dpkgbuf_pos;
00031    FILE *term_out;
00032    FILE *history_out;
00033    string dpkg_error;
00034 
00048    void handleDisappearAction(string const &pkgname);
00049 
00050    protected:
00051    int pkgFailures;
00052 
00053    // progress reporting
00054    struct DpkgState 
00055    {
00056       const char *state;     // the dpkg state (e.g. "unpack")
00057       const char *str;       // the human readable translation of the state
00058    };
00059 
00060    // the dpkg states that the pkg will run through, the string is 
00061    // the package, the vector contains the dpkg states that the package
00062    // will go through
00063    map<string,vector<struct DpkgState> > PackageOps;
00064    // the dpkg states that are already done; the string is the package
00065    // the int is the state that is already done (e.g. a package that is
00066    // going to be install is already in state "half-installed")
00067    map<string,unsigned int> PackageOpsDone;
00068 
00069    // progress reporting
00070    unsigned int PackagesDone;
00071    unsigned int PackagesTotal;
00072   
00073    struct Item
00074    {
00075       enum Ops {Install, Configure, Remove, Purge, ConfigurePending, TriggersPending} Op;
00076       string File;
00077       PkgIterator Pkg;
00078       Item(Ops Op,PkgIterator Pkg,string File = "") : Op(Op),
00079             File(File), Pkg(Pkg) {};
00080       Item() {};
00081       
00082    };
00083    vector<Item> List;
00084 
00085    // Helpers
00086    bool RunScriptsWithPkgs(const char *Cnf);
00087    bool SendV2Pkgs(FILE *F);
00088    void WriteHistoryTag(string const &tag, string value);
00089 
00090    // apport integration
00091    void WriteApportReport(const char *pkgpath, const char *errormsg);
00092 
00093    // dpkg log
00094    bool OpenLog();
00095    bool CloseLog();
00096    
00097    // input processing
00098    void DoStdin(int master);
00099    void DoTerminalPty(int master);
00100    void DoDpkgStatusFd(int statusfd, int OutStatusFd);
00101    void ProcessDpkgStatusLine(int OutStatusFd, char *line);
00102 
00103    // The Actuall installation implementation
00104    virtual bool Install(PkgIterator Pkg,string File);
00105    virtual bool Configure(PkgIterator Pkg);
00106    virtual bool Remove(PkgIterator Pkg,bool Purge = false);
00107    virtual bool Go(int StatusFd=-1);
00108    virtual void Reset();
00109    
00110    public:
00111 
00112    pkgDPkgPM(pkgDepCache *Cache);
00113    virtual ~pkgDPkgPM();
00114 };
00115 
00116 #endif