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

WIP: Egeniouss refactore. #5706

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

WIP: Egeniouss refactore. #5706

wants to merge 5 commits into from

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

instead of capturing connected and disconnected signals we can use stateChanged signal and simplify a bit.
override socketState and socketStateString from base class.
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

Copy link
Member

Choose a reason for hiding this comment

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

For Udp the same apply as per Tcp and egeniouss

@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
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.
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