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-04-27 08:55:53 Functions: 8 8 100.0 %

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

Generated by: LCOV version 1.14