diff --git a/deflect/MetaTypeRegistration.cpp b/deflect/MetaTypeRegistration.cpp index 93a0633..736d7e8 100644 --- a/deflect/MetaTypeRegistration.cpp +++ b/deflect/MetaTypeRegistration.cpp @@ -1,5 +1,5 @@ /*********************************************************************/ -/* Copyright (c) 2014-2015, EPFL/Blue Brain Project */ +/* Copyright (c) 2014-2017, EPFL/Blue Brain Project */ /* Raphael Dumusc */ /* Daniel.Nachbaur@epfl.ch */ /* All rights reserved. */ @@ -41,6 +41,7 @@ #include "Event.h" #include "Segment.h" #include "SizeHints.h" +#include "types.h" #include @@ -54,6 +55,7 @@ struct MetaTypeRegistration MetaTypeRegistration() { qRegisterMetaType("size_t"); + qRegisterMetaType("deflect::BoolPromisePtr"); qRegisterMetaType("deflect::Segment"); qRegisterMetaType("deflect::SizeHints"); qRegisterMetaType("deflect::Event"); diff --git a/deflect/Server.cpp b/deflect/Server.cpp index 814b78e..d578f96 100644 --- a/deflect/Server.cpp +++ b/deflect/Server.cpp @@ -1,5 +1,5 @@ /*********************************************************************/ -/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */ +/* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ /* Raphael Dumusc */ /* Daniel.Nachbaur@epfl.ch */ /* All rights reserved. */ @@ -100,11 +100,6 @@ void Server::closePixelStream(const QString uri) _impl->frameDispatcher.deleteStream(uri); } -void Server::replyToEventRegistration(const QString uri, const bool success) -{ - emit _eventRegistrationReply(uri, success); -} - void Server::incomingConnection(const qintptr socketHandle) { QThread* workerThread = new QThread(this); @@ -131,8 +126,6 @@ void Server::incomingConnection(const qintptr socketHandle) connect(worker, &ServerWorker::receivedData, this, &Server::receivedData); connect(this, &Server::_closePixelStream, worker, &ServerWorker::closeConnection); - connect(this, &Server::_eventRegistrationReply, worker, - &ServerWorker::replyToEventRegistration); // FrameDispatcher connect(worker, &ServerWorker::addStreamSource, &_impl->frameDispatcher, diff --git a/deflect/Server.h b/deflect/Server.h index 4140130..777112c 100644 --- a/deflect/Server.h +++ b/deflect/Server.h @@ -90,14 +90,6 @@ public slots: */ void requestFrame(QString uri); - /** - * Reply to an event registration request after a registerToEvents() signal. - * - * @param uri Identifier for the stream - * @param success Result of the registration operation - */ - void replyToEventRegistration(QString uri, bool success); - /** * Close a pixel stream, disconnecting the remote client. * @@ -136,9 +128,11 @@ public slots: * @param uri Identifier for the stream * @param exclusive true if the receiver should receive events exclusively * @param receiver the event receiver instance + * @param success the promise that must receive the success of the operation */ void registerToEvents(QString uri, bool exclusive, - deflect::EventReceiver* receiver); + deflect::EventReceiver* receiver, + deflect::BoolPromisePtr success); /** * Emitted when a remote client sends size hints for displaying the stream. @@ -165,7 +159,6 @@ public slots: signals: void _closePixelStream(QString uri); - void _eventRegistrationReply(QString uri, bool success); }; } diff --git a/deflect/ServerWorker.cpp b/deflect/ServerWorker.cpp index 1a19f72..7eeca26 100644 --- a/deflect/ServerWorker.cpp +++ b/deflect/ServerWorker.cpp @@ -117,16 +117,6 @@ void ServerWorker::closeConnection(const QString uri) emit(connectionClosed()); } -void ServerWorker::replyToEventRegistration(const QString uri, - const bool success) -{ - if (uri != _streamId) - return; - - _registeredToEvents = success; - _sendBindReply(_registeredToEvents); -} - void ServerWorker::_processMessages() { const qint64 headerSize(MessageHeader::serializedSize); @@ -268,7 +258,18 @@ void ServerWorker::_handleMessage(const MessageHeader& messageHeader, { const bool exclusive = (messageHeader.type == MESSAGE_TYPE_BIND_EVENTS_EX); - emit registerToEvents(_streamId, exclusive, this); + auto promise = std::make_shared>(); + auto future = promise->get_future(); + emit registerToEvents(_streamId, exclusive, this, + std::move(promise)); + try + { + _registeredToEvents = future.get(); + } + catch (...) + { + } + _sendBindReply(_registeredToEvents); } break; diff --git a/deflect/ServerWorker.h b/deflect/ServerWorker.h index f84cbc6..20672db 100644 --- a/deflect/ServerWorker.h +++ b/deflect/ServerWorker.h @@ -1,5 +1,5 @@ /*********************************************************************/ -/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */ +/* Copyright (c) 2013-2017, EPFL/Blue Brain Project */ /* Raphael Dumusc */ /* Daniel.Nachbaur@epfl.ch */ /* All rights reserved. */ @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -65,7 +66,6 @@ public slots: void initConnection(); void closeConnection(QString uri); - void replyToEventRegistration(QString uri, bool success); signals: void addStreamSource(QString uri, size_t sourceIndex); @@ -76,7 +76,8 @@ public slots: void receivedFrameFinished(QString uri, size_t sourceIndex); void registerToEvents(QString uri, bool exclusive, - deflect::EventReceiver* receiver); + deflect::EventReceiver* receiver, + deflect::BoolPromisePtr success); void receivedSizeHints(QString uri, deflect::SizeHints hints); diff --git a/deflect/types.h b/deflect/types.h index a7951fe..6a1c580 100644 --- a/deflect/types.h +++ b/deflect/types.h @@ -43,6 +43,7 @@ #include +#include #include #include @@ -85,9 +86,10 @@ struct Segment; struct SegmentParameters; struct SizeHints; -typedef std::shared_ptr FramePtr; -typedef std::vector Segments; -typedef std::vector SegmentParametersList; +using BoolPromisePtr = std::shared_ptr>; +using FramePtr = std::shared_ptr; +using Segments = std::vector; +using SegmentParametersList = std::vector; namespace qt { diff --git a/doc/Changelog.md b/doc/Changelog.md index 44c4f3d..804b721 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,8 @@ Changelog {#Changelog} ## Deflect 0.13 (git master) +* [157](https://github.com/BlueBrain/Deflect/pull/157): + Better event registration mechanism, fixes warnings in the multi-client case. * [154](https://github.com/BlueBrain/Deflect/pull/154): On the server side, segments can be decoded to YUV images, saving CPU time by skipping the YUV -> RGB conversion step. diff --git a/tests/cpp/ServerTests.cpp b/tests/cpp/ServerTests.cpp index 87e9e89..5d6b6f3 100644 --- a/tests/cpp/ServerTests.cpp +++ b/tests/cpp/ServerTests.cpp @@ -136,12 +136,12 @@ BOOST_AUTO_TEST_CASE(testRegisterForEventReceivedByServer) bool receivedState = false; server->connect(server, &deflect::Server::registerToEvents, [&](const QString id, const bool exclusive, - deflect::EventReceiver* receiver) { + deflect::EventReceiver* receiver, + deflect::BoolPromisePtr success) { streamId = id; exclusiveBind = exclusive; eventReceiver = receiver; - // send reply to Stream - server->replyToEventRegistration(id, true); + success->set_value(true); mutex.lock(); receivedState = true; received.wakeAll();