Ring Daemon 16.0.0
Loading...
Searching...
No Matches
ring_types.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
18#ifndef RING_TYPES_H_
19#define RING_TYPES_H_
20
21#include <type_traits>
22#include <memory>
23#include <mutex>
24#include <cstddef> // for size_t
25
26#include <ciso646> // fix windows compiler bug
27
28namespace jami {
29
30
31static constexpr size_t SIZEBUF = 16000;
37template<class T, class U>
38using enable_if_base_of = typename std::enable_if<std::is_base_of<T, U>::value, T>::type;
39
51template<class T, signed MaxRespawn = -1>
52std::shared_ptr<T>
54{
55 static std::recursive_mutex mutex; // recursive as instance calls recursively
56 static std::weak_ptr<T> wlink;
57
58 std::unique_lock<std::recursive_mutex> lock(mutex);
59
60 if (wlink.expired()) {
61 static signed counter {MaxRespawn};
62 if (not counter)
63 return nullptr;
64 auto link = std::make_shared<T>();
65 wlink = link;
66 if (counter > 0)
67 --counter;
68 return link;
69 }
70
71 return wlink.lock();
72}
73
74} // namespace jami
75
76#endif // RING_TYPES_H_
void emitSignal(Args... args)
Definition ring_signal.h:64
typename std::enable_if< std::is_base_of< T, U >::value, T >::type enable_if_base_of
About 62.5ms of buffering at 48kHz.
Definition ring_types.h:38
std::shared_ptr< T > getGlobalInstance()
Return a shared pointer on an auto-generated global instance of class T.
Definition ring_types.h:53
static constexpr size_t SIZEBUF
Definition ring_types.h:31