cfg_Base Class Reference
[Parser for config files; validation]

#include <cfg.h>

Inheritance diagram for cfg_Base:

Inheritance graph
[legend]

List of all members.


Detailed Description

Definition at line 25 of file cfg.h.


Public Member Functions

 cfg_Base ()
virtual ~cfg_Base ()
void Convert (const pf_ValueList &a_parsedList, val_RuleVec &a_rules)
val_ValueFindRule (const string &a_varName, val_RuleVec &a_rules) const
bool WasParsed (const void *a_item, val_RuleVec &a_rules)
void CheckMandatory (val_RuleVec &a_rules)
virtual void ConvertGroup (const string &a_grpName, const pf_Group &a_group)
void ConvertFileHeader (const pf_File &a_parsedFile)

Public Attributes

string m_fileType
UInt32_t m_fileVersion
ivd_Time32_t m_fileDate
string m_fileUser

Private Attributes

 log_CLASSID_m

Constructor & Destructor Documentation

cfg_Base::cfg_Base (  ) 

Definition at line 32 of file cfg.cpp.

00033   : m_fileVersion(0),
00034     m_fileDate(0) {
00035 
00036     // Empty
00037 }

virtual cfg_Base::~cfg_Base (  )  [inline, virtual]

Definition at line 31 of file cfg.h.

00031 {};


Member Function Documentation

void cfg_Base::Convert ( const pf_ValueList a_parsedList,
val_RuleVec a_rules 
)

Definition at line 39 of file cfg.cpp.

References val_Value::Add(), val_Value::AddRange(), pf_List::At(), pf_ValueList::At(), val_Value::Conv(), ConvertGroup(), dbg_DETAIL, dbg_LOW, FindRule(), ivd_BaseException::GetContext(), ivd_BaseException::GetError(), val_Value::GetName(), pf_Value::group, pf_Group::grpType, ie_DATA_CORRUPTION, ie_NYI, pf_Elem::isRange, ivd_Error, pf_Component::lineNum, pf_Value::list, log_DBG_INT_m, log_DBG_m, log_FUNC_m, val_Value::m_numParsed, pf_ValueBase::name, PF_COMMENT, PF_GROUP, PF_INCLFILE, PF_LIST, PF_RANGE, PF_SIMPLE, pf_Value::simple, pf_List::size(), pf_ValueList::size(), pf_Elem::toVal, pf_Value::type, and pf_Elem::val.

Referenced by cfg_DriveType::cfg_DriveType(), cfg_DriveVendor::cfg_DriveVendor(), cfg_Library::cfg_Library(), cfg_PMClient::cfg_PMClient(), cfg_PMFileExpiration::cfg_PMFileExpiration(), cfg_PMTree::cfg_PMTree(), cfg_RMHost::cfg_RMHost(), ConvertFileHeader(), cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), cfg_PMCfg::Refresh(), cfg_LibraryFile::Refresh(), cfg_DriveSettings::Refresh(), and cfg_CliBase::Refresh().

