#include <ModulesConf.h>
Classes | |
struct | ModuleLine |
Public Types | |
typedef list< string > | ModulesConfIndex |
typedef map< const string, ModuleEntry > | ModuleEntryMap |
typedef map< const string, ModuleEntryMap > | ModulesConfMap |
Public Member Functions | |
ModulesConf (const string &fname) | |
~ModulesConf () | |
ModulesConfMap | getDirectives () |
ModuleEntryMap | getModules (const string directive) |
ModuleEntry::EntryArg | getOptions (const string module) |
string | getOptionsAsString (const string module) |
string | getOption (const string module, const string option) |
string | getArgument (const string directive, const string module) |
string | getComment (const string directive, const string module) |
bool | setOption (const string module, const string option, const string value, ModuleEntry::Mode m) |
bool | setOptions (const string module, const ModuleEntry::EntryArg arg, ModuleEntry::Mode m) |
bool | setArgument (const string directive, const string module, const string arg, ModuleEntry::Mode m) |
bool | setComment (const string directive, const string module, const string arg, ModuleEntry::Mode m) |
bool | removeEntry (const string directive, const string module) |
bool | writeFile (const string fname="") |
Private Types | |
typedef time_t | TimeStamp |
Private Member Functions | |
TimeStamp | getTimeStamp (const string &fname) |
bool | isDirective (const string directive) const |
bool | isModule (const string directive, const string module) |
bool | isOption (const string module, const string option) |
bool | updateIfModified () |
bool | updateTimeStamp () |
bool | updateIndex (const string directive, const string module) |
bool | parseLine (const string &line, ModuleLine &l) const |
bool | parseFile (const string &file_name, ModuleEntry::Mode m, const bool with_comment=true) |
Private Attributes | |
string | file_name |
ModulesConfMap | modules_conf_map |
ModulesConfIndex | modules_conf_index |
bool | modified |
TimeStamp | time_stamp |
This class contains the modules.conf file.
typedef map<const string, ModuleEntry> ModulesConf::ModuleEntryMap |
typedef list<string> ModulesConf::ModulesConfIndex |
typedef map<const string, ModuleEntryMap> ModulesConf::ModulesConfMap |
typedef time_t ModulesConf::TimeStamp [private] |
The return type of getTimeStamp()
ModulesConf::ModulesConf | ( | const string & | fname | ) |
Default constructor.
fname | A path to the modules.conf file (usually /etc/modules.conf) |
References ModuleEntry::INIT, parseFile(), y2debug, and y2warning.
ModulesConf::~ModulesConf | ( | ) |
Destructor
References writeFile(), and y2error.
string ModulesConf::getArgument | ( | const string | directive, | |
const string | module | |||
) |
For the given directive and module returns the entry argument.
directive | A directive for which the argument is returned. | |
module | A module for which the argument is returned. |
References getOptionsAsString(), isModule(), MAGIC_ENTRY, modules_conf_map, updateIfModified(), Y2_RETURN_STR, y2debug, and y2warning.
Referenced by ModulesAgent::Read(), and writeFile().
string ModulesConf::getComment | ( | const string | directive, | |
const string | module | |||
) |
For the given directive and module returns the entry comment.
directive | A directive for which the comment is returned. | |
module | A module for which the comment is returned. |
References isModule(), modules_conf_map, updateIfModified(), and Y2_RETURN_STR.
Referenced by ModulesAgent::Read(), and writeFile().
ModulesConf::ModulesConfMap ModulesConf::getDirectives | ( | ) |
Returns map of all directives present in the current modules.conf.
References modules_conf_map, and updateIfModified().
Referenced by ModulesAgent::Dir(), and ModulesAgent::Read().
ModulesConf::ModuleEntryMap ModulesConf::getModules | ( | const string | directive | ) |
For the given directive returns all modules in a map.
directive | A directive for which the modules are returned. |
References isDirective(), modules_conf_map, updateIfModified(), and y2error.
Referenced by ModulesAgent::Dir(), and ModulesAgent::Read().
string ModulesConf::getOption | ( | const string | module, | |
const string | option | |||
) |
For the given module and option returns the option parameter.
module | A module for which the parameter is returned. | |
option | An option for which the parameter is returned. |
References isOption(), MAGIC_ENTRY, modules_conf_map, updateIfModified(), Y2_RETURN_STR, and y2debug.
Referenced by ModulesAgent::Read().
ModuleEntry::EntryArg ModulesConf::getOptions | ( | const string | module | ) |
For the given module returns all options in a map.
module | A module for which the options are returned. |
References isModule(), MAGIC_ENTRY, modules_conf_map, updateIfModified(), and y2error.
Referenced by ModulesAgent::Dir(), getOptionsAsString(), and ModulesAgent::Read().
string ModulesConf::getOptionsAsString | ( | const string | module | ) |
For the given module returns all options as one string.
module | A module for which the options are returned. |
References getOptions().
Referenced by getArgument(), and writeFile().
ModulesConf::TimeStamp ModulesConf::getTimeStamp | ( | const string & | fname | ) | [private] |
Return a time stamp of the file.
fname | A file name of the file to be stamped. |
References y2error.
Referenced by updateIfModified(), and updateTimeStamp().
bool ModulesConf::isDirective | ( | const string | directive | ) | const [private] |
Test the existence of directive.
directive | The tested directive. |
References modules_conf_map.
Referenced by getModules(), and isModule().
bool ModulesConf::isModule | ( | const string | directive, | |
const string | module | |||
) | [private] |
Test the existence of module.
directive | The directive of the tested module. | |
module | The tested module. |
References isDirective(), and modules_conf_map.
Referenced by getArgument(), getComment(), getOptions(), isOption(), removeEntry(), updateIndex(), and writeFile().
bool ModulesConf::isOption | ( | const string | module, | |
const string | option | |||
) | [private] |
Test the existence of option.
directive | The directive of the tested option. | |
module | The module of the tested option. |
References isModule(), and modules_conf_map.
Referenced by getOption().
bool ModulesConf::parseFile | ( | const string & | fname, | |
ModuleEntry::Mode | m, | |||
const bool | with_comment = true | |||
) | [private] |
Parse the modules.conf.
file_name | The name of the parsed file. | |
m | Indicates if the option is set during (re)initialization or by an agent. | |
with_comment | If the comment should be parsed. |
References ModulesConf::ModuleLine::argument, ModulesConf::ModuleLine::comment, comment, ModulesConf::ModuleLine::directive, FINAL_COMMENT, stringutil::getline(), ModulesConf::ModuleLine::module, ModulesConf::ModuleLine::options, parseLine(), setArgument(), setComment(), setOptions(), updateTimeStamp(), WHITESPACE, and y2debug.
Referenced by ModulesConf(), and updateIfModified().
bool ModulesConf::parseLine | ( | const string & | line, | |
ModuleLine & | l | |||
) | const [private] |
Parse one line of modules.conf.
line | The line to be parsed. | |
l | The parsed line. |
References ModulesConf::ModuleLine::argument, ModulesConf::ModuleLine::comment, ModulesConf::ModuleLine::directive, killspaces(), ModulesConf::ModuleLine::module, ModulesConf::ModuleLine::options, and Y2_STRING.
Referenced by parseFile().
bool ModulesConf::removeEntry | ( | const string | directive, | |
const string | module | |||
) |
Remove one entry from the modules.conf.
directive | A removed entry directive. | |
module | A removed entry module. | |
m | Indicates if the option is set during (re)initialization or by an agent. |
References isModule(), modified, modules_conf_index, modules_conf_map, Y2_RETURN_FALSE, and y2warning.
Referenced by ModulesAgent::Write().
bool ModulesConf::setArgument | ( | const string | directive, | |
const string | module, | |||
const string | arg, | |||
ModuleEntry::Mode | m | |||
) |
For the given directive and module set the entry argument.
directive | A directive for which the argument is set. | |
module | A module for which the argument is set. | |
m | Indicates if the option is set during (re)initialization or by an agent. | |
arg | An entry argument. |
References modified, modules_conf_map, ModuleEntry::SET, updateIndex(), and y2error.
Referenced by parseFile(), and ModulesAgent::Write().
bool ModulesConf::setComment | ( | const string | directive, | |
const string | module, | |||
const string | arg, | |||
ModuleEntry::Mode | m | |||
) |
For the given directive and module set the entry comment.
directive | A directive for which the comment is set. | |
module | A module for which the comment is set. | |
m | Indicates if the option is set during (re)initialization or by an agent. | |
arg | An entry comment. |
References modified, modules_conf_map, and ModuleEntry::SET.
Referenced by parseFile(), and ModulesAgent::Write().
bool ModulesConf::setOption | ( | const string | module, | |
const string | option, | |||
const string | value, | |||
ModuleEntry::Mode | m | |||
) |
For the given module and options set the option parameter.
module | A module for which the parameter is set. | |
option | An option for which the parameter is set. | |
value | The option value. |
References modified, modules_conf_map, ModuleEntry::SET, updateIndex(), and y2error.
Referenced by ModulesAgent::Write().
bool ModulesConf::setOptions | ( | const string | module, | |
const ModuleEntry::EntryArg | arg, | |||
ModuleEntry::Mode | m | |||
) |
For the given module set all options as a map.
module | A module for which the options are set. | |
value | The options as a map. | |
m | Indicates if the option is set during (re)initialization or by an agent. |
References modified, modules_conf_map, ModuleEntry::SET, updateIndex(), and Y2_RETURN_FALSE.
Referenced by parseFile(), and ModulesAgent::Write().
bool ModulesConf::updateIfModified | ( | ) | [private] |
Update internal structures if the file has been modified.
References file_name, getTimeStamp(), parseFile(), ModuleEntry::REINIT, time_stamp, Y2_RETURN_FALSE, and y2warning.
Referenced by getArgument(), getComment(), getDirectives(), getModules(), getOption(), getOptions(), and writeFile().
bool ModulesConf::updateIndex | ( | const string | directive, | |
const string | module | |||
) | [private] |
Update the file index.
directive | A directive for which the index is updated. | |
module | A module for which the index is updated. |
References isModule(), and modules_conf_index.
Referenced by setArgument(), setOption(), and setOptions().
bool ModulesConf::updateTimeStamp | ( | ) | [private] |
Update the file time stamp.
References file_name, getTimeStamp(), and time_stamp.
Referenced by parseFile(), and writeFile().
bool ModulesConf::writeFile | ( | const string | fname = "" |
) |
Write the modules.conf file to the disk.
fname | A file name of the written file. |
References BACKUP_EXTENSION, file_name, FINAL_COMMENT, getArgument(), getComment(), getOptionsAsString(), ModuleEntry::INIT, isModule(), modified, modules_conf_index, modules_conf_map, updateIfModified(), updateTimeStamp(), Y2_RETURN_FALSE, y2debug, y2error, y2milestone, and y2warning.
Referenced by ModulesAgent::Write(), and ~ModulesConf().
string ModulesConf::file_name [private] |
Referenced by updateIfModified(), updateTimeStamp(), and writeFile().
bool ModulesConf::modified [private] |
Referenced by removeEntry(), setArgument(), setComment(), setOption(), setOptions(), and writeFile().
Referenced by removeEntry(), updateIndex(), and writeFile().
ModulesConfMap ModulesConf::modules_conf_map [private] |
Referenced by getArgument(), getComment(), getDirectives(), getModules(), getOption(), getOptions(), isDirective(), isModule(), isOption(), removeEntry(), setArgument(), setComment(), setOption(), setOptions(), and writeFile().
TimeStamp ModulesConf::time_stamp [private] |
Referenced by updateIfModified(), and updateTimeStamp().