swmgr.h

00001 /******************************************************************************
00002  *  swmgr.h   - definition of class SWMgr used to interact with an install
00003  *                              base of sword modules.
00004  *
00005  * $Id: swmgr.h 2077 2007-09-14 01:34:37Z scribe $
00006  *
00007  * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
00008  *      CrossWire Bible Society
00009  *      P. O. Box 2528
00010  *      Tempe, AZ  85280-2528
00011  *
00012  * This program is free software; you can redistribute it and/or modify it
00013  * under the terms of the GNU General Public License as published by the
00014  * Free Software Foundation version 2.
00015  *
00016  * This program is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  * General Public License for more details.
00020  *
00021  */
00022 
00051 #ifndef SWMGR_H
00052 #define SWMGR_H
00053 
00054 #include <map>
00055 #include <list>
00056 #include <swbuf.h>
00057 #include <swconfig.h>
00058 
00059 #include <defs.h>
00060 
00061 SWORD_NAMESPACE_START
00062 
00063 class SWModule;
00064 class SWFilter;
00065 class SWOptionFilter;
00066 class SWFilterMgr;
00067 class SWBuf;
00068 class SWKey;
00069 
00070 typedef std::map < SWBuf, SWModule *, std::less < SWBuf > >ModMap;
00071 typedef std::map < SWBuf, SWFilter * >FilterMap;
00072 typedef std::map < SWBuf, SWOptionFilter * >OptionFilterMap;
00073 typedef std::list < SWBuf >StringList;
00074 typedef std::list < SWFilter* >FilterList;
00075 typedef std::list < SWOptionFilter* >OptionFilterList;
00076 
00077 class FileDesc;
00078 class SWOptionFilter;
00079 
00087 class SWDLLEXPORT SWMgr {
00088 
00089 
00090 private:
00091         bool mgrModeMultiMod;
00092         bool augmentHome;
00093         void commonInit(SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr, bool multiMod = false);
00094 
00095 protected:
00096         SWFilterMgr *filterMgr;         //made protected because because BibleTime needs it
00097         SWConfig *myconfig;             //made protected because because BibleTime needs it
00098         SWConfig *mysysconfig;
00099         SWConfig *homeConfig;
00100         void CreateMods(bool multiMod = false);
00101         SWModule *CreateMod(const char *name, const char *driver, ConfigEntMap &section);
00102         void DeleteMods();
00103         char configType;                // 0 = file; 1 = directory
00104         OptionFilterMap optionFilters;
00105         FilterMap cipherFilters;
00106         SWFilter *gbfplain;
00107         SWFilter *thmlplain;
00108         SWFilter *osisplain;
00109         SWFilter *teiplain;
00110         SWOptionFilter *transliterator;
00111         FilterList cleanupFilters;
00112         StringList options;
00113         virtual void init(); // use to initialize before loading modules
00114         virtual char AddModToConfig(FileDesc *conffd, const char *fname);
00115         virtual void loadConfigDir(const char *ipath);
00116         virtual void AddGlobalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
00117         virtual void AddLocalOptions(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
00118         StringList augPaths;
00119 
00126         virtual void AddEncodingFilters(SWModule *module, ConfigEntMap &section);
00127 
00134         virtual void AddRenderFilters(SWModule *module, ConfigEntMap &section);
00135 
00142         virtual void AddStripFilters(SWModule *module, ConfigEntMap &section);
00143 
00144         // ones manually specified in .conf file
00145         virtual void AddStripFilters(SWModule *module, ConfigEntMap &section, ConfigEntMap::iterator start, ConfigEntMap::iterator end);
00146 
00153         virtual void AddRawFilters(SWModule *module, ConfigEntMap &section);
00154 
00155 
00156 public:
00162         static bool debug;
00163 
00164         static bool isICU;
00165         static const char *globalConfPath;
00166 
00170         static void findConfig(char *configType, char **prefixPath, char **configPath, StringList *augPaths = 0, SWConfig *providedSysConf = 0);
00171 
00172         SWConfig *config;
00173         SWConfig *sysconfig;
00174 
00177         char *prefixPath;
00178 
00181         char *configPath;
00182 
00205         ModMap Modules;
00206 
00211         SWModule *getModule(const char *modName) { ModMap::iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
00212         const SWModule *getModule(const char *modName) const { ModMap::const_iterator it = Modules.find(modName); return ((it != Modules.end()) ? it->second : 0); }
00213 
00214 
00230         SWMgr(SWConfig *iconfig = 0, SWConfig *isysconfig = 0, bool autoload = true, SWFilterMgr *filterMgr = 0, bool multiMod = false);
00231 
00234         SWMgr(SWFilterMgr *filterMgr, bool multiMod = false);
00235 
00240         SWMgr(const char *iConfigPath, bool autoload = true, SWFilterMgr *filterMgr = 0, bool multiMod = false, bool augmentHome = true);
00241 
00247         virtual ~SWMgr();
00248 
00255         virtual void augmentModules(const char *path, bool multiMod = false);
00256 
00257         void deleteModule(const char *);
00258 
00264         virtual void InstallScan(const char *dir);
00265 
00271         virtual signed char Load();
00272 
00278         virtual void setGlobalOption(const char *option, const char *value);
00279 
00284         virtual const char *getGlobalOption(const char *option);
00285 
00291         virtual const char *getGlobalOptionTip(const char *option);
00292 
00296         virtual StringList getGlobalOptions();
00297 
00303         virtual StringList getGlobalOptionValues(const char *option);
00304 
00312         virtual char filterText(const char *filterName, SWBuf &text, const SWKey *key = 0, const SWModule *module = 0);
00313 
00355         virtual signed char setCipherKey(const char *modName, const char *key);
00356 };
00357 
00358 SWORD_NAMESPACE_END
00359 #endif