Ring Daemon 16.0.0
Loading...
Searching...
No Matches
call_set.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 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
27namespace jami {
28
30{
31public:
32 std::shared_ptr<Call> getCall(const std::string& callId) const
33 {
34 std::lock_guard l(mutex_);
35 auto i = calls_.find(callId);
36 return i == calls_.end() ? std::shared_ptr<Call> {} : i->second.lock();
37 }
38 std::shared_ptr<Conference> getConference(const std::string& conferenceId) const
39 {
40 std::lock_guard l(mutex_);
41 auto i = conferences_.find(conferenceId);
42 return i == conferences_.end() ? std::shared_ptr<Conference> {} : i->second;
43 }
44
45 void add(const std::shared_ptr<Call>& call)
46 {
47 std::lock_guard l(mutex_);
48 calls_.emplace(call->getCallId(), call);
49 }
50 void add(const std::shared_ptr<Conference>& conference)
51 {
52 std::lock_guard l(mutex_);
53 conferences_.emplace(conference->getConfId(), conference);
54 }
55 bool remove(const std::shared_ptr<Call>& call)
56 {
57 std::lock_guard l(mutex_);
58 return calls_.erase(call->getCallId()) > 0;
59 }
60 bool removeConference(const std::string& confId)
61 {
62 std::lock_guard l(mutex_);
63 return conferences_.erase(confId) > 0;
64 }
65
66 std::vector<std::string> getCallIds() const
67 {
68 std::lock_guard l(mutex_);
69 std::vector<std::string> ids;
70 ids.reserve(calls_.size());
71 for (const auto& callIt : calls_)
72 ids.emplace_back(callIt.first);
73 return ids;
74 }
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 std::vector<std::string> getConferenceIds() const
87 {
88 std::lock_guard l(mutex_);
89 std::vector<std::string> ids;
90 ids.reserve(conferences_.size());
91 for (const auto& confIt : conferences_)
92 ids.emplace_back(confIt.first);
93 return ids;
94 }
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
106private:
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
std::vector< std::shared_ptr< Conference > > getConferences() const
Definition call_set.h:95
bool remove(const std::shared_ptr< Call > &call)
Definition call_set.h:55
std::vector< std::string > getCallIds() const
Definition call_set.h:66
void add(const std::shared_ptr< Call > &call)
Definition call_set.h:45
std::vector< std::shared_ptr< Call > > getCalls() const
Definition call_set.h:75
std::vector< std::string > getConferenceIds() const
Definition call_set.h:86
std::shared_ptr< Conference > getConference(const std::string &conferenceId) const
Definition call_set.h:38
void add(const std::shared_ptr< Conference > &conference)
Definition call_set.h:50
bool removeConference(const std::string &confId)
Definition call_set.h:60
std::shared_ptr< Call > getCall(const std::string &callId) const
Definition call_set.h:32
void emitSignal(Args... args)
Definition ring_signal.h:64