[asterisk-commits] russell: branch russell/events r103676 - in /team/russell/events: main/ res/ais/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 14 12:35:39 CST 2008
Author: russell
Date: Thu Feb 14 12:35:39 2008
New Revision: 103676
URL: http://svn.digium.com/view/asterisk?view=rev&rev=103676
Log:
Reduce more duplicated code using match_ie_val(), and also fix more places in regards to
handling "raw" IE types
Modified:
team/russell/events/main/devicestate.c
team/russell/events/main/event.c
team/russell/events/res/ais/evt.c
Modified: team/russell/events/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/devicestate.c?view=diff&rev=103676&r1=103675&r2=103676
==============================================================================
--- team/russell/events/main/devicestate.c (original)
+++ team/russell/events/main/devicestate.c Thu Feb 14 12:35:39 2008
@@ -429,7 +429,7 @@
* device name if it exists. */
ast_event_queue_and_cache(event,
AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR,
- AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW,
+ AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW, sizeof(struct ast_eid),
AST_EVENT_IE_END);
} else {
ast_event_queue(event);
Modified: team/russell/events/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/event.c?view=diff&rev=103676&r1=103675&r2=103676
==============================================================================
--- team/russell/events/main/event.c (original)
+++ team/russell/events/main/event.c Thu Feb 14 12:35:39 2008
@@ -179,6 +179,13 @@
ie_val->payload.uint = va_arg(ap, uint32_t);
else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
ie_val->payload.str = ast_strdupa(va_arg(ap, const char *));
+ else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
+ void *data = va_arg(ap, void *);
+ size_t datalen = va_arg(ap, size_t);
+ ie_val->payload.raw = alloca(datalen);
+ memcpy(ie_val->payload.raw, data, datalen);
+ ie_val->raw_datalen = datalen;
+ }
AST_LIST_INSERT_TAIL(&ie_vals, ie_val, entry);
}
va_end(ap);
@@ -204,6 +211,9 @@
if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
strcmp(ie_val->payload.str, sub_ie_val->payload.str))
break;
+ if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW &&
+ memcmp(ie_val->payload.raw, sub_ie_val->payload.raw, ie_val->raw_datalen))
+ break;
}
if (!ie_val)
break;
@@ -679,6 +689,13 @@
ie_val->payload.uint = va_arg(ap, uint32_t);
else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
ie_val->payload.str = ast_strdupa(va_arg(ap, const char *));
+ else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
+ void *data = va_arg(ap, void *);
+ size_t datalen = va_arg(ap, size_t);
+ ie_val->payload.raw = alloca(datalen);
+ memcpy(ie_val->payload.raw, data, datalen);
+ ie_val->raw_datalen = datalen;
+ }
AST_LIST_INSERT_TAIL(&ie_vals, ie_val, entry);
}
va_end(ap);
@@ -694,6 +711,8 @@
ast_event_append_ie_str(&event, ie_val->ie_type, ie_val->payload.str);
else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
ast_event_append_ie_uint(&event, ie_val->ie_type, ie_val->payload.uint);
+ else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW)
+ ast_event_append_ie_raw(&event, ie_val->ie_type, ie_val->payload.raw, ie_val->raw_datalen);
if (!event)
break;
@@ -761,6 +780,13 @@
cache_arg->payload.uint = va_arg(ap, uint32_t);
else if (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
cache_arg->payload.str = ast_strdupa(va_arg(ap, const char *));
+ else if (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
+ void *data = va_arg(ap, void *);
+ size_t datalen = va_arg(ap, size_t);
+ cache_arg->payload.raw = alloca(datalen);
+ memcpy(cache_arg->payload.raw, data, datalen);
+ cache_arg->raw_datalen = datalen;
+ }
AST_LIST_INSERT_TAIL(&cache_args, cache_arg, entry);
}
va_end(ap);
@@ -774,19 +800,8 @@
AST_RWLIST_RDLOCK(&ast_event_cache[type]);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&ast_event_cache[type], event_ref, entry) {
AST_LIST_TRAVERSE(&cache_args, cache_arg, entry) {
- if ( ! ( (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_UINT &&
- (cache_arg->payload.uint ==
- ast_event_get_ie_uint(event_ref->event, cache_arg->ie_type))) ||
-
- (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
- (!strcmp(cache_arg->payload.str,
- ast_event_get_ie_str(event_ref->event, cache_arg->ie_type)))) ||
-
- (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS &&
- ast_event_get_ie_raw(event_ref->event, cache_arg->ie_type)) ) )
- {
+ if (!match_ie_val(event_ref->event, cache_arg))
break;
- }
}
if (!cache_arg) {
/* All parameters were matched on this cache entry, so return it */
@@ -826,12 +841,8 @@
uint16_t host_event_type;
struct ast_event_ref *event_ref;
int res;
- struct cache_arg {
- AST_LIST_ENTRY(cache_arg) entry;
- enum ast_event_ie_type ie_type;
- enum ast_event_ie_pltype ie_pltype;
- } *cache_arg;
- AST_LIST_HEAD_NOLOCK_STATIC(cache_args, cache_arg);
+ struct ast_event_ie_val *cache_arg;
+ AST_LIST_HEAD_NOLOCK_STATIC(cache_args, ast_event_ie_val);
host_event_type = ntohs(event->type);
@@ -851,6 +862,8 @@
memset(cache_arg, 0, sizeof(*cache_arg));
cache_arg->ie_type = ie_type;
cache_arg->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
+ if (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_RAW)
+ cache_arg->raw_datalen = va_arg(ap, size_t);
AST_LIST_INSERT_TAIL(&cache_args, cache_arg, entry);
}
va_end(ap);
@@ -864,19 +877,8 @@
AST_RWLIST_WRLOCK(&ast_event_cache[host_event_type]);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&ast_event_cache[host_event_type], event_ref, entry) {
AST_LIST_TRAVERSE(&cache_args, cache_arg, entry) {
- if ( ! ( (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_UINT &&
- (ast_event_get_ie_uint(event, cache_arg->ie_type) ==
- ast_event_get_ie_uint(event_ref->event, cache_arg->ie_type))) ||
-
- (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
- (!strcmp(ast_event_get_ie_str(event, cache_arg->ie_type),
- ast_event_get_ie_str(event_ref->event, cache_arg->ie_type)))) ||
-
- (cache_arg->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS &&
- ast_event_get_ie_raw(event_ref->event, cache_arg->ie_type)) ) )
- {
+ if (!match_ie_val(event_ref->event, cache_arg))
break;
- }
}
if (!cache_arg) {
/* All parameters were matched on this cache entry, so remove it */
@@ -944,19 +946,8 @@
AST_RWLIST_TRAVERSE(&ast_event_subs[host_event_type], sub, entry) {
struct ast_event_ie_val *ie_val;
AST_LIST_TRAVERSE(&sub->ie_vals, ie_val, entry) {
- if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS &&
- ast_event_get_ie_raw(event_ref->event, ie_val->ie_type)) {
- continue;
- } else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT &&
- ast_event_get_ie_uint(event_ref->event, ie_val->ie_type)
- == ie_val->payload.uint) {
- continue;
- } else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
- !strcmp(ast_event_get_ie_str(event_ref->event, ie_val->ie_type),
- ie_val->payload.str)) {
- continue;
- }
- break;
+ if (!match_ie_val(event_ref->event, ie_val))
+ break;
}
if (ie_val)
continue;
Modified: team/russell/events/res/ais/evt.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/res/ais/evt.c?view=diff&rev=103676&r1=103675&r2=103676
==============================================================================
--- team/russell/events/res/ais/evt.c (original)
+++ team/russell/events/res/ais/evt.c Thu Feb 14 12:35:39 2008
@@ -129,7 +129,7 @@
} else if (type == AST_EVENT_DEVICE_STATE_CHANGE) {
ast_event_queue_and_cache(ast_event,
AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR,
- AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW,
+ AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW, sizeof(struct ast_eid),
AST_EVENT_IE_END);
} else {
ast_event_queue(ast_event);
More information about the asterisk-commits
mailing list