Code

ncmpc version 0.14
[ncmpc.git] / src / plugin.h
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2009 The Music Player Daemon Project
3  * Project homepage: http://musicpd.org
4  
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
20 #ifndef PLUGIN_H
21 #define PLUGIN_H
23 #include <glib.h>
24 #include <stdbool.h>
26 /**
27  * A list of registered plugins.
28  */
29 struct plugin_list {
30         GPtrArray *plugins;
31 };
33 /**
34  * When a plugin cycle is finished, this function is called.  In any
35  * case, plugin_stop() has to be called to free all memory.
36  *
37  * @param result the plugin's output (stdout) on success; NULL on failure
38  * @param data the caller defined pointer passed to plugin_run()
39  */
40 typedef void (*plugin_callback_t)(const GString *result, void *data);
42 /**
43  * This object represents a cycle through all available plugins, until
44  * a plugin returns a positive result.
45  */
46 struct plugin_cycle;
48 /**
49  * Initialize an empty plugin_list structure.
50  */
51 static inline void
52 plugin_list_init(struct plugin_list *list)
53 {
54         list->plugins = g_ptr_array_new();
55 }
57 /**
58  * Load all plugins (executables) in a directory.
59  */
60 bool
61 plugin_list_load_directory(struct plugin_list *list, const char *path);
63 /**
64  * Frees all memory held by the plugin_list object (but not the
65  * pointer itself).
66  */
67 void plugin_list_deinit(struct plugin_list *list);
69 /**
70  * Run plugins in this list, until one returns success (or until the
71  * plugin list is exhausted).
72  *
73  * @param list the plugin list
74  * @param args NULL terminated command line arguments passed to the
75  * plugin programs
76  * @param callback the callback function which will be called when a
77  * result is available
78  * @param callback_data caller defined pointer which is passed to the
79  * callback function
80  */
81 struct plugin_cycle *
82 plugin_run(struct plugin_list *list, const char *const*args,
83            plugin_callback_t callback, void *callback_data);
85 /**
86  * Stops the plugin cycle and frees resources.  This can be called to
87  * abort the current cycle, or after the plugin_callback_t has been
88  * invoked.
89  */
90 void
91 plugin_stop(struct plugin_cycle *invocation);
93 #endif