From a06588ed77f6a18920097297084ba9084e3ee666 Mon Sep 17 00:00:00 2001 From: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com> Date: Fri, 30 Sep 2016 19:55:58 -0400 Subject: [PATCH] manager: fix Manager::createSinkClient() Manager::createSinkClient() returns a nullptr set shared_ptr when called with an id already associated to a sink client. This is not the waiting behaviour: returns the existing client. This patch fixes that and also add documentation to the public API to explicit this behaviour. Change-Id: Idc9a0b4f7d7a06e2bdafe965891469903f0d5d99 --- src/manager.cpp | 7 +++---- src/manager.h | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/manager.cpp b/src/manager.cpp index 9bb9014014..d1124f942e 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -2862,10 +2862,9 @@ Manager::createSinkClient(const std::string& id, bool mixer) { const auto& iter = sinkMap_.find(id); if (iter != std::end(sinkMap_)) { - if (iter->second.expired()) - sinkMap_.erase(iter); - else - return nullptr; + if (auto sink = iter->second.lock()) + return sink; + sinkMap_.erase(iter); // remove expired weak_ptr } auto sink = std::make_shared<video::SinkClient>(id, mixer); diff --git a/src/manager.h b/src/manager.h index 34c4ebb996..54c17a736c 100644 --- a/src/manager.h +++ b/src/manager.h @@ -994,8 +994,24 @@ class Manager { void scheduleTask(std::shared_ptr<Runnable> task, std::chrono::steady_clock::time_point when); #ifdef RING_VIDEO + /** + * Create a new SinkClient instance, store it in an internal cache as a weak_ptr + * and return it as a shared_ptr. If a SinkClient is already stored for the given id, + * this method returns this instance. + * @param id SinkClient identifier as a string. Default is empty. + * @param mixer true if the SinkCient is the sink of a VideoMixer node. Default is false. + * @return share_ptr<SinkClient> A shared pointer on the created instance. + */ std::shared_ptr<video::SinkClient> createSinkClient(const std::string& id="", bool mixer=false); + + /** + * Return an existing SinkClient instance as a shared_ptr associated to the given identifier. + * Return an empty shared_ptr (nullptr) if nothing found. + * @param id SinkClient identifier as a string. + * @return share_ptr<SinkClient> A shared pointer on the found instance. Empty if not found. + */ std::shared_ptr<video::SinkClient> getSinkClient(const std::string& id); + VideoManager& getVideoManager() const { return *videoManager_; } #endif // RING_VIDEO -- GitLab