lm::LoadMonitor::StatsProvider Class Reference

Helper class which provides base for all stats providers. More...

Inheritance diagram for lm::LoadMonitor::StatsProvider:

lm::LoadMonitor::DriveStats lm::LoadMonitor::MemoryStats lm::LoadMonitor::NetworkStats lm::LoadMonitor::ProcessorStats lm::LoadMonitor::SystemStats

Public Member Functions

 StatsProvider (void)
 Constructor.
virtual ~StatsProvider (void)
 Destructor.
virtual bool QueryData (LoadSample &target)=0
virtual bool QueryData (HardwareDescription &target)=0

Protected Member Functions

bool ReadLines (const char *file_name, std::vector< std::string > &target) const
 Read lines from text file.
template<typename T>
bool GetFieldValue (const std::string &line, const size_t index, T &result, const size_t start_at=0, const char *delim=" \t") const
 Extract value of given column from the line.
std::pair< std::string, size_t > GetFieldName (const std::string &line, const std::string &end=":", const size_t start_at=0) const
 Extract name of the field.
bool BeginsWith (const std::string &str, const std::string &what) const
 Test if string begins with another string.

Static Protected Member Functions

static int GetKernelVersionCode (void)
 Get version code of the current kernel.

Private Member Functions

 StatsProvider (const StatsProvider &)
 Empty private copy-ctor to prevent copying.

Detailed Description

Helper class which provides base for all stats providers.


Constructor & Destructor Documentation

lm::LoadMonitor::StatsProvider::StatsProvider ( void   ) 

Constructor.

lm::LoadMonitor::StatsProvider::~StatsProvider ( void   )  [virtual]

Destructor.

lm::LoadMonitor::StatsProvider::StatsProvider ( const StatsProvider  )  [inline, private]

Empty private copy-ctor to prevent copying.


Member Function Documentation

bool lm::LoadMonitor::StatsProvider::BeginsWith ( const std::string &  str,
const std::string &  what 
) const [protected]

Test if string begins with another string.

Parameters:
str String to test.
what String to search for.
Returns:
true if string begins with given substring, false otherwise.

std::pair< std::string, size_t > lm::LoadMonitor::StatsProvider::GetFieldName ( const std::string &  line,
const std::string &  end = ":",
const size_t  start_at = 0 
) const [protected]

Extract name of the field.

Retrieve name of the current line. Name is string that does not contain white-space characters at the beginning or at the end (white-spaces in the middle are allowed).

Parameters:
line String which contains data and name.
end String which marks end of the field name. Default value is ":" which is suitable for files in the /proc directory.
start_at First character of the name. May be whitespace. Default value is 0.
Returns:
Pair containing name of the field and index of the first character after the separator string after name.

template<typename T>
bool lm::LoadMonitor::StatsProvider::GetFieldValue ( const std::string &  line,
const size_t  index,
T &  result,
const size_t  start_at = 0,
const char *  delims = " \t" 
) const [protected]

Extract value of given column from the line.

Retrieve value of the column with given index. Columns can be separated by custom delimiter characters. Value will be automatically converted to the target type.

Parameters:
line String which contains requested value.
index Index of the column which contains given value. First column has index of 1.
start_at Index of the first character (or some delimiter directly before) of the first column.
delims Delimiters that are between columns. Each character of this string is threated as a delimiter.
result Reference to the variable which will receive value of the given column. Value is automatically converted to the target type via the stream operator >>. If an error occured during conversion or if column with given index does not exist, original value remains unchanged.
Returns:
true on success, false if field with given index does not exist or if an error occured while converting string to the value of target type.

int lm::LoadMonitor::StatsProvider::GetKernelVersionCode ( void   )  [static, protected]

Get version code of the current kernel.

Returns:
Version code of the kernel. Code can be calculated as 0x10000 * major + 0x100 * minor + release, where major, minor and release are version numbers as determined by uname. Zero is returned if the uname call or string conversion failed.

virtual bool lm::LoadMonitor::StatsProvider::QueryData ( HardwareDescription target  )  [pure virtual]

Query data and store their descriptions.

Parameters:
target Structure which will receive data collected by this provider.
Returns:
true on success, false otherwise.

Implemented in lm::LoadMonitor::MemoryStats, lm::LoadMonitor::ProcessorStats, lm::LoadMonitor::NetworkStats, lm::LoadMonitor::DriveStats, and lm::LoadMonitor::SystemStats.

virtual bool lm::LoadMonitor::StatsProvider::QueryData ( LoadSample target  )  [pure virtual]

Query data and store them in given sample.

Parameters:
target Sample which will receive data collected by this provider.
Returns:
true on success, false otherwise.

Implemented in lm::LoadMonitor::MemoryStats, lm::LoadMonitor::ProcessorStats, lm::LoadMonitor::NetworkStats, lm::LoadMonitor::DriveStats, and lm::LoadMonitor::SystemStats.

bool lm::LoadMonitor::StatsProvider::ReadLines ( const char *  file_name,
std::vector< std::string > &  target 
) const [protected]

Read lines from text file.

This will read all lines from the text file into given vector.

Parameters:
file_name Name of the file to read.
target Vector which will receive lines read from the file. Note that lines are added at the end of the vector and data from vector are not removed automatically.
Returns:
true on success, false otherwise.


The documentation for this class was generated from the following files:
Generated on Tue Dec 19 17:43:49 2006 for Load Monitor for Linux by  doxygen 1.4.7