[asterisk-commits] russell: branch group/newcdr r202147 - in /team/group/newcdr: include/asteris...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jun 20 10:07:08 CDT 2009


Author: russell
Date: Sat Jun 20 10:07:05 2009
New Revision: 202147

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=202147
Log:
Use existing ast_event API for finding subscribers instead of adding a new one

Modified:
    team/group/newcdr/include/asterisk/event.h
    team/group/newcdr/include/asterisk/event_defs.h
    team/group/newcdr/main/cel.c
    team/group/newcdr/main/event.c

Modified: team/group/newcdr/include/asterisk/event.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/event.h?view=diff&rev=202147&r1=202146&r2=202147
==============================================================================
--- team/group/newcdr/include/asterisk/event.h (original)
+++ team/group/newcdr/include/asterisk/event.h Sat Jun 20 10:07:05 2009
@@ -242,28 +242,13 @@
 struct ast_event_sub *ast_event_unsubscribe(struct ast_event_sub *event_sub);
 
 /*!
- * \brief Traverse subscribers
- *
- * \param et -- the event type.
- * \param curr -- the current subscriber in the list; NULL means to return the first.
- * 
- * \return a ptr to the next subscriber
- */
-
-struct ast_event_sub *ast_event_next_subscriber(enum ast_event_type et, struct ast_event_sub *curr);
-
-/*!
- * \brief Get the subscriber description
- *
- * \param curr -- the subscriber who's description is sought.
- * 
- * \return a string
- */
-
-char *ast_event_subscriber_get_description(struct ast_event_sub *curr);
-
-void ast_event_lock_subscribers(enum ast_event_type et);
-void ast_event_unlock_subscribers(enum ast_event_type et);
+ * \brief Get description for a subscription
+ *
+ * \param sub subscription
+ *
+ * \return string description of the subscription
+ */
+const char *ast_event_subscriber_get_description(struct ast_event_sub *sub);
 
 /*!
  * \brief Check if subscribers exist

Modified: team/group/newcdr/include/asterisk/event_defs.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/include/asterisk/event_defs.h?view=diff&rev=202147&r1=202146&r2=202147
==============================================================================
--- team/group/newcdr/include/asterisk/event_defs.h (original)
+++ team/group/newcdr/include/asterisk/event_defs.h Sat Jun 20 10:07:05 2009
@@ -247,13 +247,19 @@
 	 * Payload type: STR
 	 */
 	AST_EVENT_IE_CEL_EXTRA = 0x1f,
-	 /*!
-	  * \brief Entity ID
-	  * Used by All events
-	  * Payload type: RAW
-	  * This IE indicates which server the event originated from
-	  */
-	 AST_EVENT_IE_EID      = 0x20,
+	/*!
+	 * \brief Description
+	 * Used by: AST_EVENT_SUB, AST_EVENT_UNSUB
+	 * Payload type: STR
+	 */
+	AST_EVENT_IE_DESCRIPTION = 0x20,
+	/*!
+	 * \brief Entity ID
+	 * Used by All events
+	 * Payload type: RAW
+	 * This IE indicates which server the event originated from
+	 */
+	AST_EVENT_IE_EID      = 0x21,
 };
 
 #define AST_EVENT_IE_MAX AST_EVENT_IE_EID

Modified: team/group/newcdr/main/cel.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/cel.c?view=diff&rev=202147&r1=202146&r2=202147
==============================================================================
--- team/group/newcdr/main/cel.c (original)
+++ team/group/newcdr/main/cel.c Sat Jun 20 10:07:05 2009
@@ -116,10 +116,18 @@
 	return 0;
 }
 
+static void print_cel_sub(const struct ast_event *event, void *data)
+{
+	struct ast_cli_args *a = data;
+
+	ast_cli(a->fd, "CEL Event Subscriber: %s\n",
+			ast_event_get_ie_str(event, AST_EVENT_IE_DESCRIPTION));
+}
+
 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;
+	struct ast_event_sub *sub;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -136,7 +144,7 @@
 		return CLI_SHOWUSAGE;
 	}
 
-	ast_cli(a->fd, "CEL logging: %s\n", cel_enabled ? "enabled" : "disabled");
+	ast_cli(a->fd, "CEL Logging: %s\n", cel_enabled ? "Enabled" : "Disabled");
 
 	if (!cel_enabled) {
 		return CLI_SUCCESS;
@@ -157,11 +165,13 @@
 
 	ao2_callback(appset, OBJ_NODATA, print_app, a);
 
-	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 (!(sub = ast_event_subscribe_new(AST_EVENT_SUB, print_cel_sub, a))) {
+		return CLI_FAILURE;
+	}
+	ast_event_sub_append_ie_uint(sub, AST_EVENT_IE_EVENTTYPE, AST_EVENT_CEL);
+	ast_event_report_subs(sub);
+	ast_event_sub_destroy(sub);
+	sub = NULL;
 
 	return CLI_SUCCESS;
 }

Modified: team/group/newcdr/main/event.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/newcdr/main/event.c?view=diff&rev=202147&r1=202146&r2=202147
==============================================================================
--- team/group/newcdr/main/event.c (original)
+++ team/group/newcdr/main/event.c Sat Jun 20 10:07:05 2009
@@ -559,8 +559,9 @@
 	struct ast_event *event;
 
 	event = ast_event_new(AST_EVENT_SUB,
-		AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
-		AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
+		AST_EVENT_IE_UNIQUEID,    AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
+		AST_EVENT_IE_EVENTTYPE,   AST_EVENT_IE_PLTYPE_UINT, sub->type,
+		AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description,
 		AST_EVENT_IE_END);
 
 	if (!event)
@@ -869,32 +870,10 @@
 	ast_free(sub);
 }
 
-struct ast_event_sub *ast_event_next_subscriber(enum ast_event_type et, struct ast_event_sub *curr)
-{
-	if (curr)
-		return AST_RWLIST_NEXT(curr, entry);
-	else
-		return AST_RWLIST_FIRST(&ast_event_subs[et]);
-}
-
-char *ast_event_subscriber_get_description(struct ast_event_sub *curr)
-{
-	if (curr)
-		return curr->description;
-	return 0;
-}
-
-void ast_event_lock_subscribers(enum ast_event_type et)
-{
-	AST_RWLIST_RDLOCK(&ast_event_subs[et]);
-
-}
-
-void ast_event_unlock_subscribers(enum ast_event_type et)
-{
-	AST_RWLIST_UNLOCK(&ast_event_subs[et]);
-}
-
+const char *ast_event_subscriber_get_description(struct ast_event_sub *sub)
+{
+	return sub ? sub->description : NULL;
+}
 
 struct ast_event_sub *ast_event_unsubscribe(struct ast_event_sub *sub)
 {
@@ -909,8 +888,9 @@
 		AST_EVENT_IE_END) != AST_EVENT_SUB_NONE) {
 
 		event = ast_event_new(AST_EVENT_UNSUB,
-			AST_EVENT_IE_UNIQUEID,  AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
-			AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, sub->type,
+			AST_EVENT_IE_UNIQUEID,    AST_EVENT_IE_PLTYPE_UINT, sub->uniqueid,
+			AST_EVENT_IE_EVENTTYPE,   AST_EVENT_IE_PLTYPE_UINT, sub->type,
+			AST_EVENT_IE_DESCRIPTION, AST_EVENT_IE_PLTYPE_STR, sub->description,
 			AST_EVENT_IE_END);
 
 		if (event) {




More information about the asterisk-commits mailing list