This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / kernel / ckrm / ckrm_events.c
1 /* ckrm_events.c - Class-based Kernel Resource Management (CKRM)
2  *               - event handling routines
3  *
4  * Copyright (C) Hubertus Franke, IBM Corp. 2003, 2004
5  *           (C) Chandra Seetharaman,  IBM Corp. 2003
6  * 
7  * 
8  * Provides API for event registration and handling for different
9  * classtypes.
10  *
11  * Latest version, more details at http://ckrm.sf.net
12  * 
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.
17  *
18  */
19
20 /* Changes
21  *
22  * 29 Sep 2004
23  *        Separated from ckrm.c
24  *  
25  */
26
27 #include <linux/config.h>
28 #include <linux/stddef.h>
29 #include <linux/ckrm_events.h>
30
31 /*******************************************************************
32  *   Event callback invocation
33  *******************************************************************/
34
35 struct ckrm_hook_cb *ckrm_event_callbacks[CKRM_NONLATCHABLE_EVENTS];
36
37 /* Registration / Deregistration / Invocation functions */
38
39 int ckrm_register_event_cb(enum ckrm_event ev, struct ckrm_hook_cb *cb)
40 {
41         struct ckrm_hook_cb **cbptr;
42
43         if ((ev < CKRM_LATCHABLE_EVENTS) || (ev >= CKRM_NONLATCHABLE_EVENTS))
44                 return 1;
45         cbptr = &ckrm_event_callbacks[ev];
46         while (*cbptr != NULL)
47                 cbptr = &((*cbptr)->next);
48         *cbptr = cb;
49         return 0;
50 }
51
52 int ckrm_unregister_event_cb(enum ckrm_event ev, struct ckrm_hook_cb *cb)
53 {
54         struct ckrm_hook_cb **cbptr;
55
56         if ((ev < CKRM_LATCHABLE_EVENTS) || (ev >= CKRM_NONLATCHABLE_EVENTS))
57                 return -1;
58         cbptr = &ckrm_event_callbacks[ev];
59         while ((*cbptr != NULL) && (*cbptr != cb))
60                 cbptr = &((*cbptr)->next);
61         if (*cbptr)
62                 (*cbptr)->next = cb->next;
63         return (*cbptr == NULL);
64 }
65
66 int ckrm_register_event_set(struct ckrm_event_spec especs[])
67 {
68         struct ckrm_event_spec *espec = especs;
69
70         for (espec = especs; espec->ev != -1; espec++)
71                 ckrm_register_event_cb(espec->ev, &espec->cb);
72         return 0;
73 }
74
75 int ckrm_unregister_event_set(struct ckrm_event_spec especs[])
76 {
77         struct ckrm_event_spec *espec = especs;
78
79         for (espec = especs; espec->ev != -1; espec++)
80                 ckrm_unregister_event_cb(espec->ev, &espec->cb);
81         return 0;
82 }
83
84 #define ECC_PRINTK(fmt, args...) \
85 // printk("%s: " fmt, __FUNCTION__ , ## args)
86
87 void ckrm_invoke_event_cb_chain(enum ckrm_event ev, void *arg)
88 {
89         struct ckrm_hook_cb *cb, *anchor;
90
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)
94                         (*cb->fct) (arg);
95         }
96 }
97