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 170 : std::shared_ptr<Call> getCall(const std::string& callId) const 33 : { 34 170 : std::lock_guard l(mutex_); 35 170 : auto i = calls_.find(callId); 36 340 : return i == calls_.end() ? std::shared_ptr<Call> {} : i->second.lock(); 37 170 : } 38 39 : std::shared_ptr<Conference> getConference(const std::string& conferenceId) const 39 : { 40 39 : std::lock_guard l(mutex_); 41 39 : auto i = conferences_.find(conferenceId); 42 78 : return i == conferences_.end() ? std::shared_ptr<Conference> {} : i->second; 43 39 : } 44 : 45 139 : void add(const std::shared_ptr<Call>& call) 46 : { 47 139 : std::lock_guard l(mutex_); 48 139 : calls_.emplace(call->getCallId(), call); 49 139 : } 50 14 : void add(const std::shared_ptr<Conference>& conference) 51 : { 52 14 : std::lock_guard l(mutex_); 53 14 : conferences_.emplace(conference->getConfId(), conference); 54 14 : } 55 147 : bool remove(const std::shared_ptr<Call>& call) 56 : { 57 147 : std::lock_guard l(mutex_); 58 294 : return calls_.erase(call->getCallId()) > 0; 59 147 : } 60 12 : bool removeConference(const std::string& confId) 61 : { 62 12 : std::lock_guard l(mutex_); 63 24 : return conferences_.erase(confId) > 0; 64 12 : } 65 : 66 679 : std::vector<std::string> getCallIds() const 67 : { 68 679 : std::lock_guard l(mutex_); 69 679 : std::vector<std::string> ids; 70 679 : ids.reserve(calls_.size()); 71 693 : for (const auto& callIt : calls_) 72 14 : ids.emplace_back(callIt.first); 73 1358 : return ids; 74 679 : } 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