Code

Rename variable sun as it is predefined (to 1) on solaris
[ncmpc.git] / src / plugin.h
1 /*
2  * (c) 2004-2008 The Music Player Daemon Project
3  * http://www.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.
9  *
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.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
19 #ifndef PLUGIN_H
20 #define PLUGIN_H
22 #include <glib.h>
23 #include <stdbool.h>
25 /**
26  * A list of registered plugins.
27  */
28 struct plugin_list {
29         GPtrArray *plugins;
30 };
32 /**
33  * When a plugin cycle is finished, this function is called.  In any
34  * case, plugin_stop() has to be called to free all memory.
35  *
36  * @param result the plugin's output (stdout) on success; NULL on failure
37  * @param data the caller defined pointer passed to plugin_run()
38  */
39 typedef void (*plugin_callback_t)(const GString *result, void *data);
41 /**
42  * This object represents a cycle through all available plugins, until
43  * a plugin returns a positive result.
44  */
45 struct plugin_cycle;
47 /**
48  * Initialize an empty plugin_list structure.
49  */
50 static inline void
51 plugin_list_init(struct plugin_list *list)
52 {
53         list->plugins = g_ptr_array_new();
54 }
56 /**
57  * Load all plugins (executables) in a directory.
58  */
59 bool
60 plugin_list_load_directory(struct plugin_list *list, const char *path);
62 /**
63  * Frees all memory held by the plugin_list object (but not the
64  * pointer itself).
65  */
66 void plugin_list_deinit(struct plugin_list *list);
68 /**
69  * Run plugins in this list, until one returns success (or until the
70  * plugin list is exhausted).
71  *
72  * @param list the plugin list
73  * @param args NULL terminated command line arguments passed to the
74  * plugin programs
75  * @param callback the callback function which will be called when a
76  * result is available
77  * @param callback_data caller defined pointer which is passed to the
78  * callback function
79  */
80 struct plugin_cycle *
81 plugin_run(struct plugin_list *list, const char *const*args,
82            plugin_callback_t callback, void *callback_data);
84 /**
85  * Stops the plugin cycle and frees resources.  This can be called to
86  * abort the current cycle, or after the plugin_callback_t has been
87  * invoked.
88  */
89 void
90 plugin_stop(struct plugin_cycle *invocation);
92 #endif