[svn-commits] russell: branch russell/event_performance r183909 - in /team/russell/event_pe...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 24 07:36:17 CDT 2009


Author: russell
Date: Tue Mar 24 07:36:12 2009
New Revision: 183909

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183909
Log:
implement get_cached

Modified:
    team/russell/event_performance/channels/chan_dahdi.c
    team/russell/event_performance/channels/chan_iax2.c
    team/russell/event_performance/channels/chan_mgcp.c
    team/russell/event_performance/channels/chan_sip.c
    team/russell/event_performance/channels/chan_skinny.c
    team/russell/event_performance/channels/chan_unistim.c
    team/russell/event_performance/main/event.c

Modified: team/russell/event_performance/channels/chan_dahdi.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_dahdi.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_dahdi.c (original)
+++ team/russell/event_performance/channels/chan_dahdi.c Tue Mar 24 07:36:12 2009
@@ -2359,7 +2359,6 @@
 	event = ast_event_get_cached(AST_EVENT_MWI,
 		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
 		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 		AST_EVENT_IE_END);
 
 	if (event) {

Modified: team/russell/event_performance/channels/chan_iax2.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_iax2.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_iax2.c (original)
+++ team/russell/event_performance/channels/chan_iax2.c Tue Mar 24 07:36:12 2009
@@ -7226,8 +7226,6 @@
 			event = ast_event_get_cached(AST_EVENT_MWI,
 				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
 				AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-				AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-				AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 				AST_EVENT_IE_END);
 			if (event) {
 				new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);

Modified: team/russell/event_performance/channels/chan_mgcp.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_mgcp.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_mgcp.c (original)
+++ team/russell/event_performance/channels/chan_mgcp.c Tue Mar 24 07:36:12 2009
@@ -472,7 +472,6 @@
 	event = ast_event_get_cached(AST_EVENT_MWI,
 		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
 		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cntx,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 		AST_EVENT_IE_END);
 
 	if (event) {

Modified: team/russell/event_performance/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_sip.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_sip.c (original)
+++ team/russell/event_performance/channels/chan_sip.c Tue Mar 24 07:36:12 2009
@@ -20107,8 +20107,6 @@
 		event = ast_event_get_cached(AST_EVENT_MWI,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox,
 			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"),
-			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-			AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 			AST_EVENT_IE_END);
 		if (!event)
 			continue;

Modified: team/russell/event_performance/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_skinny.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_skinny.c (original)
+++ team/russell/event_performance/channels/chan_skinny.c Tue Mar 24 07:36:12 2009
@@ -2322,7 +2322,6 @@
 	event = ast_event_get_cached(AST_EVENT_MWI,
 		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
 		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 		AST_EVENT_IE_END);
 
 	if (event) {

Modified: team/russell/event_performance/channels/chan_unistim.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/channels/chan_unistim.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/channels/chan_unistim.c (original)
+++ team/russell/event_performance/channels/chan_unistim.c Tue Mar 24 07:36:12 2009
@@ -4391,7 +4391,6 @@
 	event = ast_event_get_cached(AST_EVENT_MWI,
 		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
 		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 		AST_EVENT_IE_END);
 
 	if (event) {

Modified: team/russell/event_performance/main/event.c
URL: http://svn.digium.com/svn-view/asterisk/team/russell/event_performance/main/event.c?view=diff&rev=183909&r1=183908&r2=183909
==============================================================================
--- team/russell/event_performance/main/event.c (original)
+++ team/russell/event_performance/main/event.c Tue Mar 24 07:36:12 2009
@@ -117,8 +117,6 @@
  * The event subscribers are indexed by which event they are subscribed to */
 static AST_RWDLLIST_HEAD(ast_event_sub_list, ast_event_sub) ast_event_subs[AST_EVENT_TOTAL];
 
-static struct ao2_container *ast_event_cache[AST_EVENT_TOTAL];
-
 #ifdef LOW_MEMORY
 #define NUM_CACHE_BUCKETS 17
 #else
@@ -135,10 +133,11 @@
 /*!
  * \brief Event types that are kept in the cache.
  */
-static const struct {
+static struct {
+	struct ao2_container *container;
 	ao2_hash_fn *hash_fn;
 	enum ast_event_ie_type cache_args[MAX_CACHE_ARGS];
-} cached_event_types[AST_EVENT_TOTAL] = {
+} ast_event_cache[AST_EVENT_TOTAL] = {
 	[AST_EVENT_MWI] = {
 		.hash_fn = ast_event_hash_mwi,
 		.cache_args = { AST_EVENT_IE_MAILBOX, AST_EVENT_IE_CONTEXT },
@@ -959,12 +958,24 @@
 	va_list ap;
 	enum ast_event_ie_type ie_type;
 	struct ast_event *dup_event = NULL;
-	//struct ast_event_ref *event_ref;
-	struct ast_event_ie_val *cache_arg;
-	AST_LIST_HEAD_NOLOCK_STATIC(cache_args, ast_event_ie_val);
+	struct ast_event_ref *cached_event_ref;
+	struct ast_event *cache_arg_event;
+	struct ast_event_ref tmp_event_ref = {
+		.event = NULL,
+	};
+	struct ao2_container *container = NULL;
 
 	if (type >= AST_EVENT_TOTAL) {
 		ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
+		return NULL;
+	}
+
+	if (!(container = ast_event_cache[type].container)) {
+		ast_log(LOG_ERROR, "%u is not a cached event type\n", type);
+		return NULL;
+	}
+
+	if (!(cache_arg_event = ast_event_new(type, AST_EVENT_IE_END))) {
 		return NULL;
 	}
 
@@ -973,46 +984,45 @@
 		ie_type != AST_EVENT_IE_END;
 		ie_type = va_arg(ap, enum ast_event_type))
 	{
-		cache_arg = alloca(sizeof(*cache_arg));
-		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_UINT)
-			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) {
+		enum ast_event_ie_pltype ie_pltype;
+
+		ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
+
+		switch (ie_pltype) {
+		case AST_EVENT_IE_PLTYPE_UINT:
+			ast_event_append_ie_uint(&cache_arg_event, ie_type, va_arg(ap, uint32_t));
+			break;
+		case AST_EVENT_IE_PLTYPE_STR:
+			ast_event_append_ie_str(&cache_arg_event, ie_type, va_arg(ap, const char *));
+			break;
+		case 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);
+			ast_event_append_ie_raw(&cache_arg_event, ie_type, data, datalen);
+		}
+		case AST_EVENT_IE_PLTYPE_EXISTS:
+			ast_log(LOG_WARNING, "PLTYPE_EXISTS not supported by this function\n");
+			break;
+		case AST_EVENT_IE_PLTYPE_UNKNOWN:
+			break;
+		}
 	}
 	va_end(ap);
 
-	if (AST_LIST_EMPTY(&cache_args)) {
-		ast_log(LOG_ERROR, "Events can not be retrieved from the cache without "
-			"specifying at least one IE type!\n");
-		return NULL;
-	}
-#if 0
-	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 (!match_ie_val(event_ref->event, cache_arg, NULL))
-				break;	
-		}
-		if (!cache_arg) {
-			/* All parameters were matched on this cache entry, so return it */
-			dup_event = ast_event_dup(event_ref->event);
-			break;
-		}
-	}
-	AST_RWLIST_TRAVERSE_SAFE_END
-	AST_RWLIST_UNLOCK(&ast_event_cache[type]);
-#endif
+	tmp_event_ref.event = cache_arg_event;
+
+	cached_event_ref = ao2_callback(container, OBJ_POINTER, ast_event_cmp, &tmp_event_ref);
+
+	ast_event_destroy(cache_arg_event);
+	cache_arg_event = NULL;
+
+	if (cached_event_ref) {
+		dup_event = ast_event_dup(cached_event_ref->event);
+		ao2_ref(cached_event_ref, -1);
+		cached_event_ref = NULL;
+	}
+
 	return dup_event;
 }
 
