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

View File

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

View File

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