Ring Daemon 16.0.0
Loading...
Searching...
No Matches
preferenceservicesmanager.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
19
20#include "pluginmanager.h"
22
23#include "manager.h"
24#include "sip/sipcall.h"
25#include "fileutils.h"
26#include "logger.h"
27
28namespace jami {
29
34
39
40std::vector<std::string>
42{
43 std::vector<std::string> res;
44 res.reserve(handlers_.size());
45 for (const auto& preferenceHandler : handlers_) {
46 res.emplace_back(std::to_string((uintptr_t) preferenceHandler.get()));
47 }
48 return res;
49}
50
51std::map<std::string, std::string>
53{
55 for (auto& preferenceHandler : handlers_) {
57 return preferenceHandler->getHandlerDetails();
58 }
59 }
60 return {};
61}
62
63bool
65 const std::string& value,
66 const std::string& rootPath,
67 const std::string& accountId)
68{
69 bool status {true};
70 for (auto& preferenceHandler : handlers_) {
71 if (preferenceHandler->id().find(rootPath) != std::string::npos) {
72 if (preferenceHandler->preferenceMapHasKey(key)) {
73 preferenceHandler->setPreferenceAttribute(accountId, key, value);
74 // We can return here since we expect plugins to have a single preferencehandler
75 return false;
76 }
77 }
78 }
79 return status;
80}
81
82void
84 const std::string& accountId)
85{
86 for (auto& preferenceHandler : handlers_) {
87 if (preferenceHandler->id().find(rootPath) != std::string::npos) {
88 preferenceHandler->resetPreferenceAttributes(accountId);
89 }
90 }
91}
92
93void
94PreferenceServicesManager::registerComponentsLifeCycleManagers(PluginManager& pluginManager)
95{
96 // registerHandler may be called by the PluginManager upon loading a plugin.
97 auto registerHandler = [this](void* data, std::mutex& pmMtx_) {
98 std::lock_guard lk(pmMtx_);
99 PreferenceHandlerPtr ptr {(static_cast<PreferenceHandler*>(data))};
100
101 if (!ptr)
102 return -1;
103 handlers_.emplace_back(std::move(ptr));
104 return 0;
105 };
106
107 // unregisterHandler may be called by the PluginManager while unloading.
108 auto unregisterHandler = [this](void* data, std::mutex& pmMtx_) {
109 std::lock_guard lk(pmMtx_);
110 auto handlerIt = std::find_if(handlers_.begin(),
111 handlers_.end(),
113 return (handler.get() == data);
114 });
115
116 if (handlerIt != handlers_.end()) {
117 handlers_.erase(handlerIt);
118 }
119 return true;
120 };
121
122 // Services are registered to the PluginManager.
123 pluginManager.registerComponentManager("PreferenceHandlerManager",
126}
127} // namespace jami
This class manages plugin (un)loading.
This abstract class is an API we need to implement from plugin side.
PreferenceServicesManager(PluginManager &pluginManager)
Constructor registers PreferenceHandler API services to the PluginManager instance.
void resetPreferences(const std::string &rootPath, const std::string &accountId)
Resets acc preferences to default values.
bool setPreference(const std::string &key, const std::string &value, const std::string &rootPath, const std::string &accountId)
Sets a preference.
std::vector< std::string > getHandlers() const
List all PreferenceHandlers available.
std::map< std::string, std::string > getHandlerDetails(const std::string &preferenceHandlerIdStr) const
Returns details Map from s implementation.
void emitSignal(Args... args)
Definition ring_signal.h:64
std::unique_ptr< PreferenceHandler > PreferenceHandlerPtr
SIPCall are SIP implementation of a normal Call.