plugin_manager_interface.cpp 8.14 KB
Newer Older
1
/*
2
 *  Copyright (C) 2020-2022 Savoir-faire Linux Inc.
3
4
 *
 *  Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */

#include "plugin_manager_interface.h"
22

23
24
25
26
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H

27
#ifdef ENABLE_PLUGIN
28
29
#include "manager.h"
#include "plugin/jamipluginmanager.h"
30
#endif
31

Olivier Dion's avatar
Olivier Dion committed
32
namespace libjami {
Sébastien Blin's avatar
Sébastien Blin committed
33
34
35
bool
loadPlugin(const std::string& path)
{
36
#ifdef ENABLE_PLUGIN
37
38
39
40
41
    bool status = jami::Manager::instance().getJamiPluginManager().loadPlugin(path);

    jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, status);
    jami::Manager::instance().saveConfig();
    return status;
42
43
#endif
    return false;
44
}
Sébastien Blin's avatar
Sébastien Blin committed
45
46
47
48

bool
unloadPlugin(const std::string& path)
{
49
#ifdef ENABLE_PLUGIN
50
51
52
53
54
    bool status = jami::Manager::instance().getJamiPluginManager().unloadPlugin(path);

    jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(path, false);
    jami::Manager::instance().saveConfig();
    return status;
55
56
#endif
    return false;
Sébastien Blin's avatar
Sébastien Blin committed
57
58
59
60
61
}

std::map<std::string, std::string>
getPluginDetails(const std::string& path)
{
62
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
63
    return jami::Manager::instance().getJamiPluginManager().getPluginDetails(path);
64
65
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
66
67
68
}

std::vector<std::map<std::string, std::string>>
69
getPluginPreferences(const std::string& path, const std::string& accountId)
Sébastien Blin's avatar
Sébastien Blin committed
70
{
71
#ifdef ENABLE_PLUGIN
72
    return jami::Manager::instance().getJamiPluginManager().getPluginPreferences(path, accountId);
73
74
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
75
76
77
}

bool
78
79
80
81
setPluginPreference(const std::string& path,
                    const std::string& accountId,
                    const std::string& key,
                    const std::string& value)
Sébastien Blin's avatar
Sébastien Blin committed
82
{
83
#ifdef ENABLE_PLUGIN
84
85
86
87
    return jami::Manager::instance().getJamiPluginManager().setPluginPreference(path,
                                                                                accountId,
                                                                                key,
                                                                                value);
88
89
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
90
91
92
}

std::map<std::string, std::string>
93
getPluginPreferencesValues(const std::string& path, const std::string& accountId)
Sébastien Blin's avatar
Sébastien Blin committed
94
{
95
#ifdef ENABLE_PLUGIN
96
97
    return jami::Manager::instance().getJamiPluginManager().getPluginPreferencesValuesMap(path,
                                                                                          accountId);
98
99
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
100
101
}
bool
102
resetPluginPreferencesValues(const std::string& path, const std::string& accountId)
Sébastien Blin's avatar
Sébastien Blin committed
103
{
104
#ifdef ENABLE_PLUGIN
105
106
107
    return jami::Manager::instance()
        .getJamiPluginManager()
        .resetPluginPreferencesValuesMap(path, accountId);
108
#endif
Sébastien Blin's avatar
Sébastien Blin committed
109
110
111
}

std::vector<std::string>
112
getInstalledPlugins()
Sébastien Blin's avatar
Sébastien Blin committed
113
{
114
#ifdef ENABLE_PLUGIN
115
    return jami::Manager::instance().getJamiPluginManager().getInstalledPlugins();
116
117
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
118
119
120
}

std::vector<std::string>
121
getLoadedPlugins()
Sébastien Blin's avatar
Sébastien Blin committed
122
{
123
#ifdef ENABLE_PLUGIN
124
    return jami::Manager::instance().pluginPreferences.getLoadedPlugins();
125
126
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
127
128
129
130
131
}

int
installPlugin(const std::string& jplPath, bool force)
{
132
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
133
    return jami::Manager::instance().getJamiPluginManager().installPlugin(jplPath, force);
134
135
#endif
    return -1;
Sébastien Blin's avatar
Sébastien Blin committed
136
137
138
139
140
}

int
uninstallPlugin(const std::string& pluginRootPath)
{
141
#ifdef ENABLE_PLUGIN
142
143
144
145
    int status = jami::Manager::instance().getJamiPluginManager().uninstallPlugin(pluginRootPath);
    jami::Manager::instance().pluginPreferences.saveStateLoadedPlugins(pluginRootPath, false);
    jami::Manager::instance().saveConfig();
    return status;
146
147
#endif
    return -1;
Sébastien Blin's avatar
Sébastien Blin committed
148
149
150
}

std::vector<std::string>
151
getCallMediaHandlers()
Sébastien Blin's avatar
Sébastien Blin committed
152
{
153
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
154
155
156
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getCallServicesManager()
157
        .getCallMediaHandlers();
158
159
#endif
    return {};
160
161
162
163
164
}

std::vector<std::string>
getChatHandlers()
{
165
#ifdef ENABLE_PLUGIN
166
167
168
169
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getChatServicesManager()
        .getChatHandlers();
170
171
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
172
173
174
}

void
175
toggleCallMediaHandler(const std::string& mediaHandlerId, const std::string& callId, bool toggle)
Sébastien Blin's avatar
Sébastien Blin committed
176
{
177
178
#ifdef ENABLE_PLUGIN
    jami::Manager::instance()
Sébastien Blin's avatar
Sébastien Blin committed
179
180
        .getJamiPluginManager()
        .getCallServicesManager()
181
        .toggleCallMediaHandler(mediaHandlerId, callId, toggle);
182
#endif
Sébastien Blin's avatar
Sébastien Blin committed
183
184
}

185
186
187
188
189
190
void
toggleChatHandler(const std::string& chatHandlerId,
                  const std::string& accountId,
                  const std::string& peerId,
                  bool toggle)
{
191
192
#ifdef ENABLE_PLUGIN
    jami::Manager::instance()
193
194
195
        .getJamiPluginManager()
        .getChatServicesManager()
        .toggleChatHandler(chatHandlerId, accountId, peerId, toggle);
196
#endif
197
198
}

Sébastien Blin's avatar
Sébastien Blin committed
199
std::map<std::string, std::string>
200
getCallMediaHandlerDetails(const std::string& mediaHandlerId)
Sébastien Blin's avatar
Sébastien Blin committed
201
{
202
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
203
204
205
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getCallServicesManager()
206
        .getCallMediaHandlerDetails(mediaHandlerId);
207
208
#endif
    return {};
Sébastien Blin's avatar
Sébastien Blin committed
209
210
}

211
212
213
std::vector<std::string>
getCallMediaHandlerStatus(const std::string& callId)
{
214
#ifdef ENABLE_PLUGIN
215
216
217
218
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getCallServicesManager()
        .getCallMediaHandlerStatus(callId);
219
220
#endif
    return {};
221
222
223
224
225
}

std::map<std::string, std::string>
getChatHandlerDetails(const std::string& chatHandlerId)
{
226
#ifdef ENABLE_PLUGIN
227
228
229
230
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getChatServicesManager()
        .getChatHandlerDetails(chatHandlerId);
231
232
#endif
    return {};
233
234
235
236
237
}

std::vector<std::string>
getChatHandlerStatus(const std::string& accountId, const std::string& peerId)
{
238
#ifdef ENABLE_PLUGIN
239
240
241
242
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getChatServicesManager()
        .getChatHandlerStatus(accountId, peerId);
243
244
#endif
    return {};
245
246
}

Sébastien Blin's avatar
Sébastien Blin committed
247
248
249
bool
getPluginsEnabled()
{
250
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
251
    return jami::Manager::instance().pluginPreferences.getPluginsEnabled();
252
253
#endif
    return false;
Sébastien Blin's avatar
Sébastien Blin committed
254
255
256
257
258
}

void
setPluginsEnabled(bool state)
{
259
#ifdef ENABLE_PLUGIN
Sébastien Blin's avatar
Sébastien Blin committed
260
    jami::Manager::instance().pluginPreferences.setPluginsEnabled(state);
261
262
263
264
265
266
    for (auto& item : jami::Manager::instance().pluginPreferences.getLoadedPlugins()) {
        if (state)
            jami::Manager::instance().getJamiPluginManager().loadPlugin(item);
        else
            jami::Manager::instance().getJamiPluginManager().unloadPlugin(item);
    }
Sébastien Blin's avatar
Sébastien Blin committed
267
    jami::Manager::instance().saveConfig();
268
#endif
Sébastien Blin's avatar
Sébastien Blin committed
269
}
270
271
272
273
274
275
276

void
sendWebViewMessage(const std::string& pluginId,
                   const std::string& webViewId,
                   const std::string& messageId,
                   const std::string& payload)
{
277
#ifdef ENABLE_PLUGIN
278
279
280
281
    jami::Manager::instance()
        .getJamiPluginManager()
        .getWebViewServicesManager()
        .sendWebViewMessage(pluginId, webViewId, messageId, payload);
282
#endif
283
284
285
286
287
288
289
290
}

std::string
sendWebViewAttach(const std::string& pluginId,
                  const std::string& accountId,
                  const std::string& webViewId,
                  const std::string& action)
{
291
#ifdef ENABLE_PLUGIN
292
293
294
295
    return jami::Manager::instance()
        .getJamiPluginManager()
        .getWebViewServicesManager()
        .sendWebViewAttach(pluginId, accountId, webViewId, action);
296
#endif
297
298
299
300
301
}

void
sendWebViewDetach(const std::string& pluginId, const std::string& webViewId)
{
302
#ifdef ENABLE_PLUGIN
303
304
305
306
    jami::Manager::instance()
        .getJamiPluginManager()
        .getWebViewServicesManager()
        .sendWebViewDetach(pluginId, webViewId);
307
#endif
308
}
Olivier Dion's avatar
Olivier Dion committed
309
} // namespace libjami