[asterisk-commits] russell: branch russell/events r59288 - in /team/russell/events: apps/ includ...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Mar 27 20:21:05 MST 2007


Author: russell
Date: Tue Mar 27 22:21:04 2007
New Revision: 59288

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59288
Log:
I never liked the idea of having potential event publishers
register themselves, so I am removing it.  In fact, there is a
fundamental problem with the idea.  If you let publishers check
for subscribers before creating an event, and subscribers check
for publishers before subscribing, nobody is going to get
anywhere.

Modified:
    team/russell/events/apps/app_voicemail.c
    team/russell/events/include/asterisk/event.h
    team/russell/events/include/asterisk/event_defs.h
    team/russell/events/main/event.c

Modified: team/russell/events/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/apps/app_voicemail.c?view=diff&rev=59288&r1=59287&r2=59288
==============================================================================
--- team/russell/events/apps/app_voicemail.c (original)
+++ team/russell/events/apps/app_voicemail.c Tue Mar 27 22:21:04 2007
@@ -341,7 +341,6 @@
 	char imappassword[80];           /*!< IMAP server password if authpassword not defined */
 #endif
 	double volgain;		         /*!< Volume gain for voicemails sent via email */
-	struct ast_event_pub *event_pub;     /*!< MWI event publisher for this mailbox */
 	AST_LIST_ENTRY(ast_vm_user) list;
 };
 
@@ -562,8 +561,6 @@
 static unsigned char adsisec[4] = "\x9B\xDB\xF7\xAC";
 static int adsiver = 1;
 static char emaildateformat[32] = "%A, %B %d, %Y at %r";
-
-static struct ast_event_pub *global_mwi_pub;
 
 /* Forward declarations - generic */
 static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu,int box);
@@ -2224,10 +2221,6 @@
 	if (!ast_test_flag(vmu, VM_ALLOCED))
 		return;
 
-	if (vmu->event_pub) {
-		ast_event_unreg_publisher(vmu->event_pub);
-		vmu->event_pub = NULL;
-	}
 	free(vmu);
 }
 
@@ -6932,11 +6925,6 @@
 	strcpy(full_mailbox, mbox);
 	strcat(full_mailbox, "@");
 	strcat(full_mailbox, context);
-	vmu->event_pub = ast_event_reg_publisher(AST_EVENT_MWI,
-		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, full_mailbox,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-		AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-		AST_EVENT_IE_END);
 	AST_LIST_INSERT_TAIL(&users, vmu, list);
 	
 	return vmu;
@@ -7265,20 +7253,6 @@
 	int x;
 	int tmpadsi[4];
 
-	/* For realtime, claim we can provide MWI for any mailbox, because we
-	 * don't know any better. */
-	if (global_mwi_pub) {
-		ast_event_unreg_publisher(global_mwi_pub);
-		global_mwi_pub = NULL;
-	}
-	if (ast_check_realtime("voicemail")) {
-		global_mwi_pub = ast_event_reg_publisher(AST_EVENT_MWI,
-			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_EXISTS,
-			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-			AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-			AST_EVENT_IE_END);
-	}
-
 	cfg = ast_config_load(VOICEMAIL_CONFIG);
 
 	AST_LIST_LOCK(&users);
@@ -7825,11 +7799,6 @@
 static int unload_module(void)
 {
 	int res;
-
-	if (global_mwi_pub) {
-		ast_event_unreg_publisher(global_mwi_pub);
-		global_mwi_pub = NULL;
-	}
 
 	res = ast_unregister_application(app);
 	res |= ast_unregister_application(app2);

Modified: team/russell/events/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event.h?view=diff&rev=59288&r1=59287&r2=59288
==============================================================================
--- team/russell/events/include/asterisk/event.h (original)
+++ team/russell/events/include/asterisk/event.h Tue Mar 27 22:21:04 2007
@@ -26,14 +26,6 @@
 #define AST_EVENT_H
 
 #include "asterisk/event_defs.h"
-
-/*! \brief Check for an event publisher
- */
-enum ast_event_publisher_res ast_event_check_publisher(enum ast_event_type, ...);
-
-void ast_event_unreg_publisher(struct ast_event_pub *pub);
-
-struct ast_event_pub *ast_event_reg_publisher(enum ast_event_type type, ...);
 
 typedef void (*ast_event_cb_t)(const struct ast_event *);
 

Modified: team/russell/events/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event_defs.h?view=diff&rev=59288&r1=59287&r2=59288
==============================================================================
--- team/russell/events/include/asterisk/event_defs.h (original)
+++ team/russell/events/include/asterisk/event_defs.h Tue Mar 27 22:21:04 2007
@@ -66,14 +66,8 @@
 	AST_EVENT_SUB_EXISTS,
 };
 
