You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
4.2 KiB
141 lines
4.2 KiB
15 years ago
|
/*
|
||
|
collectingprocess.cpp
|
||
|
|
||
13 years ago
|
This file is part of libtdepim.
|
||
15 years ago
|
Copyright (c) 2004 Ingo Kloecker <kloecker@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU General Public License as
|
||
|
published by the Free Software Foundation; either version 2 of the
|
||
|
License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with this program; if not, write to the Free Software
|
||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||
|
|
||
|
In addition, as a special exception, the copyright holders give
|
||
|
permission to link the code of this program with any edition of
|
||
14 years ago
|
the TQt library by Trolltech AS, Norway (or with modified versions
|
||
|
of TQt that use the same license as TQt), and distribute linked
|
||
15 years ago
|
combinations including the two. You must obey the GNU General
|
||
|
Public License in all respects for all of the code used other than
|
||
14 years ago
|
TQt. If you modify this file, you may extend this exception to
|
||
15 years ago
|
your version of the file, but you are not obligated to do so. If
|
||
|
you do not wish to do so, delete this exception statement from
|
||
|
your version.
|
||
|
*/
|
||
|
|
||
|
#include "collectingprocess.h"
|
||
|
|
||
15 years ago
|
#include <tqvaluelist.h>
|
||
15 years ago
|
|
||
|
#include <string.h>
|
||
|
|
||
|
using namespace KPIM;
|
||
|
|
||
|
struct CollectingProcess::Private {
|
||
|
Private() : stdoutSize( 0 ), stderrSize( 0 )
|
||
|
{}
|
||
|
|
||
|
uint stdoutSize;
|
||
15 years ago
|
TQValueList<TQByteArray> stdoutBuffer;
|
||
15 years ago
|
uint stderrSize;
|
||
15 years ago
|
TQValueList<TQByteArray> stderrBuffer;
|
||
15 years ago
|
};
|
||
|
|
||
|
|
||
14 years ago
|
CollectingProcess::CollectingProcess( TQObject * parent, const char * name )
|
||
|
: KProcess( parent, name )
|
||
15 years ago
|
{
|
||
|
d = new Private();
|
||
|
}
|
||
|
|
||
|
CollectingProcess::~CollectingProcess() {
|
||
|
delete d; d = 0;
|
||
|
}
|
||
|
|
||
|
bool CollectingProcess::start( RunMode runmode, Communication comm ) {
|
||
|
// prevent duplicate connection
|
||
15 years ago
|
disconnect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ),
|
||
|
this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) );
|
||
15 years ago
|
if ( comm & Stdout ) {
|
||
15 years ago
|
connect( this, TQT_SIGNAL( receivedStdout( KProcess *, char *, int ) ),
|
||
|
this, TQT_SLOT( slotReceivedStdout( KProcess *, char *, int ) ) );
|
||
15 years ago
|
}
|
||
|
// prevent duplicate connection
|
||
15 years ago
|
disconnect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ),
|
||
|
this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) );
|
||
15 years ago
|
if ( comm & Stderr ) {
|
||
15 years ago
|
connect( this, TQT_SIGNAL( receivedStderr( KProcess *, char *, int ) ),
|
||
|
this, TQT_SLOT( slotReceivedStderr( KProcess *, char *, int ) ) );
|
||
15 years ago
|
}
|
||
|
return KProcess::start( runmode, comm );
|
||
|
}
|
||
|
|
||
|
void CollectingProcess::slotReceivedStdout( KProcess *, char *buf, int len )
|
||
|
{
|
||
15 years ago
|
TQByteArray b;
|
||
15 years ago
|
b.duplicate( buf, len );
|
||
|
d->stdoutBuffer.append( b );
|
||
|
d->stdoutSize += len;
|
||
|
}
|
||
|
|
||
|
void CollectingProcess::slotReceivedStderr( KProcess *, char *buf, int len )
|
||
|
{
|
||
15 years ago
|
TQByteArray b;
|
||
15 years ago
|
b.duplicate( buf, len );
|
||
|
d->stderrBuffer.append( b );
|
||
|
d->stderrSize += len;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQByteArray CollectingProcess::collectedStdout()
|
||
15 years ago
|
{
|
||
|
if ( d->stdoutSize == 0 ) {
|
||
15 years ago
|
return TQByteArray();
|
||
15 years ago
|
}
|
||
|
|
||
|
uint offset = 0;
|
||
15 years ago
|
TQByteArray b( d->stdoutSize );
|
||
|
for ( TQValueList<TQByteArray>::const_iterator it = d->stdoutBuffer.begin();
|
||
15 years ago
|
it != d->stdoutBuffer.end();
|
||
|
++it ) {
|
||
|
memcpy( b.data() + offset, (*it).data(), (*it).size() );
|
||
|
offset += (*it).size();
|
||
|
}
|
||
|
d->stdoutBuffer.clear();
|
||
|
d->stdoutSize = 0;
|
||
|
|
||
|
return b;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQByteArray CollectingProcess::collectedStderr()
|
||
15 years ago
|
{
|
||
|
if ( d->stderrSize == 0 ) {
|
||
15 years ago
|
return TQByteArray();
|
||
15 years ago
|
}
|
||
|
|
||
|
uint offset = 0;
|
||
15 years ago
|
TQByteArray b( d->stderrSize );
|
||
|
for ( TQValueList<TQByteArray>::const_iterator it = d->stderrBuffer.begin();
|
||
15 years ago
|
it != d->stderrBuffer.end();
|
||
|
++it ) {
|
||
|
memcpy( b.data() + offset, (*it).data(), (*it).size() );
|
||
|
offset += (*it).size();
|
||
|
}
|
||
|
d->stderrBuffer.clear();
|
||
|
d->stderrSize = 0;
|
||
|
|
||
|
return b;
|
||
|
}
|
||
|
|
||
|
void CollectingProcess::virtual_hook( int id, void * data ) {
|
||
|
KProcess::virtual_hook( id, data );
|
||
|
}
|
||
|
|
||
|
#include "collectingprocess.moc"
|