Confdump Agent  1.4.0
ConfigurationFile.cpp
Go to the documentation of this file.
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 <streambuf>
00019 #include "Confdump/System/LinuxDumper.hpp"
00020 #include "Confdump/System/Linux/ConfigurationFile.hpp"
00021 
00022 using boost::shared_ptr;
00023 using std::streambuf;
00024 
00025 namespace Confdump
00026 {
00027 
00028 namespace System
00029 {
00030 
00031 namespace Linux
00032 {
00033 
00034 namespace
00035 {
00036 
00037 QByteArray slurpStreambuf( shared_ptr<streambuf> streambuf )
00038 {
00039     QByteArray content;
00040     const size_t buffer_size = 4096;
00041     while ( streambuf->sgetc() != std::streambuf::traits_type::eof() )
00042     {
00043         char buffer[ buffer_size ];
00044         size_t effective_read = streambuf->sgetn( buffer, buffer_size );
00045         content.append( buffer, effective_read );
00046     }
00047 
00048     return content;
00049 }
00050 
00051 }
00052 
00053 ConfigurationFile::ConfigurationFile( boost::shared_ptr<Confdump::System::LinuxDumper> driver, const boost::filesystem::path &filePath, QString refersToTable )
00054  : filePath_( QString::fromLocal8Bit( filePath.external_file_string().c_str() ) ),
00055    refersToTable_( refersToTable )
00056 {
00057     shared_ptr<streambuf> openedFile = driver->systemContext().openRoFile( filePath );
00058     fileContents_ = slurpStreambuf( openedFile );
00059 }
00060 
00061 ConfigurationFile::~ConfigurationFile()
00062 {
00063 
00064 }
00065 
00066 QString ConfigurationFile::filePath() const
00067 {
00068     return filePath_;
00069 }
00070 
00071 QString ConfigurationFile::refersToTable() const
00072 {
00073     return refersToTable_;
00074 }
00075 
00076 QByteArray ConfigurationFile::fileContents() const
00077 {
00078     return fileContents_;
00079 }
00080 
00081 }
00082 }
00083 }
00084 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends