Ring Daemon 16.0.0
Loading...
Searching...
No Matches
call_factory.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 <map>
20#include <memory>
21#include <mutex>
22#include <vector>
23#include <string>
24#include <utility>
25
26#include "call.h"
27#include "account.h"
28
29namespace jami {
30
31class SIPAccountBase;
32class SIPCall;
33
35{
36public:
37 CallFactory(std::mt19937_64& rand)
38 : rand_(rand)
39 {}
40
41 std::string getNewCallID() const;
42
50 std::shared_ptr<SIPCall> newSipCall(const std::shared_ptr<SIPAccountBase>& account,
51 Call::CallType type,
52 const std::vector<libjami::MediaMap>& mediaList);
53
57 void forbid();
58
62 void removeCall(Call& call);
63
67 void removeCall(const std::string& id);
68
72 std::shared_ptr<Call> getCall(const std::string& id) const;
73 std::shared_ptr<Call> getCall(const std::string& id, Call::LinkType link) const;
74
75 template<class C>
76 std::shared_ptr<C> getCall(const std::string& id)
77 {
78 return std::dynamic_pointer_cast<C>(getCall(id, C::LINK_TYPE));
79 }
80
84 bool hasCall(const std::string& id) const;
85 bool hasCall(const std::string& id, Call::LinkType link) const;
86
90 bool empty() const;
91 bool empty(Call::LinkType link) const;
92
96 void clear();
97
101 std::vector<std::shared_ptr<Call>> getAllCalls() const;
102 std::vector<std::shared_ptr<Call>> getAllCalls(Call::LinkType link) const;
103
107 std::vector<std::string> getCallIDs() const;
108 std::vector<std::string> getCallIDs(Call::LinkType link) const;
109
113 std::size_t callCount() const;
114 std::size_t callCount(Call::LinkType link) const;
115
116private:
123 const CallMap* getMap_(Call::LinkType link) const
124 {
125 auto const& itermap = callMaps_.find(link);
126 if (itermap != callMaps_.cend())
127 return &itermap->second;
128 return nullptr;
129 }
130
131 std::mt19937_64& rand_;
132
133 mutable std::recursive_mutex callMapsMutex_ {};
134
135 std::atomic_bool allowNewCall_ {true};
136
137 std::map<Call::LinkType, CallMap> callMaps_ {};
138};
139
140} // namespace jami
Interface to protocol account (ex: SIPAccount) It can be enable on loading or activate after.
std::size_t callCount() const
Return number of calls.
std::vector< std::shared_ptr< Call > > getAllCalls() const
Return all calls.
std::shared_ptr< SIPCall > newSipCall(const std::shared_ptr< SIPAccountBase > &account, Call::CallType type, const std::vector< libjami::MediaMap > &mediaList)
Create a new call instance.
CallFactory(std::mt19937_64 &rand)
std::shared_ptr< C > getCall(const std::string &id)
void forbid()
Forbid creation of new calls.
std::vector< std::string > getCallIDs() const
Return all call's IDs.
bool hasCall(const std::string &id) const
Return if given call exists.
void removeCall(Call &call)
Remove given call instance from call list.
std::shared_ptr< Call > getCall(const std::string &id) const
Return call pointer associated to given ID.Type can optionally be specified.
std::string getNewCallID() const
void clear()
Erase all calls.
bool empty() const
Return if calls exist.
CallType
This determines if the call originated from the local user (OUTGOING) or from some remote peer (INCOM...
Definition call.h:120
std::map< std::string, std::shared_ptr< Call > > CallMap
Definition call.h:61
void emitSignal(Args... args)
Definition ring_signal.h:64