1 /* plugin.c -- 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
22 /* Allocate a new plugin struct. */
23 struct plugin
*new_plugin(const char *name
, struct plugin_type
*type
)
25 struct plugin
*p
= malloc(sizeof *p
);
30 p
->name
= strdup(name
);
32 if (p
->name
== NULL
) {
38 p
->save_disabled
= false;
40 for (size_t i
= 0; i
< nr_dependencies
; i
++)
41 p
->dependencies
[i
] = list_new();
45 if (p
->type
->init(p
)) {
53 /* Destroy the given plugin. */
54 void destroy_plugin(struct plugin
*p
)
56 /* Call destroy method. */
59 /* Destroy dependency lists. */
60 for (size_t i
= 0; i
< nr_dependencies
; i
++) {
61 list_delete_for_each(p
->dependencies
[i
], dependency_item
)
62 free(dependency_item
->data
);
64 list_free(p
->dependencies
[i
]);
71 bool call_hook(struct plugin
*p
, const char *hook_name
)
73 return p
->type
->call_hook(p
, hook_name
);