Skip to content

Commit 2226283

Browse files
committed
Fix registration handling
1 parent e0b8b4d commit 2226283

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

src/FlatBufferConnection.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ FlatBufferConnection::FlatBufferConnection(const QString& origin, const QString&
2323
, _registered(false)
2424
{
2525
connect(&_socket, &QTcpSocket::readyRead, this, &FlatBufferConnection::readData, Qt::UniqueConnection);
26+
connect(&_socket, &QTcpSocket::disconnected, this, &FlatBufferConnection::disconnected);
2627

2728
// init connect
2829
connectToHost();
@@ -65,12 +66,16 @@ void FlatBufferConnection::readData()
6566

6667
if (hyperionnet::VerifyReplyBuffer(verifier))
6768
{
68-
parseReply(hyperionnet::GetReply(msgData));
69+
const hyperionnet::Reply* reply = hyperionnet::GetReply(msgData);
70+
if (!parseReply(reply))
71+
{
72+
qDebug() << "Reply received with error: " << reply->error();
73+
_socket.close();
74+
}
6975
continue;
7076
}
7177

7278
qDebug() << "Unable to parse reply";
73-
// Error(_log, "Unable to parse reply");
7479
}
7580
}
7681

@@ -160,28 +165,29 @@ void FlatBufferConnection::sendMessage(const uint8_t* buffer, uint32_t size)
160165

161166
bool FlatBufferConnection::parseReply(const hyperionnet::Reply *reply)
162167
{
163-
if (!reply->error())
168+
if (reply->error() == NULL)
164169
{
165-
// no error set must be a success or registered
166-
const auto registered = reply->registered();
170+
if (_registered)
171+
{
172+
return true;
173+
}
167174

168-
// We got a registered reply.
169-
if (registered == -1 || registered != _priority)
175+
const auto registered = reply->registered();
176+
if (registered == _priority)
170177
{
171-
_registered = false;
178+
_registered = true;
172179
}
173180
else
174181
{
175-
_registered = true;
182+
_registered = false;
176183
}
177-
178184
return true;
179185
}
180-
else
181-
{
182-
_registered = false;
183-
throw std::runtime_error(reply->error()->str());
184-
}
185-
186186
return false;
187187
}
188+
189+
void FlatBufferConnection::disconnected()
190+
{
191+
qDebug() << "Connection to Hyperion server was closed";
192+
emit serverDisconnected();
193+
}

src/FlatBufferConnection.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public slots:
6464
///
6565
void setImage(const Image<ColorRgb> &image);
6666

67+
signals:
68+
69+
///
70+
/// @brief Emits whenever the server disconnected
71+
///
72+
void serverDisconnected();
73+
6774
private slots:
6875
///
6976
/// @brief Try to connect to the Hyperion host
@@ -75,6 +82,11 @@ private slots:
7582
///
7683
void readData();
7784

85+
///
86+
/// @brief Is called when the socket closed the connection
87+
///
88+
void disconnected();
89+
7890
private:
7991

8092
///

0 commit comments

Comments
 (0)