1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #2383 from antis81:ngf/fix/ipc

This commit is contained in:
Nils Fenner 2015-10-16 18:33:30 +02:00
commit 69380d5159
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
3 changed files with 17 additions and 22 deletions

View File

@ -19,8 +19,9 @@
#include "src/ipc.h"
#include "src/persistence/settings.h"
#include <QDebug>
#include <QCoreApplication>
#include <QDebug>
#include <QThread>
#include <random>
#include <unistd.h>
@ -185,12 +186,13 @@ bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/)
{
bool result = false;
time_t start = time(0);
while (!(result = isEventAccepted(postTime)))
{
qApp->processEvents();
QThread::msleep(10);
if (timeout > 0 && difftime(time(0), start) >= timeout)
forever {
result = isEventAccepted(postTime);
if (result || (timeout > 0 && difftime(time(0), start) >= timeout))
break;
qApp->processEvents();
QThread::msleep(0);
}
return result;
}

View File

@ -21,20 +21,19 @@
#ifndef IPC_H
#define IPC_H
#include <ctime>
#include <functional>
#include <QMap>
#include <QObject>
#include <QSharedMemory>
#include <QTimer>
#include <QObject>
#include <QThread>
#include <QVector>
#include <QMap>
#include <functional>
#include <ctime>
using IPCEventHandler = std::function<bool (const QByteArray&)>;
#define IPC_PROTOCOL_VERSION "2"
class IPC : public QThread
class IPC : public QObject
{
Q_OBJECT
IPC();

View File

@ -113,7 +113,7 @@ int main(int argc, char *argv[])
parser.process(a);
#ifndef Q_OS_ANDROID
IPC::getInstance();
IPC& ipc = IPC::getInstance();
#endif
sodium_init(); // For the auto-updater
@ -157,7 +157,6 @@ int main(int argc, char *argv[])
#ifndef Q_OS_ANDROID
// Inter-process communication
IPC& ipc = IPC::getInstance();
ipc.registerEventHandler("uri", &toxURIEventHandler);
ipc.registerEventHandler("save", &toxSaveEventHandler);
ipc.registerEventHandler("activate", &toxActivateEventHandler);
@ -233,14 +232,9 @@ int main(int argc, char *argv[])
}
else if (!ipc.isCurrentOwner() && !parser.isSet("p"))
{
uint32_t dest = 0;
if (parser.isSet("p"))
dest = Settings::getInstance().getCurrentProfileId();
time_t event = ipc.postEvent("activate", QByteArray(), dest);
if (ipc.waitUntilAccepted(event, 2))
time_t event = ipc.postEvent("activate");
if (!ipc.waitUntilAccepted(event, 2))
{
if (!ipc.isCurrentOwner())
return EXIT_SUCCESS;
}
}