3 * writer/event_filter.c
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.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2013
21 * 2013 Vyacheslav Cherkashin <v.cherkashin@samsung.com>
26 #include <linux/module.h>
27 #include <linux/list.h>
28 #include "event_filter.h"
31 static LIST_HEAD(filter_list);
33 static int func_none(struct task_struct *task)
38 static struct ev_filter filter_none = {
43 static struct ev_filter *filter_current = &filter_none;
45 int check_event(struct task_struct *task)
47 return filter_current->filter(task);
50 static struct ev_filter *event_filter_find(const char *name)
52 struct ev_filter *f, *tmp;
54 list_for_each_entry_safe(f, tmp, &filter_list, list) {
55 if (strcmp(f->name, name) == 0)
62 int event_filter_register(struct ev_filter *f)
64 if (event_filter_find(f->name))
67 INIT_LIST_HEAD(&f->list);
68 list_add(&f->list, &filter_list);
72 EXPORT_SYMBOL_GPL(event_filter_register);
74 void event_filter_unregister(struct ev_filter *f)
76 struct ev_filter *filter, *tmp;
78 if (filter_current == f)
79 filter_current = &filter_none;
81 list_for_each_entry_safe(filter, tmp, &filter_list, list) {
83 list_del(&filter->list);
88 EXPORT_SYMBOL_GPL(event_filter_unregister);
90 int event_filter_set(const char *name)
94 f = event_filter_find(name);
102 EXPORT_SYMBOL_GPL(event_filter_set);
104 const char *event_filter_get(void)
106 return filter_current->name;
109 void event_filter_on_each(void (*func)(struct ev_filter *, void *),
112 struct ev_filter *f, *tmp;
114 list_for_each_entry_safe(f, tmp, &filter_list, list)
118 int event_filter_init(void)
120 return event_filter_register(&filter_none);
123 void event_filter_exit(void)
125 event_filter_unregister(&filter_none);;