[asterisk-commits] russell: branch russell/ais r78244 - in /team/russell/ais: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 6 16:10:38 CDT 2007


Author: russell
Date: Mon Aug  6 16:10:37 2007
New Revision: 78244

URL: http://svn.digium.com/view/asterisk?view=rev&rev=78244
Log:
Add the code that will take events generated inside of Asterisk
and send them out into the cluster

Modified:
    team/russell/ais/include/asterisk/event.h
    team/russell/ais/main/event.c
    team/russell/ais/res/res_ais.c

Modified: team/russell/ais/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/russell/ais/include/asterisk/event.h?view=diff&rev=78244&r1=78243&r2=78244
==============================================================================
--- team/russell/ais/include/asterisk/event.h (original)
+++ team/russell/ais/include/asterisk/event.h Mon Aug  6 16:10:37 2007
@@ -413,4 +413,13 @@
  */
 enum ast_event_type ast_event_get_type(const struct ast_event *event);
 
+/*!
+ * \brief Get the size of an event
+ *
+ * \param event the event to get the size of
+ *
+ * \return the number of bytes contained in the event
+ */
+size_t ast_event_get_size(const struct ast_event *event);
+
 #endif /* AST_EVENT_H */

Modified: team/russell/ais/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/main/event.c?view=diff&rev=78244&r1=78243&r2=78244
==============================================================================
--- team/russell/ais/main/event.c (original)
+++ team/russell/ais/main/event.c Mon Aug  6 16:10:37 2007
@@ -106,6 +106,15 @@
  * 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];
 
+size_t ast_event_get_size(const struct ast_event *event)
+{
+	size_t res;
+
+	res = event->event_len;
+
+	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)

Modified: team/russell/ais/res/res_ais.c
URL: http://svn.digium.com/view/asterisk/team/russell/ais/res/res_ais.c?view=diff&rev=78244&r1=78243&r2=78244
==============================================================================
--- team/russell/ais/res/res_ais.c (original)
+++ team/russell/ais/res/res_ais.c Mon Aug  6 16:10:37 2007
@@ -186,9 +186,79 @@
 
 }
 
+static const char *type_to_filter_str(enum ast_event_type type)
+{
+	const char *filter_str = NULL;
+	int i;
+
+	for (i = 0; i < ARRAY_LEN(supported_event_types); i++) {
+		if (supported_event_types[i].type == type) {
+			filter_str = supported_event_types[i].str;
+			break;
+		}
+	}
+
+	return filter_str;
+}
+
 static void ast_event_cb(const struct ast_event *ast_event, void *data)
 {
-
+	SaEvtEventHandleT event_handle;
+	SaAisErrorT res;
+	struct event_channel *event_channel = data;
+	SaClmClusterNodeT local_node;
+	SaEvtEventPatternArrayT pattern_array;
+	SaEvtEventPatternT pattern;
+	SaSizeT len;
+	const char *filter_str;
+	SaEvtEventIdT event_id;
+
+	res = saEvtEventAllocate(event_channel->handle, &event_handle);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error allocating event: %s\n", ais_err2str(res));
+		return;
+	}
+	
+	res = saClmClusterNodeGet(clm_handle, SA_CLM_LOCAL_NODE_ID, 
+		SA_TIME_ONE_SECOND, &local_node);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error getting local node name: %s\n", ais_err2str(res));
+		goto return_event_free;
+	}
+
+	filter_str = type_to_filter_str(ast_event_get_type(ast_event));
+	len = strlen(filter_str) + 1;
+	pattern.pattern = (SaUint8T *) filter_str;
+	pattern.patternSize = len;
+	pattern.allocatedSize = len;
+
+	pattern_array.allocatedNumber = 1;
+	pattern_array.patternsNumber = 1;
+	pattern_array.patterns = &pattern;
+
+	/*! 
+	 * /todo Make retention time configurable 
+	 * /todo Make event priorities configurable
+	 */
+	res = saEvtEventAttributesSet(event_handle, &pattern_array,
+		SA_EVT_LOWEST_PRIORITY, SA_TIME_ONE_MINUTE, &local_node.nodeName);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error setting event attributes: %s\n", ais_err2str(res));
+		goto return_event_free;
+	}
+
+	res = saEvtEventPublish(event_handle, 
+		ast_event, ast_event_get_size(ast_event), &event_id);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error publishing event: %s\n", ais_err2str(res));
+		goto return_event_free;
+	}
+
+return_event_free:
+	res = saEvtEventFree(event_handle);
+	if (res != SA_AIS_OK) {
+		ast_log(LOG_ERROR, "Error freeing allocated event: %s\n", ais_err2str(res));
+	}
 }
 
 static void *dispatch_thread(void *data)
@@ -317,14 +387,10 @@
 	SaEvtEventFilterArrayT filter_array;
 	SaEvtEventFilterT filter;
 	const char *filter_str = NULL;
-	int i;
 	SaSizeT len;
 
 	/* We know it's going to be valid.  It was checked earlier. */
-	for (i = 0; i < ARRAY_LEN(supported_event_types); i++) {
-		if (supported_event_types[i].type == subscribe_event->type)
-			filter_str = supported_event_types[i].str;
-	}
+	filter_str = type_to_filter_str(subscribe_event->type);
 
 	filter.filterType = SA_EVT_EXACT_FILTER;
 	len = strlen(filter_str) + 1;




More information about the asterisk-commits mailing list