summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Christian <andrew.christian@nokia.com>2012-03-28 19:22:47 -0400
committerChris Craig <ext-chris.craig@nokia.com>2012-03-29 22:29:21 +0200
commit993ac839b722be3b005f0df179f6e6c4d67383da (patch)
treeee5ba2c25016ece16ff37f80484138ac074c1133
parent6fb205cec824bc38b36c0f26e3463d00457205bb (diff)
Added internalProcessError signal
Change-Id: I35a1b425c3bf28d573a4f901ed916db110bc5152 Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r--src/core/pipelauncher.cpp16
-rw-r--r--src/core/pipelauncher.h3
-rw-r--r--src/core/prelaunchprocessbackendfactory.cpp1
-rw-r--r--src/core/processbackendfactory.cpp5
-rw-r--r--src/core/processbackendfactory.h1
-rw-r--r--src/core/processbackendmanager.cpp19
-rw-r--r--src/core/processbackendmanager.h10
-rw-r--r--src/core/processmanager.cpp14
-rw-r--r--src/core/processmanager.h2
-rw-r--r--src/core/remoteprocessbackendfactory.cpp4
-rw-r--r--src/core/remoteprotocol.h2
-rw-r--r--src/core/socketlauncher.cpp13
-rw-r--r--src/core/socketlauncher.h3
-rw-r--r--tests/auto/processmanager/tst_processmanager.cpp70
14 files changed, 120 insertions, 43 deletions
diff --git a/src/core/pipelauncher.cpp b/src/core/pipelauncher.cpp
index d59168c..fdccbe0 100644
--- a/src/core/pipelauncher.cpp
+++ b/src/core/pipelauncher.cpp
@@ -122,6 +122,22 @@ void PipeLauncher::handleInternalProcessChange()
/*!
\internal
+
+ We override this function to forward internal process errors
+ */
+
+void PipeLauncher::handleInternalProcessError(QProcess::ProcessError error)
+{
+ Q_ASSERT(m_client);
+
+ QJsonObject object;
+ object.insert(RemoteProtocol::remote(), RemoteProtocol::internalprocesserror());
+ object.insert(RemoteProtocol::processError(), error);
+ m_client->send(object);
+}
+
+/*!
+ \internal
*/
void PipeLauncher::receive(const QJsonObject& message)
diff --git a/src/core/pipelauncher.h b/src/core/pipelauncher.h
index afa80e2..9a56a02 100644
--- a/src/core/pipelauncher.h
+++ b/src/core/pipelauncher.h
@@ -60,6 +60,9 @@ protected:
virtual void handleIdleCpuRequest();
virtual void handleInternalProcessChange();
+protected slots:
+ virtual void handleInternalProcessError(QProcess::ProcessError);
+
private slots:
void receive(const QJsonObject& object);
diff --git a/src/core/prelaunchprocessbackendfactory.cpp b/src/core/prelaunchprocessbackendfactory.cpp
index 3d839c7..0e63c22 100644
--- a/src/core/prelaunchprocessbackendfactory.cpp
+++ b/src/core/prelaunchprocessbackendfactory.cpp
@@ -246,6 +246,7 @@ void PrelaunchProcessBackendFactory::prelaunchError(QProcess::ProcessError err)
}
updateState();
+ emit internalProcessError(err);
}
/*!
diff --git a/src/core/processbackendfactory.cpp b/src/core/processbackendfactory.cpp
index 004a6dd..c9d030b 100644
--- a/src/core/processbackendfactory.cpp
+++ b/src/core/processbackendfactory.cpp
@@ -279,6 +279,11 @@ void ProcessBackendFactory::rewrite(ProcessInfo& info)
Create a ProcessBackend object based on the ProcessInfo \a info and \a parent.
*/
+/*!
+ \fn void ProcessBackendFactory::internalProcessError(QProcess::ProcessError error)
+ This signal is emitted when an internal process has an \a error.
+*/
+
#include "moc_processbackendfactory.cpp"
QT_END_NAMESPACE_PROCESSMANAGER
diff --git a/src/core/processbackendfactory.h b/src/core/processbackendfactory.h
index 0759f90..c313442 100644
--- a/src/core/processbackendfactory.h
+++ b/src/core/processbackendfactory.h
@@ -83,6 +83,7 @@ public:
signals:
void internalProcessesChanged();
+ void internalProcessError(QProcess::ProcessError);
void matchDelegateChanged();
void rewriteDelegateChanged();
void idleCpuRequestChanged();
diff --git a/src/core/processbackendmanager.cpp b/src/core/processbackendmanager.cpp
index 2d338c4..6321929 100644
--- a/src/core/processbackendmanager.cpp
+++ b/src/core/processbackendmanager.cpp
@@ -168,6 +168,10 @@ void ProcessBackendManager::addFactory(ProcessBackendFactory *factory)
factory->setParent(this);
factory->setMemoryRestricted(m_memoryRestricted);
connect(factory, SIGNAL(internalProcessesChanged()), SLOT(updateInternalProcesses()));
+ connect(factory, SIGNAL(internalProcessError(QProcess::ProcessError)),
+ SIGNAL(internalProcessError(QProcess::ProcessError)));
+ connect(factory, SIGNAL(internalProcessError(QProcess::ProcessError)),
+ SLOT(handleInternalProcessError(QProcess::ProcessError)));
connect(factory, SIGNAL(idleCpuRequestChanged()), SLOT(updateIdleCpuRequest()));
updateIdleCpuRequest();
}
@@ -309,6 +313,16 @@ void ProcessBackendManager::handleInternalProcessChange()
}
/*!
+ Override thie function to customize your handling of internal
+ process \a error values.
+ */
+
+void ProcessBackendManager::handleInternalProcessError(QProcess::ProcessError error)
+{
+ Q_UNUSED(error);
+}
+
+/*!
\fn void ProcessBackendManager::internalProcessesChanged()
Signal emitted whenever the list of internal processes has changed.
*/
@@ -318,6 +332,11 @@ void ProcessBackendManager::handleInternalProcessChange()
Signal emitted whenever the IdleDelegate is changed.
*/
+/*!
+ \fn void ProcessBackendManager::internalProcessError(QProcess::ProcessError error)
+ Signal emitted when an internal process has an \a error.
+*/
+
#include "moc_processbackendmanager.cpp"
QT_END_NAMESPACE_PROCESSMANAGER
diff --git a/src/core/processbackendmanager.h b/src/core/processbackendmanager.h
index bfb5597..2c4fcbb 100644
--- a/src/core/processbackendmanager.h
+++ b/src/core/processbackendmanager.h
@@ -75,16 +75,18 @@ public:
void setIdleDelegate(IdleDelegate *);
bool idleCpuRequest() const { return m_idleCpuRequest; }
-protected:
- virtual void handleIdleCpuRequest();
- virtual void handleInternalProcessChange();
-
signals:
void idleDelegateChanged();
void internalProcessesChanged();
+ void internalProcessError(QProcess::ProcessError);
+
+protected:
+ virtual void handleIdleCpuRequest();
+ virtual void handleInternalProcessChange();
protected slots:
void idleCpuAvailable();
+ virtual void handleInternalProcessError(QProcess::ProcessError);
private slots:
void updateIdleCpuRequest();
diff --git a/src/core/processmanager.cpp b/src/core/processmanager.cpp
index 32eca25..ac49d23 100644
--- a/src/core/processmanager.cpp
+++ b/src/core/processmanager.cpp
@@ -70,6 +70,9 @@ ProcessManager::ProcessManager(QObject *parent)
: QObject(parent)
{
m_backend = new ProcessBackendManager(this);
+ connect(m_backend, SIGNAL(internalProcessesChanged()), SIGNAL(internalProcessesChanged()));
+ connect(m_backend, SIGNAL(internalProcessError(QProcess::ProcessError)),
+ SIGNAL(internalProcessError(QProcess::ProcessError)));
}
/*!
@@ -316,6 +319,17 @@ void ProcessManager::processFrontendDestroyed()
This signal is emitted when the idle delegate is changed
*/
+/*!
+ \fn void ProcessManager::internalProcessesChanged()
+ This signal is emitted when the list of internal processes changes.
+*/
+
+/*!
+ \fn void ProcessManager::internalProcessError(QProcess::ProcessError error)
+ This signal is emitted when an internal process has an \a error.
+*/
+
+
#include "moc_processmanager.cpp"
QT_END_NAMESPACE_PROCESSMANAGER
diff --git a/src/core/processmanager.h b/src/core/processmanager.h
index 70e8ef9..b53260d 100644
--- a/src/core/processmanager.h
+++ b/src/core/processmanager.h
@@ -89,6 +89,8 @@ public:
signals:
void memoryRestrictedChanged();
void idleDelegateChanged();
+ void internalProcessesChanged();
+ void internalProcessError(QProcess::ProcessError);
protected slots:
virtual void processFrontendAboutToStart();
diff --git a/src/core/remoteprocessbackendfactory.cpp b/src/core/remoteprocessbackendfactory.cpp
index 67293ac..ba55297 100644
--- a/src/core/remoteprocessbackendfactory.cpp
+++ b/src/core/remoteprocessbackendfactory.cpp
@@ -204,6 +204,10 @@ void RemoteProcessBackendFactory::receive(const QJsonObject& message)
qSort(plist);
setInternalProcesses(plist);
}
+ else if (remote == RemoteProtocol::internalprocesserror()) {
+ int value = (int) message.value(RemoteProtocol::processError()).toDouble();
+ emit internalProcessError(static_cast<QProcess::ProcessError>(value));
+ }
else {
int id = message.value(QLatin1String("id")).toDouble();
if (m_backendMap.contains(id))
diff --git a/src/core/remoteprotocol.h b/src/core/remoteprotocol.h
index f2b86cf..c469a38 100644
--- a/src/core/remoteprotocol.h
+++ b/src/core/remoteprotocol.h
@@ -53,6 +53,7 @@ public:
static inline const QString error() { return QStringLiteral("error"); }
static inline const QString errorString() { return QStringLiteral("errorString"); }
static inline const QString event() { return QStringLiteral("event"); }
+ static inline const QString processError() { return QStringLiteral("processError"); }
static inline const QString exitCode() { return QStringLiteral("exitCode"); }
static inline const QString exitStatus() { return QStringLiteral("exitStatus"); }
static inline const QString finished() { return QStringLiteral("finished"); }
@@ -62,6 +63,7 @@ public:
static inline const QString idlecpuavailable() { return QStringLiteral("idlecpuavailable"); }
static inline const QString info() { return QStringLiteral("info"); }
static inline const QString internalprocesses() { return QStringLiteral("internalprocesses"); }
+ static inline const QString internalprocesserror() { return QStringLiteral("internalprocesserror"); }
static inline const QString key() { return QStringLiteral("key"); }
static inline const QString memory() { return QStringLiteral("memory"); }
static inline const QString oomAdjustment() { return QStringLiteral("oomAdjustment"); }
diff --git a/src/core/socketlauncher.cpp b/src/core/socketlauncher.cpp
index dd7be2d..0adf083 100644
--- a/src/core/socketlauncher.cpp
+++ b/src/core/socketlauncher.cpp
@@ -177,6 +177,19 @@ void SocketLauncher::handleInternalProcessChange()
}
/*!
+ \internal
+ We override this function to forward internal process errors
+ */
+
+void SocketLauncher::handleInternalProcessError(QProcess::ProcessError error)
+{
+ QJsonObject object;
+ object.insert(RemoteProtocol::remote(), RemoteProtocol::internalprocesserror());
+ object.insert(RemoteProtocol::processError(), error);
+ m_server->broadcast(object);
+}
+
+/*!
\internal
*/
diff --git a/src/core/socketlauncher.h b/src/core/socketlauncher.h
index 004ba77..3eef41d 100644
--- a/src/core/socketlauncher.h
+++ b/src/core/socketlauncher.h
@@ -65,6 +65,9 @@ protected:
virtual void handleIdleCpuRequest();
virtual void handleInternalProcessChange();
+protected slots:
+ virtual void handleInternalProcessError(QProcess::ProcessError);
+
private slots:
void connectionAdded(const QString& identifier);
void connectionRemoved(const QString& identifier);
diff --git a/tests/auto/processmanager/tst_processmanager.cpp b/tests/auto/processmanager/tst_processmanager.cpp
index 9df9ac7..b62addb 100644
--- a/tests/auto/processmanager/tst_processmanager.cpp
+++ b/tests/auto/processmanager/tst_processmanager.cpp
@@ -225,6 +225,18 @@ static void waitForPriority(ProcessBackend *process, int priority, int timeout=5
}
}
+static void waitForSignal(QSignalSpy& spy, int count=1, int timeout=5000)
+{
+ QTime stopWatch;
+ stopWatch.start();
+ forever {
+ if (spy.count() >= count)
+ break;
+ if (stopWatch.elapsed() >= timeout)
+ QFAIL("Timed out");
+ QTestEventLoop::instance().enterLoop(1);
+ }
+}
/**********************************************************************/
@@ -276,16 +288,9 @@ public:
QFAIL("String not found");
}
- void waitStart(int timeout=5000) {
- stopWatch.restart();
- forever {
- if (startSpy.count())
- break;
- if (stopWatch.elapsed() >= timeout)
- QFAIL("Timed out");
- QTestEventLoop::instance().enterLoop(1);
- }
- }
+ void waitStart(int timeout=5000) { waitForSignal(startSpy, 1, timeout); }
+ void waitFinished(int timeout=5000) { waitForSignal(finishedSpy, 1, timeout); }
+ void waitStdout(int timeout=5000) { waitForSignal(stdoutSpy, stdoutSpy.count() + 1, timeout); }
void waitFailedStart(int timeout=5000) {
stopWatch.restart();
@@ -298,29 +303,6 @@ public:
}
}
- void waitFinished(int timeout=5000) {
- stopWatch.restart();
- forever {
- if (finishedSpy.count())
- break;
- if (stopWatch.elapsed() >= timeout)
- QFAIL("Timed out");
- QTestEventLoop::instance().enterLoop(1);
- }
- }
-
- void waitStdout(int timeout=5000) {
- stopWatch.restart();
- int count = stdoutSpy.count();
- forever {
- if (stdoutSpy.count() != count)
- break;
- if (stopWatch.elapsed() >= timeout)
- QFAIL("Timed out");
- QTestEventLoop::instance().enterLoop(1);
- }
- }
-
void checkExitCode(int exitCode) {
QVERIFY(finishedSpy.count() == 1);
QCOMPARE(qVariantValue<int>(finishedSpy.at(0).at(0)), exitCode);
@@ -1023,8 +1005,10 @@ void tst_ProcessManager::prelaunchChildAbort()
Q_PID pid = manager->internalProcesses().at(0);
// Kill the prelaunched process and verify that it is restarted
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 0);
+ waitForSignal(spy);
waitForInternalProcess(manager, 1, delegate->idleInterval() + 2000);
delete manager;
}
@@ -1055,8 +1039,10 @@ void tst_ProcessManager::prelaunchWaitIdleTest()
// Kill the prelaunched process and verify that it is restarted
Q_PID pid = manager->internalProcesses().at(0);
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 0);
+ waitForSignal(spy);
waitForInternalProcess(manager, 1, delegate->idleInterval() + 2000);
delete manager;
@@ -1099,8 +1085,10 @@ void tst_ProcessManager::prelaunchForPipeLauncherIdle()
// Kill the prelaunched process and verify that it is restarted
Q_PID pid = manager->internalProcesses().at(1);
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 1);
+ waitForSignal(spy);
waitForInternalProcess(manager, 2, delegate->idleInterval() + 2000);
// Kill the prelaunched process and keep it dead - otherwise we'll leave a hanging child
@@ -1108,6 +1096,7 @@ void tst_ProcessManager::prelaunchForPipeLauncherIdle()
pid = manager->internalProcesses().at(1);
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 1);
+ waitForSignal(spy, 2);
waitForTimeout(delegate->idleInterval() + 2000);
QCOMPARE(manager->internalProcesses().count(), 1);
@@ -1145,20 +1134,19 @@ void tst_ProcessManager::prelaunchForPipeLauncherMemory()
QCOMPARE(manager->internalProcesses().count(), 1);
// Now the prelaunch process should launch
- qDebug() << "Turning off memory restrictions";
manager->setMemoryRestricted(false);
waitForInternalProcess(manager, 2, delegate->idleInterval() + 2000);
QCOMPARE(manager->internalProcesses().count(), 2);
// Kill the prelaunched process and verify that it is restarted
- qDebug() << "Directly kill the prelaunched process";
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
Q_PID pid = manager->internalProcesses().at(1);
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 1);
+ waitForSignal(spy);
waitForInternalProcess(manager, 2, delegate->idleInterval() + 2000);
// Kill the prelaunched process and keep it dead - otherwise we'll leave a hanging child
- qDebug() << "Turn on memory restrictions";
manager->setMemoryRestricted(true);
waitForInternalProcess(manager, 1);
waitForTimeout(delegate->idleInterval() + 2000);
@@ -1251,8 +1239,10 @@ void tst_ProcessManager::prelaunchForSocketLauncherIdle()
// Kill the prelaunched process and verify that it is restarted
Q_PID pid = manager->internalProcesses().at(0);
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 0);
+ waitForSignal(spy);
waitForInternalProcess(manager, 1, delegate->idleInterval() + 2000);
// Kill the prelaunched process and keep it dead - otherwise we'll leave a hanging child
@@ -1260,6 +1250,7 @@ void tst_ProcessManager::prelaunchForSocketLauncherIdle()
pid = manager->internalProcesses().at(0);
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 0);
+ waitForSignal(spy, 2);
waitForTimeout(delegate->idleInterval() + 2000);
QCOMPARE(manager->internalProcesses().count(), 0);
@@ -1303,12 +1294,11 @@ void tst_ProcessManager::prelaunchForSocketLauncherMemory()
QCOMPARE(manager->internalProcesses().count(), 1);
// Kill the prelaunched process and verify that it is restarted
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
Q_PID pid = manager->internalProcesses().at(0);
- qDebug() << "Killing the prelaunched process" << pid;
::kill(pid, SIGKILL);
- qDebug() << "Verify that the process count goes to zero";
waitForInternalProcess(manager, 0);
- qDebug() << "Now wait for the process count to bounce back up";
+ waitForSignal(spy);
waitForInternalProcess(manager, 1, delegate->idleInterval() + 2000);
// Kill the prelaunched process and keep it dead - otherwise we'll leave a hanging child
@@ -1412,8 +1402,10 @@ void tst_ProcessManager::frontendWaitIdleTest()
Q_PID pid = manager->internalProcesses().at(0);
// Kill the prelaunched process and verify that it is restarted
+ QSignalSpy spy(manager, SIGNAL(internalProcessError(QProcess::ProcessError)));
::kill(pid, SIGKILL);
waitForInternalProcess(manager, 0);
+ waitForSignal(spy);
waitForInternalProcess(manager, 1, delegate->idleInterval() + 2000);
delete manager;
}