src/util.{c,h}: get rid of ensure_* functions
[vlock.git] / src / plugin.h
blobdac9661e78a0e5827575fba0f9ab38926bc38e8f
1 /* plugin.h -- header file for the generic plugin routines for vlock,
2 * the VT locking program for linux
4 * This program is copyright (C) 2007 Frank Benkstein, and is free
5 * software which is freely distributable under the terms of the
6 * GNU General Public License version 2, included as the file COPYING in this
7 * distribution. It is NOT public domain software, and any
8 * redistribution not permitted by the GNU General Public License is
9 * expressly forbidden without prior written permission from
10 * the author.
14 #include <stdbool.h>
16 /* Names of dependencies plugins may specify. */
17 #define nr_dependencies 6
18 extern const char *dependency_names[nr_dependencies];
20 /* A plugin hook consists of a name and a handler function. */
21 struct hook
23 const char *name;
24 void (*handler)(const char *);
27 /* Hooks that a plugin may define. */
28 #define nr_hooks 4
29 extern const struct hook hooks[nr_hooks];
31 struct plugin_type;
33 /* Struct representing a plugin instance. */
34 struct plugin
36 /* The name of the plugin. */
37 char *name;
39 /* Array of dependencies. Each dependency is a (possibly empty) list of
40 * strings. The dependencies must be stored in the same order as the
41 * dependency names above. The strings a freed when the plugin is destroyed
42 * thus must be stored as copies. */
43 struct list *dependencies[nr_dependencies];
45 /* Did one of the save hooks fail? */
46 bool save_disabled;
48 /* The type of the plugin. */
49 struct plugin_type *type;
51 /* The call_hook and close functions may use this pointer. */
52 void *context;
56 /* Struct representing the type of a plugin. */
57 struct plugin_type
59 /* Method that is called on plugin initialization. */
60 bool (*init)(struct plugin *p);
61 /* Method that is called on plugin destruction. */
62 void (*destroy)(struct plugin *p);
63 /* Method that is called when a hook should be executed. */
64 bool (*call_hook)(struct plugin *p, const char *name);
67 /* Modules. */
68 extern struct plugin_type *module;
69 /* Scripts. */
70 extern struct plugin_type *script;
72 /* Open a new plugin struct of the given type. On error errno is set and NULL
73 * is returned. */
74 struct plugin *new_plugin(const char *name, struct plugin_type *type);
76 /* Destroy the given plugin. This is the opposite of of __allocate_plugin.
77 * This function should not be called directly. */
78 void destroy_plugin(struct plugin *p);
80 /* Call the hook of a plugin. */
81 bool call_hook(struct plugin *p, const char *hook_name);