Browse code

core: added core events for pkg operations

- ability to track pkg used and real_used metrics

Daniel-Constantin Mierla authored on 20/12/2010 08:39:40
Showing 2 changed files
... ...
@@ -32,6 +32,9 @@
32 32
 static sr_event_cb_t _sr_events_list;
33 33
 static int _sr_events_inited = 0;
34 34
 
35
+/**
36
+ *
37
+ */
35 38
 void sr_event_cb_init(void)
36 39
 {
37 40
 	if(_sr_events_inited == 0)
... ...
@@ -41,6 +44,9 @@ void sr_event_cb_init(void)
41 44
 	}
42 45
 }
43 46
 
47
+/**
48
+ *
49
+ */
44 50
 int sr_event_register_cb(int type, sr_event_cb_f f)
45 51
 {
46 52
 	sr_event_cb_init();
... ...
@@ -65,12 +71,25 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
65 71
 					_sr_events_list.run_action = f;
66 72
 				else return -1;
67 73
 			break;
74
+		case SREV_PKG_SET_USED:
75
+				if(_sr_events_list.pkg_set_used==0)
76
+					_sr_events_list.pkg_set_used = f;
77
+				else return -1;
78
+			break;
79
+		case SREV_PKG_SET_REAL_USED:
80
+				if(_sr_events_list.pkg_set_real_used==0)
81
+					_sr_events_list.pkg_set_real_used = f;
82
+				else return -1;
83
+			break;
68 84
 		default:
69 85
 			return -1;
70 86
 	}
71 87
 	return 0;
72 88
 }
73 89
 
90
+/**
91
+ *
92
+ */
74 93
 int sr_event_exec(int type, void *data)
75 94
 {
76 95
 	int ret;
... ...
@@ -121,11 +140,26 @@ int sr_event_exec(int type, void *data)
121 140
 					ret = _sr_events_list.run_action(data);
122 141
 					return ret;
123 142
 				} else return 1;
143
+		case SREV_PKG_SET_USED:
144
+				if(unlikely(_sr_events_list.pkg_set_used!=0))
145
+				{
146
+					ret = _sr_events_list.pkg_set_used(data);
147
+					return ret;
148
+				} else return 1;
149
+		case SREV_PKG_SET_REAL_USED:
150
+				if(unlikely(_sr_events_list.pkg_set_real_used!=0))
151
+				{
152
+					ret = _sr_events_list.pkg_set_real_used(data);
153
+					return ret;
154
+				} else return 1;
124 155
 		default:
125 156
 			return -1;
126 157
 	}
127 158
 }
128 159
 
160
+/**
161
+ *
162
+ */
129 163
 int sr_event_enabled(int type)
130 164
 {
131 165
 	switch(type) {
... ...
@@ -137,6 +171,10 @@ int sr_event_enabled(int type)
137 171
 				return (_sr_events_list.core_stats!=0)?1:0;
138 172
 		case SREV_CFG_RUN_ACTION:
139 173
 				return (_sr_events_list.run_action!=0)?1:0;
174
+		case SREV_PKG_SET_USED:
175
+				return (_sr_events_list.pkg_set_used!=0)?1:0;
176
+		case SREV_PKG_SET_REAL_USED:
177
+				return (_sr_events_list.pkg_set_real_used!=0)?1:0;
140 178
 	}
141 179
 	return 0;
142 180
 }
... ...
@@ -23,10 +23,12 @@
23 23
 
24 24
 #include "parser/msg_parser.h"
25 25
 
26
-#define SREV_NET_DATA_IN	1
27
-#define SREV_NET_DATA_OUT	2
28
-#define SREV_CORE_STATS		3
29
-#define SREV_CFG_RUN_ACTION 4
26
+#define SREV_NET_DATA_IN		1
27
+#define SREV_NET_DATA_OUT		2
28
+#define SREV_CORE_STATS			3
29
+#define SREV_CFG_RUN_ACTION		4
30
+#define SREV_PKG_SET_USED		5
31
+#define SREV_PKG_SET_REAL_USED	6
30 32
 
31 33
 typedef int (*sr_event_cb_f)(void *data);
32 34
 
... ...
@@ -35,6 +37,8 @@ typedef struct sr_event_cb {
35 37
 	sr_event_cb_f net_data_out;
36 38
 	sr_event_cb_f core_stats;
37 39
 	sr_event_cb_f run_action;
40
+	sr_event_cb_f pkg_set_used;
41
+	sr_event_cb_f pkg_set_real_used;
38 42
 } sr_event_cb_t;
39 43
 
40 44
 void sr_event_cb_init(void);