Public Member Functions | Private Member Functions | Private Attributes

Config Class Reference

#include <config.h>

List of all members.

Public Member Functions

bool IsReady ()
 Function return true if all 4 needed parameters are set and no warnings were print.
 Config (string &a_file)
 Default constructor.
string GetGamserver ()
 Function get gammserver value.
string GetHostname ()
 Function get hostname value.
string GetPartionName ()
 Function get partition name value.
string GetSharedDir ()
 Function get shared directory value.
string GetLocalMountpoint ()
 Function get local mount point value.
string GetLogDirectory ()
 Function get log directory value.
string GetDbgLevel ()
 Function get dbgLeve value.
string GetDbgFile ()
 Function get dbgFile value.
string GetDbgFlags ()
 Function get dbgFlags value.

Private Member Functions

string RemoveWhiteSpaces (string &a_line)
 Function remove white spaces.from the input string.
string TabToSpace (string &a_line)
 Function replace tab with 4 spaces.
void ReadFile (string &a_file)
 Read file and get value paramaters.
void ErrorReport (string &a_line, int &a_countLine, string a_error)
 Error report function.

Private Attributes

string m_gamserver
string m_hostname
string m_partitionName
string m_sharedDir
string m_localMountpoint
string m_logDirectory
string m_dbgLevel
string m_dbgFile
string m_dbgFlags
bool m_noWarning

Detailed Description

Definition at line 41 of file ivdapi/config.h.


Constructor & Destructor Documentation

Config::Config ( string &  a_file  ) 

Default constructor.

Definition at line 23 of file config.cpp.

References m_noWarning, and ReadFile().

                              {
    ReadFile(a_file);
    m_noWarning = true;
}

Here is the call graph for this function:


Member Function Documentation

void Config::ErrorReport ( string &  a_line,
int &  a_countLine,
string  a_error 
) [private]

Error report function.

Parameters:
input string
input integer
input string

Definition at line 202 of file config.cpp.

References m_noWarning.

Referenced by ReadFile().

                                                                          {
    m_noWarning = false;
    cerr << "****************************************************************************************" << endl;
    cerr << "!! Warning (" << "Line " << a_countLine << ": " << a_error.c_str() << "   " << "[" << a_line << "]) !!" << endl;
    cerr << "****************************************************************************************" << endl;
    cerr << endl;
}

Here is the caller graph for this function:

string Config::GetDbgFile (  ) 

Function get dbgFile value.

Return string.

Definition at line 184 of file config.cpp.

References m_dbgFile.

                         {
    return m_dbgFile;
}

string Config::GetDbgFlags (  ) 

Function get dbgFlags value.

Return string.

Definition at line 188 of file config.cpp.

References m_dbgFlags.

                          {
    return m_dbgFlags;
}

string Config::GetDbgLevel (  ) 

Function get dbgLeve value.

Return string.

Definition at line 180 of file config.cpp.

References m_dbgLevel.

                          {
    return m_dbgLevel;
}

string Config::GetGamserver (  ) 

Function get gammserver value.

Return string.

Definition at line 156 of file config.cpp.

References m_gamserver.

                           {
    return m_gamserver;
}

string Config::GetHostname (  ) 

Function get hostname value.

Return string.

Definition at line 160 of file config.cpp.

References m_hostname.

                          {
    return m_hostname;
}

string Config::GetLocalMountpoint (  ) 

Function get local mount point value.

Return string.

Definition at line 172 of file config.cpp.

References m_localMountpoint.

                                 {
    return m_localMountpoint;
}

string Config::GetLogDirectory (  ) 

Function get log directory value.

Return string.

Definition at line 176 of file config.cpp.

References m_logDirectory.

                              {
    return m_logDirectory;
}

string Config::GetPartionName (  ) 

Function get partition name value.

Return string.

Definition at line 164 of file config.cpp.

References m_partitionName.

                             {
    return m_partitionName;
}

string Config::GetSharedDir (  ) 

Function get shared directory value.

Return string.

Definition at line 168 of file config.cpp.

References m_sharedDir.

                           {
    return m_sharedDir;
}

bool Config::IsReady (  ) 

Function return true if all 4 needed parameters are set and no warnings were print.

Definition at line 193 of file config.cpp.

References m_gamserver, m_localMountpoint, m_noWarning, m_partitionName, and m_sharedDir.

                    {
    return ((m_gamserver.length() != 0)
         && (m_partitionName.length() != 0)
         && (m_localMountpoint.length() != 0)
         && (m_sharedDir.length() != 0)
         && (m_noWarning));
}

void Config::ReadFile ( string &  a_file  )  [private]

Read file and get value paramaters.

Parameters:
a_file string

Definition at line 29 of file config.cpp.

References DEBUG, ErrorReport(), file, getline(), m_dbgFile, m_dbgFlags, m_dbgLevel, m_gamserver, m_hostname, m_localMountpoint, m_logDirectory, m_partitionName, m_sharedDir, RemoveWhiteSpaces(), and TabToSpace().

