fw_comm instead of pub_sub
[projects/modsched/linux.git] / framework / fw_comm.c
1 #include "fw_comm.h"
2
3 #include <fw.h>
4
5 fw_list_head_t topics[LAST-FIRST];
6
7 struct fw_topic_element {
8         fw_list_head_t list;
9         void *callback;
10 };
11
12
13 void fw_subscribe(topic_t topic, void *callback)
14 {
15         struct fw_topic_element *subscriber = fw_malloc(sizeof(struct fw_topic_element));
16         subscriber->callback = callback;
17
18         fw_list_add_tail(&subscriber->list, &topics[topic]);
19 }
20
21 void fw_notify(topic_t topic, void *data)
22 {
23         struct fw_topic_element *iter;
24
25         //TODO: Kill this also
26         if(data!=NULL){
27                 struct fw_task *task = register_task(data);
28                 data = task;
29         }
30
31         fw_list_for_each_entry(iter, &topics[topic], list)
32                 ((void (*)(void *))iter->callback)(data);
33 }
34
35 void fw_init_comm()
36 {
37         int i;
38
39         for(i=FIRST;i<LAST;i++){
40                 FW_LIST_INIT(topics[i]);
41         }
42 }