keyrouter: Fix wrong return value
[platform/core/uifw/libds-tizen.git] / src / libds / addon.c
1 #include <assert.h>
2
3 #include "addon.h"
4
5 void
6 ds_addon_set_init(struct ds_addon_set *set)
7 {
8     wl_list_init(&set->addons);
9 }
10
11 void
12 ds_addon_set_finish(struct ds_addon_set *set)
13 {
14     struct ds_addon *addon, *tmp;
15
16     wl_list_for_each_safe(addon, tmp, &set->addons, link) {
17         ds_addon_finish(addon);
18         addon->impl->destroy(addon);
19     }
20 }
21
22 void
23 ds_addon_init(struct ds_addon *addon, struct ds_addon_set *set,
24         const void *owner, const struct ds_addon_interface *impl)
25 {
26     struct ds_addon *iter;
27
28     assert(owner && impl);
29
30     wl_list_for_each(iter, &set->addons, link) {
31         if (iter->owner == addon->owner && iter->impl == addon->impl)
32             assert(0 && "Can't have two addons of the same type with the same owner");
33     }
34
35     wl_list_insert(&set->addons, &addon->link);
36
37     addon->owner = owner;
38     addon->impl = impl;
39 }
40
41 void
42 ds_addon_finish(struct ds_addon *addon)
43 {
44     wl_list_remove(&addon->link);
45     wl_list_init(&addon->link);
46 }
47
48 struct ds_addon *
49 ds_addon_find(struct ds_addon_set *set, const void *owner,
50         const struct ds_addon_interface *impl)
51 {
52     struct ds_addon *addon;
53
54     wl_list_for_each(addon, &set->addons, link) {
55         if (addon->owner == owner && addon->impl == impl)
56             return addon;
57     }
58
59     return NULL;
60 }