• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • utils
iodevicelogger.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  iodevicelogger.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "iodevicelogger.h"
36 
37 #include <cassert>
38 
39 using namespace boost;
40 using namespace Kleo;
41 
42 class IODeviceLogger::Private {
43  IODeviceLogger* const q;
44 public:
45 
46  static bool write( const shared_ptr<QIODevice>& dev, const char* data, qint64 max );
47 
48  explicit Private( const shared_ptr<QIODevice>& io_, IODeviceLogger* qq ) : q( qq ), io( io_ ), writeLog(), readLog()
49  {
50  assert( io );
51  connect( io.get(), SIGNAL(aboutToClose()), q, SIGNAL(aboutToClose()) );
52  connect( io.get(), SIGNAL(bytesWritten(qint64)), q, SIGNAL(bytesWritten(qint64)) );
53  connect( io.get(), SIGNAL(readyRead()), q, SIGNAL(readyRead()) );
54  q->setOpenMode( io->openMode() );
55  }
56 
57  ~Private()
58  {
59  }
60 
61  const shared_ptr<QIODevice> io;
62  shared_ptr<QIODevice> writeLog;
63  shared_ptr<QIODevice> readLog;
64 };
65 
66 bool IODeviceLogger::Private::write( const shared_ptr<QIODevice>& dev, const char* data, qint64 max )
67 {
68  assert( dev );
69  assert( data );
70  assert( max >= 0 );
71  qint64 toWrite = max;
72  while ( toWrite > 0 )
73  {
74  const qint64 written = dev->write( data, toWrite );
75  if ( written < 0 )
76  return false;
77  toWrite -= written;
78  }
79  return true;
80 }
81 
82 IODeviceLogger::IODeviceLogger( const shared_ptr<QIODevice>& iod, QObject* parent ) : QIODevice( parent ), d( new Private( iod, this ) )
83 {
84 }
85 
86 IODeviceLogger::~IODeviceLogger()
87 {
88 }
89 
90 void IODeviceLogger::setWriteLogDevice( const shared_ptr<QIODevice>& dev )
91 {
92  d->writeLog = dev;
93 }
94 
95 void IODeviceLogger::setReadLogDevice( const shared_ptr<QIODevice>& dev )
96 {
97  d->readLog = dev;
98 }
99 
100 bool IODeviceLogger::atEnd() const
101 {
102  return d->io->atEnd();
103 }
104 
105 qint64 IODeviceLogger::bytesAvailable() const
106 {
107  return d->io->bytesAvailable();
108 }
109 
110 qint64 IODeviceLogger::bytesToWrite() const
111 {
112  return d->io->bytesToWrite();
113 }
114 
115 bool IODeviceLogger::canReadLine() const
116 {
117  return d->io->canReadLine();
118 }
119 
120 void IODeviceLogger::close()
121 {
122  d->io->close();
123 }
124 
125 bool IODeviceLogger::isSequential() const
126 {
127  return d->io->isSequential();
128 }
129 
130 bool IODeviceLogger::open( OpenMode mode )
131 {
132  QIODevice::open( mode );
133  return d->io->open( mode );
134 }
135 
136 qint64 IODeviceLogger::pos() const
137 {
138  return d->io->pos();
139 }
140 
141 bool IODeviceLogger::reset()
142 {
143  return d->io->reset();
144 }
145 
146 bool IODeviceLogger::seek( qint64 pos )
147 {
148  return d->io->seek( pos );
149 }
150 
151 qint64 IODeviceLogger::size() const
152 {
153  return d->io->size();
154 }
155 
156 bool IODeviceLogger::waitForBytesWritten( int msecs )
157 {
158  return d->io->waitForBytesWritten( msecs );
159 }
160 
161 bool IODeviceLogger::waitForReadyRead( int msecs )
162 {
163  return d->io->waitForReadyRead( msecs );
164 }
165 
166 qint64 IODeviceLogger::readData( char* data, qint64 maxSize )
167 {
168  const qint64 num = d->io->read( data, maxSize );
169  if ( num > 0 && d->readLog )
170  Private::write( d->readLog, data, num );
171  return num;
172 }
173 
174 qint64 IODeviceLogger::writeData( const char* data, qint64 maxSize )
175 {
176  const qint64 num = d->io->write( data, maxSize );
177  if ( num > 0 && d->writeLog )
178  Private::write( d->writeLog, data, num );
179  return num;
180 }
181 
182 qint64 IODeviceLogger::readLineData( char* data, qint64 maxSize )
183 {
184  const qint64 num = d->io->readLine( data, maxSize );
185  if ( num > 0 && d->readLog )
186  Private::write( d->readLog, data, num );
187  return num;
188 }
189 
190 
191 
Kleo::IODeviceLogger::readLineData
qint64 readLineData(char *data, qint64 maxSize)
Definition: iodevicelogger.cpp:182
Kleo::IODeviceLogger::setWriteLogDevice
void setWriteLogDevice(const boost::shared_ptr< QIODevice > &dev)
Definition: iodevicelogger.cpp:90
Kleo::IODeviceLogger::readData
qint64 readData(char *data, qint64 maxSize)
Definition: iodevicelogger.cpp:166
Kleo::IODeviceLogger::isSequential
bool isSequential() const
Definition: iodevicelogger.cpp:125
Kleo::IODeviceLogger::setReadLogDevice
void setReadLogDevice(const boost::shared_ptr< QIODevice > &dev)
Definition: iodevicelogger.cpp:95
iodevicelogger.h
Kleo::IODeviceLogger::close
void close()
Definition: iodevicelogger.cpp:120
Kleo::IODeviceLogger::canReadLine
bool canReadLine() const
Definition: iodevicelogger.cpp:115
Kleo::IODeviceLogger::atEnd
bool atEnd() const
Definition: iodevicelogger.cpp:100
Kleo::IODeviceLogger::bytesAvailable
qint64 bytesAvailable() const
Definition: iodevicelogger.cpp:105
boost::shared_ptr< QIODevice >
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::IODeviceLogger::pos
qint64 pos() const
Definition: iodevicelogger.cpp:136
Kleo::IODeviceLogger::size
qint64 size() const
Definition: iodevicelogger.cpp:151
Kleo::IODeviceLogger::bytesToWrite
qint64 bytesToWrite() const
Definition: iodevicelogger.cpp:110
Kleo::IODeviceLogger::writeData
qint64 writeData(const char *data, qint64 maxSize)
Definition: iodevicelogger.cpp:174
Kleo::IODeviceLogger::waitForReadyRead
bool waitForReadyRead(int msecs)
Definition: iodevicelogger.cpp:161
Kleo::IODeviceLogger
Definition: iodevicelogger.h:44
Kleo::IODeviceLogger::open
bool open(OpenMode mode)
Definition: iodevicelogger.cpp:130
Kleo::IODeviceLogger::reset
bool reset()
Definition: iodevicelogger.cpp:141
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::IODeviceLogger::waitForBytesWritten
bool waitForBytesWritten(int msecs)
Definition: iodevicelogger.cpp:156
QIODevice
Kleo::IODeviceLogger::seek
bool seek(qint64 pos)
Definition: iodevicelogger.cpp:146
Kleo::IODeviceLogger::~IODeviceLogger
~IODeviceLogger()
Definition: iodevicelogger.cpp:86
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal