Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Positioning device refactoring #5706

Merged
merged 5 commits into from
Oct 15, 2024
Merged

Positioning device refactoring #5706

merged 5 commits into from
Oct 15, 2024

Conversation

mohsenD98
Copy link
Collaborator

@mohsenD98 mohsenD98 commented Oct 1, 2024

PR Description

In this PR we are going to address these:


Step 1 of Refactor 1: Instead of capturing connected and disconnected signals we can use stateChanged signal and simplify a bit.

This pattern is been used in:

connect( mSocket, &QBluetoothSocket::stateChanged, this, &BluetoothReceiver::setSocketState );

connect( mSocket, &QAbstractSocket::stateChanged, this, &TcpReceiver::setSocketState );

connect( mSocket, &QAbstractSocket::stateChanged, this, &UdpReceiver::setSocketState );


Step 2 of Refactor 1: lets go for the bigger refactoring changing all of these.

@domi4484: It feels a bit strange to me that subclasses of postioning device have to manage mSocketState that way. mSocketState and mSocketStateString have a quite risk to get out of sync. Wouldn't be it a cleaner interface to reimplement AbstractGnssReceiver::socketState() and socketStateString in subclasses and get rid of the variables mSocketState and mSocketStateString?

@mohsenD98 mohsenD98 self-assigned this Oct 1, 2024
@qfield-fairy
Copy link
Collaborator

qfield-fairy commented Oct 1, 2024

@mohsenD98 mohsenD98 force-pushed the egeniouss-refactor branch 2 times, most recently from 8a0ffe9 to d5277ec Compare October 1, 2024 16:03
src/core/positioning/abstractgnssreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.h Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/bluetoothreceiver.cpp Outdated Show resolved Hide resolved
Comment on lines 68 to 69
emit socketStateChanged( socketState );
emit socketStateStringChanged( socketStateString() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like for egeniouss, could be replaced by a direct connection of the socket stateChanged with abstracGnss::stateChanged

switch ( socketState )
QAbstractSocket::SocketState TcpReceiver::socketState()
{
return mSocket ? mSocket->state() : QAbstractSocket::UnconnectedState;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as wel mSocket doesn't need to be a pointer

case QAbstractSocket::UnconnectedState:
{
mSocketStateString = tr( "Disconnected" );
QString mSocketStateString = tr( "Disconnected" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
QString mSocketStateString = tr( "Disconnected" );
QString socketStateString = tr( "Disconnected" );

@@ -122,6 +116,9 @@ void TcpReceiver::handleError( QAbstractSocket::SocketError error )
mLastError = tr( "TCP receiver error (%1)" ).arg( QMetaEnum::fromType<QAbstractSocket::SocketError>().valueToKey( error ) );
break;
}

setSocketState( QAbstractSocket::UnconnectedState );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not be there

src/core/positioning/udpreceiver.cpp Show resolved Hide resolved
@mohsenD98
Copy link
Collaborator Author

Thank you @domi4484 for your review. most of them addressed.

src/core/positioning/abstractgnssreceiver.cpp Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.cpp Outdated Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/abstractgnssreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/bluetoothreceiver.cpp Outdated Show resolved Hide resolved
src/core/positioning/egenioussreceiver.cpp Outdated Show resolved Hide resolved
src/core/positioning/tcpreceiver.cpp Show resolved Hide resolved
src/core/positioning/tcpreceiver.h Outdated Show resolved Hide resolved
src/core/positioning/udpreceiver.cpp Show resolved Hide resolved
src/core/positioning/udpreceiver.h Outdated Show resolved Hide resolved
instead of capturing connected and disconnected signals we can use stateChanged signal and simplify a bit.
override socketState and socketStateString from base class.
Remove duplicated codes of `socketState` and `socketStateString` also extract some logic from `socketStateString`.
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.
@nirvn nirvn changed the title WIP: Egeniouss refactore. Positioning device refactoring Oct 12, 2024
@nirvn nirvn marked this pull request as ready for review October 12, 2024 10:07
Copy link
Member

@domi4484 domi4484 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave a try to the APK with a device via UDP and Bluetooth. Everything seems to work as usual

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
virtual QString socketStateString();
virtual QString socketStateString() const;

@nirvn nirvn merged commit 6fd7021 into master Oct 15, 2024
23 checks passed
@nirvn nirvn deleted the egeniouss-refactor branch October 15, 2024 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants