1 /* ncmpc (Ncurses MPD Client)
2 * (c) 2004-2017 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.
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 *
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; summary of all error
38 * messages on failure as determined by success
39 * @param success result of the plugin cycle; true if result is meaningful
40 * output, false if result contains error messages
41 * @param plugin_name the name of the plugin which succeeded; becomes invalid
42 * when plugin_stop is called (i.e. strdup it if you need it afterwards).
43 * @param data the caller defined pointer passed to plugin_run()
44 */
45 typedef void (*plugin_callback_t)(const GString *result, const bool success,
46 const char *plugin_name, void *data);
48 /**
49 * This object represents a cycle through all available plugins, until
50 * a plugin returns a positive result.
51 */
52 struct plugin_cycle;
54 /**
55 * Initialize an empty plugin_list structure.
56 */
57 static inline void
58 plugin_list_init(struct plugin_list *list)
59 {
60 list->plugins = g_ptr_array_new();
61 }
63 /**
64 * Load all plugins (executables) in a directory.
65 */
66 bool
67 plugin_list_load_directory(struct plugin_list *list, const char *path);
69 /**
70 * Frees all memory held by the plugin_list object (but not the
71 * pointer itself).
72 */
73 void plugin_list_deinit(struct plugin_list *list);
75 /**
76 * Run plugins in this list, until one returns success (or until the
77 * plugin list is exhausted).
78 *
79 * @param list the plugin list
80 * @param args NULL terminated command line arguments passed to the
81 * plugin programs
82 * @param callback the callback function which will be called when a
83 * result is available
84 * @param callback_data caller defined pointer which is passed to the
85 * callback function
86 */
87 struct plugin_cycle *
88 plugin_run(struct plugin_list *list, const char *const*args,
89 plugin_callback_t callback, void *callback_data);
91 /**
92 * Stops the plugin cycle and frees resources. This can be called to
93 * abort the current cycle, or after the plugin_callback_t has been
94 * invoked.
95 */
96 void
97 plugin_stop(struct plugin_cycle *invocation);
99 #endif