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 41
 	}
42 42
 }
43 43
 
44
+/**
45
+ *
46
+ */
44 47
 int sr_event_register_cb(int type, sr_event_cb_f f)
45 48
 {
46 49
 	sr_event_cb_init();
... ...
@@ -65,12 +71,25 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
65 65
 					_sr_events_list.run_action = f;
66 66
 				else return -1;
67 67
 			break;
68
+		case SREV_PKG_SET_USED:
69
+				if(_sr_events_list.pkg_set_used==0)
70
+					_sr_events_list.pkg_set_used = f;
71
+				else return -1;
72
+			break;
73
+		case SREV_PKG_SET_REAL_USED:
74
+				if(_sr_events_list.pkg_set_real_used==0)
75
+					_sr_events_list.pkg_set_real_used = f;
76
+				else return -1;
77
+			break;
68 78
 		default:
69 79
 			return -1;
70 80
 	}
71 81
 	return 0;
72 82
 }
73 83
 
84
+/**
85
+ *
86
+ */
74 87
 int sr_event_exec(int type, void *data)
75 88
 {
76 89
 	int ret;
... ...
@@ -121,11 +140,26 @@ int sr_event_exec(int type, void *data)
121 121
 					ret = _sr_events_list.run_action(data);
122 122
 					return ret;
123 123
 				} else return 1;
124
+		case SREV_PKG_SET_USED:
125
+				if(unlikely(_sr_events_list.pkg_set_used!=0))
126
+				{
127
+					ret = _sr_events_list.pkg_set_used(data);
128
+					return ret;
129
+				} else return 1;
130
+		case SREV_PKG_SET_REAL_USED:
131
+				if(unlikely(_sr_events_list.pkg_set_real_used!=0))
132
+				{
133
+					ret = _sr_events_list.pkg_set_real_used(data);
134
+					return ret;
135
+				} else return 1;
124 136
 		default:
125 137
 			return -1;
126 138
 	}
127 139
 }
128 140
 
141
+/**
142
+ *
143
+ */
129 144
 int sr_event_enabled(int type)
130 145
 {
131 146
 	switch(type) {
... ...
@@ -137,6 +171,10 @@ int sr_event_enabled(int type)
137 137
 				return (_sr_events_list.core_stats!=0)?1:0;
138 138
 		case SREV_CFG_RUN_ACTION:
139 139
 				return (_sr_events_list.run_action!=0)?1:0;
140
+		case SREV_PKG_SET_USED:
141
+				return (_sr_events_list.pkg_set_used!=0)?1:0;
142
+		case SREV_PKG_SET_REAL_USED:
143
+				return (_sr_events_list.pkg_set_real_used!=0)?1:0;
140 144
 	}
141 145
 	return 0;
142 146
 }
... ...
@@ -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 35
 	sr_event_cb_f net_data_out;
36 36
 	sr_event_cb_f core_stats;
37 37
 	sr_event_cb_f run_action;
38
+	sr_event_cb_f pkg_set_used;
39
+	sr_event_cb_f pkg_set_real_used;
38 40
 } sr_event_cb_t;
39 41
 
40 42
 void sr_event_cb_init(void);