#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 807 of file swmgr.cpp.
00807 { 00808 00809 if (filterMgr) 00810 filterMgr->AddEncodingFilters(module, section); 00811 } |
|
Adds the raw filters which are defined in "section" to the SWModule object "module".
Definition at line 790 of file swmgr.cpp. References SWModule::AddRawFilter, and SWModule::Name.
00790 { 00791 string sourceformat, cipherKey; 00792 ConfigEntMap::iterator entry; 00793 00794 cipherKey = ((entry = section.find("CipherKey")) != section.end()) ? (*entry).second : (string)""; 00795 if (!cipherKey.empty()) { 00796 SWFilter *cipherFilter = new CipherFilter(cipherKey.c_str()); 00797 cipherFilters.insert(FilterMap::value_type(module->Name(), cipherFilter)); 00798 cleanupFilters.push_back(cipherFilter); 00799 module->AddRawFilter(cipherFilter); 00800 } 00801 00802 if (filterMgr) 00803 filterMgr->AddRawFilters(module, section); 00804 } |
|
Adds the render filters which are defined in "section" to the SWModule object "module".
Definition at line 814 of file swmgr.cpp.
00814 { 00815 string sourceformat; 00816 ConfigEntMap::iterator entry; 00817 00818 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)""; 00819 00820 // Temporary: To support old module types 00821 // TODO: Remove at 1.6.0 release? 00822 if (sourceformat.empty()) { 00823 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)""; 00824 if (!stricmp(sourceformat.c_str(), "RawGBF")) 00825 sourceformat = "GBF"; 00826 else sourceformat = ""; 00827 } 00828 00829 // process module - eg. follows 00830 // if (!stricmp(sourceformat.c_str(), "GBF")) { 00831 // module->AddRenderFilter(gbftortf); 00832 // } 00833 00834 if (filterMgr) 00835 filterMgr->AddRenderFilters(module, section); 00836 00837 } |
|
Adds the strip filters which are defined in "section" to the SWModule object "module".
Definition at line 840 of file swmgr.cpp. References SWModule::AddStripFilter.
00841 { 00842 string sourceformat; 00843 ConfigEntMap::iterator entry; 00844 00845 sourceformat = ((entry = section.find("SourceType")) != section.end()) ? (*entry).second : (string)""; 00846 // Temporary: To support old module types 00847 if (sourceformat.empty()) { 00848 sourceformat = ((entry = section.find("ModDrv")) != section.end()) ? (*entry).second : (string)""; 00849 if (!stricmp(sourceformat.c_str(), "RawGBF")) 00850 sourceformat = "GBF"; 00851 else sourceformat = ""; 00852 } 00853 00854 if (!stricmp(sourceformat.c_str(), "GBF")) { 00855 module->AddStripFilter(gbfplain); 00856 } 00857 else if (!stricmp(sourceformat.c_str(), "ThML")) { 00858 module->AddStripFilter(thmlplain); 00859 } 00860 00861 if (filterMgr) 00862 filterMgr->AddStripFilters(module, section); 00863 00864 } |
|
Gives the value of the given option.
Definition at line 987 of file swmgr.cpp.
00988 { 00989 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00990 if ((*it).second->getOptionName()) { 00991 if (!stricmp(option, (*it).second->getOptionName())) 00992 return (*it).second->getOptionValue(); 00993 } 00994 } 00995 return 0; 00996 } |
|
A list of all availble options with the currently set values.
Definition at line 1011 of file swmgr.cpp.
01012 { 01013 return options; 01014 } |
|
Gives a description for the given option.
Definition at line 999 of file swmgr.cpp.
01000 { 01001 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 01002 if ((*it).second->getOptionName()) { 01003 if (!stricmp(option, (*it).second->getOptionName())) 01004 return (*it).second->getOptionTip(); 01005 } 01006 } 01007 return 0; 01008 } |
|
Installs a scan for modules in the directory givan as parameter.
Definition at line 913 of file swmgr.cpp. References config, and SWConfig::filename. Referenced by Load.
00914 { 00915 DIR *dir; 00916 struct dirent *ent; 00917 int conffd = 0; 00918 string newmodfile; 00919 string targetName; 00920 00921 if (!access(dirname, 04)) { 00922 if ((dir = opendir(dirname))) { 00923 rewinddir(dir); 00924 while ((ent = readdir(dir))) { 00925 if ((strcmp(ent->d_name, ".")) && (strcmp(ent->d_name, ".."))) { 00926 newmodfile = dirname; 00927 if ((dirname[strlen(dirname)-1] != '\\') && (dirname[strlen(dirname)-1] != '/')) 00928 newmodfile += "/"; 00929 newmodfile += ent->d_name; 00930 if (configType) { 00931 if (config > 0) 00932 close(conffd); 00933 targetName = configPath; 00934 if ((configPath[strlen(configPath)-1] != '\\') && (configPath[strlen(configPath)-1] != '/')) 00935 targetName += "/"; 00936 targetName += ent->d_name; 00937 conffd = open(targetName.c_str(), O_WRONLY|O_CREAT, S_IREAD|S_IWRITE); 00938 } 00939 else { 00940 if (conffd < 1) { 00941 conffd = open(config->filename.c_str(), O_WRONLY|O_APPEND); 00942 if (conffd > 0) 00943 lseek(conffd, 0L, SEEK_END); 00944 } 00945 } 00946 AddModToConfig(conffd, newmodfile.c_str()); 00947 unlink(newmodfile.c_str()); 00948 } 00949 } 00950 if (conffd > 0) 00951 close(conffd); 00952 closedir(dir); 00953 } 00954 } 00955 } |
|
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 1032 of file swmgr.cpp. References Modules.
01032 { 01033 FilterMap::iterator it; 01034 ModMap::iterator it2; 01035 01036 // check for filter that already exists 01037 it = cipherFilters.find(modName); 01038 if (it != cipherFilters.end()) { 01039 ((CipherFilter *)(*it).second)->getCipher()->setCipherKey(key); 01040 return 0; 01041 } 01042 // check if module exists 01043 else { 01044 it2 = Modules.find(modName); 01045 if (it2 != Modules.end()) { 01046 SWFilter *cipherFilter = new CipherFilter(key); 01047 cipherFilters.insert(FilterMap::value_type(modName, cipherFilter)); 01048 cleanupFilters.push_back(cipherFilter); 01049 (*it2).second->AddRawFilter(cipherFilter); 01050 return 0; 01051 } 01052 } 01053 return -1; 01054 } |
|
Set a global option Set a global option using the parameters. A global option could be for example footnotes.
Definition at line 976 of file swmgr.cpp.
00977 { 00978 for (FilterMap::iterator it = optionFilters.begin(); it != optionFilters.end(); it++) { 00979 if ((*it).second->getOptionName()) { 00980 if (!stricmp(option, (*it).second->getOptionName())) 00981 (*it).second->setOptionValue(value); 00982 } 00983 } 00984 } |
|
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. |