#include <swmgr.h>
Collaboration diagram for SWMgr:
Public Methods | |
SWMgr (SWConfig *iconfig=0, SWConfig *isysconfig=0, bool autoload=true, SWFilterMgr *filterMgr=0) | |
Constructor of SWMgr. More... | |
SWMgr (SWFilterMgr *filterMgr) | |
SWMgr (const char *iConfigPath, bool autoload=true, SWFilterMgr *filterMgr=0) | |
virtual | ~SWMgr () |
The destructor of SWMgr. More... | |
virtual void | InstallScan (const char *dir) |
Installs a scan for modules in the directory givan as parameter. More... | |
virtual signed char | Load () |
Load the modules. More... | |
virtual void | setGlobalOption (const char *option, const char *value) |
Set a global option Set a global option using the parameters. More... | |
virtual const char * | getGlobalOption (const char *option) |
Gives the value of the given option. More... | |
virtual const char * | getGlobalOptionTip (const char *option) |
Gives a description for the given option. More... | |
virtual OptionsList | getGlobalOptions () |
A list of all availble options with the currently set values. More... | |
virtual OptionsList | getGlobalOptionValues (const char *option) |
virtual signed char | setCipherKey (const char *modName, const char *key) |
Sets the cipher key for the given module. More... | |
Static Public Methods | |
void | findConfig (char *configType, char **prefixPath, char **configPath) |
Public Attributes | |
SWConfig * | config |
The global config object. More... | |
SWConfig * | sysconfig |
ModMap | Modules |
The map of available modules. More... | |
char * | prefixPath |
The path to your Sword directory. | |
char * | configPath |
Static Public Attributes | |
bool | debug = false |
Enable / Disable debug output on runtime Set this to true to get more verbose output of SWMgr at runtime. More... | |
const char * | globalConfPath = "/etc/sword.conf:/usr/local/etc/sword.conf" |
Protected Methods | |
void | CreateMods () |
SWModule * | CreateMod (string name, string driver, ConfigEntMap §ion) |
void | DeleteMods () |
virtual void | init () |
virtual char | AddModToConfig (int conffd, const char *fname) |
virtual void | loadConfigDir (const char *ipath) |
virtual void | AddGlobalOptions (SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) |
virtual void | AddLocalOptions (SWModule *module, ConfigEntMap §ion, ConfigEntMap::iterator start, ConfigEntMap::iterator end) |
virtual void | AddEncodingFilters (SWModule *module, ConfigEntMap §ion) |
Adds the encoding filters which are defined in "section" to the SWModule object "module". More... | |
virtual void | AddRenderFilters (SWModule *module, ConfigEntMap §ion) |
Adds the render filters which are defined in "section" to the SWModule object "module". More... | |
virtual void | AddStripFilters (SWModule *module, ConfigEntMap §ion) |
Adds the strip filters which are defined in "section" to the SWModule object "module". More... | |
virtual void | AddRawFilters (SWModule *module, ConfigEntMap §ion) |
Adds the raw filters which are defined in "section" to the SWModule object "module". More... | |
Protected Attributes | |
SWFilterMgr * | filterMgr |
SWConfig * | myconfig |
SWConfig * | mysysconfig |
SWConfig * | homeConfig |
char | configType |
FilterMap | optionFilters |
FilterMap | cipherFilters |
SWFilter * | gbfplain |
SWFilter * | thmlplain |
FilterList | cleanupFilters |
OptionsList | options |
Private Methods | |
void | commonInit (SWConfig *iconfig, SWConfig *isysconfig, bool autoload, SWFilterMgr *filterMgr) |
SWmgr manages the installed modules, the filters and global options like footnotes or strong numbers. The class SWMgr is the most important class of Sword. It is used to manage the installed modules. It also manages the filters (Render-, Strip- and Rawfilters).
To get the SWModule objects of the instalelled modules use Modules for this.
Definition at line 69 of file swmgr.h.
|
Constructor of SWMgr.
Definition at line 179 of file swmgr.cpp.
00179 { 00180 commonInit(iconfig, isysconfig, autoload, filterMgr); 00181 } |
|
Definition at line 174 of file swmgr.cpp.
00174 { 00175 commonInit(0, 0, true, filterMgr); 00176 } |
|
Definition at line 207 of file swmgr.cpp. References config, Load(), and prefixPath.
00207 { 00208 00209 string path; 00210 00211 this->filterMgr = filterMgr; 00212 if (filterMgr) 00213 filterMgr->setParentMgr(this); 00214 00215 init(); 00216 00217 path = iConfigPath; 00218 if ((iConfigPath[strlen(iConfigPath)-1] != '\\') && (iConfigPath[strlen(iConfigPath)-1] != '/')) 00219 path += "/"; 00220 if (FileMgr::existsFile(path.c_str(), "mods.conf")) { 00221 stdstr(&prefixPath, path.c_str()); 00222 path += "mods.conf"; 00223 stdstr(&configPath, path.c_str()); 00224 } 00225 else { 00226 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00227 stdstr(&prefixPath, path.c_str()); 00228 path += "mods.d"; 00229 stdstr(&configPath, path.c_str()); 00230 configType = 1; 00231 } 00232 } 00233 00234 config = 0; 00235 sysconfig = 0; 00236 00237 if (autoload && configPath) 00238 Load(); 00239 } |
|
The destructor of SWMgr. This function cleans up the modules and deletes the created object. Destroy the SWMgr at last object in your application, because otherwise you may experience crashes because the SWModule objects become invalid. Definition at line 242 of file swmgr.cpp. References prefixPath.
00242 { 00243 00244 DeleteMods(); 00245 00246 for (FilterList::iterator it = cleanupFilters.begin(); it != cleanupFilters.end(); it++) 00247 delete (*it); 00248 00249 if (homeConfig) 00250 delete homeConfig; 00251 00252 if (myconfig) 00253 delete myconfig; 00254 00255 if (prefixPath) 00256 delete [] prefixPath; 00257 00258 if (configPath) 00259 delete [] configPath; 00260 00261 if (filterMgr) 00262 delete filterMgr; 00263 } |
|
Adds the encoding filters which are defined in "section" to the SWModule object "module".
Definition at line 808 of file swmgr.cpp.
00808 { 00809 00810 if (filterMgr) 00811 filterMgr->AddEncodingFilters(module, section); 00812 } |
|
Adds the raw filters which are defined in "section" to the SWModule object "module".
Definition at line 791 of file swmgr.cpp. References SWModule::AddRawFilter(), and SWModule::Name().
00791 { 00792 string sourceformat, cipherKey; 00793 ConfigEntMap::iterator entry; 00794 00795 cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (string)""; 00796 if (!cipherKey.empty()) { 00797 SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str()); 00798 cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter)); 00799 cleanupFilters.push_back(cipherFilter); 00800 module->AddRawFilter(cipherFilter); 00801 } 00802 00803 if (filterMgr) 00804 filterMgr->AddRawFilters(module, section); 00805 } |
|
Adds the render filters which are defined in "section" to the SWModule object "module".
Definition at line 815 of file swmgr.cpp.
00815 { 00816 string sourceformat; 00817 ConfigEntMap::iterator entry; 00818 00819 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)""; 00820 00821 // Temporary: To support old module types 00822 // TODO: Remove at 1.6.0 release? 00823 if (sourceformat.empty()) { 00824 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)""; 00825 if (!stricmp(sourceformat.c_str(), "RawGBF")) 00826 sourceformat = "GBF"; 00827 else sourceformat = ""; 00828 } 00829 00830 // process module - eg. follows 00831 // if (!stricmp(sourceformat.c_str(), "GBF")) { 00832 // module->AddRenderFilter(gbftortf); 00833 // } 00834 00835 if (filterMgr) 00836 filterMgr->AddRenderFilters(module, section); 00837 00838 } |
|
Adds the strip filters which are defined in "section" to the SWModule object "module".
Definition at line 841 of file swmgr.cpp. References SWModule::AddStripFilter().
00842 { 00843 string sourceformat; 00844 ConfigEntMap::iterator entry; 00845 00846 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)""; 00847 // Temporary: To support old module types 00848 if (sourceformat.empty()) { 00849 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)""; 00850 if (!stricmp(sourceformat.c_str(), "RawGBF")) 00851 sourceformat = "GBF"; 00852 else sourceformat = ""; 00853 } 00854 00855 if (!stricmp(sourceformat.c_str(), "GBF")) { 00856 module->AddStripFilter(gbfplain); 00857 } 00858 else if (!stricmp(sourceformat.c_str(), "ThML")) { 00859 module->AddStripFilter(thmlplain); 00860 } 00861 00862 if (filterMgr) 00863 filterMgr->AddStripFilters(module, section); 00864 00865 } |
|
Gives the value of the given option.
Definition at line 988 of file swmgr.cpp.
00989 { 00990 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00991 if ((*it).second->getOptionName()) { 00992 if (!stricmp(option, (*it).second->getOptionName())) 00993 return (*it).second->getOptionValue(); 00994 } 00995 } 00996 return 0; 00997 } |
|
A list of all availble options with the currently set values.
Definition at line 1012 of file swmgr.cpp.
01013 { 01014 return options; 01015 } |
|
Gives a description for the given option.
Definition at line 1000 of file swmgr.cpp.
01001 { 01002 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01003 if ((*it).second->getOptionName()) { 01004 if (!stricmp(option, (*it).second->getOptionName())) 01005 return (*it).second->getOptionTip(); 01006 } 01007 } 01008 return 0; 01009 } |
|
Installs a scan for modules in the directory givan as parameter.
Definition at line 914 of file swmgr.cpp. References config, and SWConfig::filename. Referenced by Load().
00915 { 00916 DIR *dir; 00917 struct dirent *ent; 00918 int conffd = 0; 00919 string newmodfile; 00920 string targetName; 00921 00922 if (!access(dirname, 04)) { 00923 if ((dir = opendir(dirname))) { 00924 rewinddir(dir); 00925 while ((ent = readdir(dir))) { 00926 if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { 00927 newmodfile = dirname; 00928 if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/')) 00929 newmodfile += "/"; 00930 newmodfile += ent->d_name; 00931 if (configType) { 00932 if (config > 0) 00933 close(conffd); 00934 targetName = configPath; 00935 if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/')) 00936 targetName += "/"; 00937 targetName += ent->d_name; 00938 conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE); 00939 } 00940 else { 00941 if (conffd < 1) { 00942 conffd = open(config->filename.c_str(), O_WRONLY|O_APPEND); 00943 if (conffd > 0) 00944 lseek(conffd, 0L, SEEK_END); 00945 } 00946 } 00947 AddModToConfig(conffd, newmodfile.c_str()); 00948 unlink(newmodfile.c_str()); 00949 } 00950 } 00951 if (conffd > 0) 00952 close(conffd); 00953 closedir(dir); 00954 } 00955 } 00956 } |
|
Load the modules. Reimplement this function to use your own Load function, for example to use your own filters. Definition at line 536 of file swmgr.cpp. References config, InstallScan(), SWConfig::Load(), Modules, prefixPath, and SWConfig::Sections. Referenced by SWMgr().
00536 { 00537 signed char ret = 0; 00538 00539 if (!config) { // If we weren't passed a config object at construction, find a config file 00540 if (!configPath) // If we weren't passed a config path at construction... 00541 findConfig(&configType, &prefixPath, &configPath); 00542 if (configPath) { 00543 if (configType) 00544 loadConfigDir(configPath); 00545 else config = myconfig = new SWConfig(configPath); 00546 } 00547 } 00548 00549 if (config) { 00550 SectionMap::iterator Sectloop, Sectend; 00551 ConfigEntMap::iterator Entryloop, Entryend; 00552 00553 DeleteMods(); 00554 00555 for (Sectloop = config->Sections.lower_bound("Globals"), Sectend = config->Sections.upper_bound("Globals"); Sectloop != Sectend; Sectloop++) { // scan thru all 'Globals' sections 00556 for (Entryloop = (*Sectloop).second.lower_bound("AutoInstall"), Entryend = (*Sectloop).second.upper_bound("AutoInstall"); Entryloop != Entryend; Entryloop++) // scan thru all AutoInstall entries 00557 InstallScan((*Entryloop).second.c_str()); // Scan AutoInstall entry directory for new modules and install 00558 } 00559 if (configType) { // force reload on config object because we may have installed new modules 00560 delete myconfig; 00561 config = myconfig = 0; 00562 loadConfigDir(configPath); 00563 } 00564 else config->Load(); 00565 00566 CreateMods(); 00567 00568 // augment config with ~/.sword/mods.d if it exists --------------------- 00569 char *envhomedir = getenv ("HOME"); 00570 if (envhomedir != NULL && configType != 2) { // 2 = user only 00571 string path = envhomedir; 00572 if ((envhomedir[strlen(envhomedir)-1] != '\\') && (envhomedir[strlen(envhomedir)-1] != '/')) 00573 path += "/"; 00574 path += ".sword/"; 00575 if (FileMgr::existsDir(path.c_str(), "mods.d")) { 00576 char *savePrefixPath = 0; 00577 char *saveConfigPath = 0; 00578 SWConfig *saveConfig = 0; 00579 stdstr(&savePrefixPath, prefixPath); 00580 stdstr(&prefixPath, path.c_str()); 00581 path += "mods.d"; 00582 stdstr(&saveConfigPath, configPath); 00583 stdstr(&configPath, path.c_str()); 00584 saveConfig = config; 00585 config = myconfig = 0; 00586 loadConfigDir(configPath); 00587 00588 CreateMods(); 00589 00590 stdstr(&prefixPath, savePrefixPath); 00591 delete []savePrefixPath; 00592 stdstr(&configPath, saveConfigPath); 00593 delete []saveConfigPath; 00594 (*saveConfig) += *config; 00595 homeConfig = myconfig; 00596 config = myconfig = saveConfig; 00597 } 00598 } 00599 // ------------------------------------------------------------------------- 00600 if ( !Modules.size() ) // config exists, but no modules 00601 ret = 1; 00602 00603 } 00604 else { 00605 SWLog::systemlog->LogError("SWMgr: Can't find 'mods.conf' or 'mods.d'. Try setting:\n\tSWORD_PATH=<directory containing mods.conf>\n\tOr see the README file for a full description of setup options (%s)", (configPath) ? configPath : "<configPath is null>"); 00606 ret = -1; 00607 } 00608 00609 return ret; 00610 } |
|
Sets the cipher key for the given module. This function updates the key at runtime, but it does not write to the config file. To write the new unlock key to the config file use code like this:
SectionMap::iterator section; ConfigEntMap::iterator entry; DIR *dir = opendir(configPath); struct dirent *ent; char* modFile; if (dir) { // find and update .conf file rewinddir(dir); while ((ent = readdir(dir))) { if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { modFile = m_backend->configPath; modFile += "/"; modFile += ent->d_name; SWConfig *myConfig = new SWConfig( modFile ); section = myConfig->Sections.find( m_module->Name() ); if ( section != myConfig->Sections.end() ) { entry = section->second.find("CipherKey"); if (entry != section->second.end()) { entry->second = unlockKey;//set cipher key myConfig->Save();//save config file } } delete myConfig; } } } closedir(dir);
Definition at line 1033 of file swmgr.cpp. References Modules.
01033 { 01034 FilterMap::iterator it; 01035 ModMap::iterator it2; 01036 01037 // check for filter that already exists 01038 it = cipherFilters.find(modName); 01039 if (it != cipherFilters.end()) { 01040 ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key); 01041 return 0; 01042 } 01043 // check if module exists 01044 else { 01045 it2 = Modules.find(modName); 01046 if (it2 != Modules.end()) { 01047 SWFilter *cipherFilter = new CipherFilter(key); 01048 cipherFilters.insert(FilterMap::value_type(modName, cipherFilter)); 01049 cleanupFilters.push_back(cipherFilter); 01050 (*it2).second->AddRawFilter(cipherFilter); 01051 return 0; 01052 } 01053 } 01054 return -1; 01055 } |
|
Set a global option Set a global option using the parameters. A global option could be for example footnotes.
Definition at line 977 of file swmgr.cpp.
00978 { 00979 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00980 if ((*it).second->getOptionName()) { 00981 if (!stricmp(option, (*it).second->getOptionName())) 00982 (*it).second->setOptionValue(value); 00983 } 00984 } 00985 } |
|
The global config object. This is the global config object. It contains all items of all modules, so lookups of entries should use this config object. If you want to save a cipher key or other things to the module config file, DO NOT USE this object, because it would corrupt your config files after config->Save(). If you want to write to the modules config file read the informtaion of setCipherKey() for an example of this. Definition at line 145 of file swmgr.h. Referenced by InstallScan(), Load(), and SWMgr(). |
|
Enable / Disable debug output on runtime Set this to true to get more verbose output of SWMgr at runtime. Set it to false to get no debug output. The default is "false". |
|
The map of available modules. This map contains thew list of available modules in Sword. Here's an example how to got through the map and how toc ehck for the module type.
ModMap::iterator it; SWModule* curMod = 0; for (it = Modules.begin(); it != Modules.end(); it++) { curMod = (*it).second; if (!strcmp(curMod->Type(), "Biblical Texts")) { //do something with curMod } else if (!strcmp(curMod->Type(), "Commentaries")) { //do something with curMod } else if (!strcmp(curMod->Type(), "Lexicons / Dictionaries")) { //do something with curMod } } Definition at line 172 of file swmgr.h. Referenced by Load(), and setCipherKey(). |