Confdump Agent
1.4.0
|
00001 /* 00002 * Confdump-Agent - Dump static and runtime system configuration 00003 * Copyright (C) 2009-2012 Straton IT, SAS 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 3 as 00007 * published by the Free Software Foundation. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "Confdump/System/LinuxDumper.hpp" 00019 #include "Confdump/System/Linux/Uptime.hpp" 00020 00021 using boost::shared_ptr; 00022 00023 namespace Confdump 00024 { 00025 00026 namespace System 00027 { 00028 00029 namespace Linux 00030 { 00031 00032 Uptime::Uptime( quint64 millisecondsUptime ) 00033 : millisecondsUptime_( millisecondsUptime ) 00034 { 00035 } 00036 00037 Uptime::~Uptime() 00038 { 00039 } 00040 00041 /* The custom parsing done below will preserve precision, unlike any floating 00042 * type and without requiring any "big number" library. 00043 */ 00044 Result Uptime::uptime( boost::shared_ptr<LinuxDumper> driver ) 00045 { 00046 QByteArray contents = driver->systemContext().slurpConfigurationFile( boost::filesystem::path( "/proc/uptime" ), "CD_Uptime" ); 00047 QString rawUptime = QString::fromLocal8Bit( contents ); 00048 00049 Result entries; 00050 QRegExp firstDecimal( "^(\\d+)\\.(\\d{1,3})" ); 00051 if ( firstDecimal.indexIn( rawUptime ) != -1 ) 00052 { 00053 QString integer = firstDecimal.cap( 1 ); 00054 QString decimals = firstDecimal.cap( 2 ).leftJustified( 3, '0' ); 00055 quint64 uptime = integer.toULongLong() * 1000 + decimals.toULongLong(); 00056 entries.push_back( shared_ptr<Uptime>( new Uptime( uptime ) ) ); 00057 } 00058 00059 return entries; 00060 } 00061 00062 } // ns Linux 00063 } // ns System 00064 } // ns Confdump 00065