summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qdb/client/client.cpp33
-rw-r--r--qdb/client/client.h6
2 files changed, 8 insertions, 31 deletions
diff --git a/qdb/client/client.cpp b/qdb/client/client.cpp
index 953919f..f3687a2 100644
--- a/qdb/client/client.cpp
+++ b/qdb/client/client.cpp
@@ -85,7 +85,7 @@ void Client::ignoreErrors(bool ignoreErrors)
void Client::askDevices()
{
- setupSocketAndConnect(&Client::handleDevicesConnection, &Client::handleDevicesError);
+ setupSocketAndConnect(&Client::handleDevicesConnection, std::bind(&Client::handleErrorWithRetry, this, std::placeholders::_1, &Client::askDevices));
}
void Client::startServer()
@@ -96,12 +96,12 @@ void Client::startServer()
void Client::stopServer()
{
- setupSocketAndConnect(&Client::handleStopConnection, &Client::handleStopError);
+ setupSocketAndConnect(&Client::handleStopConnection, std::bind(&Client::handleStopError, this, std::placeholders::_1));
}
void Client::watchDevices()
{
- setupSocketAndConnect(&Client::handleWatchConnection, &Client::handleWatchError);
+ setupSocketAndConnect(&Client::handleWatchConnection, std::bind(&Client::handleErrorWithRetry, this, std::placeholders::_1, &Client::watchDevices));
}
void Client::handleDevicesConnection()
@@ -121,7 +121,7 @@ void Client::handleDevicesConnection()
shutdown(0);
}
-void Client::handleDevicesError(QLocalSocket::LocalSocketError error)
+void Client::handleErrorWithRetry(QLocalSocket::LocalSocketError error, ConnectedSlot repeatFunction)
{
if (error == QLocalSocket::PeerClosedError)
return;
@@ -141,7 +141,7 @@ void Client::handleDevicesError(QLocalSocket::LocalSocketError error)
std::cout << "Starting QDB host server\n";
m_triedToStart = true;
forkHostServer();
- QTimer::singleShot(startupDelay, this, &Client::askDevices);
+ QTimer::singleShot(startupDelay, this, repeatFunction);
}
void Client::handleStopConnection()
@@ -180,29 +180,6 @@ void Client::handleWatchConnection()
m_socket->write(createRequest(RequestType::WatchDevices));
}
-void Client::handleWatchError(QLocalSocket::LocalSocketError error)
-{
- if (error == QLocalSocket::PeerClosedError)
- return;
- if (error != QLocalSocket::ServerNotFoundError &&
- error != QLocalSocket::ConnectionRefusedError) {
- std::cerr << "Unexpected QLocalSocket error:" << qUtf8Printable(m_socket->errorString())
- << std::endl;
- shutdown(1);
- return;
- }
-
- if (m_triedToStart) {
- std::cerr << "Could not connect QDB host server even after trying to start it\n";
- shutdown(1);
- return;
- }
- std::cout << "Starting QDB host server\n";
- m_triedToStart = true;
- forkHostServer();
- QTimer::singleShot(startupDelay, this, &Client::watchDevices);
-}
-
void Client::handleWatchMessage()
{
while (m_socket->bytesAvailable() > 0) {
diff --git a/qdb/client/client.h b/qdb/client/client.h
index eccc607..482641c 100644
--- a/qdb/client/client.h
+++ b/qdb/client/client.h
@@ -36,6 +36,7 @@ class QCoreApplication;
QT_END_NAMESPACE
#include <memory>
+#include <functional>
int execClient(const QCoreApplication &app, const QString &command, const QCommandLineParser &parser);
@@ -55,14 +56,13 @@ public slots:
private:
using ConnectedSlot = void (Client::*)();
- using ErrorSlot = void (Client::*)(QLocalSocket::LocalSocketError);
+ using ErrorSlot = std::function<void(QLocalSocket::LocalSocketError)>;
void handleDevicesConnection();
- void handleDevicesError(QLocalSocket::LocalSocketError error);
+ void handleErrorWithRetry(QLocalSocket::LocalSocketError error, ConnectedSlot repeatFunction);
void handleStopConnection();
void handleStopError(QLocalSocket::LocalSocketError error);
void handleWatchConnection();
- void handleWatchError(QLocalSocket::LocalSocketError error);
void handleWatchMessage();
void setupSocketAndConnect(ConnectedSlot handleConnection, ErrorSlot handleError);
void shutdown(int exitCode);