Skip to content
This repository was archived by the owner on Mar 4, 2023. It is now read-only.

Commit 7b10fdb

Browse files
committed
added "connecting" state to RemoteConnector
1 parent 78ec7f8 commit 7b10fdb

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

src/datasync/changecontroller.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ void ChangeController::setRemoteStatus(RemoteConnector::RemoteState state, const
7373
emit updateSyncState(SyncController::Disconnected);
7474
remoteReady = false;
7575
break;
76+
case RemoteConnector::RemoteConnecting:
7677
case RemoteConnector::RemoteLoadingState:
7778
emit updateSyncState(SyncController::Loading);
7879
remoteReady = false;

src/datasync/remoteconnector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class Q_DATASYNC_EXPORT RemoteConnector : public QObject
2626
//! Describes the current state of the connector
2727
enum RemoteState {
2828
RemoteDisconnected,//!< The remote server is "not available"
29-
RemoteLoadingState,//!< The remote is available, and the remote state is currently beeing loaded
29+
RemoteConnecting,//!< The controller is currently trying to connect to the remote (may result in disconnected or loading states)
30+
RemoteLoadingState,//!< The remote is available (or trying to connect to it), and the remote state is currently beeing loaded
3031
RemoteReady//!< The remote state was successfully loaded and the connector is ready for synchronization
3132
};
3233
Q_ENUM(RemoteState)

src/datasync/wsauthenticator.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,22 @@ RemoteConnector *WsAuthenticator::connector()
134134

135135
void WsAuthenticator::updateConnected(int connected)
136136
{
137-
d->connected = (connected != RemoteConnector::RemoteDisconnected);
138-
emit connectedChanged(connected);
137+
auto cOld = d->connected;
138+
switch (connected) {
139+
case RemoteConnector::RemoteDisconnected:
140+
case RemoteConnector::RemoteConnecting:
141+
d->connected = false;
142+
break;
143+
case RemoteConnector::RemoteLoadingState:
144+
case RemoteConnector::RemoteReady:
145+
d->connected = true;
146+
break;
147+
default:
148+
Q_UNREACHABLE();
149+
break;
150+
}
151+
if(d->connected != cOld)
152+
emit connectedChanged(connected);
139153
}
140154

141155
WsAuthenticatorPrivate::WsAuthenticatorPrivate(WsRemoteConnector *connector) :

src/datasync/wsremoteconnector.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ void WsRemoteConnector::reconnect()
9191
emit clearAuthenticationError();
9292
state = Connecting;
9393
settings->sync();
94+
emit remoteStateChanged(RemoteConnecting);
9495

9596
auto remoteUrl = settings->value(keyRemoteUrl).toUrl();
9697
if(!remoteUrl.isValid() || !settings->value(keyRemoteEnabled, true).toBool()) {
9798
state = Disconnected;
98-
remoteStateChanged(RemoteDisconnected);
99+
emit remoteStateChanged(RemoteDisconnected);
99100
return;
100101
}
101102

@@ -144,7 +145,7 @@ void WsRemoteConnector::reloadRemoteState()
144145
reconnect();
145146
break;
146147
case Idle:
147-
remoteStateChanged(RemoteLoadingState);
148+
emit remoteStateChanged(RemoteLoadingState);
148149
if(needResync)
149150
emit performLocalReset(false);//direct connected, thus "inline"
150151
state = Reloading;
@@ -346,6 +347,7 @@ void WsRemoteConnector::error()
346347
{
347348
qCWarning(LOG) << "Socket error"
348349
<< socket->errorString();
350+
emit remoteStateChanged(RemoteDisconnected);
349351
socket->close();
350352
}
351353

@@ -356,8 +358,10 @@ void WsRemoteConnector::sslErrors(const QList<QSslError> &errors)
356358
<< error.errorString();
357359
}
358360

359-
if(settings->value(keyVerifyPeer, true).toBool())
361+
if(settings->value(keyVerifyPeer, true).toBool()) {
362+
emit remoteStateChanged(RemoteDisconnected);
360363
socket->close();
364+
}
361365
}
362366

363367
void WsRemoteConnector::sendCommand(const QByteArray &command, const QJsonValue &data)

tests/auto/datasync/WsRemoteConnectorTest/tst_wsremoteconnector.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ void WsRemoteConnectorTest::testServerConnecting()
9494
auth->setUserIdentity("invalid");
9595
auth->reconnect();
9696

97-
QVERIFY(conSpy.wait());
98-
QVERIFY(!auth->isConnected());
99-
for(auto i = 0; i < 10 && syncSpy.count() < 1; i++)
97+
for(auto i = 0; i < 10 && syncSpy.count() < 3; i++)
10098
syncSpy.wait(500);
101-
QCOMPARE(syncSpy.count(), 1);
99+
QVERIFY(!auth->isConnected());
100+
QCOMPARE(syncSpy.count(), 3);
102101
QCOMPARE(syncSpy[0][0], QVariant::fromValue(SyncController::Disconnected));
102+
QCOMPARE(syncSpy[1][0], QVariant::fromValue(SyncController::Loading));
103+
QCOMPARE(syncSpy[2][0], QVariant::fromValue(SyncController::Disconnected));
103104
QCOMPARE(controller->syncState(), SyncController::Disconnected);
104105

105106
//now connect again, but reset id first
@@ -123,9 +124,8 @@ void WsRemoteConnectorTest::testServerConnecting()
123124
syncSpy.clear();
124125
auth->reconnect();
125126

126-
QVERIFY(conSpy.wait());
127-
QVERIFY(!auth->isConnected());
128-
QVERIFY(conSpy.wait());
127+
QVERIFY(conSpy.wait());//disconnect
128+
QVERIFY(conSpy.wait());//reconnect
129129
QVERIFY(auth->isConnected());
130130
for(auto i = 0; i < 10 && syncSpy.count() < 4; i++)
131131
syncSpy.wait(500);

0 commit comments

Comments
 (0)