Referenced by Config().

                                     {
    DEBUG("==>","ReadFile");
    int countLine = 0;
    fstream file(a_file.c_str(), ios::in);
    if (file.good() == false) {
        DEBUG("Error occured!","Fstream not created");
        cerr << "File not found!" << endl;
        DEBUG("<==","ReadFile");
        return;
    }
    if (file.is_open() == true) { //if not open something needed ... termination
        DEBUG("File is","open!");
        while (!file.eof()) {
            string line;
            getline(file, line);
            countLine++;
            line = RemoveWhiteSpaces(line);
            line = TabToSpace(line);
            DEBUG("Current line : ", line);
            string name; //name of parameter
            string param;//value of parameter

            // Is this line empty?
            size_t lineSize = line.size();
            if (int(lineSize) == 0) {
                DEBUG("Line : ", countLine);
                DEBUG("!Line is ","EMPTY!");
                continue;
            }
            // Is this line a comment?
            size_t hashPos = line.find('#',0); //hash position
            if (int(hashPos) == 0) {
                DEBUG("Line number: ", countLine);
                DEBUG("Line is comment : ", line);
                continue;
            }
            // Is this line in valid format (keyword value)?
            size_t ePos = line.find('='); //= position
            if (int(ePos) < 0) {
                DEBUG("Line:", countLine);
                DEBUG("ePos is", "negative");
                DEBUG("Not found in line", line);
                ErrorReport(line,countLine,"Invalid format!");
                continue;
            }

            DEBUG("Line:", countLine);
            DEBUG("e position-start",int(ePos));

            // Parsing the line!
            param = line.substr(ePos+1,lineSize); // value right of ePos
            param = RemoveWhiteSpaces(param);
            name = line.substr(0, ePos);
            name = RemoveWhiteSpaces(name);//value left of ePos

            // Seting values to parameters variables
            if (name.compare("gamserver") == 0) {
                m_gamserver = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("hostname") == 0) {
                m_hostname = param;
                DEBUG("Found parameter:", param);
            }
            else if (name.compare("partitionName") == 0) {
                m_partitionName = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("sharedDir") == 0) {
                m_sharedDir = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("localMountpoint") == 0) {
                m_localMountpoint = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("logDirectory") == 0) {
                m_logDirectory = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("HSM_DEBUG_LEVEL") == 0) {
                m_dbgLevel = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("HSM_DEBUG_FILE") == 0) {
                m_dbgFile = param;
                DEBUG("Found parameter: ", param);
            }
            else if (name.compare("HSM_DEBUG_FLAGS") == 0) {
                m_dbgFlags = param;
                DEBUG("Found parameter: ", param);
            }
            else {
                DEBUG("!","Nothing found");
                ErrorReport(line, countLine,"Found wrong keyword!");
            }
        }// while (!file.eof())
        file.close();
    }// if (file.is_open() == true)
    else {
        DEBUG("File is NOT","OPEN");
        cerr << "File is not open!" << endl;
    }
    DEBUG("<==","ReadFile");
}// ReadFile(string & a_file)

Here is the call graph for this function:

Here is the caller graph for this function:

string Config::RemoveWhiteSpaces ( string &  a_line  )  [private]

Function remove white spaces.from the input string.

Parameters:
input string

Definition at line 136 of file config.cpp.

Referenced by ReadFile().

                                               {
    char const* delimiters = "\t,' '"; // search delimiters
    size_t firstnotWhite = a_line.find_first_not_of(delimiters); // find first character not equal to delimiters
    a_line.erase(0,firstnotWhite);
    size_t lastnotWhite = a_line.find_last_not_of(delimiters); // find last character not equal to delimiters
    a_line.erase(lastnotWhite+1);
    return a_line;
}

Here is the caller graph for this function:

string Config::TabToSpace ( string &  a_line  )  [private]

Function replace tab with 4 spaces.

Parameters:
input string

Definition at line 146 of file config.cpp.

Referenced by ReadFile().

                                        {
    size_t tabPos = a_line.find('\t'); // find first tab position
    if (int(tabPos) >= 0) {
    string spaces = "    ";
    a_line.replace(tabPos, 1, spaces);
    TabToSpace(a_line);
    }
    return a_line;
}

Here is the caller graph for this function:


Member Data Documentation

string Config::m_dbgFile [private]

Definition at line 51 of file ivdapi/config.h.

Referenced by GetDbgFile(), and ReadFile().

string Config::m_dbgFlags [private]

Definition at line 52 of file ivdapi/config.h.

Referenced by GetDbgFlags(), and ReadFile().

string Config::m_dbgLevel [private]

Definition at line 50 of file ivdapi/config.h.

Referenced by GetDbgLevel(), and ReadFile().

string Config::m_gamserver [private]

Definition at line 44 of file ivdapi/config.h.

Referenced by GetGamserver(), IsReady(), and ReadFile().

string Config::m_hostname [private]

Definition at line 45 of file ivdapi/config.h.

Referenced by GetHostname(), and ReadFile().

string Config::m_localMountpoint [private]

Definition at line 48 of file ivdapi/config.h.

Referenced by GetLocalMountpoint(), IsReady(), and ReadFile().

string Config::m_logDirectory [private]

Definition at line 49 of file ivdapi/config.h.

Referenced by GetLogDirectory(), and ReadFile().

bool Config::m_noWarning [private]

Definition at line 54 of file ivdapi/config.h.

Referenced by Config(), ErrorReport(), and IsReady().

string Config::m_partitionName [private]

Definition at line 46 of file ivdapi/config.h.

Referenced by GetPartionName(), IsReady(), and ReadFile().

string Config::m_sharedDir [private]

Definition at line 47 of file ivdapi/config.h.

Referenced by GetSharedDir(), IsReady(), and ReadFile().


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