LCOV - code coverage report
Current view: top level - src - call_set.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 42 42 100.0 %
Date: 2024-11-15 09:04:49 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  This program is free software: you can redistribute it and/or modify
       5             :  *  it under the terms of the GNU General Public License as published by
       6             :  *  the Free Software Foundation, either version 3 of the License, or
       7             :  *  (at your option) any later version.
       8             :  *
       9             :  *  This program is distributed in the hope that it will be useful,
      10             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      12             :  *  GNU General Public License for more details.
      13             :  *
      14             :  *  You should have received a copy of the GNU General Public License
      15             :  *  along with this program. If not, see <https://www.gnu.org/licenses/>.
      16             :  */
      17             : #pragma once
      18             : 
      19             : #include "call.h"
      20             : #include "conference.h"
      21             : 
      22             : #include <map>
      23             : #include <memory>
      24             : #include <string>
      25             : #include <mutex>
      26             : 
      27             : namespace jami {
      28             : 
      29             : class CallSet
      30             : {
      31             : public:
      32         706 :     std::shared_ptr<Call> getCall(const std::string& callId) const
      33             :     {
      34         706 :         std::lock_guard l(mutex_);
      35         706 :         auto i = calls_.find(callId);
      36        1412 :         return i == calls_.end() ? std::shared_ptr<Call> {} : i->second.lock();
      37         706 :     }
      38         105 :     std::shared_ptr<Conference> getConference(const std::string& conferenceId) const
      39             :     {
      40         105 :         std::lock_guard l(mutex_);
      41         105 :         auto i = conferences_.find(conferenceId);
      42         210 :         return i == conferences_.end() ? std::shared_ptr<Conference> {} : i->second;
      43         105 :     }
      44             : 
      45         395 :     void add(const std::shared_ptr<Call>& call)
      46             :     {
      47         395 :         std::lock_guard l(mutex_);
      48         395 :         calls_.emplace(call->getCallId(), call);
      49         395 :     }
      50          38 :     void add(const std::shared_ptr<Conference>& conference)
      51             :     {
      52          38 :         std::lock_guard l(mutex_);
      53          38 :         conferences_.emplace(conference->getConfId(), conference);
      54          38 :     }
      55         408 :     bool remove(const std::shared_ptr<Call>& call)
      56             :     {
      57         408 :         std::lock_guard l(mutex_);
      58         816 :         return calls_.erase(call->getCallId()) > 0;
      59         408 :     }
      60          56 :     bool removeConference(const std::string& confId)
      61             :     {
      62          56 :         std::lock_guard l(mutex_);
      63         112 :         return conferences_.erase(confId) > 0;
      64          56 :     }
      65             : 
      66         780 :     std::vector<std::string> getCallIds() const
      67             :     {
      68         780 :         std::lock_guard l(mutex_);
      69         780 :         std::vector<std::string> ids;
      70         780 :         ids.reserve(calls_.size());
      71         804 :         for (const auto& callIt : calls_)
      72          24 :             ids.emplace_back(callIt.first);
      73        1560 :         return ids;
      74         780 :     }
      75             :     std::vector<std::shared_ptr<Call>> getCalls() const
      76             :     {
      77             :         std::lock_guard l(mutex_);
      78             :         std::vector<std::shared_ptr<Call>> calls;
      79             :         calls.reserve(calls_.size());
      80             :         for (const auto& callIt : calls_)
      81             :             if (auto call = callIt.second.lock())
      82             :                 calls.emplace_back(std::move(call));
      83             :         return calls;
      84             :     }
      85             : 
      86           4 :     std::vector<std::string> getConferenceIds() const
      87             :     {
      88           4 :         std::lock_guard l(mutex_);
      89           4 :         std::vector<std::string> ids;
      90           4 :         ids.reserve(conferences_.size());
      91           6 :         for (const auto& confIt : conferences_)
      92           2 :             ids.emplace_back(confIt.first);
      93           8 :         return ids;
      94           4 :     }
      95             :     std::vector<std::shared_ptr<Conference>> getConferences() const
      96             :     {
      97             :         std::lock_guard l(mutex_);
      98             :         std::vector<std::shared_ptr<Conference>> confs;
      99             :         confs.reserve(conferences_.size());
     100             :         for (const auto& confIt : conferences_)
     101             :             if (const auto& conf = confIt.second)
     102             :                 confs.emplace_back(conf);
     103             :         return confs;
     104             :     }
     105             : 
     106             : private:
     107             :     mutable std::mutex mutex_;
     108             :     std::map<std::string, std::weak_ptr<Call>> calls_;
     109             :     std::map<std::string, std::shared_ptr<Conference>> conferences_;
     110             : };
     111             : 
     112             : } // namespace jami

Generated by: LCOV version 1.14