sessionlogger.cpp
00001 /* 00002 Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 00003 Author: Kevin Ottens <kevin@kdab.com> 00004 00005 This library is free software; you can redistribute it and/or modify it 00006 under the terms of the GNU Library General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or (at your 00008 option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, but WITHOUT 00011 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to the 00017 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 00018 02110-1301, USA. 00019 */ 00020 00021 #include "sessionlogger_p.h" 00022 00023 #include <unistd.h> 00024 00025 using namespace KIMAP; 00026 00027 SessionLogger::SessionLogger() 00028 : m_id( 0 ) 00029 { 00030 static qint64 nextId = 0; 00031 m_id = ++nextId; 00032 00033 m_file.setFileName( qgetenv( "KIMAP_LOGFILE" ) 00034 + '.' + QString::number( getpid() ) 00035 + '.' + QString::number( m_id ) ); 00036 m_file.open( QFile::WriteOnly ); 00037 } 00038 00039 SessionLogger::~SessionLogger() 00040 { 00041 m_file.close(); 00042 } 00043 00044 void SessionLogger::dataSent( const QByteArray &data ) 00045 { 00046 m_file.write( "C: "+data.trimmed()+'\n' ); 00047 m_file.flush(); 00048 } 00049 00050 void SessionLogger::dataReceived( const QByteArray &data ) 00051 { 00052 m_file.write( "S: "+data.trimmed()+'\n' ); 00053 m_file.flush(); 00054 } 00055 00056 void SessionLogger::disconnectionOccured() 00057 { 00058 m_file.write( "X\n" ); 00059 } 00060 00061 00062