summaryrefslogtreecommitdiffstats
path: root/installerbuilder/libinstaller
diff options
context:
space:
mode:
authorkh1 <qt-info@nokia.com>2011-05-13 18:36:26 +0200
committerkh1 <qt-info@nokia.com>2011-05-16 20:37:25 +0200
commit367477f07449f25cdfbd2c1d4274df698f279a21 (patch)
treecf3edcc27c8f2e4ef144c7c02dd9ad3e29ab04b0 /installerbuilder/libinstaller
parent2f382c906bb77a99ff3c2363304fff5138e86497 (diff)
Make use of the QProcessWrapper own source.
Diffstat (limited to 'installerbuilder/libinstaller')
-rw-r--r--installerbuilder/libinstaller/elevatedexecuteoperation.cpp1
-rw-r--r--installerbuilder/libinstaller/fsengineclient.cpp367
-rw-r--r--installerbuilder/libinstaller/fsengineclient.h88
-rw-r--r--installerbuilder/libinstaller/libinstaller.pro6
-rw-r--r--installerbuilder/libinstaller/macrelocateqt.cpp1
-rw-r--r--installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp1
-rw-r--r--installerbuilder/libinstaller/qinstaller.cpp2
7 files changed, 9 insertions, 457 deletions
diff --git a/installerbuilder/libinstaller/elevatedexecuteoperation.cpp b/installerbuilder/libinstaller/elevatedexecuteoperation.cpp
index 7a19dbca6..288c6f29e 100644
--- a/installerbuilder/libinstaller/elevatedexecuteoperation.cpp
+++ b/installerbuilder/libinstaller/elevatedexecuteoperation.cpp
@@ -35,6 +35,7 @@
#include "environment.h"
#include "fsengineclient.h"
#include "common/utils.h"
+#include "qprocesswrapper.h"
#include <QThread>
diff --git a/installerbuilder/libinstaller/fsengineclient.cpp b/installerbuilder/libinstaller/fsengineclient.cpp
index 3df09b166..f5f8d8c5b 100644
--- a/installerbuilder/libinstaller/fsengineclient.cpp
+++ b/installerbuilder/libinstaller/fsengineclient.cpp
@@ -1269,372 +1269,5 @@ RETURN_NO_ARGS_CONST( QSettingsWrapper::Status, status );
VOID_NO_ARGS( sync )
RETURN_TWO_ARGS_CONST( QVariant, value, const QString&, const QVariant& )
-class QProcessWrapper::Private
-{
-public:
- Private( QProcessWrapper* qq )
- : q( qq ),
- ignoreTimer( false ),
- socket( 0 )
- {
- }
-
- bool createSocket()
- {
- if( !FSEngineClientHandler::instance()->isActive() )
- return false;
- if( socket != 0 && socket->state() == static_cast< int >( QLocalSocket::ConnectedState ) )
- return true;
- if( socket != 0 )
- delete socket;
-#ifdef FSENGINE_TCP
- socket = new QTcpSocket;
-#else
- socket = new QLocalSocket;
-#endif
- if( !FSEngineClientHandler::instance()->connect( socket ) )
- return false;
- stream.setDevice( socket );
- stream.setVersion( QDataStream::Qt_4_2 );
-
- stream << QString::fromLatin1( "createQProcess" );
- socket->flush();
- stream.device()->waitForReadyRead( -1 );
- quint32 test;
- stream >> test;
- stream.device()->readAll();
-
- q->startTimer( 250 );
-
- return true;
- }
-
- class TimerBlocker
- {
- public:
- explicit TimerBlocker( const QProcessWrapper* wrapper )
- : w( const_cast< QProcessWrapper* >( wrapper ) )
- {
- w->d->ignoreTimer = true;
- }
- ~TimerBlocker()
- {
- w->d->ignoreTimer = false;
- }
-
- private:
- QProcessWrapper* const w;
- };
-
-private:
- QProcessWrapper* const q;
-
-public:
- bool ignoreTimer;
-
- QProcess process;
-#ifdef FSENGINE_TCP
- mutable QTcpSocket* socket;
-#else
- mutable QLocalSocket* socket;
-#endif
- mutable QDataStream stream;
-};
-
-QProcessWrapper::QProcessWrapper( QObject* parent )
- : QObject( parent ),
- d( new Private( this ) )
-{
- KDMetaMethodIterator it( QProcess::staticMetaObject, KDMetaMethodIterator::Signal, KDMetaMethodIterator::IgnoreQObjectMethods );
- while( it.hasNext() )
- {
- it.next();
- connect( &d->process, it.connectableSignature(), this, it.connectableSignature() );
- }
-}
-
-QProcessWrapper::~QProcessWrapper()
-{
- if( d->socket != 0 )
- {
- d->stream << QString::fromLatin1( "destroyQProcess" );
- d->socket->flush();
- quint32 result;
- d->stream >> result;
-
- if( QThread::currentThread() == d->socket->thread() )
- {
- d->socket->close();
- delete d->socket;
- }
- else
- {
- d->socket->deleteLater();
- }
- }
- delete d;
-}
-
-void QProcessWrapper::timerEvent( QTimerEvent* event )
-{
- Q_UNUSED( event )
-
- if( d->ignoreTimer )
- return;
-
- QList< QVariant > receivedSignals;
-
- {
- const Private::TimerBlocker blocker( this );
-
- d->stream << QString::fromLatin1( "getQProcessSignals" );
- d->socket->flush();
- d->stream.device()->waitForReadyRead( -1 );
- quint32 test;
- d->stream >> test;
- d->stream >> receivedSignals;
- d->stream.device()->readAll();
- }
-
- while( !receivedSignals.isEmpty() )
- {
- const QString name = receivedSignals.takeFirst().toString();
- if( name == QLatin1String( "started" ) )
- {
- emit started();
- }
- else if( name == QLatin1String( "readyRead" ) )
- {
- emit readyRead();
- }
- else if( name == QLatin1String( "stateChanged" ) )
- {
- const QProcess::ProcessState newState = static_cast< QProcess::ProcessState >( receivedSignals.takeFirst().toInt() );
- emit stateChanged( newState );
- }
- else if( name == QLatin1String( "finished" ) )
- {
- const int exitCode = receivedSignals.takeFirst().toInt();
- const QProcess::ExitStatus exitStatus = static_cast< QProcess::ExitStatus >( receivedSignals.takeFirst().toInt() );
- emit finished( exitCode );
- emit finished( exitCode, exitStatus );
- }
- }
-}
-
-static QDataStream& operator>>( QDataStream& stream, QProcessWrapper::ProcessState& state )
-{
- int s;
- stream >> s;
- state = static_cast< QProcessWrapper::ProcessState >( s );
- return stream;
-}
-
-static QDataStream& operator>>( QDataStream& stream, QProcessWrapper::ExitStatus& status )
-{
- int s;
- stream >> s;
- status = static_cast< QProcessWrapper::ExitStatus >( s );
- return stream;
-}
-
-static QDataStream& operator>>( QDataStream& stream, QProcessWrapper::ProcessChannelMode& status )
-{
- int s;
- stream >> s;
- status = static_cast< QProcessWrapper::ProcessChannelMode >( s );
- return stream;
-}
-
-static QDataStream& operator>>( QDataStream& stream, QProcessWrapper::ProcessChannel& status )
-{
- int s;
- stream >> s;
- status = static_cast< QProcessWrapper::ProcessChannel >( s );
- return stream;
-}
-
-#undef RETURN_NO_ARGS_CONST
-#define RETURN_NO_ARGS_CONST( RESULT, NAME ) \
-RESULT QProcessWrapper::NAME() const \
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QProcess::"#NAME ) ); \
- else \
- return static_cast< RESULT >( d->process.NAME() ); \
-}
-
-#define RETURN_NO_ARGS( RESULT, NAME ) \
-RESULT QProcessWrapper::NAME() \
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QProcess::"#NAME ) ); \
- else \
- return d->process.NAME(); \
-}
-
-#undef RETURN_ONE_ARG
-#define RETURN_ONE_ARG( RESULT, NAME, TYPE1 ) \
-RESULT QProcessWrapper::NAME( TYPE1 param1 ) \
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QProcess::"#NAME ), param1 ); \
- else \
- return d->process.NAME( param1 ); \
-}
-
-#undef RETURN_ONE_ARG_CONST
-#define RETURN_ONE_ARG_CONST( RESULT, NAME, TYPE1 ) \
-RESULT QProcessWrapper::NAME( TYPE1 param1 ) const \
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QProcess::"#NAME ), param1 ); \
- else \
- return d->process.NAME( param1 ); \
-}
-
-#undef RETURN_TWO_ARGS_CONST
-#define RETURN_TWO_ARGS_CONST( RESULT, NAME, TYPE1, TYPE2 ) \
-RESULT QProcessWrapper::NAME( TYPE1 param1, TYPE2 param2 ) const \
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QProcess::"#NAME ), param1, param2 ); \
- else \
- return d->process.NAME( param1, param2 ); \
-}
-
-#undef VOID_NO_ARGS
-#define VOID_NO_ARGS( NAME ) \
-void QProcessWrapper::NAME() \
-{ \
- qDebug() << Q_FUNC_INFO; \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::"#NAME ) ); \
- else \
- d->process.NAME(); \
-}
-
-#undef VOID_ONE_ARG
-#define VOID_ONE_ARG( NAME, TYPE1 ) \
-void QProcessWrapper::NAME( TYPE1 param1 ) \
-{ \
- qDebug() << Q_FUNC_INFO; \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::"#NAME ), param1 ); \
- else \
- d->process.NAME( param1 ); \
-}
-
-#undef VOID_TWO_ARGS
-#define VOID_TWO_ARGS( NAME, TYPE1, TYPE2 ) \
-void QProcessWrapper::NAME( TYPE1 param1, TYPE2 param2 ) \
-{ \
- qDebug() << Q_FUNC_INFO; \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::"#NAME ), param1, param2 ); \
- else \
- d->process.NAME( param1, param2 ); \
-}
-
-#define VOID_THREE_ARGS( NAME, TYPE1, TYPE2, TYPE3 ) \
-void QProcessWrapper::NAME( TYPE1 param1, TYPE2 param2, TYPE3 param3 ) \
-{ \
- qDebug() << Q_FUNC_INFO; \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::"#NAME ), param1, param2, param3 ); \
- else \
- d->process.NAME( param1, param2, param3 ); \
-}
-
-VOID_NO_ARGS( closeWriteChannel );
-RETURN_NO_ARGS_CONST( int, exitCode );
-RETURN_NO_ARGS_CONST( QProcessWrapper::ExitStatus, exitStatus );
-VOID_NO_ARGS( kill )
-RETURN_NO_ARGS( QByteArray, readAll );
-RETURN_NO_ARGS( QByteArray, readAllStandardOutput );
-VOID_THREE_ARGS( start, const QString&, const QStringList&, QIODevice::OpenMode )
-VOID_ONE_ARG( start, const QString& )
-
-bool startDetached( const QString& program, const QStringList& args, const QString& workingDirectory, qint64* pid );
-
-bool QProcessWrapper::startDetached( const QString& program, const QStringList& arguments, const QString& workingDirectory, qint64* pid )
-{
- QProcessWrapper w;
- if( w.d->createSocket() )
- {
- const QPair< bool, qint64 > result = callRemoteMethod< QPair< bool, qint64 > >( w.d->stream, QLatin1String( "QProcess::startDetached" ), program, arguments, workingDirectory );
- if( pid != 0 )
- *pid = result.second;
- return result.first;
- }
- else
- {
- return ::startDetached( program, arguments, workingDirectory, pid );
- }
-}
-
-bool QProcessWrapper::startDetached( const QString& program, const QStringList& arguments )
-{
- return startDetached( program, arguments, QDir::currentPath() );
-}
-
-bool QProcessWrapper::startDetached( const QString& program )
-{
- return startDetached( program, QStringList() );
-}
-
-void QProcessWrapper::setProcessChannelMode( QProcessWrapper::ProcessChannelMode mode )
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::setProcessChannelMode" ), static_cast<QProcess::ProcessChannelMode>( mode ) ); \
- else \
- d->process.setProcessChannelMode( static_cast<QProcess::ProcessChannelMode>( mode ) ); \
-}
-
-/*!
- Cancels the process. This methods tries to terminate the process
- gracefully by calling QProcess::terminate. After 10 seconds, the process gets killed.
- */
-void QProcessWrapper::cancel()
-{
- if( state() == QProcessWrapper::Running )
- terminate();
- if( !waitForFinished( 10000 ) )
- kill();
-}
-
-void QProcessWrapper::setReadChannel( QProcessWrapper::ProcessChannel chan )
-{ \
- const Private::TimerBlocker blocker( this );\
- if( d->createSocket() ) \
- callRemoteVoidMethod( d->stream, QLatin1String( "QProcess::setReadChannel" ), static_cast<QProcess::ProcessChannel>( chan ) ); \
- else \
- d->process.setReadChannel( static_cast<QProcess::ProcessChannel>( chan ) ); \
-}
-
-RETURN_NO_ARGS_CONST( QProcessWrapper::ProcessState, state )
-VOID_NO_ARGS( terminate )
-RETURN_ONE_ARG( bool, waitForFinished, int )
-RETURN_ONE_ARG( bool, waitForStarted, int )
-RETURN_NO_ARGS_CONST( QProcessWrapper::ProcessChannel, readChannel )
-RETURN_NO_ARGS_CONST( QProcessWrapper::ProcessChannelMode, processChannelMode )
-RETURN_NO_ARGS_CONST( QString, workingDirectory )
-RETURN_ONE_ARG( qint64, write, const QByteArray& )
-VOID_ONE_ARG( setEnvironment, const QStringList& )
-#ifdef Q_OS_WIN
-VOID_ONE_ARG( setNativeArguments, const QString& )
-#endif
-VOID_ONE_ARG( setWorkingDirectory, const QString& )
-
#include "moc_fsengineclient.cpp"
#include "fsengineclient.moc"
diff --git a/installerbuilder/libinstaller/fsengineclient.h b/installerbuilder/libinstaller/fsengineclient.h
index 99fb6e40b..68f826a49 100644
--- a/installerbuilder/libinstaller/fsengineclient.h
+++ b/installerbuilder/libinstaller/fsengineclient.h
@@ -27,7 +27,6 @@
#define FSENGINECLIENT_H
#include <QtCore/QAbstractFileEngineHandler>
-#include <QtCore/QProcess>
#include <QtCore/QSettings>
#ifdef FSENGINE_TCP
@@ -149,91 +148,4 @@ private:
#define QSettings QSettingsWrapper
-class INSTALLER_EXPORT QProcessWrapper : public QObject
-{
- Q_OBJECT
-public:
- enum ProcessState
- {
- NotRunning,
- Starting,
- Running
- };
-
- enum ExitStatus
- {
- NormalExit,
- CrashExit
- };
-
- enum ProcessChannel
- {
- StandardOutput = 0,
- StandardError = 1
- };
-
- enum ProcessChannelMode
- {
- SeparateChannels = 0,
- MergedChannels = 1,
- ForwardedChannels = 2
- };
-
- explicit QProcessWrapper( QObject* parent = 0 );
- ~QProcessWrapper();
-
- void closeWriteChannel();
- int exitCode() const;
- ExitStatus exitStatus() const;
- void kill();
- QByteArray readAll();
- QByteArray readAllStandardOutput();
- void setWorkingDirectory( const QString& dir );
- void start( const QString& program, const QStringList& arguments, QIODevice::OpenMode mode = QIODevice::ReadWrite );
- void start( const QString& program );
- static bool startDetached( const QString& program, const QStringList& arguments, const QString& workingDirectory, qint64* pid = 0 );
- static bool startDetached( const QString& program, const QStringList& arguments );
- static bool startDetached( const QString& program );
-
- ProcessState state() const;
- void terminate();
- bool waitForFinished( int msecs = 30000 );
- bool waitForStarted( int msecs = 30000 );
- void setEnvironment( const QStringList& environment );
- QString workingDirectory() const;
- qint64 write( const QByteArray& byteArray );
- QProcessWrapper::ProcessChannel readChannel() const;
- void setReadChannel( QProcessWrapper::ProcessChannel channel );
- QProcessWrapper::ProcessChannelMode processChannelMode() const;
- void setProcessChannelMode( QProcessWrapper::ProcessChannelMode channel );
-#ifdef Q_OS_WIN
- void setNativeArguments(const QString& arguments);
-#endif
-
-Q_SIGNALS:
- void bytesWritten( qint64 );
- void aboutToClose();
- void readChannelFinished();
- void error( QProcess::ProcessError );
- void readyReadStandardOutput();
- void readyReadStandardError();
- void finished( int exitCode );
- void finished( int exitCode, QProcess::ExitStatus exitStatus );
- void readyRead();
- void started();
- void stateChanged( QProcess::ProcessState newState );
-
-public Q_SLOTS:
- void cancel();
-
-protected:
- void timerEvent( QTimerEvent* event );
-
-private:
- class Private;
- Private* d;
-};
-
-#define QProcess QProcessWrapper
-
#endif
diff --git a/installerbuilder/libinstaller/libinstaller.pro b/installerbuilder/libinstaller/libinstaller.pro
index 6d9c00681..bd53ab6e1 100644
--- a/installerbuilder/libinstaller/libinstaller.pro
+++ b/installerbuilder/libinstaller/libinstaller.pro
@@ -91,7 +91,8 @@ HEADERS += $$PWD/qinstaller.h \
getrepositoriesmetainfojob.h \
licenseoperation.h \
qinstallercomponent_p.h \
- qtcreator_constants.h
+ qtcreator_constants.h \
+ qprocesswrapper.h
SOURCES += $$PWD/qinstaller.cpp \
$$PWD/qinstaller_p.cpp \
@@ -149,7 +150,8 @@ SOURCES += $$PWD/qinstaller.cpp \
messageboxhandler.cpp \
getrepositoriesmetainfojob.cpp \
licenseoperation.cpp \
- qinstallercomponent_p.cpp
+ qinstallercomponent_p.cpp \
+ qprocesswrapper.cpp
macx {
HEADERS += macrelocateqt.h \
diff --git a/installerbuilder/libinstaller/macrelocateqt.cpp b/installerbuilder/libinstaller/macrelocateqt.cpp
index 4f59e9f2f..5660256e8 100644
--- a/installerbuilder/libinstaller/macrelocateqt.cpp
+++ b/installerbuilder/libinstaller/macrelocateqt.cpp
@@ -33,6 +33,7 @@
#include "macrelocateqt.h"
#include "common/utils.h"
#include "fsengineclient.h"
+#include "qprocesswrapper.h"
#include <QtCore/QDirIterator>
#include <QtCore/QDebug>
diff --git a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp
index 377b58688..ed31d7a43 100644
--- a/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp
+++ b/installerbuilder/libinstaller/macreplaceinstallnamesoperation.cpp
@@ -32,6 +32,7 @@
**************************************************************************/
#include "macreplaceinstallnamesoperation.h"
#include "fsengineclient.h"
+#include "qprocesswrapper.h"
#include <QtCore/QDirIterator>
#include <QtCore/QDebug>
diff --git a/installerbuilder/libinstaller/qinstaller.cpp b/installerbuilder/libinstaller/qinstaller.cpp
index 8d378c028..b2d0175bd 100644
--- a/installerbuilder/libinstaller/qinstaller.cpp
+++ b/installerbuilder/libinstaller/qinstaller.cpp
@@ -45,6 +45,7 @@
#include "qinstaller_p.h"
#include "qinstallercomponent.h"
#include "qinstallerglobal.h"
+#include "qprocesswrapper.h"
#include <QtCore/QTemporaryFile>
@@ -1229,6 +1230,7 @@ bool Installer::isProcessRunning(const QString &name) const
command as first item, the return code as second item.
\note On Unix, the output is just the output to stdout, not to stderr.
*/
+
QList<QVariant> Installer::execute(const QString &program, const QStringList &arguments,
const QString &stdIn) const
{