LCOV - code coverage report
Current view: top level - src - call_set.h (source / functions) Coverage Total Hit
Test: jami-coverage-filtered.info Lines: 81.0 % 42 34
Test Date: 2026-07-29 09:02:12 Functions: 87.5 % 8 7

            Line data    Source code
       1              : /*
       2              :  *  Copyright (C) 2004-2026 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          231 :     std::shared_ptr<Call> getCall(const std::string& callId) const
      33              :     {
      34          231 :         std::lock_guard l(mutex_);
      35          231 :         auto i = calls_.find(callId);
      36          462 :         return i == calls_.end() ? std::shared_ptr<Call> {} : i->second.lock();
      37          231 :     }
      38           46 :     std::shared_ptr<Conference> getConference(const std::string& conferenceId) const
      39              :     {
      40           46 :         std::lock_guard l(mutex_);
      41           46 :         auto i = conferences_.find(conferenceId);
      42           92 :         return i == conferences_.end() ? std::shared_ptr<Conference> {} : i->second;
      43           46 :     }
      44              : 
      45          163 :     void add(const std::shared_ptr<Call>& call)
      46              :     {
      47          163 :         std::lock_guard l(mutex_);
      48          163 :         calls_.emplace(call->getCallId(), call);
      49          163 :     }
      50           15 :     void add(const std::shared_ptr<Conference>& conference)
      51              :     {
      52           15 :         std::lock_guard l(mutex_);
      53           15 :         conferences_.emplace(conference->getConfId(), conference);
      54           15 :     }
      55          168 :     bool remove(const std::shared_ptr<Call>& call)
      56              :     {
      57          168 :         std::lock_guard l(mutex_);
      58          336 :         return calls_.erase(call->getCallId()) > 0;
      59          168 :     }
      60           13 :     bool removeConference(const std::string& confId)
      61              :     {
      62           13 :         std::lock_guard l(mutex_);
      63           26 :         return conferences_.erase(confId) > 0;
      64           13 :     }
      65              : 
      66          718 :     std::vector<std::string> getCallIds() const
      67              :     {
      68          718 :         std::lock_guard l(mutex_);
      69          718 :         std::vector<std::string> ids;
      70          718 :         ids.reserve(calls_.size());
      71          736 :         for (const auto& callIt : calls_)
      72           18 :             ids.emplace_back(callIt.first);
      73         1436 :         return ids;
      74          718 :     }
      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            0 :     std::vector<std::string> getConferenceIds() const
      87              :     {
      88            0 :         std::lock_guard l(mutex_);
      89            0 :         std::vector<std::string> ids;
      90            0 :         ids.reserve(conferences_.size());
      91            0 :         for (const auto& confIt : conferences_)
      92            0 :             ids.emplace_back(confIt.first);
      93            0 :         return ids;
      94            0 :     }
      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 2.0-1