Skip to content

Commit

Permalink
Address review (part 3): Header, Read-only, Protected, Blind casting, ..
Browse files Browse the repository at this point in the history
1- Add header to abstractgnssreceiver.cpp,  egeniousseeceiver.cpp,  egeniousseeceiver.h.
2- Read-only socketState.
3- protected: `void setSocketState`
4- QBluetoothSocket::SocketState to QAbstractSocket::SocketState.
5- Pruning methods in sub classes.
  • Loading branch information
mohsenD98 committed Oct 4, 2024
1 parent daa6b27 commit aa8ced3
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/core/positioning/abstractgnssreceiver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/***************************************************************************
abstractgnssreceiver.cpp - AbstractGnssReceiver
---------------------
begin : October 2024
copyright : (C) 2024 by Mohsen Dehghanzadeh
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "abstractgnssreceiver.h"

AbstractGnssReceiver::AbstractGnssReceiver( QObject *parent )
Expand Down Expand Up @@ -25,8 +41,12 @@ QString AbstractGnssReceiver::socketStateString()
void AbstractGnssReceiver::setSocketState( const QAbstractSocket::SocketState &state )
{
if ( mSocketState == state )
{
return;
}

mSocketState = state;

emit socketStateChanged( mSocketState );
emit socketStateStringChanged( socketStateString() );
}
7 changes: 3 additions & 4 deletions src/core/positioning/abstractgnssreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AbstractGnssReceiver : public QObject
Q_OBJECT

Q_PROPERTY( GnssPositionInformation lastGnssPositionInformation READ lastGnssPositionInformation NOTIFY lastGnssPositionInformationChanged )
Q_PROPERTY( QAbstractSocket::SocketState socketState READ socketState WRITE setSocketState NOTIFY socketStateChanged )
Q_PROPERTY( QAbstractSocket::SocketState socketState READ socketState NOTIFY socketStateChanged )
Q_PROPERTY( QString socketStateString READ socketStateString NOTIFY socketStateStringChanged )
Q_PROPERTY( QString lastError READ lastError NOTIFY lastErrorChanged )

Expand Down Expand Up @@ -60,10 +60,9 @@ class AbstractGnssReceiver : public QObject

virtual QList<QPair<QString, QVariant>> details() const { return {}; }
virtual QAbstractSocket::SocketState socketState() const { return mSocketState; }


public slots:
virtual QString socketStateString();

protected:
void setSocketState( const QAbstractSocket::SocketState &state );

signals:
Expand Down
28 changes: 25 additions & 3 deletions src/core/positioning/bluetoothreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,38 @@ BluetoothReceiver::BluetoothReceiver( const QString &address, QObject *parent )
{
connect( mSocket, qOverload<QBluetoothSocket::SocketError>( &QBluetoothSocket::errorOccurred ), this, &BluetoothReceiver::handleError );
connect( mSocket, &QBluetoothSocket::stateChanged, this, [=]( QBluetoothSocket::SocketState state ) {
const QAbstractSocket::SocketState currentState = static_cast<QAbstractSocket::SocketState>( state );
QAbstractSocket::SocketState currentState;
switch ( state )
{
case QBluetoothSocket::SocketState::UnconnectedState:
currentState = QAbstractSocket::UnconnectedState;
break;
case QBluetoothSocket::SocketState::ConnectingState:
currentState = QAbstractSocket::ConnectingState;
break;
case QBluetoothSocket::SocketState::ConnectedState:
currentState = QAbstractSocket::ConnectedState;
break;
case QBluetoothSocket::SocketState::ClosingState:
currentState = QAbstractSocket::ClosingState;
break;
case QBluetoothSocket::SocketState::ListeningState:
currentState = QAbstractSocket::ListeningState;
break;
default:
currentState = QAbstractSocket::UnconnectedState;
break;
}
setSocketState( currentState );
if ( currentState == QAbstractSocket::SocketState::UnconnectedState && mConnectOnDisconnect )

if ( currentState == QAbstractSocket::UnconnectedState && mConnectOnDisconnect )
{
doConnectDevice();
}
} );

connect( mLocalDevice.get(), &QBluetoothLocalDevice::pairingFinished, this, &BluetoothReceiver::pairingFinished );
connect( mLocalDevice.get(), &QBluetoothLocalDevice::errorOccurred, [=]( QBluetoothLocalDevice::Error error ) {
connect( mLocalDevice.get(), &QBluetoothLocalDevice::errorOccurred, this, [=]( QBluetoothLocalDevice::Error error ) {
if ( error != QBluetoothLocalDevice::NoError )
{
mLastError = QStringLiteral( "Local device returned an error (%1) for %2" ).arg( QMetaEnum::fromType<QBluetoothLocalDevice::Error>().valueToKey( error ), mAddress );
Expand Down
20 changes: 17 additions & 3 deletions src/core/positioning/egenioussreceiver.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/***************************************************************************
egeniousseeceiver.cpp - EgenioussReceiver
---------------------
begin : October 2024
copyright : (C) 2024 by Mohsen Dehghanzadeh
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "egenioussreceiver.h"

#include <QHostAddress>
Expand All @@ -9,9 +25,7 @@ EgenioussReceiver::EgenioussReceiver( QObject *parent )
{
connect( mTcpSocket, &QTcpSocket::readyRead, this, &EgenioussReceiver::onReadyRead );
connect( mTcpSocket, &QTcpSocket::errorOccurred, this, &EgenioussReceiver::handleError );
connect( mTcpSocket, &QTcpSocket::stateChanged, this, [=]( QAbstractSocket::SocketState state ) {
setSocketState( state );
} );
connect( mTcpSocket, &QTcpSocket::stateChanged, this, &AbstractGnssReceiver::setSocketState );

setValid( true );
}
Expand Down
16 changes: 16 additions & 0 deletions src/core/positioning/egenioussreceiver.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/***************************************************************************
egeniousseeceiver.h - EgenioussReceiver
---------------------
begin : October 2024
copyright : (C) 2024 by Mohsen Dehghanzadeh
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef EGENIOUSSRECEIVER_H
#define EGENIOUSSRECEIVER_H

Expand Down

0 comments on commit aa8ced3

Please sign in to comment.