installmgr.h

00001 #ifndef INSTALLMGR_H
00002 #define INSTALLMGR_H
00003 
00004 #include <defs.h>
00005 #include <swbuf.h>
00006 #include <map>
00007 #include <set>
00008 
00009 SWORD_NAMESPACE_START
00010 
00011 class SWMgr;
00012 class SWModule;
00013 class SWConfig;
00014 class FTPTransport;
00015 class StatusReporter;
00016 
00019 class SWDLLEXPORT InstallSource {
00020         SWMgr *mgr;
00021 public:
00022         InstallSource(const char *type, const char *confEnt = 0);
00023         virtual ~InstallSource();
00024         SWBuf getConfEnt() {
00025                 return caption +"|" + source + "|" + directory;
00026         }
00027         SWBuf type;
00028         SWBuf source;
00029         SWBuf directory;
00030         SWBuf caption;
00031         SWBuf localShadow;
00032         void *userData;
00033         SWMgr *getMgr();
00034         void flush();
00035 };
00036 
00037 typedef std::map<SWBuf, InstallSource *> InstallSourceMap;
00038 
00041 class SWDLLEXPORT InstallMgr {
00042 
00043 protected:
00044         std::set<SWBuf> defaultMods;
00045         char *privatePath;
00046         StatusReporter *statusReporter;
00047         bool passive;
00048         
00049         // override this method and provide your own custom FTPTransport subclass
00050         virtual FTPTransport *createFTPTransport(const char *host, StatusReporter *statusReporter);
00051 
00052         // we have a transport member to set as current running transport so we
00053         // can ask it to terminate below, if user requests
00054         FTPTransport *transport;        
00055         
00056 public:
00057 
00058         const static int MODSTAT_OLDER;
00059         const static int MODSTAT_SAMEVERSION;
00060         const static int MODSTAT_UPDATED;
00061         const static int MODSTAT_NEW;
00062         const static int MODSTAT_CIPHERED;
00063         const static int MODSTAT_CIPHERKEYPRESENT;
00064 
00065         SWConfig *installConf;
00066         InstallSourceMap sources;
00067         bool term;
00068 
00069         InstallMgr(const char *privatePath = "./", StatusReporter *statusReporter = 0);
00070         virtual ~InstallMgr();
00071 
00072         virtual int removeModule(SWMgr *manager, const char *modName);
00073         virtual int ftpCopy(InstallSource *is, const char *src, const char *dest, bool dirTransfer = false, const char *suffix = "");
00074         virtual int installModule(SWMgr *destMgr, const char *fromLocation, const char *modName, InstallSource *is = 0);
00075         
00076         virtual int refreshRemoteSource(InstallSource *is);
00077         virtual bool getCipherCode(const char *modName, SWConfig *config);
00078         void setFTPPassive(bool passive) { this->passive = passive; }
00079         void terminate();
00080 
00081         /************************************************************************
00082          * getModuleStatus - compare the modules of two SWMgrs and return a 
00083          *      vector describing the status of each.  See MODSTAT_*
00084          */
00085         static std::map<SWModule *, int> getModuleStatus(const SWMgr &base, const SWMgr &other);
00086 
00087         /************************************************************************
00088          * isDefaultModule - allows an installation to provide a set of modules
00089          *   in installMgr.conf like:
00090          *     [General]
00091          *     DefaultMod=KJV
00092          *     DefaultMod=StrongsGreek
00093          *     DefaultMod=Personal
00094          *   This method allows a user interface to ask if a module is specified
00095          *   as a default in the above way.  The logic is, if no modules are
00096          *   installed then all default modules should be automatically selected for install
00097          *   to help the user select a basic foundation of useful modules
00098          */
00099         bool isDefaultModule(const char *modName);
00100 };
00101 
00102 
00103 SWORD_NAMESPACE_END
00104 
00105 #endif