[asterisk-commits] russell: branch group/newcdr r202028 - /team/group/newcdr/main/cel.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jun 19 16:22:37 CDT 2009
Author: russell
Date: Fri Jun 19 16:22:33 2009
New Revision: 202028
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202028
Log:
Simplify event list parsing, make "cel show status" list tracked event types
Modified:
team/group/newcdr/main/cel.c
Modified: team/group/newcdr/main/cel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=202028&r1=202027&r2=202028
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Fri Jun 19 16:22:33 2009
@@ -43,8 +43,15 @@
/*! \brief CEL is off by default */
static const unsigned int CEL_ENALBED_DEFAULT = 0;
-/*! which events we want to track; up to 64 events */
-static long long eventset;
+/*!
+ * \brief which events we want to track
+ *
+ * \note bit field, up to 64 events
+ */
+static int64_t eventset;
+
+/*! \brief Track no events by default. */
+static const int64_t CEL_DEFAULT_EVENTS = 0;
static struct ast_hashtab *appset;
@@ -58,6 +65,7 @@
static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
struct ast_event_sub *sub = 0;
+ unsigned int i;
switch (cmd) {
case CLI_INIT:
@@ -69,18 +77,36 @@
case CLI_GENERATE:
return NULL;
}
+
if (a->argc > 3) {
return CLI_SHOWUSAGE;
}
+
ast_cli(a->fd, "CEL logging: %s\n", cel_enabled ? "enabled" : "disabled");
- if (cel_enabled) {
- ast_event_lock_subscribers(AST_EVENT_CEL);
- while ((sub = ast_event_next_subscriber(AST_EVENT_CEL, sub))) {
- ast_cli(a->fd, "CEL registered backend: %s\n", ast_event_subscriber_get_description(sub));
- }
- ast_event_unlock_subscribers(AST_EVENT_CEL);
- }
+ if (!cel_enabled) {
+ return CLI_SUCCESS;
+ }
+
+ for (i = 0; i < (sizeof(eventset) * 8); i++) {
+ const char *name;
+
+ if (!(eventset & ((int64_t) 1 << i))) {
+ continue;
+ }
+
+ name = ast_cel_get_type_name(i);
+ if (strcasecmp(name, "Unknown")) {
+ ast_cli(a->fd, "CEL Tracking Event: %s\n", name);
+ }
+ }
+
+ ast_event_lock_subscribers(AST_EVENT_CEL);
+ while ((sub = ast_event_next_subscriber(AST_EVENT_CEL, sub))) {
+ ast_cli(a->fd, "CEL registered backend: %s\n", ast_event_subscriber_get_description(sub));
+ }
+ ast_event_unlock_subscribers(AST_EVENT_CEL);
+
return CLI_SUCCESS;
}
@@ -147,7 +173,34 @@
static int ast_cel_track_event(enum ast_cel_event_type et)
{
- return (eventset & (1 << (int)et));
+ return (eventset & ((int64_t) 1 << et));
+}
+
+static void parse_events(const char *val)
+{
+ char *events = ast_strdupa(val);
+ char *cur_event;
+
+ while ((cur_event = strsep(&events, ","))) {
+ enum ast_cel_event_type event_type;
+
+ cur_event = ast_strip(cur_event);
+ if (ast_strlen_zero(cur_event)) {
+ continue;
+ }
+
+ event_type = ast_cel_str_to_event_type(cur_event);
+
+ if (event_type == 0) {
+ /* All events */
+ eventset = (int64_t) -1;
+ } else if (event_type == -1) {
+ ast_log(LOG_WARNING, "Unknown event name '%s'\n",
+ cur_event);
+ } else {
+ eventset |= ((int64_t) 1 << event_type);
+ }
+ }
}
AST_MUTEX_DEFINE_STATIC(reload_lock);
@@ -156,16 +209,15 @@
{
struct ast_config *config;
const char *enabled_value;
- const char *eventlist;
- const char *applist;
+ const char *val;
int res = 0;
- enum ast_cel_event_type et;
struct ast_flags config_flags = { CONFIG_FLAG_FILEUNCHANGED };
const char *s;
ast_mutex_lock(&reload_lock);
cel_enabled = CEL_ENALBED_DEFAULT;
+ eventset = CEL_DEFAULT_EVENTS;
if (appset) {
char *str;
@@ -199,62 +251,12 @@
ast_copy_string(cel_dateformat, s, sizeof(cel_dateformat));
}
- if ((eventlist = ast_variable_retrieve(config, "general", "events"))) {
- char *t1, *t2, *t3, *myeventlist = ast_strdup(eventlist);
- t1 = myeventlist;
- if (!t1 || !(*t1)) {
- ast_log(LOG_ERROR, "no events line? Turning off CEL capability!\n");
- cel_enabled = 0;
- } else {
- while (t1 && *t1) {
- t2 = strchr(t1,',');
- if (!t2) {
- t2 = t1 + strlen(t1) - 1;
- } else {
- *t2 = 0;
- }
- /*push t1 to the first non-blank char */
- while (t1 && *t1 && isspace(*t1)) {
- t1++;
- }
- if (t2 == t1) {
- ast_log(LOG_ERROR, "A comma with no preceeding event name? --Ignored\n");
- t1 = t2+1;
- continue;
- }
- if (!(*t1)) {
- ast_log(LOG_ERROR, "no events to log? Turning off CEL capability!\n");
- cel_enabled = 0;
- break;
- }
- /* pull t3 (a copy of t2) to last non-blank char */
- t3 = t2;
- if (!(*t2)) {
- t3 = t2-1;
- }
- while (t3 && *t3 && isspace(*t3)) {
- t3--;
- }
- *(t3+1) = 0;
- /* t1 now points to null-terminated entry */
- et = ast_cel_str_to_event_type(t1);
- if ((int)et == 0) { /* all events */
- eventset = -1; /* turn on all the bits */
- } else if ((int)et == -1) { /* unmatched event */
- ast_log(LOG_ERROR, "Unrecognized event name %s!\n", t1);
- } else {
- eventset |= (1 << (int)et);
- }
- t1 = t2+1;
- }
- }
- if (myeventlist) {
- free(myeventlist);
- }
- }
-
- if ((applist = ast_variable_retrieve(config, "general", "apps"))) {
- char *t1, *t2, *t3, *myapplist = ast_strdup(applist);
+ if ((val = ast_variable_retrieve(config, "general", "events"))) {
+ parse_events(val);
+ }
+
+ if ((val = ast_variable_retrieve(config, "general", "apps"))) {
+ char *t1, *t2, *t3, *myapplist = ast_strdup(val);
if (!ast_cel_track_event(AST_CEL_APP_START) && !ast_cel_track_event(AST_CEL_APP_END)) {
ast_log(LOG_ERROR, "An apps= config line, but not tracking APP events!\n");
} else {
More information about the asterisk-commits
mailing list