1 /* Simple Plugin API
2 *
3 * Copyright © 2021 Wim Taymans
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #ifndef SPA_PLUGIN_LOADER_H
26 #define SPA_PLUGIN_LOADER_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include <spa/utils/hook.h>
33 #include <spa/utils/dict.h>
34
35 /** \defgroup spa_plugin_loader Plugin Loader
36 * SPA plugin loader
37 */
38
39 /**
40 * \addtogroup spa_plugin_loader
41 * \{
42 */
43
44 #define SPA_TYPE_INTERFACE_PluginLoader SPA_TYPE_INFO_INTERFACE_BASE "PluginLoader"
45
46 #define SPA_VERSION_PLUGIN_LOADER 0
47 struct spa_plugin_loader { struct spa_interface iface; };
48
49 struct spa_plugin_loader_methods {
50 #define SPA_VERSION_PLUGIN_LOADER_METHODS 0
51 uint32_t version;
52
53 /**
54 * Load a SPA plugin.
55 *
56 * \param factory_name Plugin factory name
57 * \param info Info dictionary for plugin. NULL if none.
58 * \return plugin handle, or NULL on error
59 */
60 struct spa_handle *(*load) (void *object, const char *factory_name, const struct spa_dict *info);
61
62 /**
63 * Unload a SPA plugin.
64 *
65 * \param handle Plugin handle.
66 * \return 0 on success, < 0 on error
67 */
68 int (*unload)(void *object, struct spa_handle *handle);
69 };
70
71 static inline struct spa_handle *
spa_plugin_loader_load(struct spa_plugin_loader * loader,const char * factory_name,const struct spa_dict * info)72 spa_plugin_loader_load(struct spa_plugin_loader *loader, const char *factory_name, const struct spa_dict *info)
73 {
74 struct spa_handle *res = NULL;
75 if (SPA_LIKELY(loader != NULL))
76 spa_interface_call_res(&loader->iface,
77 struct spa_plugin_loader_methods, res,
78 load, 0, factory_name, info);
79 return res;
80 }
81
82 static inline int
spa_plugin_loader_unload(struct spa_plugin_loader * loader,struct spa_handle * handle)83 spa_plugin_loader_unload(struct spa_plugin_loader *loader, struct spa_handle *handle)
84 {
85 int res = -1;
86 if (SPA_LIKELY(loader != NULL))
87 spa_interface_call_res(&loader->iface,
88 struct spa_plugin_loader_methods, res,
89 unload, 0, handle);
90 return res;
91 }
92
93 /**
94 * \}
95 */
96
97 #ifdef __cplusplus
98 } /* extern "C" */
99 #endif
100
101 #endif /* SPA_PLUGIN_LOADER_H */
102