Format singleapplication sources
This commit is contained in:
@@ -148,7 +148,6 @@ SingleApplication::SingleApplication(int &argc, char *argv[], bool allowSecondar
|
|||||||
delete d;
|
delete d;
|
||||||
|
|
||||||
::exit(EXIT_SUCCESS);
|
::exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,5 +192,4 @@ bool SingleApplication::sendMessage(QByteArray message, int timeout) {
|
|||||||
bool dataWritten = d->socket->waitForBytesWritten(timeout);
|
bool dataWritten = d->socket->waitForBytesWritten(timeout);
|
||||||
d->socket->flush();
|
d->socket->flush();
|
||||||
return dataWritten;
|
return dataWritten;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
SingleApplicationPrivate *d_ptr;
|
SingleApplicationPrivate *d_ptr;
|
||||||
Q_DECLARE_PRIVATE(SingleApplication)
|
Q_DECLARE_PRIVATE(SingleApplication)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_OPERATORS_FOR_FLAGS(SingleApplication::Options)
|
Q_DECLARE_OPERATORS_FOR_FLAGS(SingleApplication::Options)
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ SingleApplicationPrivate::SingleApplicationPrivate(SingleApplication *_q_ptr)
|
|||||||
memory(nullptr),
|
memory(nullptr),
|
||||||
socket(nullptr),
|
socket(nullptr),
|
||||||
server(nullptr),
|
server(nullptr),
|
||||||
instanceNumber(-1)
|
instanceNumber(-1) {}
|
||||||
{}
|
|
||||||
|
|
||||||
SingleApplicationPrivate::~SingleApplicationPrivate() {
|
SingleApplicationPrivate::~SingleApplicationPrivate() {
|
||||||
|
|
||||||
@@ -88,7 +87,6 @@ SingleApplicationPrivate::~SingleApplicationPrivate() {
|
|||||||
memory->unlock();
|
memory->unlock();
|
||||||
|
|
||||||
delete memory;
|
delete memory;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::genBlockServerName() {
|
void SingleApplicationPrivate::genBlockServerName() {
|
||||||
@@ -139,7 +137,6 @@ void SingleApplicationPrivate::genBlockServerName() {
|
|||||||
|
|
||||||
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
|
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
|
||||||
blockServerName = appData.result().toBase64().replace("/", "_");
|
blockServerName = appData.result().toBase64().replace("/", "_");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::initializeMemoryBlock() {
|
void SingleApplicationPrivate::initializeMemoryBlock() {
|
||||||
@@ -149,7 +146,6 @@ void SingleApplicationPrivate::initializeMemoryBlock() {
|
|||||||
inst->secondary = 0;
|
inst->secondary = 0;
|
||||||
inst->primaryPid = -1;
|
inst->primaryPid = -1;
|
||||||
inst->checksum = blockChecksum();
|
inst->checksum = blockChecksum();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::startPrimary() {
|
void SingleApplicationPrivate::startPrimary() {
|
||||||
@@ -181,7 +177,6 @@ void SingleApplicationPrivate::startPrimary() {
|
|||||||
inst->checksum = blockChecksum();
|
inst->checksum = blockChecksum();
|
||||||
|
|
||||||
instanceNumber = 0;
|
instanceNumber = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::startSecondary() {}
|
void SingleApplicationPrivate::startSecondary() {}
|
||||||
@@ -239,7 +234,6 @@ void SingleApplicationPrivate::connectToPrimary(const int msecs, const Connectio
|
|||||||
socket->flush();
|
socket->flush();
|
||||||
socket->waitForBytesWritten(msecs);
|
socket->waitForBytesWritten(msecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 SingleApplicationPrivate::blockChecksum() {
|
quint16 SingleApplicationPrivate::blockChecksum() {
|
||||||
@@ -251,7 +245,6 @@ quint16 SingleApplicationPrivate::blockChecksum() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
return checksum;
|
return checksum;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SingleApplicationPrivate::primaryPid() {
|
qint64 SingleApplicationPrivate::primaryPid() {
|
||||||
@@ -264,7 +257,6 @@ qint64 SingleApplicationPrivate::primaryPid() {
|
|||||||
memory->unlock();
|
memory->unlock();
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,15 +271,13 @@ void SingleApplicationPrivate::slotConnectionEstablished() {
|
|||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
auto &info = connectionMap[nextConnSocket];
|
auto &info = connectionMap[nextConnSocket];
|
||||||
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
|
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
|
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
|
||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
connectionMap.remove(nextConnSocket);
|
connectionMap.remove(nextConnSocket);
|
||||||
nextConnSocket->deleteLater();
|
nextConnSocket->deleteLater();
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
|
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
|
||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
@@ -305,9 +295,7 @@ void SingleApplicationPrivate::slotConnectionEstablished() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
||||||
@@ -334,7 +322,6 @@ void SingleApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
|||||||
if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
|
if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
|
||||||
readInitMessageBody(sock);
|
readInitMessageBody(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
||||||
@@ -397,19 +384,16 @@ void SingleApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
|||||||
if (sock->bytesAvailable() > 0) {
|
if (sock->bytesAvailable() > 0) {
|
||||||
Q_EMIT this->slotDataAvailable(sock, instanceId);
|
Q_EMIT this->slotDataAvailable(sock, instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
|
void SingleApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
|
||||||
|
|
||||||
Q_Q(SingleApplication);
|
Q_Q(SingleApplication);
|
||||||
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
|
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
|
void SingleApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
|
||||||
|
|
||||||
if (closedSocket->bytesAvailable() > 0)
|
if (closedSocket->bytesAvailable() > 0)
|
||||||
Q_EMIT slotDataAvailable(closedSocket, instanceId);
|
Q_EMIT slotDataAvailable(closedSocket, instanceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ SingleCoreApplication::SingleCoreApplication(int &argc, char *argv[], bool allow
|
|||||||
delete d;
|
delete d;
|
||||||
|
|
||||||
::exit(EXIT_SUCCESS);
|
::exit(EXIT_SUCCESS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -193,5 +192,4 @@ bool SingleCoreApplication::sendMessage(QByteArray message, int timeout) {
|
|||||||
bool dataWritten = d->socket->waitForBytesWritten(timeout);
|
bool dataWritten = d->socket->waitForBytesWritten(timeout);
|
||||||
d->socket->flush();
|
d->socket->flush();
|
||||||
return dataWritten;
|
return dataWritten;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ SingleCoreApplicationPrivate::SingleCoreApplicationPrivate(SingleCoreApplication
|
|||||||
memory(nullptr),
|
memory(nullptr),
|
||||||
socket(nullptr),
|
socket(nullptr),
|
||||||
server(nullptr),
|
server(nullptr),
|
||||||
instanceNumber(-1)
|
instanceNumber(-1) {}
|
||||||
{}
|
|
||||||
|
|
||||||
SingleCoreApplicationPrivate::~SingleCoreApplicationPrivate() {
|
SingleCoreApplicationPrivate::~SingleCoreApplicationPrivate() {
|
||||||
|
|
||||||
@@ -88,7 +87,6 @@ SingleCoreApplicationPrivate::~SingleCoreApplicationPrivate() {
|
|||||||
memory->unlock();
|
memory->unlock();
|
||||||
|
|
||||||
delete memory;
|
delete memory;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::genBlockServerName() {
|
void SingleCoreApplicationPrivate::genBlockServerName() {
|
||||||
@@ -139,7 +137,6 @@ void SingleCoreApplicationPrivate::genBlockServerName() {
|
|||||||
|
|
||||||
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
|
// Replace the backslash in RFC 2045 Base64 [a-zA-Z0-9+/=] to comply with server naming requirements.
|
||||||
blockServerName = appData.result().toBase64().replace("/", "_");
|
blockServerName = appData.result().toBase64().replace("/", "_");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::initializeMemoryBlock() {
|
void SingleCoreApplicationPrivate::initializeMemoryBlock() {
|
||||||
@@ -149,7 +146,6 @@ void SingleCoreApplicationPrivate::initializeMemoryBlock() {
|
|||||||
inst->secondary = 0;
|
inst->secondary = 0;
|
||||||
inst->primaryPid = -1;
|
inst->primaryPid = -1;
|
||||||
inst->checksum = blockChecksum();
|
inst->checksum = blockChecksum();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::startPrimary() {
|
void SingleCoreApplicationPrivate::startPrimary() {
|
||||||
@@ -181,7 +177,6 @@ void SingleCoreApplicationPrivate::startPrimary() {
|
|||||||
inst->checksum = blockChecksum();
|
inst->checksum = blockChecksum();
|
||||||
|
|
||||||
instanceNumber = 0;
|
instanceNumber = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::startSecondary() {}
|
void SingleCoreApplicationPrivate::startSecondary() {}
|
||||||
@@ -239,7 +234,6 @@ void SingleCoreApplicationPrivate::connectToPrimary(const int msecs, const Conne
|
|||||||
socket->flush();
|
socket->flush();
|
||||||
socket->waitForBytesWritten(msecs);
|
socket->waitForBytesWritten(msecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 SingleCoreApplicationPrivate::blockChecksum() {
|
quint16 SingleCoreApplicationPrivate::blockChecksum() {
|
||||||
@@ -251,7 +245,6 @@ quint16 SingleCoreApplicationPrivate::blockChecksum() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
return checksum;
|
return checksum;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 SingleCoreApplicationPrivate::primaryPid() {
|
qint64 SingleCoreApplicationPrivate::primaryPid() {
|
||||||
@@ -264,7 +257,6 @@ qint64 SingleCoreApplicationPrivate::primaryPid() {
|
|||||||
memory->unlock();
|
memory->unlock();
|
||||||
|
|
||||||
return pid;
|
return pid;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,15 +271,13 @@ void SingleCoreApplicationPrivate::slotConnectionEstablished() {
|
|||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
auto &info = connectionMap[nextConnSocket];
|
auto &info = connectionMap[nextConnSocket];
|
||||||
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
|
Q_EMIT this->slotClientConnectionClosed(nextConnSocket, info.instanceId);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
|
QObject::connect(nextConnSocket, &QLocalSocket::disconnected,
|
||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
connectionMap.remove(nextConnSocket);
|
connectionMap.remove(nextConnSocket);
|
||||||
nextConnSocket->deleteLater();
|
nextConnSocket->deleteLater();
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
|
QObject::connect(nextConnSocket, &QLocalSocket::readyRead,
|
||||||
[nextConnSocket, this]() {
|
[nextConnSocket, this]() {
|
||||||
@@ -305,9 +295,7 @@ void SingleCoreApplicationPrivate::slotConnectionEstablished() {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
||||||
@@ -334,7 +322,6 @@ void SingleCoreApplicationPrivate::readInitMessageHeader(QLocalSocket *sock) {
|
|||||||
if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
|
if (sock->bytesAvailable() >= static_cast<qint64>(msgLen)) {
|
||||||
readInitMessageBody(sock);
|
readInitMessageBody(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
||||||
@@ -397,19 +384,16 @@ void SingleCoreApplicationPrivate::readInitMessageBody(QLocalSocket *sock) {
|
|||||||
if (sock->bytesAvailable() > 0) {
|
if (sock->bytesAvailable() > 0) {
|
||||||
Q_EMIT this->slotDataAvailable(sock, instanceId);
|
Q_EMIT this->slotDataAvailable(sock, instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
|
void SingleCoreApplicationPrivate::slotDataAvailable(QLocalSocket *dataSocket, const quint32 instanceId) {
|
||||||
|
|
||||||
Q_Q(SingleCoreApplication);
|
Q_Q(SingleCoreApplication);
|
||||||
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
|
Q_EMIT q->receivedMessage(instanceId, dataSocket->readAll());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SingleCoreApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
|
void SingleCoreApplicationPrivate::slotClientConnectionClosed(QLocalSocket *closedSocket, const quint32 instanceId) {
|
||||||
|
|
||||||
if (closedSocket->bytesAvailable() > 0)
|
if (closedSocket->bytesAvailable() > 0)
|
||||||
Q_EMIT slotDataAvailable(closedSocket, instanceId);
|
Q_EMIT slotDataAvailable(closedSocket, instanceId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user