1 /* GSequencer - Advanced GTK Sequencer
2 * Copyright (C) 2005-2015 Joël Krähemann
3 *
4 * This file is part of GSequencer.
5 *
6 * GSequencer 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 * GSequencer 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 GSequencer. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <ags/object/ags_plugin.h>
21
22 #include <math.h>
23
24 void ags_plugin_base_init(AgsPluginInterface *ginterface);
25
26 /**
27 * SECTION:ags_plugin
28 * @short_description: interfacing plugins
29 * @title: AgsPlugin
30 * @section_id: AgsPlugin
31 * @include: ags/object/ags_plugin.h
32 *
33 * The #AgsPlugin interface gives you a unique access to classes. It
34 * can be used by #AgsFile and solves some of the serialization.
35 */
36
37 GType
ags_plugin_get_type()38 ags_plugin_get_type()
39 {
40 static volatile gsize g_define_type_id__volatile = 0;
41
42 if(g_once_init_enter (&g_define_type_id__volatile)){
43 GType ags_type_plugin = 0;
44
45 static const GTypeInfo ags_plugin_info = {
46 sizeof(AgsPluginInterface),
47 (GBaseInitFunc) ags_plugin_base_init,
48 NULL, /* base_finalize */
49 };
50
51 ags_type_plugin = g_type_register_static(G_TYPE_INTERFACE,
52 "AgsPlugin", &ags_plugin_info,
53 0);
54
55 g_once_init_leave(&g_define_type_id__volatile, ags_type_plugin);
56 }
57
58 return g_define_type_id__volatile;
59 }
60
61 void
ags_plugin_base_init(AgsPluginInterface * ginterface)62 ags_plugin_base_init(AgsPluginInterface *ginterface)
63 {
64 /* empty */
65 }
66
67 /**
68 * ags_plugin_get_name:
69 * @plugin: an @AgsPlugin
70 *
71 * Retrieve the name of the plugin.
72 *
73 * Returns: the plugins name
74 *
75 * Since: 3.0.0
76 */
77 gchar*
ags_plugin_get_name(AgsPlugin * plugin)78 ags_plugin_get_name(AgsPlugin *plugin)
79 {
80 AgsPluginInterface *plugin_interface;
81 gchar *ret_val;
82
83 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
84 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
85 g_return_val_if_fail(plugin_interface->get_name, NULL);
86 ret_val = plugin_interface->get_name(plugin);
87
88 return(ret_val);
89 }
90
91 /**
92 * ags_plugin_set_name:
93 * @plugin: an @AgsPlugin
94 * @name: the name of plugin
95 *
96 * Set the name of the plugin.
97 *
98 * Since: 3.0.0
99 */
100 void
ags_plugin_set_name(AgsPlugin * plugin,gchar * name)101 ags_plugin_set_name(AgsPlugin *plugin, gchar *name)
102 {
103 AgsPluginInterface *plugin_interface;
104
105 g_return_if_fail(AGS_IS_PLUGIN(plugin));
106 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
107 g_return_if_fail(plugin_interface->set_name);
108 plugin_interface->set_name(plugin, name);
109 }
110
111 /**
112 * ags_plugin_get_version:
113 * @plugin: an @AgsPlugin
114 *
115 * Retrieve the version of the plugin.
116 *
117 * Returns: the plugins version
118 *
119 * Since: 3.0.0
120 */
121 gchar*
ags_plugin_get_version(AgsPlugin * plugin)122 ags_plugin_get_version(AgsPlugin *plugin)
123 {
124 AgsPluginInterface *plugin_interface;
125 gchar *ret_val;
126
127 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
128 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
129 g_return_val_if_fail(plugin_interface->get_version, NULL);
130 ret_val = plugin_interface->get_version(plugin);
131
132 return(ret_val);
133 }
134
135 /**
136 * ags_plugin_set_version:
137 * @plugin: an @AgsPlugin
138 * @version: the version of plugin
139 *
140 * Set the version of the plugin.
141 *
142 * Since: 3.0.0
143 */
144 void
ags_plugin_set_version(AgsPlugin * plugin,gchar * version)145 ags_plugin_set_version(AgsPlugin *plugin, gchar *version)
146 {
147 AgsPluginInterface *plugin_interface;
148
149 g_return_if_fail(AGS_IS_PLUGIN(plugin));
150 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
151 g_return_if_fail(plugin_interface->set_version);
152 plugin_interface->set_version(plugin, version);
153 }
154
155 /**
156 * ags_plugin_get_build_id:
157 * @plugin: an @AgsPlugin
158 *
159 * Retrieve the build id of the plugin.
160 *
161 * Returns: the plugins build id
162 *
163 * Since: 3.0.0
164 */
165 gchar*
ags_plugin_get_build_id(AgsPlugin * plugin)166 ags_plugin_get_build_id(AgsPlugin *plugin)
167 {
168 AgsPluginInterface *plugin_interface;
169 gchar *ret_val;
170
171 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
172 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
173 g_return_val_if_fail(plugin_interface->get_build_id, NULL);
174 ret_val = plugin_interface->get_build_id(plugin);
175
176 return(ret_val);
177 }
178
179 /**
180 * ags_plugin_set_build_id:
181 * @plugin: an @AgsPlugin
182 * @build_id: the build id of plugin
183 *
184 * Set the build id of the plugin.
185 *
186 * Since: 3.0.0
187 */
188 void
ags_plugin_set_build_id(AgsPlugin * plugin,gchar * build_id)189 ags_plugin_set_build_id(AgsPlugin *plugin, gchar *build_id)
190 {
191 AgsPluginInterface *plugin_interface;
192
193 g_return_if_fail(AGS_IS_PLUGIN(plugin));
194 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
195 g_return_if_fail(plugin_interface->set_build_id);
196 plugin_interface->set_build_id(plugin, build_id);
197 }
198
199 /**
200 * ags_plugin_get_xml_type:
201 * @plugin: an @AgsPlugin
202 *
203 * Retrieve the xml type of the plugin.
204 *
205 * Returns: the plugins xml type
206 *
207 * Since: 3.0.0
208 */
209 gchar*
ags_plugin_get_xml_type(AgsPlugin * plugin)210 ags_plugin_get_xml_type(AgsPlugin *plugin)
211 {
212 AgsPluginInterface *plugin_interface;
213 gchar *ret_val;
214
215 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
216 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
217 g_return_val_if_fail(plugin_interface->get_xml_type, NULL);
218 ret_val = plugin_interface->get_xml_type(plugin);
219
220 return(ret_val);
221 }
222
223 /**
224 * ags_plugin_set_xml_type:
225 * @plugin: an @AgsPlugin
226 * @xml_type: the build id of plugin
227 *
228 * Set the build id of the plugin.
229 *
230 * Since: 3.0.0
231 */
232 void
ags_plugin_set_xml_type(AgsPlugin * plugin,gchar * xml_type)233 ags_plugin_set_xml_type(AgsPlugin *plugin, gchar *xml_type)
234 {
235 AgsPluginInterface *plugin_interface;
236
237 g_return_if_fail(AGS_IS_PLUGIN(plugin));
238 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
239 g_return_if_fail(plugin_interface->set_xml_type);
240 plugin_interface->set_xml_type(plugin, xml_type);
241 }
242
243 /**
244 * ags_plugin_get_ports:
245 * @plugin: an @AgsPlugin
246 *
247 * Retrieve the ports of the plugin.
248 *
249 * Returns: (element-type GObject) (transfer full): the plugins ports
250 *
251 * Since: 3.0.0
252 */
253 GList*
ags_plugin_get_ports(AgsPlugin * plugin)254 ags_plugin_get_ports(AgsPlugin *plugin)
255 {
256 AgsPluginInterface *plugin_interface;
257 GList *ret_val;
258
259 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
260 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
261 g_return_val_if_fail(plugin_interface->get_ports, NULL);
262 ret_val = plugin_interface->get_ports(plugin);
263
264 return(ret_val);
265 }
266
267 /**
268 * ags_plugin_set_ports:
269 * @plugin: an @AgsPlugin
270 * @ports: (element-type GObject) (transfer none): the build id of plugin
271 *
272 * Set the build id of the plugin.
273 *
274 * Since: 3.0.0
275 */
276 void
ags_plugin_set_ports(AgsPlugin * plugin,GList * ports)277 ags_plugin_set_ports(AgsPlugin *plugin, GList *ports)
278 {
279 AgsPluginInterface *plugin_interface;
280
281 g_return_if_fail(AGS_IS_PLUGIN(plugin));
282 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
283 g_return_if_fail(plugin_interface->set_ports);
284 plugin_interface->set_ports(plugin, ports);
285 }
286
287 /**
288 * ags_plugin_read:
289 * @file: the #GObject
290 * @node: the node
291 * @plugin: the #AgsPlugin
292 *
293 * Read of file.
294 *
295 * Since: 3.0.0
296 */
297 void
ags_plugin_read(GObject * file,xmlNode * node,AgsPlugin * plugin)298 ags_plugin_read(GObject *file,
299 xmlNode *node,
300 AgsPlugin *plugin)
301 {
302 AgsPluginInterface *plugin_interface;
303
304 g_return_if_fail(AGS_IS_PLUGIN(plugin));
305 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
306 g_return_if_fail(plugin_interface->read);
307 plugin_interface->read(file, node, plugin);
308 }
309
310
311 /**
312 * ags_plugin_write:
313 * @file: the #GObject
314 * @parent: the parent node
315 * @plugin: the #AgsPlugin
316 *
317 * Write to file.
318 *
319 * Returns: (transfer none): the new node you created
320 *
321 * Since: 3.0.0
322 */
323 xmlNode*
ags_plugin_write(GObject * file,xmlNode * parent,AgsPlugin * plugin)324 ags_plugin_write(GObject *file,
325 xmlNode *parent,
326 AgsPlugin *plugin)
327 {
328 AgsPluginInterface *plugin_interface;
329 xmlNode *retval;
330
331 g_return_val_if_fail(AGS_IS_PLUGIN(plugin), NULL);
332 plugin_interface = AGS_PLUGIN_GET_INTERFACE(plugin);
333 g_return_val_if_fail(plugin_interface->write, NULL);
334 retval = plugin_interface->write(file, parent, plugin);
335
336 return(retval);
337 }
338