Line data Source code
1 : /*
2 : * Copyright (C) 2020-2024 Savoir-faire Linux Inc.
3 : *
4 : * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5 : *
6 : * This program is free software; you can redistribute it and/or modify
7 : * it under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation; either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * This program is distributed in the hope that it will be useful,
12 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : * GNU General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License
17 : * along with this program; if not, write to the Free Software
18 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 : */
20 :
21 : #include "plugin_manager_interface.h"
22 :
23 : #ifdef HAVE_CONFIG_H
24 : #include "config.h"
25 : #endif // HAVE_CONFIG_H
26 :
27 : #ifdef ENABLE_PLUGIN
28 : #include "manager.h"
29 : #include "plugin/jamipluginmanager.h"
30 : #endif
31 :
32 : namespace libjami {
33 : bool
34 7 : loadPlugin(const std::string& path)
35 : {
36 : #ifdef ENABLE_PLUGIN
37 7 : bool status = jami::Manager::instance().getJamiPluginManager().loadPlugin(path);
38 :
39 7 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, status);
40 7 : jami::Manager::instance().saveConfig();
41 7 : return status;
42 : #endif
43 : return false;
44 : }
45 :
46 : bool
47 5 : unloadPlugin(const std::string& path)
48 : {
49 : #ifdef ENABLE_PLUGIN
50 5 : bool status = jami::Manager::instance().getJamiPluginManager().unloadPlugin(path);
51 :
52 5 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, false);
53 5 : jami::Manager::instance().saveConfig();
54 5 : return status;
55 : #endif
56 : return false;
57 : }
58 :
59 : std::map<std::string, std::string>
60 0 : getPluginDetails(const std::string& path)
61 : {
62 : #ifdef ENABLE_PLUGIN
63 0 : return jami::Manager::instance().getJamiPluginManager().getPluginDetails(path);
64 : #endif
65 : return {};
66 : }
67 :
68 : std::vector<std::map<std::string, std::string>>
69 0 : getPluginPreferences(const std::string& path, const std::string& accountId)
70 : {
71 : #ifdef ENABLE_PLUGIN
72 0 : return jami::Manager::instance().getJamiPluginManager().getPluginPreferences(path, accountId);
73 : #endif
74 : return {};
75 : }
76 :
77 : bool
78 0 : setPluginPreference(const std::string& path,
79 : const std::string& accountId,
80 : const std::string& key,
81 : const std::string& value)
82 : {
83 : #ifdef ENABLE_PLUGIN
84 0 : return jami::Manager::instance().getJamiPluginManager().setPluginPreference(path,
85 : accountId,
86 : key,
87 0 : value);
88 : #endif
89 : return {};
90 : }
91 :
92 : std::map<std::string, std::string>
93 0 : getPluginPreferencesValues(const std::string& path, const std::string& accountId)
94 : {
95 : #ifdef ENABLE_PLUGIN
96 0 : return jami::Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(path,
97 0 : accountId);
98 : #endif
99 : return {};
100 : }
101 : bool
102 0 : resetPluginPreferencesValues(const std::string& path, const std::string& accountId)
103 : {
104 : #ifdef ENABLE_PLUGIN
105 0 : return jami::Manager::instance()
106 0 : .getJamiPluginManager()
107 0 : .resetPluginPreferencesValuesMap(path, accountId);
108 : #endif
109 : }
110 :
111 : std::vector<std::string>
112 0 : getInstalledPlugins()
113 : {
114 : #ifdef ENABLE_PLUGIN
115 0 : return jami::Manager::instance().getJamiPluginManager().getInstalledPlugins();
116 : #endif
117 : return {};
118 : }
119 :
120 : std::vector<std::string>
121 0 : getLoadedPlugins()
122 : {
123 : #ifdef ENABLE_PLUGIN
124 0 : return jami::Manager::instance().pluginPreferences.getLoadedPlugins();
125 : #endif
126 : return {};
127 : }
128 :
129 : int
130 0 : installPlugin(const std::string& jplPath, bool force)
131 : {
132 : #ifdef ENABLE_PLUGIN
133 0 : return jami::Manager::instance().getJamiPluginManager().installPlugin(jplPath, force);
134 : #endif
135 : return -1;
136 : }
137 :
138 : int
139 0 : uninstallPlugin(const std::string& pluginRootPath)
140 : {
141 : #ifdef ENABLE_PLUGIN
142 0 : int status = jami::Manager::instance().getJamiPluginManager().uninstallPlugin(pluginRootPath);
143 0 : jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(pluginRootPath, false);
144 0 : jami::Manager::instance().saveConfig();
145 0 : return status;
146 : #endif
147 : return -1;
148 : }
149 :
150 : std::map<std::string, std::string>
151 0 : getPlatformInfo() {
152 : #ifdef ENABLE_PLUGIN
153 0 : return jami::Manager::instance().getJamiPluginManager().getPlatformInfo();
154 : #endif
155 : return {};
156 : }
157 :
158 : std::vector<std::string>
159 0 : getCallMediaHandlers()
160 : {
161 : #ifdef ENABLE_PLUGIN
162 0 : return jami::Manager::instance()
163 0 : .getJamiPluginManager()
164 0 : .getCallServicesManager()
165 0 : .getCallMediaHandlers();
166 : #endif
167 : return {};
168 : }
169 :
170 : std::vector<std::string>
171 0 : getChatHandlers()
172 : {
173 : #ifdef ENABLE_PLUGIN
174 0 : return jami::Manager::instance()
175 0 : .getJamiPluginManager()
176 0 : .getChatServicesManager()
177 0 : .getChatHandlers();
178 : #endif
179 : return {};
180 : }
181 :
182 : void
183 0 : toggleCallMediaHandler(const std::string& mediaHandlerId, const std::string& callId, bool toggle)
184 : {
185 : #ifdef ENABLE_PLUGIN
186 0 : jami::Manager::instance()
187 0 : .getJamiPluginManager()
188 0 : .getCallServicesManager()
189 0 : .toggleCallMediaHandler(mediaHandlerId, callId, toggle);
190 : #endif
191 0 : }
192 :
193 : void
194 0 : toggleChatHandler(const std::string& chatHandlerId,
195 : const std::string& accountId,
196 : const std::string& peerId,
197 : bool toggle)
198 : {
199 : #ifdef ENABLE_PLUGIN
200 0 : jami::Manager::instance()
201 0 : .getJamiPluginManager()
202 0 : .getChatServicesManager()
203 0 : .toggleChatHandler(chatHandlerId, accountId, peerId, toggle);
204 : #endif
205 0 : }
206 :
207 : std::map<std::string, std::string>
208 0 : getCallMediaHandlerDetails(const std::string& mediaHandlerId)
209 : {
210 : #ifdef ENABLE_PLUGIN
211 0 : return jami::Manager::instance()
212 0 : .getJamiPluginManager()
213 0 : .getCallServicesManager()
214 0 : .getCallMediaHandlerDetails(mediaHandlerId);
215 : #endif
216 : return {};
217 : }
218 :
219 : std::vector<std::string>
220 0 : getCallMediaHandlerStatus(const std::string& callId)
221 : {
222 : #ifdef ENABLE_PLUGIN
223 0 : return jami::Manager::instance()
224 0 : .getJamiPluginManager()
225 0 : .getCallServicesManager()
226 0 : .getCallMediaHandlerStatus(callId);
227 : #endif
228 : return {};
229 : }
230 :
231 : std::map<std::string, std::string>
232 0 : getChatHandlerDetails(const std::string& chatHandlerId)
233 : {
234 : #ifdef ENABLE_PLUGIN
235 0 : return jami::Manager::instance()
236 0 : .getJamiPluginManager()
237 0 : .getChatServicesManager()
238 0 : .getChatHandlerDetails(chatHandlerId);
239 : #endif
240 : return {};
241 : }
242 :
243 : std::vector<std::string>
244 0 : getChatHandlerStatus(const std::string& accountId, const std::string& peerId)
245 : {
246 : #ifdef ENABLE_PLUGIN
247 0 : return jami::Manager::instance()
248 0 : .getJamiPluginManager()
249 0 : .getChatServicesManager()
250 0 : .getChatHandlerStatus(accountId, peerId);
251 : #endif
252 : return {};
253 : }
254 :
255 : bool
256 7 : getPluginsEnabled()
257 : {
258 : #ifdef ENABLE_PLUGIN
259 7 : return jami::Manager::instance().pluginPreferences.getPluginsEnabled();
260 : #endif
261 : return false;
262 : }
263 :
264 : void
265 0 : setPluginsEnabled(bool state)
266 : {
267 : #ifdef ENABLE_PLUGIN
268 0 : jami::Manager::instance().pluginPreferences.setPluginsEnabled(state);
269 0 : for (auto& item : jami::Manager::instance().pluginPreferences.getLoadedPlugins()) {
270 0 : if (state)
271 0 : jami::Manager::instance().getJamiPluginManager().loadPlugin(item);
272 : else
273 0 : jami::Manager::instance().getJamiPluginManager().unloadPlugin(item);
274 0 : }
275 0 : jami::Manager::instance().saveConfig();
276 : #endif
277 0 : }
278 :
279 : void
280 0 : sendWebViewMessage(const std::string& pluginId,
281 : const std::string& webViewId,
282 : const std::string& messageId,
283 : const std::string& payload)
284 : {
285 : #ifdef ENABLE_PLUGIN
286 0 : jami::Manager::instance()
287 0 : .getJamiPluginManager()
288 0 : .getWebViewServicesManager()
289 0 : .sendWebViewMessage(pluginId, webViewId, messageId, payload);
290 : #endif
291 0 : }
292 :
293 : std::string
294 0 : sendWebViewAttach(const std::string& pluginId,
295 : const std::string& accountId,
296 : const std::string& webViewId,
297 : const std::string& action)
298 : {
299 : #ifdef ENABLE_PLUGIN
300 0 : return jami::Manager::instance()
301 0 : .getJamiPluginManager()
302 0 : .getWebViewServicesManager()
303 0 : .sendWebViewAttach(pluginId, accountId, webViewId, action);
304 : #endif
305 : }
306 :
307 : void
308 0 : sendWebViewDetach(const std::string& pluginId, const std::string& webViewId)
309 : {
310 : #ifdef ENABLE_PLUGIN
311 0 : jami::Manager::instance()
312 0 : .getJamiPluginManager()
313 0 : .getWebViewServicesManager()
314 0 : .sendWebViewDetach(pluginId, webViewId);
315 : #endif
316 0 : }
317 : } // namespace libjami
|