Line data Source code
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 : #include "plugin_manager_interface.h"
19 :
20 : #ifdef HAVE_CONFIG_H
21 : #include "config.h"
22 : #endif // HAVE_CONFIG_H
23 :
24 : #ifdef ENABLE_PLUGIN
25 : #include "manager.h"
26 : #include "plugin/jamipluginmanager.h"
27 : #endif
28 :
29 : namespace libjami {
30 : bool
31 0 : loadPlugin(const std::string& path)
32 : {
33 : #ifdef ENABLE_PLUGIN
34 0 : bool status = jami::Manager::instance().getJamiPluginManager().loadPlugin(path);
35 :
36 0 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, status);
37 0 : jami::Manager::instance().saveConfig();
38 0 : return status;
39 : #endif
40 : return false;
41 : }
42 :
43 : bool
44 0 : unloadPlugin(const std::string& path)
45 : {
46 : #ifdef ENABLE_PLUGIN
47 0 : bool status = jami::Manager::instance().getJamiPluginManager().unloadPlugin(path);
48 :
49 0 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, false);
50 0 : jami::Manager::instance().saveConfig();
51 0 : return status;
52 : #endif
53 : return false;
54 : }
55 :
56 : std::map<std::string, std::string>
57 0 : getPluginDetails(const std::string& path)
58 : {
59 : #ifdef ENABLE_PLUGIN
60 0 : return jami::Manager::instance().getJamiPluginManager().getPluginDetails(path);
61 : #endif
62 : return {};
63 : }
64 :
65 : std::vector<std::map<std::string, std::string>>
66 0 : getPluginPreferences(const std::string& path, const std::string& accountId)
67 : {
68 : #ifdef ENABLE_PLUGIN
69 0 : return jami::Manager::instance().getJamiPluginManager().getPluginPreferences(path, accountId);
70 : #endif
71 : return {};
72 : }
73 :
74 : bool
75 0 : setPluginPreference(const std::string& path,
76 : const std::string& accountId,
77 : const std::string& key,
78 : const std::string& value)
79 : {
80 : #ifdef ENABLE_PLUGIN
81 0 : return jami::Manager::instance().getJamiPluginManager().setPluginPreference(path, accountId, key, value);
82 : #endif
83 : return {};
84 : }
85 :
86 : std::map<std::string, std::string>
87 0 : getPluginPreferencesValues(const std::string& path, const std::string& accountId)
88 : {
89 : #ifdef ENABLE_PLUGIN
90 0 : return jami::Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(path, accountId);
91 : #endif
92 : return {};
93 : }
94 : bool
95 0 : resetPluginPreferencesValues(const std::string& path, const std::string& accountId)
96 : {
97 : #ifdef ENABLE_PLUGIN
98 0 : return jami::Manager::instance().getJamiPluginManager().resetPluginPreferencesValuesMap(path, accountId);
99 : #endif
100 : }
101 :
102 : std::vector<std::string>
103 0 : getInstalledPlugins()
104 : {
105 : #ifdef ENABLE_PLUGIN
106 0 : return jami::Manager::instance().getJamiPluginManager().getInstalledPlugins();
107 : #endif
108 : return {};
109 : }
110 :
111 : std::vector<std::string>
112 0 : getLoadedPlugins()
113 : {
114 : #ifdef ENABLE_PLUGIN
115 0 : return jami::Manager::instance().pluginPreferences.getLoadedPlugins();
116 : #endif
117 : return {};
118 : }
119 :
120 : int
121 0 : installPlugin(const std::string& jplPath, bool force)
122 : {
123 : #ifdef ENABLE_PLUGIN
124 0 : return jami::Manager::instance().getJamiPluginManager().installPlugin(jplPath, force);
125 : #endif
126 : return -1;
127 : }
128 :
129 : int
130 0 : uninstallPlugin(const std::string& pluginRootPath)
131 : {
132 : #ifdef ENABLE_PLUGIN
133 0 : int status = jami::Manager::instance().getJamiPluginManager().uninstallPlugin(pluginRootPath);
134 0 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(pluginRootPath, false);
135 0 : jami::Manager::instance().saveConfig();
136 0 : return status;
137 : #endif
138 : return -1;
139 : }
140 :
141 : std::map<std::string, std::string>
142 0 : getPlatformInfo()
143 : {
144 : #ifdef ENABLE_PLUGIN
145 0 : return jami::Manager::instance().getJamiPluginManager().getPlatformInfo();
146 : #endif
147 : return {};
148 : }
149 :
150 : std::vector<std::string>
151 0 : getCallMediaHandlers()
152 : {
153 : #ifdef ENABLE_PLUGIN
154 0 : return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlers();
155 : #endif
156 : return {};
157 : }
158 :
159 : std::vector<std::string>
160 0 : getChatHandlers()
161 : {
162 : #ifdef ENABLE_PLUGIN
163 0 : return jami::Manager::instance().getJamiPluginManager().getChatServicesManager().getChatHandlers();
164 : #endif
165 : return {};
166 : }
167 :
168 : void
169 0 : toggleCallMediaHandler(const std::string& mediaHandlerId, const std::string& callId, bool toggle)
170 : {
171 : #ifdef ENABLE_PLUGIN
172 0 : jami::Manager::instance().getJamiPluginManager().getCallServicesManager().toggleCallMediaHandler(mediaHandlerId,
173 : callId,
174 : toggle);
175 : #endif
176 0 : }
177 :
178 : void
179 0 : toggleChatHandler(const std::string& chatHandlerId, const std::string& accountId, const std::string& peerId, bool toggle)
180 : {
181 : #ifdef ENABLE_PLUGIN
182 0 : jami::Manager::instance().getJamiPluginManager().getChatServicesManager().toggleChatHandler(chatHandlerId,
183 : accountId,
184 : peerId,
185 : toggle);
186 : #endif
187 0 : }
188 :
189 : std::map<std::string, std::string>
190 0 : getCallMediaHandlerDetails(const std::string& mediaHandlerId)
191 : {
192 : #ifdef ENABLE_PLUGIN
193 0 : return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlerDetails(
194 0 : mediaHandlerId);
195 : #endif
196 : return {};
197 : }
198 :
199 : std::vector<std::string>
200 0 : getCallMediaHandlerStatus(const std::string& callId)
201 : {
202 : #ifdef ENABLE_PLUGIN
203 0 : return jami::Manager::instance().getJamiPluginManager().getCallServicesManager().getCallMediaHandlerStatus(callId);
204 : #endif
205 : return {};
206 : }
207 :
208 : std::map<std::string, std::string>
209 0 : getChatHandlerDetails(const std::string& chatHandlerId)
210 : {
211 : #ifdef ENABLE_PLUGIN
212 0 : return jami::Manager::instance().getJamiPluginManager().getChatServicesManager().getChatHandlerDetails(
213 0 : chatHandlerId);
214 : #endif
215 : return {};
216 : }
217 :
218 : std::vector<std::string>
219 0 : getChatHandlerStatus(const std::string& accountId, const std::string& peerId)
220 : {
221 : #ifdef ENABLE_PLUGIN
222 0 : return jami::Manager::instance().getJamiPluginManager().getChatServicesManager().getChatHandlerStatus(accountId,
223 0 : peerId);
224 : #endif
225 : return {};
226 : }
227 :
228 : bool
229 0 : getPluginsEnabled()
230 : {
231 : #ifdef ENABLE_PLUGIN
232 0 : return jami::Manager::instance().pluginPreferences.getPluginsEnabled();
233 : #endif
234 : return false;
235 : }
236 :
237 : void
238 0 : setPluginsEnabled(bool state)
239 : {
240 : #ifdef ENABLE_PLUGIN
241 0 : jami::Manager::instance().pluginPreferences.setPluginsEnabled(state);
242 0 : for (auto& item : jami::Manager::instance().pluginPreferences.getLoadedPlugins()) {
243 0 : if (state)
244 0 : jami::Manager::instance().getJamiPluginManager().loadPlugin(item);
245 : else
246 0 : jami::Manager::instance().getJamiPluginManager().unloadPlugin(item);
247 0 : }
248 0 : jami::Manager::instance().saveConfig();
249 : #endif
250 0 : }
251 :
252 : void
253 0 : sendWebViewMessage(const std::string& pluginId,
254 : const std::string& webViewId,
255 : const std::string& messageId,
256 : const std::string& payload)
257 : {
258 : #ifdef ENABLE_PLUGIN
259 0 : jami::Manager::instance().getJamiPluginManager().getWebViewServicesManager().sendWebViewMessage(pluginId,
260 : webViewId,
261 : messageId,
262 : payload);
263 : #endif
264 0 : }
265 :
266 : std::string
267 0 : sendWebViewAttach(const std::string& pluginId,
268 : const std::string& accountId,
269 : const std::string& webViewId,
270 : const std::string& action)
271 : {
272 : #ifdef ENABLE_PLUGIN
273 0 : return jami::Manager::instance().getJamiPluginManager().getWebViewServicesManager().sendWebViewAttach(pluginId,
274 : accountId,
275 : webViewId,
276 0 : action);
277 : #endif
278 : }
279 :
280 : void
281 0 : sendWebViewDetach(const std::string& pluginId, const std::string& webViewId)
282 : {
283 : #ifdef ENABLE_PLUGIN
284 0 : jami::Manager::instance().getJamiPluginManager().getWebViewServicesManager().sendWebViewDetach(pluginId, webViewId);
285 : #endif
286 0 : }
287 : } // namespace libjami
|