-enum ast_event_publisher_res {
-	AST_EVENT_PUB_NONE,
-	AST_EVENT_PUB_EXISTS,
-};
-
 struct ast_event;
 struct ast_event_ie;
 struct ast_event_sub;
-struct ast_event_pub;
 
 #endif /* AST_EVENT_DEFS_H */

Modified: team/russell/events/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/event.c?view=diff&rev=59288&r1=59287&r2=59288
==============================================================================
--- team/russell/events/main/event.c (original)
+++ team/russell/events/main/event.c Tue Mar 27 22:21:04 2007
@@ -87,166 +87,18 @@
  * The event subscribers are indexed by which event they are subscribed to */
 static AST_RWLIST_HEAD(ast_event_sub_list, ast_event_sub) ast_event_subs[AST_EVENT_TOTAL];
 
-/*! \brief Event publisher */
-struct ast_event_pub {
-	enum ast_event_type type;
-	AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
-	AST_RWLIST_ENTRY(ast_event_pub) entry;
-};
-
-/*! \brief List of event publishers
- * This is used to be able to know if there is even a chance for a certain
- * event to occur, with optionally specified parameters to be even more
- * specific when appropriate. */
-static AST_RWLIST_HEAD(ast_event_pub_list, ast_event_pub) ast_event_pubs[AST_EVENT_TOTAL];
-
 /*! \brief Cached events
  * The event cache is indexed on the event type.  The purpose of this is 
  * for events that express some sort of state.  So, when someone first
  * needs to know this state, it can get the last known state from the cache. */
 static AST_RWLIST_HEAD(ast_event_ref_list, ast_event_ref) ast_event_cache[AST_EVENT_TOTAL];
 
-enum ast_event_publisher_res ast_event_check_publisher(enum ast_event_type type, ...)
-{
-	va_list ap;
-	enum ast_event_ie_type ie_type;
-	enum ast_event_publisher_res res = AST_EVENT_PUB_NONE;
-	struct ast_event_ie_val *ie_val, *pub_ie_val;
-	struct ast_event_pub *pub;
-	AST_LIST_HEAD_NOLOCK_STATIC(ie_vals, ast_event_ie_val);
-
-	if (type >= AST_EVENT_TOTAL) {
-		ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
-		return res;
-	}
-
-	va_start(ap, type);
-	for (ie_type = va_arg(ap, enum ast_event_type);
-		ie_type != AST_EVENT_IE_END;
-		ie_type = va_arg(ap, enum ast_event_type))
-	{
-		struct ast_event_ie_val *ie_val = alloca(sizeof(*ie_val));
-		memset(ie_val, 0, sizeof(*ie_val));
-		ie_val->ie_type = ie_type;
-		ie_val->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
-		if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
-			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 *));
-		AST_LIST_INSERT_TAIL(&ie_vals, ie_val, entry);
-	}
-	va_end(ap);
-
-	AST_RWLIST_RDLOCK(&ast_event_pubs[type]);
-	AST_RWLIST_TRAVERSE(&ast_event_pubs[type], pub, entry) {
-		AST_LIST_TRAVERSE(&ie_vals, ie_val, entry) {
-			AST_LIST_TRAVERSE(&pub->ie_vals, pub_ie_val, entry) {
-				if (pub_ie_val->ie_type == ie_val->ie_type)
-					break;
-			}
-			if (!pub_ie_val) {
-				if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS)
-					break;
-				continue;
-			}
-			/* Publisher registered a wildcard field */
-			if (pub_ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_EXISTS)
-				continue;
-			if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT &&
-				ie_val->payload.uint != pub_ie_val->payload.uint) {
-				break;
-			}
-			if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR &&
-				strcmp(ie_val->payload.str, pub_ie_val->payload.str)) {
-				break;
-			}
-		}
-		if (!ie_val)
-			break;
-	}
-	AST_RWLIST_UNLOCK(&ast_event_pubs[type]);
-
-	if (pub) /* All parameters were matched */
-		return AST_EVENT_PUB_EXISTS;
-
-	AST_RWLIST_RDLOCK(&ast_event_pubs[AST_EVENT_ALL]);
-	if (!AST_RWLIST_EMPTY(&ast_event_pubs[AST_EVENT_ALL]))
-		res = AST_EVENT_PUB_EXISTS;
-	AST_RWLIST_UNLOCK(&ast_event_pubs[AST_EVENT_ALL]);
-
-	return res;
-}
-
 static void ast_event_ie_val_destroy(struct ast_event_ie_val *ie_val)
 {
 	if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR)
 		free((void *) ie_val->payload.str);
 
 	free(ie_val);
