mirror of
https://github.com/itay-grudev/SingleApplication.git
synced 2025-04-21 04:24:43 +08:00
Merge pull request #114 from Shatur95/fix-clang-tidy-warnings
Fix Clang Tidy warnings
This commit is contained in:
commit
a627bc24fa
@ -57,7 +57,7 @@ SingleApplication::SingleApplication( int &argc, char *argv[], bool allowSeconda
|
|||||||
|
|
||||||
// To mitigate QSharedMemory issues with large amount of processes
|
// To mitigate QSharedMemory issues with large amount of processes
|
||||||
// attempting to attach at the same time
|
// attempting to attach at the same time
|
||||||
d->randomSleep();
|
SingleApplicationPrivate::randomSleep();
|
||||||
|
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
// By explicitly attaching it and then deleting it we make sure that the
|
// 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() << "SingleApplication: Unable to unlock memory for random wait.";
|
||||||
qDebug() << d->memory->errorString();
|
qDebug() << d->memory->errorString();
|
||||||
}
|
}
|
||||||
d->randomSleep();
|
SingleApplicationPrivate::randomSleep();
|
||||||
if( ! d->memory->lock() ){
|
if( ! d->memory->lock() ){
|
||||||
qCritical() << "SingleApplication: Unable to lock memory after random wait.";
|
qCritical() << "SingleApplication: Unable to lock memory after random wait.";
|
||||||
abortSafely();
|
abortSafely();
|
||||||
@ -224,8 +224,7 @@ QString SingleApplication::primaryUser()
|
|||||||
*/
|
*/
|
||||||
QString SingleApplication::currentUser()
|
QString SingleApplication::currentUser()
|
||||||
{
|
{
|
||||||
Q_D( SingleApplication );
|
return SingleApplicationPrivate::getUsername();
|
||||||
return d->getUsername();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -158,7 +158,7 @@ void SingleApplicationPrivate::genBlockServerName()
|
|||||||
blockServerName = appData.result().toBase64().replace("/", "_");
|
blockServerName = appData.result().toBase64().replace("/", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::initializeMemoryBlock()
|
void SingleApplicationPrivate::initializeMemoryBlock() const
|
||||||
{
|
{
|
||||||
auto *inst = static_cast<InstancesInfo*>( memory->data() );
|
auto *inst = static_cast<InstancesInfo*>( memory->data() );
|
||||||
inst->primary = false;
|
inst->primary = false;
|
||||||
@ -170,13 +170,11 @@ void SingleApplicationPrivate::initializeMemoryBlock()
|
|||||||
|
|
||||||
void SingleApplicationPrivate::startPrimary()
|
void SingleApplicationPrivate::startPrimary()
|
||||||
{
|
{
|
||||||
Q_Q(SingleApplication);
|
|
||||||
|
|
||||||
// Reset the number of connections
|
// Reset the number of connections
|
||||||
auto *inst = static_cast <InstancesInfo*>( memory->data() );
|
auto *inst = static_cast <InstancesInfo*>( memory->data() );
|
||||||
|
|
||||||
inst->primary = true;
|
inst->primary = true;
|
||||||
inst->primaryPid = q->applicationPid();
|
inst->primaryPid = QCoreApplication::applicationPid();
|
||||||
qstrncpy( inst->primaryUser, getUsername().toUtf8().data(), sizeof(inst->primaryUser) );
|
qstrncpy( inst->primaryUser, getUsername().toUtf8().data(), sizeof(inst->primaryUser) );
|
||||||
inst->checksum = blockChecksum();
|
inst->checksum = blockChecksum();
|
||||||
instanceNumber = 0;
|
instanceNumber = 0;
|
||||||
@ -211,7 +209,7 @@ void SingleApplicationPrivate::startSecondary()
|
|||||||
instanceNumber = inst->secondary;
|
instanceNumber = inst->secondary;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SingleApplicationPrivate::connectToPrimary( int timeout, ConnectionType connectionType )
|
bool SingleApplicationPrivate::connectToPrimary( int msecs, ConnectionType connectionType )
|
||||||
{
|
{
|
||||||
QElapsedTimer time;
|
QElapsedTimer time;
|
||||||
time.start();
|
time.start();
|
||||||
@ -233,14 +231,14 @@ bool SingleApplicationPrivate::connectToPrimary( int timeout, ConnectionType con
|
|||||||
socket->connectToServer( blockServerName );
|
socket->connectToServer( blockServerName );
|
||||||
|
|
||||||
if( socket->state() == QLocalSocket::ConnectingState ){
|
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 connected break out of the loop
|
||||||
if( socket->state() == QLocalSocket::ConnectedState ) break;
|
if( socket->state() == QLocalSocket::ConnectedState ) break;
|
||||||
|
|
||||||
// If elapsed time since start is longer than the method timeout return
|
// 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( header );
|
||||||
socket->write( initMsg );
|
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();
|
socket->flush();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 SingleApplicationPrivate::blockChecksum()
|
quint16 SingleApplicationPrivate::blockChecksum() const
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||||
quint16 checksum = qChecksum(QByteArray(static_cast<const char*>(memory->constData()), offsetof(InstancesInfo, checksum)));
|
quint16 checksum = qChecksum(QByteArray(static_cast<const char*>(memory->constData()), offsetof(InstancesInfo, checksum)));
|
||||||
@ -288,7 +286,7 @@ quint16 SingleApplicationPrivate::blockChecksum()
|
|||||||
return checksum;
|
return checksum;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SingleApplicationPrivate::primaryPid()
|
qint64 SingleApplicationPrivate::primaryPid() const
|
||||||
{
|
{
|
||||||
qint64 pid;
|
qint64 pid;
|
||||||
|
|
||||||
@ -300,7 +298,7 @@ qint64 SingleApplicationPrivate::primaryPid()
|
|||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString SingleApplicationPrivate::primaryUser()
|
QString SingleApplicationPrivate::primaryUser() const
|
||||||
{
|
{
|
||||||
QByteArray username;
|
QByteArray username;
|
||||||
|
|
||||||
|
@ -70,18 +70,18 @@ public:
|
|||||||
SingleApplicationPrivate( SingleApplication *q_ptr );
|
SingleApplicationPrivate( SingleApplication *q_ptr );
|
||||||
~SingleApplicationPrivate() override;
|
~SingleApplicationPrivate() override;
|
||||||
|
|
||||||
QString getUsername();
|
static QString getUsername();
|
||||||
void genBlockServerName();
|
void genBlockServerName();
|
||||||
void initializeMemoryBlock();
|
void initializeMemoryBlock() const;
|
||||||
void startPrimary();
|
void startPrimary();
|
||||||
void startSecondary();
|
void startSecondary();
|
||||||
bool connectToPrimary( int msecs, ConnectionType connectionType );
|
bool connectToPrimary( int msecs, ConnectionType connectionType );
|
||||||
quint16 blockChecksum();
|
quint16 blockChecksum() const;
|
||||||
qint64 primaryPid();
|
qint64 primaryPid() const;
|
||||||
QString primaryUser();
|
QString primaryUser() const;
|
||||||
void readInitMessageHeader(QLocalSocket *socket);
|
void readInitMessageHeader(QLocalSocket *socket);
|
||||||
void readInitMessageBody(QLocalSocket *socket);
|
void readInitMessageBody(QLocalSocket *socket);
|
||||||
void randomSleep();
|
static void randomSleep();
|
||||||
|
|
||||||
SingleApplication *q_ptr;
|
SingleApplication *q_ptr;
|
||||||
QSharedMemory *memory;
|
QSharedMemory *memory;
|
||||||
|
Loading…
Reference in New Issue
Block a user