1 /* ckrm_events.c - Class-based Kernel Resource Management (CKRM)
2 * - event handling routines
4 * Copyright (C) Hubertus Franke, IBM Corp. 2003, 2004
5 * (C) Chandra Seetharaman, IBM Corp. 2003
8 * Provides API for event registration and handling for different
11 * Latest version, more details at http://ckrm.sf.net
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
23 * Separated from ckrm.c
27 #include <linux/config.h>
28 #include <linux/stddef.h>
29 #include <linux/ckrm_events.h>
31 /*******************************************************************
32 * Event callback invocation
33 *******************************************************************/
35 struct ckrm_hook_cb *ckrm_event_callbacks[CKRM_NONLATCHABLE_EVENTS];
37 /* Registration / Deregistration / Invocation functions */
39 int ckrm_register_event_cb(enum ckrm_event ev, struct ckrm_hook_cb *cb)
41 struct ckrm_hook_cb **cbptr;
43 if ((ev < CKRM_LATCHABLE_EVENTS) || (ev >= CKRM_NONLATCHABLE_EVENTS))
45 cbptr = &ckrm_event_callbacks[ev];
46 while (*cbptr != NULL)
47 cbptr = &((*cbptr)->next);
52 int ckrm_unregister_event_cb(enum ckrm_event ev, struct ckrm_hook_cb *cb)
54 struct ckrm_hook_cb **cbptr;
56 if ((ev < CKRM_LATCHABLE_EVENTS) || (ev >= CKRM_NONLATCHABLE_EVENTS))
58 cbptr = &ckrm_event_callbacks[ev];
59 while ((*cbptr != NULL) && (*cbptr != cb))
60 cbptr = &((*cbptr)->next);
62 (*cbptr)->next = cb->next;
63 return (*cbptr == NULL);
66 int ckrm_register_event_set(struct ckrm_event_spec especs[])
68 struct ckrm_event_spec *espec = especs;
70 for (espec = especs; espec->ev != -1; espec++)
71 ckrm_register_event_cb(espec->ev, &espec->cb);
75 int ckrm_unregister_event_set(struct ckrm_event_spec especs[])
77 struct ckrm_event_spec *espec = especs;
79 for (espec = especs; espec->ev != -1; espec++)
80 ckrm_unregister_event_cb(espec->ev, &espec->cb);
84 #define ECC_PRINTK(fmt, args...) \
85 // printk("%s: " fmt, __FUNCTION__ , ## args)
87 void ckrm_invoke_event_cb_chain(enum ckrm_event ev, void *arg)
89 struct ckrm_hook_cb *cb, *anchor;
91 ECC_PRINTK("%d %x\n", current, ev, arg);
92 if ((anchor = ckrm_event_callbacks[ev]) != NULL) {
93 for (cb = anchor; cb; cb = cb->next)