Commit 3edeb6a0 authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files
parent 8d8c82f5
Pipeline #165325 passed with stage
in 14 minutes and 13 seconds
......@@ -569,7 +569,7 @@ int main(int argc, char **argv)
*/
return !app.sendMessage(QJsonDocument::fromVariant(QVariant(message)).toJson(),
1000,
needToBlock ? SingleApplication::BlockingSend : SingleApplication::SendOptions());
needToBlock ? SingleApplication::BlockUntilPrimaryExit : SingleApplication::NonBlocking);
}
/**
......
......@@ -235,10 +235,10 @@ QString SingleApplication::currentUser() const
* Sends message to the Primary Instance.
* @param message The message to send.
* @param timeout the maximum timeout in milliseconds for blocking functions.
* @param block block until the primary application exits
* @param sendMode mode of operation
* @return true if the message was sent successfuly, false otherwise.
*/
bool SingleApplication::sendMessage( const QByteArray &message, int timeout, SendOptions options )
bool SingleApplication::sendMessage( const QByteArray &message, int timeout, SendMode sendMode )
{
Q_D( SingleApplication );
......@@ -249,7 +249,7 @@ bool SingleApplication::sendMessage( const QByteArray &message, int timeout, Sen
if( ! d->connectToPrimary( timeout, SingleApplicationPrivate::Reconnect ) )
return false;
return d->writeConfirmedMessage( timeout, message, options );
return d->writeConfirmedMessage( timeout, message, sendMode );
}
/**
......
......@@ -129,22 +129,19 @@ public:
* @enum
*/
enum SendMode {
/**
* Should the sendMessage call block until the primary instance is terminated?
*/
BlockingSend = 1 << 0,
NonBlocking, /** Do not wait for the primary instance termination and return immediately */
BlockUntilPrimaryExit, /** Wait until the primary instance is terminated */
};
Q_DECLARE_FLAGS(SendOptions, SendMode)
/**
* @brief Sends a message to the primary instance. Returns true on success.
* @param {int} timeout - Timeout for connecting
* @param {bool} block - Block until the primary application exits.
* @param {SendMode} sendMode - Mode of operation.
* @returns {bool}
* @note sendMessage() will return false if invoked from the primary
* instance.
*/
bool sendMessage( const QByteArray &message, int timeout = 100, SendOptions options = {} );
bool sendMessage( const QByteArray &message, int timeout = 100, SendMode sendMode = NonBlocking );
/**
* @brief Get the set user data.
......
......@@ -283,7 +283,7 @@ void SingleApplicationPrivate::writeAck( QLocalSocket *sock ) {
sock->putChar('\n');
}
bool SingleApplicationPrivate::writeConfirmedMessage (int msecs, const QByteArray &msg, SingleApplication::SendOptions options)
bool SingleApplicationPrivate::writeConfirmedMessage (int msecs, const QByteArray &msg, SingleApplication::SendMode sendMode)
{
QElapsedTimer time;
time.start();
......@@ -303,8 +303,8 @@ bool SingleApplicationPrivate::writeConfirmedMessage (int msecs, const QByteArra
// Frame 2: The message
const bool result = writeConfirmedFrame( static_cast<int>(msecs - time.elapsed()), msg );
// block if needed
if (socket && (options & SingleApplication::BlockingSend))
// Block if needed
if (socket && sendMode == SingleApplication::BlockUntilPrimaryExit)
socket->waitForDisconnected(-1);
return result;
......
......@@ -85,7 +85,7 @@ public:
void readInitMessageBody(QLocalSocket *socket);
void writeAck(QLocalSocket *sock);
bool writeConfirmedFrame(int msecs, const QByteArray &msg);
bool writeConfirmedMessage(int msecs, const QByteArray &msg, SingleApplication::SendOptions options = {});
bool writeConfirmedMessage(int msecs, const QByteArray &msg, SingleApplication::SendMode sendMode = SingleApplication::NonBlocking);
static void randomSleep();
void addAppData(const QString &data);
QStringList appData() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment