Module: sip-router
Branch: master
Commit: 70e7b57085ea7453c2a49393241af2328169167a
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=70e7b57…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: Mon Dec 20 09:39:40 2010 +0100
core: added core events for pkg operations
- ability to track pkg used and real_used metrics
---
events.c | 38 ++++++++++++++++++++++++++++++++++++++
events.h | 12 ++++++++----
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/events.c b/events.c
index 61abc5f..881da1d 100644
--- a/events.c
+++ b/events.c
@@ -32,6 +32,9 @@
static sr_event_cb_t _sr_events_list;
static int _sr_events_inited = 0;
+/**
+ *
+ */
void sr_event_cb_init(void)
{
if(_sr_events_inited == 0)
@@ -41,6 +44,9 @@ void sr_event_cb_init(void)
}
}
+/**
+ *
+ */
int sr_event_register_cb(int type, sr_event_cb_f f)
{
sr_event_cb_init();
@@ -65,12 +71,25 @@ int sr_event_register_cb(int type, sr_event_cb_f f)
_sr_events_list.run_action = f;
else return -1;
break;
+ case SREV_PKG_SET_USED:
+ if(_sr_events_list.pkg_set_used==0)
+ _sr_events_list.pkg_set_used = f;
+ else return -1;
+ break;
+ case SREV_PKG_SET_REAL_USED:
+ if(_sr_events_list.pkg_set_real_used==0)
+ _sr_events_list.pkg_set_real_used = f;
+ else return -1;
+ break;
default:
return -1;
}
return 0;
}
+/**
+ *
+ */
int sr_event_exec(int type, void *data)
{
int ret;
@@ -121,11 +140,26 @@ int sr_event_exec(int type, void *data)
ret = _sr_events_list.run_action(data);
return ret;
} else return 1;
+ case SREV_PKG_SET_USED:
+ if(unlikely(_sr_events_list.pkg_set_used!=0))
+ {
+ ret = _sr_events_list.pkg_set_used(data);
+ return ret;
+ } else return 1;
+ case SREV_PKG_SET_REAL_USED:
+ if(unlikely(_sr_events_list.pkg_set_real_used!=0))
+ {
+ ret = _sr_events_list.pkg_set_real_used(data);
+ return ret;
+ } else return 1;
default:
return -1;
}
}
+/**
+ *
+ */
int sr_event_enabled(int type)
{
switch(type) {
@@ -137,6 +171,10 @@ int sr_event_enabled(int type)
return (_sr_events_list.core_stats!=0)?1:0;
case SREV_CFG_RUN_ACTION:
return (_sr_events_list.run_action!=0)?1:0;
+ case SREV_PKG_SET_USED:
+ return (_sr_events_list.pkg_set_used!=0)?1:0;
+ case SREV_PKG_SET_REAL_USED:
+ return (_sr_events_list.pkg_set_real_used!=0)?1:0;
}
return 0;
}
diff --git a/events.h b/events.h
index 6f79070..fdbcb45 100644
--- a/events.h
+++ b/events.h
@@ -23,10 +23,12 @@
#include "parser/msg_parser.h"
-#define SREV_NET_DATA_IN 1
-#define SREV_NET_DATA_OUT 2
-#define SREV_CORE_STATS 3
-#define SREV_CFG_RUN_ACTION 4
+#define SREV_NET_DATA_IN 1
+#define SREV_NET_DATA_OUT 2
+#define SREV_CORE_STATS 3
+#define SREV_CFG_RUN_ACTION 4
+#define SREV_PKG_SET_USED 5
+#define SREV_PKG_SET_REAL_USED 6
typedef int (*sr_event_cb_f)(void *data);
@@ -35,6 +37,8 @@ typedef struct sr_event_cb {
sr_event_cb_f net_data_out;
sr_event_cb_f core_stats;
sr_event_cb_f run_action;
+ sr_event_cb_f pkg_set_used;
+ sr_event_cb_f pkg_set_real_used;
} sr_event_cb_t;
void sr_event_cb_init(void);