@@ -1038,7 +1048,7 @@
 
 	event_ref->event = dup_event;
 
-	ao2_link(ast_event_cache[ast_event_get_type(event)], event_ref);
+	ao2_link(ast_event_cache[ast_event_get_type(event)].container, event_ref);
 
 	ao2_ref(event_ref, -1);
 
@@ -1052,7 +1062,7 @@
 		.event = event,
 	};
 
-	if (!(container = ast_event_cache[ast_event_get_type(event)])) {
+	if (!(container = ast_event_cache[ast_event_get_type(event)].container)) {
 		ast_log(LOG_WARNING, "cache requested for non-cached event type\n");
 		goto queue_event;
 	}
@@ -1163,7 +1173,7 @@
 	event_ref = obj;
 	event = event_ref->event;
 
-	if (!(hash_fn = cached_event_types[ast_event_get_type(event)].hash_fn)) {
+	if (!(hash_fn = ast_event_cache[ast_event_get_type(event)].hash_fn)) {
 		return 0;
 	}
 
@@ -1184,9 +1194,9 @@
 	event_ref2 = arg;
 	event2 = event_ref2->event;
 
-	cache_args = cached_event_types[ast_event_get_type(event)].cache_args;
-
-	for (i = 0; i < ARRAY_LEN(cached_event_types[0].cache_args) && cache_args[i]; i++) {
+	cache_args = ast_event_cache[ast_event_get_type(event)].cache_args;
+
+	for (i = 0; i < ARRAY_LEN(ast_event_cache[0].cache_args) && cache_args[i]; i++) {
 		struct ast_event_ie_val ie_val = {
 			.ie_type = cache_args[i],
 		};
@@ -1209,12 +1219,12 @@
 	}
 
 	for (i = 0; i < AST_EVENT_TOTAL; i++) {
-		if (!cached_event_types[i].hash_fn) {
+		if (!ast_event_cache[i].hash_fn) {
 			/* This event type is not cached. */
 			continue;
 		}
 
-		if (!(ast_event_cache[i] = ao2_container_alloc(NUM_CACHE_BUCKETS,
+		if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
 				ast_event_hash, ast_event_cmp))) {
 			return -1;
 		}




More information about the svn-commits mailing list