Ring Daemon 16.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ring_api.cpp
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#include <asio.hpp>
18#include <string>
19#include <vector>
20#include <map>
21#include <cstdlib>
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include "manager.h"
28#include "logger.h"
29#include "jami.h"
33#include "client/ring_signal.h"
34
35#ifdef ENABLE_VIDEO
36#include "client/videomanager.h"
37#endif // ENABLE_VIDEO
38
39namespace libjami {
40
42
43bool
44init(enum InitFlag flags) noexcept
45{
46 initFlags = flags;
47 jami::Logger::setDebugMode(LIBJAMI_FLAG_DEBUG == (flags & LIBJAMI_FLAG_DEBUG));
48 jami::Logger::setSysLog(LIBJAMI_FLAG_SYSLOG == (flags & LIBJAMI_FLAG_SYSLOG));
49 jami::Logger::setConsoleLog(LIBJAMI_FLAG_CONSOLE_LOG == (flags & LIBJAMI_FLAG_CONSOLE_LOG));
50
51 const char* log_file = getenv("JAMI_LOG_FILE");
52
53 if (log_file) {
54 jami::Logger::setFileLog(log_file);
55 }
56
57 // Following function create a local static variable inside
58 // This var must have the same live as Manager.
59 // So we call it now to create this var.
61
62 try {
63 // current implementation use static variable
64 auto& manager = jami::Manager::instance();
65 manager.setAutoAnswer(flags & LIBJAMI_FLAG_AUTOANSWER);
66
67#if TARGET_OS_IOS
69 manager.isIOSExtension = true;
70#endif
71 if (flags & LIBJAMI_FLAG_NO_AUTOSYNC)
72 manager.syncOnRegister = false;
73
74 return true;
75 } catch (...) {
76 return false;
77 }
78}
79
80bool
81start(const std::filesystem::path& config_file) noexcept
82{
83 try {
85 } catch (...) {
86 return false;
87 }
88 return true;
89}
90
91bool
92initialized() noexcept
93{
95}
96
97void
98fini() noexcept
99{
101 jami::Logger::fini();
102}
103
104void
105logging(const std::string& whom, const std::string& action) noexcept
106{
107 if ("syslog" == whom) {
108 jami::Logger::setSysLog(not action.empty());
109 } else if ("console" == whom) {
110 jami::Logger::setConsoleLog(not action.empty());
111 } else if ("monitor" == whom) {
112 jami::Logger::setMonitorLog(not action.empty());
113 } else if ("file" == whom) {
114 jami::Logger::setFileLog(action);
115 } else {
116 JAMI_ERR("Bad log handler %s", whom.c_str());
117 }
118}
119
120void
121CallbackWrapperBase::post(std::function<void()> cb)
122{
123 if (auto io = jami::Manager::instance().ioContext())
124 asio::post(*io, std::move(cb));
125}
126
127} // namespace libjami
void finish() noexcept
Definition manager.cpp:855
static LIBJAMI_TEST_EXPORT Manager & instance()
Definition manager.cpp:676
static std::atomic_bool initialized
Definition manager.h:108
void init(const std::filesystem::path &config_file, libjami::InitFlag flags)
Initialisation of thread (sound) and map.
Definition manager.cpp:718
void post(std::function< void()> cb)
Definition ring_api.cpp:121
#define JAMI_ERR(...)
Definition logger.h:218
SignalHandlerMap & getSignalHandlers()
LIBJAMI_PUBLIC bool start(const std::filesystem::path &config_file={}) noexcept
Start asynchronously daemon created by init().
Definition ring_api.cpp:81
LIBJAMI_PUBLIC void logging(const std::string &whom, const std::string &action) noexcept
Control log handlers.
Definition ring_api.cpp:105
enum LIBJAMI_PUBLIC enum LIBJAMI_PUBLIC io
LIBJAMI_PUBLIC bool init(enum InitFlag flags) noexcept
Initialize globals, create underlaying daemon.
Definition ring_api.cpp:44
LIBJAMI_PUBLIC bool initialized() noexcept
Definition ring_api.cpp:92
InitFlag initFlags
Definition ring_api.cpp:41
LIBJAMI_PUBLIC void fini() noexcept
Stop and freeing any resource allocated by daemon.
Definition ring_api.cpp:98
InitFlag
Definition jami.h:35
@ LIBJAMI_FLAG_CONSOLE_LOG
Definition jami.h:37
@ LIBJAMI_FLAG_IOS_EXTENSION
Definition jami.h:40
@ LIBJAMI_FLAG_SYSLOG
Definition jami.h:38
@ LIBJAMI_FLAG_AUTOANSWER
Definition jami.h:39
@ LIBJAMI_FLAG_NO_AUTOSYNC
Definition jami.h:44
@ LIBJAMI_FLAG_DEBUG
Definition jami.h:36