00039                                                                              {
00040     log_FUNC_m(Convert);
00041 
00042 
00043     for (unsigned int i = 0; i < a_parsedList.size(); i++) {
00044         const pf_Value  &varValue = a_parsedList.At(i);
00045         string          varName = varValue.name;
00046         log_DBG_m(dbg_DETAIL,"variable " << varName);
00047 
00048         if (varValue.type == PF_COMMENT) {
00049             //log_DBG_m(dbg_DETAIL, "Skipping comment.");
00050             continue;
00051         }
00052         try {
00053             if (varValue.type == PF_GROUP) {
00054                 log_DBG_INT_m(dbg_DETAIL,
00055                     "Converting Group: " << varValue.group->grpType );
00056 
00057                 // varValue.name is GroupName
00058                 // *(varValue.group).grpType is GroupType
00059                 ConvertGroup(varValue.name, *(varValue.group) );
00060             }
00061             else {
00062                 val_Value *valRule = FindRule(varName, a_rules);
00063                 valRule->m_numParsed++;
00064 
00065                 log_DBG_m(dbg_DETAIL, "Parsing : " <<  valRule->GetName()
00066                                      << " varValue.type: " << varValue.type
00067                                      << " varValue.simple.val> " << varValue.simple.val);
00068 
00069                 switch (varValue.type) {
00070                     case PF_SIMPLE:
00071                         valRule->Conv(varValue.simple.val);
00072                         break;
00073                     case PF_RANGE:
00074                         valRule->Conv(
00075                             varValue.simple.val,
00076                             varValue.simple.toVal);
00077                         break;
00078                     case PF_LIST:
00079                         {
00080                             for (UInt32_t j=0; j < varValue.list.size(); j++) {
00081                                 if (varValue.list.At(j).isRange) {
00082                                     valRule->AddRange(
00083                                         varValue.list.At(j).val,
00084                                         varValue.list.At(j).toVal
00085                                     );
00086                                 }
00087                                 else {
00088                                     valRule->Add(varValue.list.At(j).val);
00089                                 }
00090                             };
00091                         }
00092                         break;
00093                     case PF_INCLFILE:
00094                         throw ivd_Error(ie_NYI);
00095                     /*
00096                         Comment has already been taken care of above.
00097                     case PF_COMMENT:
00098                         break;
00099                     */
00100                     default:
00101                         log_FUNC_m(Convert);
00102                         throw ivd_Error(ie_DATA_CORRUPTION,
00103                                 "Unexpected variable type", true);
00104                         break;
00105                 }
00106             }
00107         }
00108         catch (ivd_Error e) {
00109             log_FUNC_m(Convert);
00110             log_DBG_m(dbg_LOW,"Error at line number " << varValue.lineNum);
00111             ostringstream newErrorText;
00112             newErrorText
00113                 << e.GetContext()
00114                 << " at line number:" << varValue.lineNum;
00115 
00116             throw ivd_Error(e.GetError(), newErrorText.str());
00117         }
00118     }
00119 }

Here is the call graph for this function:

Here is the caller graph for this function:

val_Value * cfg_Base::FindRule ( const string &  a_varName,
val_RuleVec a_rules 
) const

Definition at line 154 of file cfg.cpp.

References dbg_DETAIL, ie_UNKNOWN_VAR, ivd_Error, log_DBG_m, log_FUNC_m, NULL, val_RuleVec::rules, val_RuleVec::size(), and strcasecmp.

Referenced by Convert().

00154                                                                                  {
00155 
00156     for (UInt32_t i = 0; i < a_rules.size(); i++) {
00157         if( strcasecmp(
00158                 a_rules.rules[i]->GetName().c_str(),
00159                 a_varName.c_str()) == 0 ) {
00160             return a_rules.rules[i];
00161         }
00162     }
00163 
00164     {
00165         log_FUNC_m(FindRule);
00166 
00167         log_DBG_m(dbg_DETAIL,"did NOT found rule for variable: " << a_varName );
00168         // Variable not found
00169         throw ivd_Error(ie_UNKNOWN_VAR, "Name: " + a_varName, true);
00170     }
00171     return NULL;
00172 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool cfg_Base::WasParsed ( const void *  a_item,
val_RuleVec a_rules 
)

void cfg_Base::CheckMandatory ( val_RuleVec a_rules  ) 

Definition at line 121 of file cfg.cpp.

References dbg_NORM, ie_MISSING_VAR, ie_TOO_MANY_VAR, ivd_Error, log_DBG_INT_m, log_FUNC_m, val_RuleVec::rules, and val_RuleVec::size().

Referenced by cfg_Library::cfg_Library(), cfg_PMClient::cfg_PMClient(), cfg_PMFileExpiration::cfg_PMFileExpiration(), cfg_PMTree::cfg_PMTree(), cfg_RMHost::cfg_RMHost(), cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), and cfg_PMCfg::Refresh().

