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 : #ifdef HAVE_CONFIG_H
20 : #include "config.h"
21 : #endif
22 :
23 : #include "callmanager_interface.h"
24 : #include "configurationmanager_interface.h"
25 : #include "conversation_interface.h"
26 : #include "networkservice_interface.h"
27 : #include "presencemanager_interface.h"
28 : #include "datatransfer_interface.h"
29 :
30 : #ifdef ENABLE_VIDEO
31 : #include "videomanager_interface.h"
32 : #endif
33 :
34 : #ifdef ENABLE_PLUGIN
35 : #include "plugin_manager_interface.h"
36 : #endif
37 :
38 : #include "jami.h"
39 : #include "logger.h"
40 : #include "tracepoint.h"
41 :
42 : #ifdef __APPLE__
43 : #include <TargetConditionals.h>
44 : #endif
45 :
46 : #include <exception>
47 : #include <memory>
48 : #include <map>
49 : #include <utility>
50 : #include <string>
51 :
52 : namespace jami {
53 :
54 : using SignalHandlerMap = std::map<std::string, std::shared_ptr<libjami::CallbackWrapperBase>>;
55 : extern SignalHandlerMap& getSignalHandlers();
56 :
57 : /*
58 : * Find related user given callback and call it with given
59 : * arguments.
60 : */
61 : #pragma GCC diagnostic push
62 : #pragma GCC diagnostic ignored "-Wunused-parameter"
63 : template<typename Ts, typename... Args>
64 : void
65 30403 : emitSignal(Args... args)
66 : {
67 : jami_tracepoint_if_enabled(emit_signal, demangle<Ts>().c_str());
68 :
69 30403 : const auto& handlers = getSignalHandlers();
70 69265 : if (auto wrap = libjami::CallbackWrapper<typename Ts::cb_type>(handlers.at(Ts::name))) {
71 : try {
72 8455 : auto cb = *wrap;
73 : jami_tracepoint(emit_signal_begin_callback, wrap.file_, wrap.linum_);
74 8455 : cb(args...);
75 : jami_tracepoint(emit_signal_end_callback);
76 8455 : } catch (std::exception& e) {
77 0 : JAMI_ERROR("Exception during emit signal {}:\n{}", Ts::name, e.what());
78 : }
79 : }
80 :
81 : jami_tracepoint(emit_signal_end);
82 30404 : }
83 : #pragma GCC diagnostic pop
84 :
85 : template<typename Ts>
86 : std::pair<std::string, std::shared_ptr<libjami::CallbackWrapper<typename Ts::cb_type>>>
87 3496 : exported_callback()
88 : {
89 : return std::make_pair((const std::string&) Ts::name,
90 10488 : std::make_shared<libjami::CallbackWrapper<typename Ts::cb_type>>());
91 : }
92 :
93 : } // namespace jami
|