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

Merge branches 'pr1429' and 'pr1431'

This commit is contained in:
Dubslow 2015-03-19 11:03:37 -05:00
commit 44662310da
No known key found for this signature in database
GPG Key ID: 3DB8E05315C220AA
4 changed files with 47 additions and 40 deletions

View File

@ -150,7 +150,7 @@ void IPC::registerEventHandler(const QString &name, IPCEventHandler handler)
eventHandlers[name] = handler;
}
bool IPC::isEventProcessed(time_t time)
bool IPC::isEventAccepted(time_t time)
{
bool result = false;
if (globalMemory.lock())
@ -161,32 +161,6 @@ bool IPC::isEventProcessed(time_t time)
for (uint32_t i = 0; i < EVENT_QUEUE_SIZE; i++)
{
if (mem->events[i].posted == time && mem->events[i].processed)
{
result = true;
break;
}
}
}
globalMemory.unlock();
}
else
{
qWarning() << "IPC: isEventProcessed failed to lock, returning false";
}
return result;
}
bool IPC::isEventAccepted(time_t time)
{
bool result = false;
if (globalMemory.lock())
{
// if (difftime(global()->lastProcessed, time) > 0)
{
IPCMemory* mem = global();
for (uint32_t i = 0; i < EVENT_QUEUE_SIZE; i++)
{
if (mem->events[i].posted == time)
{
result = mem->events[i].accepted;
break;
@ -202,11 +176,11 @@ bool IPC::isEventAccepted(time_t time)
return result;
}
bool IPC::waitUntilProcessed(time_t postTime, int32_t timeout/*=-1*/)
bool IPC::waitUntilAccepted(time_t postTime, int32_t timeout/*=-1*/)
{
bool result = false;
time_t start = time(0);
while (!(result = isEventProcessed(postTime)))
while (!(result = isEventAccepted(postTime)))
{
qApp->processEvents();
if (timeout > 0 && difftime(time(0), start) >= timeout)
@ -232,10 +206,7 @@ IPC::IPCEvent *IPC::fetchEvent()
if (evt->posted && !evt->processed && evt->sender != getpid())
{
if (evt->dest == Settings::getInstance().getCurrentProfileId() || (evt->dest == 0 && isCurrentOwner()))
{
evt->processed = time(0);
return evt;
}
}
}
return 0;
@ -291,9 +262,19 @@ void IPC::processEvents()
auto it = eventHandlers.find(name);
if (it != eventHandlers.end())
{
evt->accepted = runEventHandler(it.value(), evt->data);
qDebug() << "IPC: Processing event: " << name << ":" << evt->posted << "=" << evt->accepted;
evt->accepted = runEventHandler(it.value(), evt->data);
if (evt->dest == 0)
{
// Global events should be processed only by instance that accepted event. Otherwise global
// event would be consumed by very first instance that gets to check it.
if (evt->accepted)
evt->processed = time(0);
}
else
evt->processed = time(0);
}
}
globalMemory.unlock();

View File

@ -73,9 +73,8 @@ public:
time_t postEvent(const QString& name, const QByteArray &data=QByteArray(), uint32_t dest=0);
bool isCurrentOwner();
void registerEventHandler(const QString& name, IPCEventHandler handler);
bool isEventProcessed(time_t time);
bool isEventAccepted(time_t time);
bool waitUntilProcessed(time_t time, int32_t timeout=-1);
bool waitUntilAccepted(time_t time, int32_t timeout=-1);
protected slots:
void processEvents();

View File

@ -227,7 +227,7 @@ int main(int argc, char *argv[])
else
{
time_t event = ipc.postEvent("uri", firstParam.toUtf8());
ipc.waitUntilProcessed(event);
ipc.waitUntilAccepted(event);
// If someone else processed it, we're done here, no need to actually start qTox
if (!ipc.isCurrentOwner())
return EXIT_SUCCESS;
@ -242,7 +242,7 @@ int main(int argc, char *argv[])
else
{
time_t event = ipc.postEvent("save", firstParam.toUtf8());
ipc.waitUntilProcessed(event);
ipc.waitUntilAccepted(event);
// If someone else processed it, we're done here, no need to actually start qTox
if (!ipc.isCurrentOwner())
return EXIT_SUCCESS;
@ -260,7 +260,7 @@ int main(int argc, char *argv[])
if (parser.isSet("p"))
dest = Settings::getInstance().getCurrentProfileId();
time_t event = ipc.postEvent("activate", QByteArray(), dest);
if (ipc.waitUntilProcessed(event, 2) && ipc.isEventAccepted(event))
if (ipc.waitUntilAccepted(event, 2))
{
if (!ipc.isCurrentOwner())
return EXIT_SUCCESS;

View File

@ -146,7 +146,21 @@ void CameraWorker::subscribe()
if (!cam.isOpened())
{
queue.clear();
cam.open(camIndex);
bool bSuccess = false;
try
{
bSuccess = cam.open(camIndex);
}
catch( cv::Exception& e )
{
qDebug() << "CameraWorker:" << "OpenCV exception caught: " << e.what();
}
if(!bSuccess)
{
qDebug() << "CameraWorker: Could not open camera";
}
applyProps(); // restore props
}
}
@ -166,7 +180,20 @@ void CameraWorker::doWork()
if (!cam.isOpened())
return;
if (!cam.read(frame))
bool bSuccess = false;
try
{
bSuccess = cam.read(frame);
}
catch( cv::Exception& e )
{
qDebug() << "CameraWorker:" << "OpenCV exception caught: " << e.what();;
this->clock->stop(); // prevent log spamming
qDebug() << "CameraWorker: stopped clock";
}
if (!bSuccess)
{
qDebug() << "CameraWorker: Cannot read frame";
return;