00121                                                  {
00122     log_FUNC_m(CheckMandatory);
00123 
00124     /*
00125     For each unparsed element default value is applied
00126     or if option is mandatory exception is thrown
00127     */
00128 
00129     for (UInt32_t i = 0 ; i < a_rules.size() ; i++){
00130         if (a_rules.rules[i]->m_numParsed == 0) {
00131             // options was not parsed
00132             if (a_rules.rules[i]->m_minNumOfVal == 1) {
00133                 // This option is mandatory! Parsing will fail
00134                 throw ivd_Error(ie_MISSING_VAR, a_rules.rules[i]->GetName());
00135             }
00136             else {
00137                 //apply default values for simple value (list?, group?)
00138                 if (a_rules.rules[i]->m_useDefault) {
00139                     log_DBG_INT_m(dbg_NORM,
00140                         "Option " << a_rules.rules[i]->GetName() <<
00141                         " was not parsed. Will use default value");
00142                     a_rules.rules[i]->Conv(a_rules.rules[i]->m_default);
00143                 }
00144             }
00145         }
00146         else if (a_rules.rules[i]->m_numParsed > a_rules.rules[i]->m_maxNumOfVal) {
00147             // too many valuse parsed
00148             throw ivd_Error(ie_TOO_MANY_VAR,a_rules.rules[i]->GetName());
00149         }
00150     }
00151 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void cfg_Base::ConvertGroup ( const string &  a_grpName,
const pf_Group a_group 
) [inline, virtual]

Reimplemented in cfg_DriveVendor, cfg_DriveSettings, cfg_LibraryFile, cfg_PMCfg, and cfg_RMDrive.

Definition at line 38 of file cfg.h.

References ie_NO_SUBGROUP, and ivd_Error.

Referenced by Convert().

00038                                                                                 {
00039         throw ivd_Error(ie_NO_SUBGROUP);
00040     }

Here is the caller graph for this function:

void cfg_Base::ConvertFileHeader ( const pf_File a_parsedFile  ) 

Definition at line 175 of file cfg.cpp.

References val_RuleVec::Add(), cfg_MAX_FILE_DATE, cfg_MAX_FILE_USER, cfg_MAX_FILE_VERSION, cfg_MIN_FILE_DATE, cfg_MIN_FILE_USER, cfg_MIN_FILE_VERSION, Convert(), dbg_NORM, pf_File::GetFileType(), log_DBG_m, log_FUNC_m, m_fileDate, m_fileType, m_fileUser, m_fileVersion, and pf_File::m_header.

Referenced by cfg_Server::Refresh(), cfg_RMPool::Refresh(), cfg_RMLibrary::Refresh(), cfg_RMDrive::Refresh(), cfg_PMCfg::Refresh(), cfg_LibraryFile::Refresh(), and cfg_DriveSettings::Refresh().

00175                                                             {
00176     static const string c_fileVersion   ("Version");
00177     static const string c_fileDate      ("Date");
00178     static const string c_fileUser      ("User");
00179 
00180     log_FUNC_m(ConvertFileHeader);
00181 
00182     val_RuleVec  rules;
00183 
00184     rules.Add(new val_Integer(c_fileVersion,
00185         val_Limit(cfg_MIN_FILE_VERSION, cfg_MAX_FILE_VERSION)), this->m_fileVersion);
00186 
00187     // Lower limit is set to 0 to allow having empty string as entry for the
00188     // modification time in the header (converted to Epoch).
00189     rules.Add(new val_Date(c_fileDate,
00190         val_Limit(cfg_MIN_FILE_DATE, cfg_MAX_FILE_DATE)), this->m_fileDate);
00191     rules.Add(new val_StrictString(c_fileUser,
00192         val_Limit(cfg_MIN_FILE_USER, cfg_MAX_FILE_USER)), this->m_fileUser);
00193 
00194     Convert(a_parsedFile.m_header, rules);
00195 
00196     m_fileType = a_parsedFile.GetFileType();
00197 
00198     log_DBG_m(dbg_NORM,
00199         "File header -> type: " << m_fileType <<
00200         ", ver: " << m_fileVersion <<
00201         ", date: " << m_fileDate <<
00202         ", user: " << m_fileUser );
00203 }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 44 of file cfg.h.

Referenced by ConvertFileHeader(), and cfg_DriveSettings::Refresh().

Definition at line 45 of file cfg.h.

Referenced by ConvertFileHeader().

Definition at line 46 of file cfg.h.

Referenced by ConvertFileHeader().

Definition at line 47 of file cfg.h.

Referenced by ConvertFileHeader().


The documentation for this class was generated from the following files:

Generated on Mon Feb 27 19:03:05 2012 for OPENARCHIVE by  doxygen 1.5.6