-}
-
-static void ast_event_pub_destroy(struct ast_event_pub *pub)
-{
-	struct ast_event_ie_val *ie_val;
-
-	while ((ie_val = AST_LIST_REMOVE_HEAD(&pub->ie_vals, entry)))
-		ast_event_ie_val_destroy(ie_val);
-
-	free(pub);
-}
-
-void ast_event_unreg_publisher(struct ast_event_pub *pub)
-{
-	AST_RWLIST_WRLOCK(&ast_event_pubs[pub->type]);
-	AST_RWLIST_REMOVE(&ast_event_pubs[pub->type], pub, entry);
-	AST_RWLIST_UNLOCK(&ast_event_pubs[pub->type]);
-
-	ast_event_pub_destroy(pub);
-}
-
-struct ast_event_pub *ast_event_reg_publisher(enum ast_event_type type, ...)
-{
-	struct ast_event_pub *pub;
-	va_list ap;
-	enum ast_event_ie_type ie_type;
-
-	if (type >= AST_EVENT_TOTAL) {
-		ast_log(LOG_ERROR, "%u is an invalid type!\n", type);
-		return NULL;
-	}
-
-	if (!(pub = ast_calloc(1, sizeof(*pub))))
-		return NULL;
-
-	pub->type = type;
-
-	va_start(ap, type);
-	for (ie_type = va_arg(ap, enum ast_event_type);
-		ie_type != AST_EVENT_IE_END;
-		ie_type = va_arg(ap, enum ast_event_type))
-	{
-		struct ast_event_ie_val *ie_val;
-		if (!(ie_val = ast_calloc(1, sizeof(*ie_val))))
-			continue;
-		ie_val->ie_type = ie_type;
-		ie_val->ie_pltype = va_arg(ap, enum ast_event_ie_pltype);
-		if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_UINT)
-			ie_val->payload.uint = va_arg(ap, uint32_t);
-		else if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_STR) {
-			if (!(ie_val->payload.str = ast_strdup(va_arg(ap, const char *)))) {
-				free(ie_val);
-				continue;
-			}
-		}
-		AST_LIST_INSERT_TAIL(&pub->ie_vals, ie_val, entry);
-	}
-	va_end(ap);
-
-	AST_RWLIST_WRLOCK(&ast_event_pubs[type]);
-	AST_LIST_INSERT_TAIL(&ast_event_pubs[type], pub, entry);
-	AST_RWLIST_UNLOCK(&ast_event_pubs[type]);
-
-	return pub;
 }
 
 enum ast_event_subscriber_res ast_event_check_subscriber(enum ast_event_type type, ...)



More information about the asterisk-commits mailing list