Merge pull request #114 from Shatur95/fix-clang-tidy-warnings

Fix Clang Tidy warnings
This commit is contained in:
Itay Grudev 2020-10-18 09:44:21 +01:00 committed by GitHub
commit a627bc24fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 22 deletions

View File

@ -57,7 +57,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
// To mitigate QSharedMemory issues with large amount of processes
// attempting to attach at the same time
d->randomSleep();
SingleApplicationPrivate::randomSleep();
#ifdef Q_OS_UNIX
// By explicitly attaching it and then deleting it we make sure that the
@ -117,7 +117,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
qDebug() << "SingleApplication: Unable to unlock memory for random wait.";
qDebug() << d->memory->errorString();
}
d->randomSleep();
SingleApplicationPrivate::randomSleep();
if( ! d->memory->lock() ){
qCritical() << "SingleApplication: Unable to lock memory after random wait.";
abortSafely();
@ -224,8 +224,7 @@ QString SingleApplication::primaryUser()
*/
QString SingleApplication::currentUser()
{
Q_D( SingleApplication );
return d->getUsername();
return SingleApplicationPrivate::getUsername();
}
/**

View File

@ -158,7 +158,7 @@ void SingleApplicationPrivate::genBlockServerName()
blockServerName = appData.result().toBase64().replace("/", "_");
}
void SingleApplicationPrivate::initializeMemoryBlock()
void SingleApplicationPrivate::initializeMemoryBlock() const
{
auto *inst = static_cast<InstancesInfo*>( memory->data() );
inst->primary = false;
@ -170,13 +170,11 @@ void SingleApplicationPrivate::initializeMemoryBlock()
void SingleApplicationPrivate::startPrimary()
{
Q_Q(SingleApplication);
// Reset the number of connections
auto *inst = static_cast <InstancesInfo*>( memory->data() );
inst->primary = true;
inst->primaryPid = q->applicationPid();
inst->primaryPid = QCoreApplication::applicationPid();
qstrncpy( inst->primaryUser, getUsername().toUtf8().data(), sizeof(inst->primaryUser) );
inst->checksum = blockChecksum();
instanceNumber = 0;
@ -211,7 +209,7 @@ void SingleApplicationPrivate::startSecondary()
instanceNumber = inst->secondary;
}
bool SingleApplicationPrivate::connectToPrimary( int timeout, ConnectionType connectionType )
bool SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
{
QElapsedTimer time;
time.start();
@ -233,14 +231,14 @@ bool SingleApplicationPrivate::connectToPrimary( int timeout, ConnectionType con
socket->connectToServer( blockServerName );
if( socket->state() == QLocalSocket::ConnectingState ){
socket->waitForConnected( static_cast<int>(timeout - time.elapsed()) );
socket->waitForConnected( static_cast<int>(msecs - time.elapsed()) );
}
// If connected break out of the loop
if( socket->state() == QLocalSocket::ConnectedState ) break;
// If elapsed time since start is longer than the method timeout return
if( time.elapsed() >= timeout ) return false;
if( time.elapsed() >= msecs ) return false;
}
}
@ -273,12 +271,12 @@ bool SingleApplicationPrivate::connectToPrimary( int timeout, ConnectionType con
socket->write( header );
socket->write( initMsg );
bool result = socket->waitForBytesWritten( static_cast<int>(timeout - time.elapsed()) );
bool result = socket->waitForBytesWritten( static_cast<int>(msecs - time.elapsed()) );
socket->flush();
return result;
}
quint16 SingleApplicationPrivate::blockChecksum()
quint16 SingleApplicationPrivate::blockChecksum() const
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
quint16 checksum = qChecksum(QByteArray(static_cast<const char*>(memory->constData()), offsetof(InstancesInfo, checksum)));
@ -288,7 +286,7 @@ quint16 SingleApplicationPrivate::blockChecksum()
return checksum;
}
qint64 SingleApplicationPrivate::primaryPid()
qint64 SingleApplicationPrivate::primaryPid() const
{
qint64 pid;
@ -300,7 +298,7 @@ qint64 SingleApplicationPrivate::primaryPid()
return pid;
}
QString SingleApplicationPrivate::primaryUser()
QString SingleApplicationPrivate::primaryUser() const
{
QByteArray username;

View File

@ -70,18 +70,18 @@ public:
SingleApplicationPrivate( SingleApplication *q_ptr );
~SingleApplicationPrivate() override;
QString getUsername();
static QString getUsername();
void genBlockServerName();
void initializeMemoryBlock();
void initializeMemoryBlock() const;
void startPrimary();
void startSecondary();
bool connectToPrimary(int msecs, ConnectionType connectionType );
quint16 blockChecksum();
qint64 primaryPid();
QString primaryUser();
bool connectToPrimary( int msecs, ConnectionType connectionType );
quint16 blockChecksum() const;
qint64 primaryPid() const;
QString primaryUser() const;
void readInitMessageHeader(QLocalSocket *socket);
void readInitMessageBody(QLocalSocket *socket);
void randomSleep();
static void randomSleep();
SingleApplication *q_ptr;
QSharedMemory *memory;